/* Aliyar Farm — mobile-first styles */

/* Noto Nastaliq Urdu — self-hosted (offline-first; works in Capacitor). */
@font-face {
  font-family: 'Noto Nastaliq Urdu';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/nastaliq-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Noto Nastaliq Urdu';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/nastaliq-700.woff2') format('woff2');
}

/* Nastaliq is a tall calligraphic script — give Urdu text room so it never clips. */
html[dir="rtl"] body { line-height: 1.9; }

:root {
  --brand-dark:  #1F4E78;
  --brand:       #2E75B6;
  --brand-light: #DEEBF7;
  --accent:      #C55A11;
  --ok:          #548235;
  --warn:        #BF8F00;
  --danger:      #C00000;
  --bg:          #F5F5F5;
  --card:        #FFFFFF;
  --text:        #1a1a1a;
  --text-muted:  #666;
  --border:      #E0E0E0;
  --shadow:      0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg:   0 4px 12px rgba(0,0,0,0.12);
  --radius:      12px;
  --tap:         48px;             /* minimum tap target */
  --font-ur:     'Noto Nastaliq Urdu', 'Jameel Noori Nastaleeq', Arial, sans-serif;
  --font-en:     -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-en);
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
html[dir="rtl"] body { font-family: var(--font-ur); }

.hidden { display: none !important; }

/* ============ HEADER ============ */
#app-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--brand-dark); color: white;
  padding: env(safe-area-inset-top) 0 0 0;
  box-shadow: var(--shadow);
}
.header-inner {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; min-height: 56px;
}
#page-title {
  flex: 1; font-size: 18px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.header-right { display: flex; align-items: center; gap: 4px; }
.icon-btn, .lang-btn, .user-btn {
  min-width: var(--tap); min-height: var(--tap);
  background: transparent; border: none; color: white;
  font-size: 20px; cursor: pointer; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  padding: 8px;
}
.icon-btn:active, .lang-btn:active, .user-btn:active {
  background: rgba(255,255,255,0.15);
}
.lang-btn { font-size: 14px; font-weight: 700; }
.user-btn {
  width: 36px; height: 36px; min-width: 36px; min-height: 36px;
  background: rgba(255,255,255,0.2); border-radius: 50%;
  font-size: 14px; font-weight: 700;
}
.sync-dot {
  font-size: 12px; padding: 0 6px;
  color: #999;  /* default = local only */
}
.sync-dot.online { color: #7FE07F; }
.sync-dot.syncing { color: #FFD966; }
.sync-dot.offline { color: #FF6B6B; }

/* ============ MAIN ============ */
#app-main {
  padding: 16px 16px 88px 16px;   /* room for bottom nav */
  min-height: calc(100vh - 56px - 64px);
  max-width: 720px; margin: 0 auto;
}

/* ============ BOTTOM NAV ============ */
#app-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  display: flex; background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 8px 4px; min-height: 64px;
  text-decoration: none; color: var(--text-muted);
  font-size: 11px; gap: 2px;
  transition: color 0.15s;
}
.nav-item.active { color: var(--brand); }
.nav-item.disabled { opacity: 0.35; pointer-events: none; }
.nav-icon { font-size: 22px; line-height: 1; }
.nav-label { font-size: 11px; }

/* ============ CARDS + LAYOUT ============ */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.card-tight { padding: 12px; }

.section-title {
  font-size: 14px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin: 20px 4px 8px; padding: 0 4px;
}
.section-title:first-child { margin-top: 4px; }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 12px 20px;
  border: none; border-radius: 10px;
  font-size: 16px; font-weight: 600; cursor: pointer;
  text-decoration: none; gap: 8px;
  transition: transform 0.05s, background 0.15s;
  font-family: inherit;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--brand-dark); color: white; }
.btn-primary:active { background: var(--brand); }
.btn-secondary { background: var(--brand-light); color: var(--brand-dark); }
.btn-danger { background: var(--danger); color: white; }
.btn-ghost { background: transparent; color: var(--brand-dark); }
.btn-block { width: 100%; }
.btn-lg { min-height: 56px; font-size: 17px; }

.fab {
  position: fixed; bottom: 80px; right: 20px;
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--brand-dark); color: white;
  border: none; font-size: 30px; cursor: pointer;
  box-shadow: var(--shadow-lg); z-index: 50;
  display: flex; align-items: center; justify-content: center;
}
html[dir="rtl"] .fab { right: auto; left: 20px; }
.fab:active { transform: scale(0.95); }

/* ============ FORMS ============ */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block; font-size: 14px; font-weight: 600;
  color: var(--text-muted); margin-bottom: 6px;
}
.form-label .required { color: var(--danger); }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 12px; font-size: 16px;
  border: 1.5px solid var(--border); border-radius: 8px;
  background: white; font-family: inherit;
  min-height: var(--tap);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--brand);
}
.form-textarea { min-height: 96px; resize: vertical; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Radio/checkbox chip group — for tap-don't-type */
.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 12px 16px; min-height: var(--tap);
  border: 1.5px solid var(--border); border-radius: 24px;
  background: white; font-size: 15px; cursor: pointer;
  display: flex; align-items: center;
  font-family: inherit;
}
.chip.selected {
  background: var(--brand-dark); color: white; border-color: var(--brand-dark);
}
.chip:active { transform: scale(0.97); }

/* Photo capture */
.photo-capture {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 20px; border: 2px dashed var(--border); border-radius: var(--radius);
  min-height: 140px; justify-content: center; cursor: pointer;
  background: #FAFAFA;
}
.photo-capture img {
  max-width: 100%; max-height: 200px; border-radius: 8px;
}
.photo-capture .capture-hint {
  font-size: 14px; color: var(--text-muted);
}
.photo-capture-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; background: var(--brand-light); color: var(--brand-dark);
  border-radius: 8px; font-weight: 600;
}

/* ============ ANIMAL LIST ITEM ============ */
.animal-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; background: var(--card); border-radius: var(--radius);
  margin-bottom: 8px; cursor: pointer; box-shadow: var(--shadow);
  border-inline-start: 4px solid transparent;
}
.animal-item:active { transform: scale(0.99); }
.animal-item.flag { border-inline-start-color: var(--warn); }
.animal-item.critical { border-inline-start-color: var(--danger); }

.animal-photo {
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--brand-light); overflow: hidden; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
}
.animal-photo img { width: 100%; height: 100%; object-fit: cover; }
.animal-info { flex: 1; min-width: 0; }
.animal-name {
  font-size: 16px; font-weight: 600; margin-bottom: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.animal-meta {
  font-size: 13px; color: var(--text-muted);
  display: flex; gap: 10px; flex-wrap: wrap;
}
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge-doe { background: #FDE9D9; color: #C55A11; }
.badge-buck { background: #DEEBF7; color: #1F4E78; }
.badge-kid { background: #E2F0D9; color: #548235; }
.badge-flag { background: #FFF2CC; color: #806000; }

/* Nested kids under doe */
.kids-nest {
  margin-inline-start: 24px; margin-top: 4px; margin-bottom: 12px;
  border-inline-start: 2px solid var(--brand-light); padding-inline-start: 12px;
}
.kids-nest .animal-item { margin-bottom: 6px; }

/* ============ DASHBOARD ============ */
.kpi-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
  border-block-start: 4px solid var(--brand);
}
.kpi-card.ok { border-block-start-color: var(--ok); }
.kpi-card.warn { border-block-start-color: var(--warn); }
.kpi-card.danger { border-block-start-color: var(--danger); }
.kpi-value {
  font-size: 32px; font-weight: 700; color: var(--brand-dark);
  line-height: 1.1; margin-bottom: 4px;
}
.kpi-label {
  font-size: 13px; color: var(--text-muted); font-weight: 500;
}
.kpi-sublabel {
  font-size: 11px; color: var(--text-muted); margin-top: 6px;
}

.health-strip {
  padding: 14px 16px; border-radius: var(--radius);
  color: white; font-weight: 600; margin-bottom: 16px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow);
}
.health-strip.green { background: var(--ok); }
.health-strip.amber { background: var(--warn); }
.health-strip.red { background: var(--danger); }
.health-strip .strip-icon { font-size: 22px; }

.mini-list-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.mini-list-item:last-child { border-bottom: none; }
.mini-list-item .name { font-weight: 500; }
.mini-list-item .meta { font-size: 13px; color: var(--text-muted); }

/* ============ USER PICKER ============ */
.user-picker {
  min-height: 100vh; padding: 24px 20px;
  display: flex; flex-direction: column; justify-content: center;
  background: linear-gradient(180deg, var(--brand-dark) 0%, var(--brand) 100%);
  color: white;
}
.user-picker h1 {
  font-size: 28px; margin-bottom: 8px; text-align: center;
}
.user-picker .subtitle {
  text-align: center; opacity: 0.85; margin-bottom: 32px; font-size: 15px;
}
.user-option {
  display: flex; align-items: center; gap: 16px;
  padding: 16px; background: rgba(255,255,255,0.12);
  border: none; border-radius: var(--radius);
  color: white; margin-bottom: 12px; cursor: pointer;
  font-size: 16px; text-align: start; width: 100%;
  font-family: inherit;
}
.user-option:active { background: rgba(255,255,255,0.2); }
.user-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  background: white; color: var(--brand-dark);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700;
}
.user-info { flex: 1; }
.user-name { font-weight: 600; margin-bottom: 2px; }
.user-role { font-size: 13px; opacity: 0.8; }

/* ============ SEARCH BAR ============ */
.search-bar {
  display: flex; gap: 8px; margin-bottom: 16px;
  padding: 10px 14px; background: var(--card);
  border-radius: 24px; box-shadow: var(--shadow);
}
.search-bar input {
  flex: 1; border: none; outline: none; font-size: 15px;
  background: transparent; font-family: inherit;
}
.search-icon { color: var(--text-muted); font-size: 18px; }

/* ============ EMPTY STATE ============ */
.empty-state {
  text-align: center; padding: 48px 20px; color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { font-size: 18px; margin-bottom: 8px; color: var(--text); }
.empty-state p { margin-bottom: 20px; font-size: 14px; }

/* ============ TOAST ============ */
#toast-container {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  z-index: 1000; pointer-events: none;
}
.toast {
  background: rgba(0,0,0,0.85); color: white;
  padding: 12px 20px; border-radius: 24px;
  margin-bottom: 8px; font-size: 14px;
  animation: toast-in 0.2s ease-out;
}
.toast.success { background: var(--ok); }
.toast.error { background: var(--danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============ MODAL ============ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 600px) {
  .modal-overlay { align-items: center; }
}
.modal {
  background: var(--card); border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px; width: 100%; max-width: 500px;
  max-height: 90vh; overflow-y: auto;
  animation: modal-in 0.2s ease-out;
}
@media (min-width: 600px) {
  .modal { border-radius: var(--radius); }
}
@keyframes modal-in {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal h2 { font-size: 20px; margin-bottom: 16px; }

/* ============ DETAIL VIEW ============ */
.detail-hero {
  display: flex; gap: 16px; align-items: center;
  padding: 20px; background: var(--card); border-radius: var(--radius);
  margin-bottom: 16px; box-shadow: var(--shadow);
}
.detail-hero .animal-photo { width: 96px; height: 96px; font-size: 44px; }
.detail-hero .name { font-size: 22px; font-weight: 700; }
.detail-hero .tag { font-size: 14px; color: var(--text-muted); }

.detail-tabs {
  display: flex; background: var(--card); border-radius: var(--radius);
  padding: 4px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.detail-tab {
  flex: 1; padding: 10px; text-align: center; cursor: pointer;
  border-radius: 8px; font-size: 14px; font-weight: 600;
  color: var(--text-muted);
}
.detail-tab.active { background: var(--brand-dark); color: white; }

.kv-row {
  display: flex; justify-content: space-between; padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.kv-row:last-child { border-bottom: none; }
.kv-key { color: var(--text-muted); font-size: 14px; }
.kv-value { font-weight: 500; font-size: 14px; text-align: end; }

/* Growth curve chart (simple SVG) */
.growth-chart {
  background: var(--card); padding: 16px; border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 12px;
}
.growth-chart svg { width: 100%; height: auto; display: block; }
.growth-chart-legend {
  display: flex; gap: 16px; margin-top: 8px; font-size: 12px;
  color: var(--text-muted); justify-content: center;
}
.growth-chart-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-inline-end: 6px; vertical-align: middle; }

/* ============ MORE MENU ============ */
.menu-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; background: var(--card);
  border-radius: 10px; margin-bottom: 8px;
  color: var(--text); text-decoration: none;
  min-height: var(--tap); cursor: pointer;
  font-family: inherit; border: none; width: 100%; text-align: start;
  font-size: 15px;
}
.menu-item:active { background: var(--brand-light); }
.menu-item .menu-icon { font-size: 22px; width: 32px; text-align: center; }
.menu-item .menu-label { flex: 1; }
.menu-item .menu-chevron { color: var(--text-muted); }

/* ============ UTIL ============ */
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-ok { color: var(--ok); }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mt-16 { margin-top: 16px; }
.center { text-align: center; }
.row { display: flex; gap: 8px; align-items: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; }
.spacer { flex: 1; }
