/**
 * Sheep Farm Tracker - Stylesheet
 * Mobile-first design, CSS custom properties, PWA-optimized.
 * Base breakpoint: 320-480px. Desktop: centered max-width 480px.
 */

/* === Cairo Font === */
@font-face {
  font-family: 'Cairo';
  src: url('/static/fonts/Cairo-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Cairo';
  src: url('/static/fonts/Cairo-Medium.ttf') format('truetype');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Cairo';
  src: url('/static/fonts/Cairo-SemiBold.ttf') format('truetype');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Cairo';
  src: url('/static/fonts/Cairo-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* === CSS Variables & Reset === */
:root {
  --color-primary: #2d6a4f;
  --color-primary-dark: #1b4332;
  --color-primary-light: #95d5b2;
  --color-secondary: #e9c46a;
  --color-danger: #e63946;
  --color-warning: #f4a261;
  --color-info: #457b9d;
  --color-bg: #f8f9fa;
  --color-card: #ffffff;
  --color-surface: #f1f3f4;
  --color-text: #212529;
  --color-text-secondary: #495057;
  --color-text-muted: #6c757d;
  --color-border: #dee2e6;
  --sidebar-bg: #2c3e50;
  --sidebar-text: rgba(255,255,255,0.8);
  --sidebar-text-hover: #fff;
  --sidebar-heading: #fff;
  --sidebar-muted: rgba(255,255,255,0.45);
  --sidebar-border: rgba(255,255,255,0.08);
  --sidebar-hover: rgba(255,255,255,0.06);
  --sidebar-active-bg: rgba(255,255,255,0.1);
  --sidebar-active-text: #fff;
  --sidebar-logo-bg: #fff;
  --font-main: 'Cairo', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
  --nav-height: 64px;
  --header-height: 52px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; font-family: var(--font-main); color: var(--color-text); background: var(--color-bg); overscroll-behavior-y: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; -webkit-appearance: none; }
input, select, textarea { font-family: inherit; font-size: 16px; }
a { color: var(--color-primary); text-decoration: none; }

/* === App Layout === */
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
#app-header {
  height: var(--header-height);
  min-height: var(--header-height);
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 8px;
  flex-shrink: 0;
  z-index: 100;
}
#app-header.hidden { display: none; }
#header-back { color: #fff; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: 50%; }
#header-back.hidden { display: none; }
#header-back:active { background: rgba(255,255,255,0.15); }
#header-title { font-size: 17px; font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#header-actions { display: flex; gap: 4px; align-items: center; }
#header-notify, #header-user, #header-theme {
  color: #fff;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
}
#header-notify.hidden, #header-user.hidden, #header-theme.hidden { display: none; }
#header-notify:active, #header-user:active, #header-theme:active { background: rgba(255,255,255,0.15); }
#header-user {
  background: rgba(255,255,255,0.15);
  border: 2px solid rgba(255,255,255,0.3);
}

#app-main { flex: 1; overflow-y: auto; overflow-x: hidden; background: var(--color-bg); }
#app-main.has-bottom-nav { padding-bottom: calc(var(--nav-height) + 8px); }

/* === Pull-to-Refresh === */
.ptr-indicator {
  position: fixed;
  top: -60px;
  left: 0;
  right: 0;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: 13px;
  gap: 8px;
  z-index: 110;
  pointer-events: none;
  transition: top 0.3s ease;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

/* Dark mode support for PTR indicator */
@media (prefers-color-scheme: dark) {
  .ptr-indicator {
    background: rgba(36, 36, 36, 0.92);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  }
}

[data-theme="dark"] .ptr-indicator {
  background: rgba(36, 36, 36, 0.92);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
#ptr-wrapper {
  position: relative;
}
.ptr-indicator.ptr-refreshing .ptr-spinner {
  animation: ptr-spin 0.6s linear infinite;
}
.ptr-indicator .ptr-spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: ptr-spin 0.8s linear infinite;
}
@keyframes ptr-spin {
  to { transform: rotate(360deg); }
}

/* === Bottom Navigation === */
#bottom-nav {
  height: var(--nav-height);
  min-height: var(--nav-height);
  background: var(--color-card);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: flex-start;
  justify-content: space-around;
  padding-top: 6px;
  flex-shrink: 0;
  z-index: 100;
}
#bottom-nav.hidden { display: none; }
.nav-item { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--color-text-muted); font-size: 11px; min-width: 56px; padding: 2px 0; transition: color 0.2s; }
.nav-item svg { stroke-width: 1.8; }
.nav-item.active { color: var(--color-primary); }
.nav-item.nav-center { position: relative; margin-top: -20px; }
.nav-center-btn {
  width: 52px; height: 52px; border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-lg);
}

/* === Loading Screen === */
#loading-screen { display: flex; align-items: center; justify-content: center; height: 100%; }
.loading-logo { text-align: center; color: var(--color-text-muted); }
.spinner { width: 48px; height: 48px; border: 3px solid var(--color-border); border-top-color: var(--color-primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* === Utility Classes === */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.p-16 { padding: 16px; }
.p-12 { padding: 12px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mt-8 { margin-top: 8px; }
.text-center { text-align: center; }
.text-muted { color: var(--color-text-muted); }
.text-sm { font-size: 13px; }
.text-lg { font-size: 18px; }
.font-semibold { font-weight: 600; }
.w-full { width: 100%; }

/* === Cards === */
.card {
  background: var(--color-card);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.card-flat {
  background: var(--color-card);
  border-radius: var(--radius-md);
  padding: 16px;
  border: 1px solid var(--color-border);
  margin-bottom: 12px;
}

/* === Stat Cards === */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stat-card {
  background: var(--color-card); border-radius: var(--radius-md); padding: 14px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px;
}
.stat-card .stat-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; }
.stat-card .stat-value { font-size: 22px; font-weight: 700; color: var(--color-text); }
.stat-card .stat-label { font-size: 12px; color: var(--color-text-muted); }

/* === Stat Cards V2 (New Design) === */
.stats-grid-v2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; padding: 0 16px; }
.stat-card-v2 {
  background: var(--color-card);
  border-radius: 16px;
  padding: 16px 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
  border: 1.5px solid transparent;
  transition: transform 0.15s ease;
}
.stat-card-v2:active { transform: scale(0.98); }
.stat-card-v2 .stat-icon-v2 {
  font-size: 28px;
  line-height: 1;
  margin-bottom: 2px;
}
.stat-card-v2 .stat-icon-v2 svg {
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.15));
}
.stat-card-v2 .stat-value-v2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.2;
}
.stat-card-v2 .stat-label-v2 {
  font-size: 12px;
  color: var(--color-text-muted);
  font-weight: 500;
}
/* Colored borders like reference images */
.stat-card-v2.border-green { border-color: #2d6a4f; }
.stat-card-v2.border-orange { border-color: #f4a261; }
.stat-card-v2.border-blue { border-color: #457b9d; }
.stat-card-v2.border-red { border-color: #e63946; }
.stat-card-v2.border-purple { border-color: #9b59b6; }
.stat-card-v2.border-yellow { border-color: #e9c46a; }
.stat-card-v2.border-teal { border-color: #2a9d8f; }
.stat-card-v2.border-gray { border-color: #adb5bd; }
.stat-card-v2.border-cyan { border-color: #06b6d4; }

/* === Layout helpers used by screen files === */
.screen-header {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  flex-wrap: wrap;
  align-items: center;
}
.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

/* === Buttons === */
/* Standalone variants used without .btn base in many screen files */
.btn-primary, .btn-danger, .btn-warning {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 20px; border-radius: var(--radius-sm); font-size: 15px; font-weight: 500;
  min-height: 44px; transition: all 0.2s;
  border: none; font-family: inherit; cursor: pointer;
}
.btn-small {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
  min-height: 36px; transition: all 0.2s; width: auto;
  border: none; font-family: inherit; cursor: pointer;
  background: var(--color-surface); color: var(--color-text-secondary);
}
.btn-small:active { transform: scale(0.98); opacity: 0.9; }
.btn-small.btn-primary { background: var(--color-primary); color: #fff; }
.btn-small.btn-danger { background: var(--color-danger); color: #fff; }
.btn-small.btn-warning { background: var(--color-warning); color: #fff; }
.btn-small.btn-outline { background: transparent; color: var(--color-primary); border: 1.5px solid var(--color-primary); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 20px; border-radius: var(--radius-sm); font-size: 15px; font-weight: 500;
  min-height: 44px; transition: all 0.2s; width: 100%;
}
.btn:active { transform: scale(0.98); opacity: 0.9; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-warning { background: var(--color-warning); color: #fff; }
.btn-outline { background: transparent; color: var(--color-primary); border: 1.5px solid var(--color-primary); }
.btn-ghost { background: transparent; color: var(--color-text-secondary); }
.btn-sm { padding: 8px 14px; font-size: 13px; min-height: 36px; width: auto; }

/* === Forms === */
.form-card { padding: 16px; }
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 14px; font-weight: 500; color: var(--color-text-secondary); margin-bottom: 6px; }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm); background: var(--color-card); color: var(--color-text);
  outline: none; transition: border-color 0.2s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--color-primary); }
/* Always show number input spinners on mobile */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  opacity: 1;
  display: inline-block;
}

/* === Stepper Input (Pregnancy form) === */
.stepper-input {
  display: flex;
  align-items: stretch;
  gap: 0;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.stepper-input .stepper-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-height: 44px;
  font-size: 20px;
  font-weight: 600;
  background: var(--color-surface);
  color: var(--color-text);
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.stepper-input .stepper-btn:active { background: var(--color-border); }
.stepper-input .stepper-field {
  flex: 1;
  text-align: center;
  border: none;
  border-radius: 0;
  min-height: 44px;
  padding: 0 4px;
  -moz-appearance: textfield;
}
.stepper-input .stepper-field::-webkit-inner-spin-button,
.stepper-input .stepper-field::-webkit-outer-spin-button {
  display: none;
  -webkit-appearance: none;
  margin: 0;
}

.form-textarea { min-height: 80px; resize: vertical; }
.form-hint { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; }
.form-error { font-size: 12px; color: var(--color-danger); margin-top: 4px; }

.radio-group { display: flex; gap: 12px; }
.radio-option {
  flex: 1; padding: 12px; border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm); text-align: center; cursor: pointer;
  transition: all 0.2s; font-size: 14px;
}
.radio-option.selected { border-color: var(--color-primary); background: rgba(45,106,79,0.08); color: var(--color-primary); font-weight: 500; }

/* === Badges === */
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 500; }
.badge-success { background: #d4edda; color: #155724; }
.badge-warning { background: #fff3cd; color: #856404; }
.badge-danger { background: #f8d7da; color: #721c24; }
.badge-info { background: #cce5ff; color: #004085; }
.badge-muted { background: var(--color-surface); color: var(--color-text-muted); }
.badge-young { background: #fff3cd; color: #856404; }

/* === Sheep Cards === */
.sheep-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--color-card); border-radius: var(--radius-md);
  padding: 12px 14px; box-shadow: var(--shadow); margin-bottom: 10px;
}
.sheep-photo {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--color-surface); object-fit: cover; flex-shrink: 0;
}
.sheep-photo-placeholder {
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary-light), var(--color-primary));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 600; flex-shrink: 0;
}
.sheep-photo-lg {
  width: 100px; height: 100px; border-radius: 50%;
  background: var(--color-surface); object-fit: cover;
}
.sheep-info { flex: 1; min-width: 0; }
.sheep-name { font-size: 15px; font-weight: 600; color: var(--color-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheep-meta {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-top: 2px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0;
}
.meta-badges {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.meta-sep {
  display: inline-flex;
  align-items: center;
  margin: 0 4px;
}
.meta-sep::before {
  content: '·';
  color: var(--color-text-muted);
}
html[dir="rtl"] .sheep-meta {
  flex-direction: row-reverse;
}
html[dir="rtl"] .meta-badges {
  flex-direction: row-reverse;
}

/* === Search & Filters === */
.search-bar {
  position: sticky; top: 0; z-index: 10;
  background: var(--color-bg); padding: 10px 16px;
  border-bottom: 1px solid var(--color-border);
}
.search-input {
  width: 100%; padding: 10px 14px 10px 38px;
  border: 1.5px solid var(--color-border); border-radius: var(--radius-sm);
  background: var(--color-card); font-size: 15px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%236c757d' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 12px center;
}
.filter-chips { display: flex; gap: 8px; padding: 8px 16px; overflow-x: auto; scrollbar-width: none; flex-wrap: wrap; }
.filter-chips::-webkit-scrollbar { display: none; }
.chip {
  padding: 6px 14px; border-radius: 20px; font-size: 13px;
  border: 1px solid var(--color-border); background: var(--color-card);
  color: var(--color-text-secondary); white-space: nowrap; transition: all 0.2s;
  flex-shrink: 0;
}
.chip.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.dash-preg-chip.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* === Bulk Edit Bar === */
.bulk-bar {
  position: fixed;
  bottom: var(--nav-height);
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid var(--color-border);
  padding: 12px 16px;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  align-items: center;
  z-index: 110;
}
html[dir="rtl"] .bulk-bar {
  direction: rtl;
}
@media (min-width: 1024px) {
  .bulk-bar {
    bottom: 0;
  }
}

/* === FAB === */
.fab {
  position: fixed; bottom: calc(var(--nav-height) + 16px); right: 16px;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--color-primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-lg); z-index: 90;
}
.fab:active { transform: scale(0.95); }

/* === Expenses totals bar (fixed above bottom nav) === */
#exp-totals-bar {
  padding: 10px 80px 10px 16px;
}
html[dir="rtl"] #exp-totals-bar {
  padding: 10px 16px 10px 80px;
}

/* === Tabs === */
.tabs { 
  display: flex; 
  gap: 0; 
  border-bottom: 1px solid var(--color-border); 
  background: var(--color-card); 
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tab-btn { 
  flex: 0 0 auto;
  padding: 10px 10px; 
  font-size: 12px; 
  color: var(--color-text-muted); 
  border-bottom: 2px solid transparent; 
  transition: all 0.2s; 
  white-space: nowrap;
  min-width: 0;
}
.tab-btn.active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 600; }
.tab-content { display: none; padding: 16px; }
.tab-content.active { display: block; }

/* === Lists === */
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; background: var(--color-card);
  border-bottom: 1px solid var(--color-border);
}
.list-item:last-child { border-bottom: none; }
.list-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.list-icon svg {
  transition: transform 0.3s ease;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1));
}
.list-item:hover .list-icon svg {
  transform: scale(1.2) rotate(5deg);
  filter: drop-shadow(0 3px 6px rgba(0,0,0,0.2));
}

/* === Checklist === */
.checklist-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--color-card);
  border-bottom: 1px solid var(--color-border);
}
.checklist-checkbox {
  width: 24px; height: 24px; border: 2px solid var(--color-border);
  border-radius: 6px; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.2s;
}
.checklist-checkbox.checked { background: var(--color-primary); border-color: var(--color-primary); }
.checklist-checkbox.checked::after { content: '✓'; color: #fff; font-size: 14px; font-weight: 600; }

/* Skipped vaccination items */
.skipped-item {
  opacity: 0.75;
  background: var(--color-surface);
}
.skipped-item .sheep-photo {
  filter: grayscale(0.5);
}

/* === Toast === */
#toast-container {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  z-index: 10000; display: flex; flex-direction: column; gap: 8px;
  pointer-events: none; max-width: min(90vw, 480px);
}
.toast {
  padding: 12px 18px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
  color: #fff; box-shadow: var(--shadow-lg); animation: toastIn 0.3s ease;
  width: 100%; display: flex; align-items: center; gap: 12px;
  pointer-events: auto; word-break: break-word; line-height: 1.4;
  box-sizing: border-box;
}
.toast .toast-msg {
  flex: 1; min-width: 0;
}
.toast .toast-action {
  flex-shrink: 0; font-size: 12px; padding: 4px 12px;
  border: 1px solid currentColor; border-radius: 6px;
  background: transparent; color: inherit; cursor: pointer;
  white-space: nowrap; font-weight: 600; transition: background 0.2s;
}
.toast .toast-action:hover {
  background: rgba(255,255,255,0.15);
}
.toast-success { background: var(--color-primary); }
.toast-error { background: var(--color-danger); }
.toast-warning { background: var(--color-warning); }
.toast-info { background: var(--color-info); }
.toast-exit { animation: toastOut 0.3s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-10px); } }

/* === Currency Toggle === */
.currency-toggle { display: flex; gap: 0; border: 1.5px solid var(--color-primary); border-radius: var(--radius-sm); overflow: hidden; }
.currency-toggle button { flex: 1; padding: 8px; font-size: 14px; font-weight: 500; background: transparent; color: var(--color-primary); }
.currency-toggle button.active { background: var(--color-primary); color: #fff; }

/* === Charts (CSS-only) === */
.chart-bar-container { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding: 10px 0; }
.chart-bar-group { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.chart-bar { width: 100%; border-radius: 4px 4px 0 0; min-height: 4px; transition: height 0.3s ease; }
.chart-bar-income { background: var(--color-primary); }
.chart-bar-expense { background: var(--color-danger); }
.chart-label { font-size: 10px; color: var(--color-text-muted); }

.pie-chart { width: 120px; height: 120px; border-radius: 50%; margin: 0 auto; }

/* === Progress Bar === */
.progress-bar { height: 6px; background: var(--color-surface); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--color-primary); border-radius: 3px; transition: width 0.3s ease; }

/* === Empty State === */
.empty-state { text-align: center; padding: 48px 24px; color: var(--color-text-muted); }
.empty-state-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state-icon svg {
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.15));
}
.empty-state-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; color: var(--color-text); }
.empty-state-desc { font-size: 14px; }

/* === Skeleton Loading === */
.skeleton { background: linear-gradient(90deg, var(--color-surface) 25%, #e9ecef 50%, var(--color-surface) 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* === Modal === */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 500; display: flex; align-items: flex-end; justify-content: center; }
.modal-content { background: var(--color-card); border-radius: var(--radius-lg) var(--radius-lg) 0 0; padding: 20px; width: 100%; max-height: 80vh; overflow-y: auto; animation: slideUp 0.3s ease; }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-title { font-size: 18px; font-weight: 600; margin-bottom: 16px; }

/* === Quick Add Menu === */
.quick-add-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px; }
.quick-add-item {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 20px; background: var(--color-card); border-radius: var(--radius-md);
  border: 1px solid var(--color-border); font-size: 14px; font-weight: 500;
}
.quick-add-item:active { background: var(--color-surface); }
.quick-add-item .icon { font-size: 28px; }
.quick-add-item .icon svg {
  transition: transform 0.3s ease, filter 0.3s ease;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.12));
}
.quick-add-item:hover .icon svg {
  transform: scale(1.2) rotate(-8deg);
  filter: drop-shadow(0 5px 10px rgba(0,0,0,0.2));
}

/* === Bottom Sheet Menu (New Design) === */
.bottom-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 600;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
.bottom-sheet-overlay.closing {
  animation: fadeOut 0.2s ease forwards;
}
.bottom-sheet {
  background: var(--color-card);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  animation: slideUpSheet 0.3s ease;
  padding-bottom: 24px;
}
.bottom-sheet-overlay.closing .bottom-sheet {
  animation: slideDownSheet 0.25s ease forwards;
}
.bottom-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 8px;
  position: sticky;
  top: 0;
  background: var(--color-card);
  z-index: 2;
}
.bottom-sheet-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text);
}
.bottom-sheet-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
  color: var(--color-text-secondary);
  font-size: 18px;
  border: none;
  cursor: pointer;
}
.bottom-sheet-close:active { opacity: 0.8; }
.bottom-sheet-section {
  padding: 8px 20px;
}
.bottom-sheet-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--color-text-muted);
  margin-bottom: 6px;
  font-weight: 600;
}
.bottom-sheet-list {
  background: var(--color-card);
  border-radius: 12px;
  border: 1px solid var(--color-border);
  overflow: hidden;
}
.bottom-sheet-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--color-border);
  width: 100%;
  font-size: 15px;
  color: var(--color-text);
  text-align: right;
  cursor: pointer;
  direction: rtl;
}
.bottom-sheet-item:last-child {
  border-bottom: none;
}
.bottom-sheet-item:active {
  background: var(--color-surface);
}
.bottom-sheet-item-icon {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
  width: 28px;
  text-align: center;
}
.bottom-sheet-item-icon svg {
  transition: transform 0.25s ease;
}
.bottom-sheet-item:hover .bottom-sheet-item-icon svg {
  transform: scale(1.25) rotate(-5deg);
}
.bottom-sheet-item-text {
  flex: 1;
  font-weight: 500;
}
.bottom-sheet-item-arrow {
  color: var(--color-text-muted);
  font-size: 14px;
  flex-shrink: 0;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes slideUpSheet { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes slideDownSheet { from { transform: translateY(0); } to { transform: translateY(100%); } }

/* RTL Bottom Sheet */
html[dir="rtl"] .bottom-sheet-item { direction: rtl; text-align: right; }
html[dir="rtl"] .bottom-sheet-item-arrow { transform: scaleX(-1); }
html[dir="rtl"] .bottom-sheet-header {
  flex-direction: row-reverse;
}
html[dir="rtl"] .bottom-sheet-title {
  text-align: right;
}

/* === Profile Card === */
.profile-card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--color-card);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  width: min(320px, 90vw);
  padding: 28px 24px 20px;
  text-align: center;
  z-index: 1001;
  animation: scaleIn 0.25s ease;
}
@keyframes scaleIn {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.profile-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
}
.profile-close:active { background: var(--color-surface); }
.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), #40916c);
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}
.profile-name { font-size: 17px; font-weight: 700; color: var(--color-text); margin-bottom: 4px; }
.profile-email { font-size: 12px; color: var(--color-text-muted); margin-bottom: 8px; word-break: break-all; }
.profile-role {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  background: rgba(45,106,79,0.1);
  color: var(--color-primary);
  padding: 3px 12px;
  border-radius: 12px;
  margin-bottom: 16px;
}
.profile-actions { display: flex; flex-direction: column; gap: 8px; }
.profile-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.profile-btn-outline {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.profile-btn-outline:active { background: var(--color-border); }
.profile-btn-danger {
  background: var(--color-danger);
  color: #fff;
}
.profile-btn-danger:active { background: #c0392b; transform: scale(0.98); }

/* RTL Profile */
html[dir="rtl"] .profile-close { right: auto; left: 10px; }
html[dir="rtl"] .profile-card { direction: rtl; }

/* === Calendar === */
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.calendar-day-header { font-size: 12px; color: var(--color-text-muted); padding: 8px 0; font-weight: 500; }
.calendar-day { padding: 8px 0; border-radius: var(--radius-sm); font-size: 14px; position: relative; }
.calendar-day.has-event::after { content: ''; position: absolute; bottom: 2px; left: 50%; transform: translateX(-50%); width: 4px; height: 4px; background: var(--color-primary); border-radius: 50%; }
.calendar-day.selected { background: var(--color-primary); color: #fff; }
.calendar-day.today { font-weight: 700; color: var(--color-primary); }
.calendar-day.other-month { color: var(--color-border); }

/* === Photo Upload === */
.photo-upload {
  width: 100px; height: 100px; border-radius: 50%;
  border: 2px dashed var(--color-border); margin: 0 auto 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--color-text-muted); font-size: 12px; cursor: pointer;
  background: var(--color-card); overflow: hidden; position: relative;
}
.photo-upload img { width: 100%; height: 100%; object-fit: cover; }
.photo-upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* === Screen: Login === */
.login-screen { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(160deg, var(--color-primary-dark) 0%, var(--color-primary) 100%); }
.login-logo { width: 80px; height: 80px; background: #fff; border-radius: 20px; display: flex; align-items: center; justify-content: center; font-size: 32px; font-weight: 700; color: var(--color-primary); margin-bottom: 20px; box-shadow: var(--shadow-lg); }
.login-title { color: #fff; font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.login-subtitle { color: rgba(255,255,255,0.7); font-size: 14px; margin-bottom: 32px; }
.login-form { width: 100%; max-width: 360px; }
.login-form .form-group { margin-bottom: 16px; }
.login-form .form-input { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.2); color: #fff; }
.login-form .form-input::placeholder { color: rgba(255,255,255,0.5); }
.login-form .btn { margin-top: 8px; background: #fff; color: var(--color-primary); font-weight: 600; }
.login-form .form-label { color: rgba(255,255,255,0.8); }
.login-footer { color: rgba(255,255,255,0.5); font-size: 13px; margin-top: 24px; }
.login-footer a { color: rgba(255,255,255,0.8); text-decoration: underline; }

/* === Screen: More Menu === */
.more-menu { padding: 16px; }
.menu-section { margin-bottom: 20px; }
.menu-section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--color-text-muted); margin-bottom: 8px; padding: 0 4px; }
.menu-list { background: var(--color-card); border-radius: var(--radius-md); overflow: hidden; }
.menu-item { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-bottom: 1px solid var(--color-border); font-size: 15px; color: var(--color-text); }
.menu-item:last-child { border-bottom: none; }
.menu-item:active { background: var(--color-surface); }
.menu-item-icon { width: 36px; height: 36px; border-radius: 10px; background: rgba(45,106,79,0.1); color: var(--color-primary); display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.menu-item-icon svg {
  transition: transform 0.3s ease;
}
.menu-item:hover .menu-item-icon svg {
  transform: scale(1.2) rotate(-8deg);
}
.menu-item-arrow { margin-left: auto; color: var(--color-text-muted); font-size: 18px; display: inline-block; }

/* === Horizontal Scroll === */
.h-scroll { display: flex; gap: 12px; overflow-x: auto; padding: 4px 16px 16px; scrollbar-width: none; }
.h-scroll::-webkit-scrollbar { display: none; }
.h-card { min-width: 180px; background: var(--color-card); border-radius: var(--radius-md); padding: 14px; box-shadow: var(--shadow); flex-shrink: 0; }

.desktop-only { display: none !important; }

/* === Responsive === */
@media (min-width: 769px) {
  body { background: var(--color-bg); }
}

@media (min-width: 1024px) {
  .mobile-only { display: none !important; }
  .desktop-only.sidebar-brand { display: flex !important; }
  .desktop-only.sidebar-section { display: block !important; }
  .nav-item.desktop-only { display: flex !important; }

  #app {
    display: grid;
    grid-template-areas:
      "nav header"
      "nav main";
    grid-template-columns: 260px 1fr;
    grid-template-rows: auto 1fr;
    max-width: none;
    margin: 0;
    border: none;
  }

  #bottom-nav {
    grid-area: nav;
    position: static;
    width: 260px;
    min-width: 260px;
    height: 100%;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    padding: 0;
    gap: 0;
    border-top: none;
    border-right: none;
    background: var(--sidebar-bg, #2c3e50);
    color: var(--sidebar-text, rgba(255,255,255,0.75));
    z-index: 200;
    overflow-y: auto;
    scrollbar-width: thin;
  }
  html[dir="rtl"] #bottom-nav {
    border-left: none;
  }

  .sidebar-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--sidebar-border, rgba(255,255,255,0.08));
    margin-bottom: 8px;
    text-align: center;
  }
  .sidebar-brand img {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    background: var(--sidebar-logo-bg, #fff);
    padding: 3px;
    object-fit: cover;
    margin-bottom: 4px;
  }
  .sidebar-brand span {
    font-size: 15px;
    font-weight: 700;
    color: var(--sidebar-heading, #fff);
    line-height: 1.3;
  }
  .sidebar-brand span:last-child {
    font-size: 12px;
    font-weight: 400;
    color: var(--sidebar-muted, rgba(255,255,255,0.65));
  }

  .sidebar-section {
    padding: 12px 16px 4px;
  }
  .sidebar-section span {
    font-size: 11px;
    font-weight: 600;
    color: var(--sidebar-muted, rgba(255,255,255,0.45));
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  .nav-item {
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    font-size: 14px;
    border-radius: 6px;
    margin: 2px 10px;
    min-width: 0;
    color: var(--sidebar-text, rgba(255,255,255,0.8));
    transition: background 0.15s;
  }
  .nav-item:hover {
    background: var(--sidebar-hover, rgba(255,255,255,0.06));
    color: var(--sidebar-text-hover, #fff);
  }
  .nav-item.active {
    background: var(--sidebar-active-bg, rgba(255,255,255,0.1));
    color: var(--sidebar-active-text, #fff);
    border-right: 3px solid var(--color-primary, #2d6a4f);
  }
  html[dir="rtl"] .nav-item.active {
    border-right: none;
    border-left: 3px solid #2d6a4f;
  }
  .nav-item svg {
    width: 20px;
    height: 20px;
    stroke-width: 2;
    flex-shrink: 0;
  }

  #app-header {
    grid-area: header;
    padding: 0 24px;
    height: 60px;
    min-height: 60px;
    background: #fff;
    color: var(--color-text);
    border-bottom: 1px solid var(--color-border);
  }
  #header-back { color: var(--color-text); }
  #header-title { color: var(--color-text); font-size: 18px; }
  #header-notify, #header-user, #header-theme { color: var(--color-text); }
  #header-user {
    background: var(--color-surface);
    border-color: var(--color-border);
    color: var(--color-primary);
  }

  #app-main {
    grid-area: main;
    padding: 24px;
    overflow-y: auto;
    background: var(--color-bg);
  }
  #app-main.has-bottom-nav {
    padding-bottom: 24px;
  }

  .stats-grid-v2 {
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    padding: 0;
  }
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
  }

  .card, .card-flat {
    padding: 20px;
  }

  .list-item {
    padding: 16px 20px;
  }

  .h-scroll {
    padding: 4px 0 16px;
  }
  .h-card {
    min-width: 220px;
  }

  .quick-add-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .form-card {
    max-width: 800px;
    margin: 0 auto;
  }

  .fab {
    bottom: 24px;
    right: 24px;
  }
  html[dir="rtl"] .fab {
    right: auto;
    left: 24px;
  }

  .modal-overlay {
    align-items: center;
    padding: 24px;
  }
  .modal-content {
    border-radius: var(--radius-lg);
    max-width: 560px;
    animation: scaleIn 0.3s ease;
  }
  .bottom-sheet-overlay {
    align-items: center;
    padding: 24px;
  }
  .bottom-sheet {
    border-radius: var(--radius-lg);
    max-width: 600px;
    max-height: 80vh;
  }
}

/* === Animations === */
.page-enter { animation: fadeSlideUp 0.25s ease; }
@keyframes fadeSlideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* === Dark mode support === */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #121212;
    --color-card: #1e1e1e;
    --color-surface: #2a2a2a;
    --color-text: #e0e0e0;
    --color-text-secondary: #b0b0b0;
    --color-border: #333;
    --sidebar-bg: #1a1a2e;
    --sidebar-text: rgba(255,255,255,0.7);
    --sidebar-text-hover: #fff;
    --sidebar-heading: #e0e0e0;
    --sidebar-muted: rgba(255,255,255,0.4);
    --sidebar-border: rgba(255,255,255,0.06);
    --sidebar-hover: rgba(255,255,255,0.08);
    --sidebar-active-bg: rgba(255,255,255,0.12);
    --sidebar-active-text: #fff;
    --sidebar-logo-bg: rgba(255,255,255,0.1);
  }
  :root:not([data-theme="light"]) .login-form .form-input { background: rgba(255,255,255,0.08); }
}
/* Manual dark mode override (takes precedence over system preference) */
:root[data-theme="dark"] {
  --color-bg: #121212;
  --color-card: #1e1e1e;
  --color-surface: #2a2a2a;
  --color-text: #e0e0e0;
  --color-text-secondary: #b0b0b0;
  --color-border: #333;
  --sidebar-bg: #1a1a2e;
  --sidebar-text: rgba(255,255,255,0.7);
  --sidebar-text-hover: #fff;
  --sidebar-heading: #e0e0e0;
  --sidebar-muted: rgba(255,255,255,0.4);
  --sidebar-border: rgba(255,255,255,0.06);
  --sidebar-hover: rgba(255,255,255,0.08);
  --sidebar-active-bg: rgba(255,255,255,0.12);
  --sidebar-active-text: #fff;
  --sidebar-logo-bg: rgba(255,255,255,0.1);
}
:root[data-theme="dark"] .login-form .form-input { background: rgba(255,255,255,0.08); }

/* === RTL Support === */
html[dir="rtl"] #header-back svg { transform: rotate(180deg); }
html[dir="rtl"] .menu-item-arrow { margin-left: 0; margin-right: auto; transform: scaleX(-1); }
html[dir="rtl"] .sheep-card svg:last-child { transform: scaleX(-1); }
html[dir="rtl"] .search-input { background-position: calc(100% - 12px) center; padding: 10px 38px 10px 14px; }
html[dir="rtl"] .nav-item span { direction: rtl; }
html[dir="rtl"] .login-language { direction: rtl; }
html[dir="rtl"] .currency-toggle { direction: ltr; }
html[dir="rtl"] .form-label { text-align: right; }
html[dir="rtl"] .empty-state { direction: rtl; }
html[dir="rtl"] .quick-add-item { direction: rtl; }
html[dir="rtl"] .card { direction: rtl; }
html[dir="rtl"] .menu-item { direction: rtl; }
html[dir="rtl"] .page-enter { direction: rtl; }
html[dir="rtl"] .toast { direction: rtl; }
html[dir="rtl"] h1, html[dir="rtl"] h2, html[dir="rtl"] h3, html[dir="rtl"] p { text-align: right; }
html[dir="rtl"] .form-input { text-align: right; }
html[dir="rtl"] .form-group { direction: rtl; }
html[dir="rtl"] .btn { direction: rtl; }
html[dir="rtl"] .login-screen { direction: rtl; }
html[dir="rtl"] .login-form { direction: rtl; }
html[dir="rtl"] .more-menu { direction: rtl; }

/* RTL overflow fixes - horizontal scroll containers */
html[dir="rtl"] .filter-chips { direction: rtl; width: 100%; max-width: 100%; }
html[dir="rtl"] .h-scroll { direction: rtl; width: 100%; max-width: 100%; }
html[dir="rtl"] .stats-grid { direction: rtl; }
html[dir="rtl"] .quick-add-grid { direction: rtl; }
html[dir="rtl"] .list-item { direction: rtl; }
html[dir="rtl"] .checklist-item { direction: rtl; }
html[dir="rtl"] .sheep-card { direction: rtl; }
html[dir="rtl"] .tab-btn { direction: rtl; }
html[dir="rtl"] .modal-content { direction: rtl; }
html[dir="rtl"] .chart-label { direction: rtl; }

/* Prevent flex/grid overflow in RTL */
html[dir="rtl"] .stat-card { min-width: 0; }
html[dir="rtl"] .h-card { min-width: 140px; max-width: calc(50vw - 24px); }
html[dir="rtl"] .sheep-info { min-width: 0; }
html[dir="rtl"] .chip { overflow: hidden; text-overflow: ellipsis; }

/* FAB position fix for RTL */
html[dir="rtl"] .fab { right: auto; left: 16px; }

/* Ensure main content doesn't overflow */
html[dir="rtl"] #app-main { overflow-x: hidden; }

/* Scroll padding for RTL horizontal scrolls */
html[dir="rtl"] .filter-chips,
html[dir="rtl"] .h-scroll { padding-right: 16px; padding-left: 16px; }

/* Fix flex rows in RTL to prevent overflow */
html[dir="rtl"] .search-bar > div,
html[dir="rtl"] .card > div { max-width: 100%; }

/* Ensure stat values don't overflow their cards */
html[dir="rtl"] .stat-value { direction: ltr; text-align: right; }

/* === RTL-safe utility classes (replace inline directional styles) === */

/* Card text alignment - flips automatically in RTL */
.card-text { text-align: left; }
html[dir="rtl"] .card-text { text-align: right; }

/* List amount alignment - amounts sit on the outer edge */
.list-amount { text-align: right; }
html[dir="rtl"] .list-amount { text-align: left; }

/* Badge spacing */
.badge-spacer { margin-left: 4px; }
html[dir="rtl"] .badge-spacer { margin-left: 0; margin-right: 4px; }
.badge-spacer-lg { margin-left: 6px; }
html[dir="rtl"] .badge-spacer-lg { margin-left: 0; margin-right: 6px; }

/* Checkbox spacing in vaccination list */
.check-spacer { margin-right: 8px; }
html[dir="rtl"] .check-spacer { margin-right: 0; margin-left: 8px; }

/* Overdue indicator border */
.overdue-border { border-left: 3px solid var(--color-danger); }
html[dir="rtl"] .overdue-border { border-left: none; border-right: 3px solid var(--color-danger); }

/* Population pyramid female side */
.pyramid-female { text-align: right; padding-right: 4px; }
html[dir="rtl"] .pyramid-female { text-align: left; padding-right: 0; padding-left: 4px; }
/* Population pyramid male side */
.pyramid-male { text-align: left; padding-left: 4px; }
html[dir="rtl"] .pyramid-male { text-align: right; padding-left: 0; padding-right: 4px; }

/* --- Additional RTL overflow hardening --- */

/* Ensure body/html don't cause horizontal overflow in RTL */
html[dir="rtl"] body { overflow-x: hidden; }
html[dir="rtl"] #app { overflow-x: hidden; }

/* Quick add grid should never exceed viewport */
html[dir="rtl"] .quick-add-grid {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* Horizontal scroll containers - constrain contents */
html[dir="rtl"] .h-scroll > * {
  max-width: calc(100vw - 32px);
}

/* Card children shouldn't overflow */
html[dir="rtl"] .card,
html[dir="rtl"] .card-flat {
  max-width: 100%;
  box-sizing: border-box;
  word-wrap: break-word;
}

/* Stat grid cells shouldn't overflow */
html[dir="rtl"] .stats-grid > * {
  min-width: 0;
  max-width: 100%;
}

/* Ensure all text containers wrap properly in RTL */
html[dir="rtl"] .sheep-name,
html[dir="rtl"] .sheep-meta,
html[dir="rtl"] .stat-label,
html[dir="rtl"] .menu-item,
html[dir="rtl"] .list-item,
html[dir="rtl"] .checklist-item {
  word-wrap: break-word;
  overflow-wrap: break-word;
}


/* Ensure form inputs don't overflow */
html[dir="rtl"] .form-input,
html[dir="rtl"] .form-select,
html[dir="rtl"] .form-textarea {
  max-width: 100%;
  box-sizing: border-box;
}

/* === Breeding Screen === */
.breeding-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--color-border); background: var(--color-card); margin-top: 8px; }
.breeding-tab { flex: 1; padding: 12px; font-size: 14px; color: var(--color-text-muted); border-bottom: 2px solid transparent; transition: all 0.2s; background: none; }
.breeding-tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 600; }
.tab-content { display: none; padding: 12px; }
.tab-content.active { display: block; }
.breeding-list, .eligible-females-list { display: flex; flex-direction: column; gap: 10px; }

/* === Accordion List (Breeding Seasons) === */
.accordion-list { display: flex; flex-direction: column; gap: 8px; }
.accordion-item {
  background: var(--color-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow 0.2s;
}
.accordion-item.open { box-shadow: var(--shadow-lg, 0 4px 12px rgba(0,0,0,0.12)); }
.accordion-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.accordion-header:active { opacity: 0.85; }
.accordion-title {
  flex: 1;
  font-weight: 600;
  font-size: 15px;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.accordion-meta {
  font-size: 13px;
  color: var(--color-text-muted);
  white-space: nowrap;
}
.accordion-chevron {
  color: var(--color-text-muted);
  transition: transform 0.25s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.accordion-item.open .accordion-chevron { transform: rotate(180deg); }
.accordion-body {
  display: none;
  padding: 0 16px 14px;
  animation: accordionFadeIn 0.2s ease;
}
.accordion-item.open .accordion-body { display: block; }
.accordion-info { margin-bottom: 10px; }
.info-row {
  display: flex;
  gap: 6px;
  padding: 4px 0;
  font-size: 14px;
}
.info-label { color: var(--color-text-muted); font-weight: 500; }
.info-value { color: var(--color-text); }
@keyframes accordionFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Sub-cards inside accordion (mating records) */
.sub-cards { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.sub-card {
  background: var(--color-surface, #f8fafc);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.sub-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 14px;
  color: var(--color-text);
  margin-bottom: 4px;
}
.sub-card-body {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-bottom: 8px;
  line-height: 1.5;
}
.sub-card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.empty-state-small {
  text-align: center;
  font-size: 13px;
  color: var(--color-text-muted);
  padding: 10px;
  background: var(--color-surface, #f8fafc);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--color-border);
}

.card-ewe .card-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 6px; }
.ewe-number { font-weight: 600; color: var(--color-text); }
.ewe-badges { display: flex; gap: 4px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 500; }
.badge-pregnant { background: #fde2e2; color: #9b1c1c; }
.badge-breeding { background: #d1fae5; color: #065f46; }

/* Prevent calendar overflow */
html[dir="rtl"] .calendar-grid {
  width: 100%;
  max-width: 100%;
}

/* Ensure chart containers don't overflow */
html[dir="rtl"] .chart-bar-container,
html[dir="rtl"] .pie-chart {
  max-width: 100%;
}

/* Tab buttons shouldn't overflow */
html[dir="rtl"] .tabs {
  width: 100%;
  max-width: 100%;
}
html[dir="rtl"] .tab-btn {
  min-width: 0;
}

/* === Sheep Select Screen (Mating) === */
.sheep-select-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 16px 16px;
}
.sheep-select-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--color-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  border: 2px solid transparent;
  transition: all 0.2s;
  cursor: pointer;
}
.sheep-select-item.selected {
  border-color: var(--color-primary);
  background: rgba(45,106,79,0.05);
}
.sheep-select-item:active {
  transform: scale(0.99);
}
.sheep-select-item.disabled {
  cursor: not-allowed;
  background: var(--color-surface-alt);
  border-color: transparent;
}
.sheep-select-item.disabled .sheep-select-name {
  color: var(--color-text-muted);
}
.sheep-select-check {
  flex-shrink: 0;
}
.sheep-select-check input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--color-primary);
  cursor: pointer;
}
.sheep-select-info {
  flex: 1;
  min-width: 0;
}
.sheep-select-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sheep-select-meta {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-top: 2px;
}
.sheep-select-badges {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  flex-wrap: wrap;
}
.females-summary-box {
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.6;
  max-height: 120px;
  overflow-y: auto;
  border: 1px solid var(--color-border);
}
html[dir="rtl"] .sheep-select-item {
  direction: rtl;
}
html[dir="rtl"] .sheep-select-name {
  text-align: right;
}

/* ============================================= */
/* === ICON COLORS & STATIC EFFECTS ONLY === */
/* ============================================= */

/* Dashboard stat icons - static colored shadow only */
.stat-card-v2 .stat-icon-v2 svg {
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.15));
}

/* Empty state icon - static colored shadow */
.empty-state-icon svg {
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.15));
}

/* Nav item icons - static shadow when active */
.nav-item.active svg {
  filter: drop-shadow(0 2px 4px rgba(45,106,79,0.3));
}

/* Quick action cards shadow */
.quick-add-item .icon svg {
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.12));
}

/* List item icons shadow */
.list-icon svg {
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1));
}

/* Menu item icons */
.menu-item-icon svg {
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1));
}

/* Bottom sheet item icons */
.bottom-sheet-item-icon svg {
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1));
}

/* === Pagination Controls === */
.pagination-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  gap: 12px;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  margin: 16px 0;
  flex-wrap: wrap;
}
.pagination-controls .btn {
  width: auto !important;
  min-width: 60px;
  flex: 0 1 auto;
  padding: 6px 12px;
  font-size: 13px;
}
.pagination-controls span {
  font-size: 13px;
  color: var(--color-text-muted);
  font-weight: 600;
  white-space: nowrap;
}

@media (max-width: 480px) {
  .pagination-controls {
    gap: 8px;
    padding: 8px;
  }
  .pagination-controls .btn {
    min-width: 50px;
    font-size: 12px;
    padding: 5px 10px;
  }
  .pagination-controls span {
    font-size: 12px;
  }
}

/* === Flatpickr Theme Overrides === */
.flatpickr-calendar {
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-lg) !important;
  border: 1px solid var(--color-border) !important;
  font-family: var(--font-main) !important;
}
.flatpickr-day.selected, .flatpickr-day.startRange, .flatpickr-day.endRange, 
.flatpickr-day.selected.inRange, .flatpickr-day.startRange.inRange, 
.flatpickr-day.endRange.inRange, .flatpickr-day.selected:focus, 
.flatpickr-day.startRange:focus, .flatpickr-day.endRange:focus, 
.flatpickr-day.selected:hover, .flatpickr-day.startRange:hover, 
.flatpickr-day.endRange:hover, .flatpickr-day.selected.prevMonthDay, 
.flatpickr-day.startRange.prevMonthDay, .flatpickr-day.endRange.prevMonthDay, 
.flatpickr-day.selected.nextMonthDay, .flatpickr-day.startRange.nextMonthDay, 
.flatpickr-day.endRange.nextMonthDay {
  background: var(--color-primary) !important;
  border-color: var(--color-primary) !important;
}
.flatpickr-day.today {
  border-color: var(--color-primary) !important;
}
.flatpickr-day.today:hover {
  background: var(--color-primary) !important;
  color: #fff !important;
}
.flatpickr-months .flatpickr-month {
  color: var(--color-primary) !important;
  fill: var(--color-primary) !important;
}
.flatpickr-current-month .flatpickr-monthDropdown-months:hover {
  background: rgba(0,0,0,0.05) !important;
}
.flatpickr-calendar.arrowTop:before, .flatpickr-calendar.arrowTop:after {
  border-bottom-color: var(--color-primary) !important;
}

/* Ensure flatpickr inputs don't overflow */
.flatpickr-input[readonly] {
  background-color: var(--color-card) !important;
}
.flatpickr-mobile {
  width: 100% !important;
}
/* This targets the visible input created by altInput: true */
input.flatpickr-input.form-control {
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* === Print styles === */
@media print {
  .sidebar,
  .bottom-nav,
  .screen-header button,
  .card-actions,
  .sub-card-actions,
  .pagination-controls,
  .empty-state-small,
  .accordion-chevron,
  button.btn-small,
  button.btn-danger,
  button.btn-primary {
    display: none !important;
  }
  .app-main {
    margin: 0 !important;
    padding: 0 !important;
    max-width: 100% !important;
  }
  body {
    background: #fff !important;
  }
  .accordion-item {
    break-inside: avoid;
    page-break-inside: avoid;
    border: 1px solid #ddd;
    margin-bottom: 12px;
  }
  .sub-card {
    break-inside: avoid;
    page-break-inside: avoid;
    border: 1px solid #eee;
    padding: 8px;
    margin-bottom: 6px;
  }
}

/* ===================================================================
   NOTIFICATION CENTER
   =================================================================== */

/* ── Bell badge on header icon ─────────────────────────────────────── */
.notif-bell-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--color-danger, #e63946);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  border-radius: 999px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  pointer-events: none;
  animation: notifBadgePop 0.3s cubic-bezier(0.68, -0.55, 0.27, 1.55);
}
html[dir="rtl"] .notif-bell-badge {
  right: auto;
  left: -4px;
}
@keyframes notifBadgePop {
  0% { transform: scale(0); }
  60% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* ── Stats header bar ─────────────────────────────────────────────── */
.notif-header-stats {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  margin-bottom: 4px;
}
.notif-stat {
  flex: 1;
  background: var(--color-card);
  border-radius: var(--radius-md);
  padding: 12px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.notif-stat-value {
  display: block;
  font-size: 24px;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.2;
}
.notif-stat-label {
  display: block;
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.notif-stat-critical .notif-stat-value { color: var(--color-danger, #e63946); }
.notif-stat-upcoming .notif-stat-value { color: var(--color-warning, #f4a261); }

/* ── Category groups ──────────────────────────────────────────────── */
.notif-category-group {
  margin-bottom: 12px;
}
.notif-category-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.notif-category-icon {
  opacity: 0.6;
  display: flex;
  align-items: center;
}
.notif-category-label {
  flex: 1;
}
.notif-category-count {
  background: var(--color-surface);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
}

/* ── Alert cards ──────────────────────────────────────────────────── */
.notif-list {
  padding: 0 12px 80px;
}
.notif-category-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 12px;
}
.notif-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--color-card);
  border-radius: var(--radius-md);
  padding: 12px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  border-left: 3px solid transparent;
}
.notif-card:active {
  transform: scale(0.98);
  box-shadow: var(--shadow-xs);
}
.notif-card-critical {
  border-left-color: var(--color-danger, #e63946);
  background: linear-gradient(135deg, var(--color-card) 0%, rgba(230,57,70,0.03) 100%);
}
html[dir="rtl"] .notif-card {
  border-left: none;
  border-right: 3px solid transparent;
}
html[dir="rtl"] .notif-card-critical {
  border-right-color: var(--color-danger, #e63946);
  border-left-color: transparent;
}

/* ── Icon area ────────────────────────────────────────────────────── */
.notif-icon {
  position: relative;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
.notif-priority-dot {
  position: absolute;
  top: 0;
  right: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-danger, #e63946);
  border: 2px solid var(--color-card);
  animation: notifPulse 2s infinite;
}
html[dir="rtl"] .notif-priority-dot {
  right: auto;
  left: 0;
}
@keyframes notifPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.7; }
}

/* ── Body ─────────────────────────────────────────────────────────── */
.notif-body {
  flex: 1;
  min-width: 0;
}
.notif-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.3;
  margin-bottom: 2px;
}
.notif-desc {
  font-size: 12px;
  color: var(--color-text-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.notif-time {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 4px;
  opacity: 0.7;
}

/* ── Action button ────────────────────────────────────────────────── */
.notif-action {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: none;
  background: var(--color-surface);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--color-text-muted);
  transition: background 0.15s ease, color 0.15s ease;
  margin-top: 4px;
}
.notif-action:hover {
  background: var(--color-primary);
  color: #fff;
}
.notif-action:active {
  transform: scale(0.9);
}

/* ── Load more ────────────────────────────────────────────────────── */
.notif-load-more {
  text-align: center;
  padding: 16px;
}

/* ── Skeleton loading ─────────────────────────────────────────────── */
.notif-card.skeleton {
  pointer-events: none;
}
.notif-card.skeleton .notif-icon {
  background: var(--color-surface) !important;
}
.notif-card.skeleton .skeleton-line {
  background: var(--color-surface);
  border-radius: 4px;
}
.notif-card.skeleton .skeleton-pulse {
  animation: skeletonPulse 1.5s ease-in-out infinite;
}
@keyframes skeletonPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===================================================================
   NOTIFICATION FILTER BAR
   =================================================================== */

/* ── Filter bar container ─────────────────────────────────────────── */
.notif-filter-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  border-bottom: 1px solid var(--color-border, #e2e8f0);
  background: var(--color-card);
}
.notif-filter-bar::-webkit-scrollbar { display: none; }

/* ── Filter buttons ───────────────────────────────────────────────── */
.notif-filter-btn {
  flex-shrink: 0;
  padding: 6px 14px;
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
}
.notif-filter-btn:hover {
  border-color: var(--color-primary, #10b981);
  color: var(--color-primary, #10b981);
}
.notif-filter-btn.active {
  background: var(--color-primary, #10b981);
  border-color: var(--color-primary, #10b981);
  color: #fff;
}
.notif-filter-btn.active:hover {
  opacity: 0.9;
}

/* ── Spacer to push right-side buttons ────────────────────────────── */
.notif-filter-spacer {
  flex: 1;
  min-width: 4px;
}

/* ── Print button ─────────────────────────────────────────────────── */
.notif-print-btn {
  color: var(--color-text-muted);
}
.notif-print-btn:hover {
  border-color: var(--color-primary, #10b981);
  color: var(--color-primary, #10b981);
}

/* ── Category dropdown ────────────────────────────────────────────── */
.notif-category-dropdown {
  position: absolute;
  top: 100%;
  right: 16px;
  z-index: 1000;
  min-width: 180px;
  background: var(--color-card);
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
html[dir="rtl"] .notif-category-dropdown {
  right: auto;
  left: 16px;
}
.notif-cat-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease;
  text-align: left;
  width: 100%;
}
html[dir="rtl"] .notif-cat-dropdown-item {
  text-align: right;
}
.notif-cat-dropdown-item:hover {
  background: var(--color-surface);
}
.notif-cat-dropdown-item.active {
  background: var(--color-primary, #10b981);
  color: #fff;
}
.notif-cat-dropdown-item.active .notif-cat-dropdown-icon {
  opacity: 1;
}
.notif-cat-dropdown-item:active {
  background: var(--color-primary-light, rgba(16,185,129,0.1));
}
.notif-cat-dropdown-icon {
  display: flex;
  align-items: center;
  opacity: 0.6;
}
