/* Jameel Noori Nastaleeq for Urdu/Arabic script only (unicode-range): Latin text keeps the system font,
   and the font file is only downloaded when Urdu text is shown or printed. */
@font-face {
  font-family: 'Jameel Noori Nastaleeq';
  src: url('../fonts/jameel-noori-nastaleeq.woff') format('woff');
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F;
}
:root {
  --bs-font-sans-serif: 'Jameel Noori Nastaleeq', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', 'Noto Sans', 'Liberation Sans', Arial, sans-serif;
  --bs-body-font-family: var(--bs-font-sans-serif);
  --topbar-h: 52px;
  --bottomnav-h: 62px;
  --sidebar-w: 236px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --farm-green: #2e7d32;
  --bs-primary: #2e7d32;
  --bs-primary-rgb: 46,125,50;
}

/* RTL layout overrides for Urdu */
[dir="rtl"] #sidebar { left: auto; right: 0; border-right: 0; border-left: 1px solid var(--bs-border-color); }
[dir="rtl"] .app-main { margin-left: 0; }
@media (min-width: 992px) { [dir="rtl"] .app-main { margin-right: var(--sidebar-w); } }
[dir="rtl"] .nav-menu .nav-link { border-left: 0; border-right: 3px solid transparent; }
[dir="rtl"] .nav-menu .nav-link.active { border-right-color: var(--bs-primary); border-left: 0; }
[dir="rtl"] .list-row .end { text-align: left; }
[dir="rtl"] .offcanvas-start { left: auto; right: 0; transform: translateX(100%); }
[dir="rtl"] .offcanvas-start.show { transform: none; }
[dir="rtl"] .dropdown-menu-end { --bs-position: start; }
[dir="rtl"] .page-header { flex-direction: row-reverse; }
[dir="rtl"] .page-header a { flex-direction: row-reverse; }
[dir="rtl"] .table-report td.num, [dir="rtl"] .table-report th.num { text-align: left; }
html, body { height: 100%; }
body { -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; background: var(--bs-tertiary-bg); }
[data-bs-theme="dark"] body { background: #14171a; }
button, .btn, a { touch-action: manipulation; }
[data-bs-theme="dark"] .btn-light { --bs-btn-bg: var(--bs-tertiary-bg); --bs-btn-color: var(--bs-body-color); --bs-btn-border-color: var(--bs-border-color); --bs-btn-hover-bg: var(--bs-secondary-bg); --bs-btn-hover-color: var(--bs-body-color); --bs-btn-hover-border-color: var(--bs-border-color); --bs-btn-active-bg: var(--bs-secondary-bg); --bs-btn-active-color: var(--bs-body-color); --bs-btn-disabled-bg: var(--bs-tertiary-bg); --bs-btn-disabled-color: var(--bs-secondary-color); }
[data-bs-theme="dark"] .table-light { --bs-table-bg: var(--bs-tertiary-bg); --bs-table-color: var(--bs-body-color); --bs-table-border-color: var(--bs-border-color); }
[data-bs-theme="dark"] .text-bg-light { background-color: var(--bs-tertiary-bg) !important; color: var(--bs-body-color) !important; }
input[type=number] { -moz-appearance: textfield; }
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Splash */
#splash { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--bs-body-bg); z-index: 3000; }
#splash img { border-radius: 20px; }

/* Login */
.login-bg {
  min-height: 100vh;
  background: linear-gradient(150deg, #1b5e20 0%, #2e7d32 55%, #388e3c 100%);
  display: flex; align-items: center; justify-content: center; padding: 20px 16px;
}
.login-wrap { width: 100%; max-width: 430px; margin: 0 auto; }
.login-card { border-radius: 22px !important; overflow: hidden; }
/* Farm scene header */
.login-scene-wrap { position: relative; background: #87ceeb; }
.login-scene { display: block; width: 100%; height: auto; }
.login-brand-bar {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.62) 0%, transparent 100%);
  display: flex; align-items: center; gap: 12px;
  padding: 20px 20px 16px;
  color: white;
}
.login-logo-img { border-radius: 10px; flex-shrink: 0; box-shadow: 0 3px 10px rgba(0,0,0,0.25); }
.login-brand-name { font-size: 1.1rem; font-weight: 700; line-height: 1.2; }
.login-brand-sub { font-size: .72rem; opacity: 0.82; margin-top: 1px; }
/* Form area */
.login-form-area { padding: 22px 24px 26px; background: var(--bs-body-bg); }
.login-footer-note { color: rgba(255,255,255,0.65); }
#toggle-pw { z-index: 5; }
/* Sidebar brand logo */
.brand-logo { border-radius: 6px; }

/* Layout */
#view-app { min-height: 100vh; }
#sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: var(--sidebar-w); background: var(--bs-body-bg); border-right: 1px solid var(--bs-border-color); z-index: 1020; }
.sidebar-brand { height: var(--topbar-h); display: flex; align-items: center; gap: 8px; padding: 0 16px; font-weight: 600; border-bottom: 1px solid var(--bs-border-color); }
.sidebar-brand img { border-radius: 6px; }
.nav-menu { flex-wrap: nowrap; }
#sidebar .nav-menu { overflow-x: hidden; }
.app-main { min-height: 100vh; }
@media (min-width: 992px) { .app-main { margin-left: var(--sidebar-w); } }
.app-topbar { position: sticky; top: 0; z-index: 1010; height: var(--topbar-h); display: flex; align-items: center; gap: 8px; padding: 0 8px 0 12px; background: var(--bs-body-bg); border-bottom: 1px solid var(--bs-border-color); }
#content { padding: 12px 12px calc(var(--bottomnav-h) + var(--safe-b) + 16px); max-width: 1400px; margin: 0 auto; outline: none; }
@media (min-width: 992px) { #content { padding: 20px 24px 32px; } }

.nav-menu .nav-link { color: var(--bs-body-color); padding: 10px 16px; display: flex; align-items: center; gap: 12px; border-left: 3px solid transparent; }
.nav-menu .nav-link i { font-size: 1.15rem; width: 22px; text-align: center; }
.nav-menu .nav-link:hover { background: var(--bs-secondary-bg); }
.nav-menu .nav-link.active { color: var(--bs-primary); background: var(--bs-primary-bg-subtle); border-left-color: var(--bs-primary); font-weight: 600; }
.nav-menu .nav-section { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--bs-secondary-color); padding: 14px 16px 4px; }

#bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030; height: calc(var(--bottomnav-h) + var(--safe-b)); padding-bottom: var(--safe-b); display: flex; background: var(--bs-body-bg); border-top: 1px solid var(--bs-border-color); }
#bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-decoration: none; color: var(--bs-secondary-color); font-size: .7rem; gap: 2px; }
#bottom-nav a i { font-size: 1.3rem; }
#bottom-nav a.active { color: var(--bs-primary); }
#bottom-nav a.nav-sell i { background: var(--bs-primary); color: #fff; width: 50px; height: 50px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin-top: -22px; box-shadow: 0 4px 12px rgba(13,110,253,.4); font-size: 1.4rem; }
#bottom-nav a.nav-milk i { background: #1565c0; color: #fff; width: 50px; height: 50px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin-top: -22px; box-shadow: 0 4px 12px rgba(21,101,192,.4); font-size: 1.4rem; }
body.focus-mode #bottom-nav { display: none; }
body.focus-mode #content { padding-bottom: 0; }

/* Animal status badges */
.badge-active   { background: #e8f5e9; color: #1b5e20; border: 1px solid #a5d6a7; }
.badge-sold     { background: #e3f2fd; color: #0d47a1; border: 1px solid #90caf9; }
.badge-dead     { background: #fafafa; color: #616161; border: 1px solid #bdbdbd; }
.badge-culled   { background: #fff3e0; color: #e65100; border: 1px solid #ffcc80; }
.badge-pregnant { background: #fce4ec; color: #880e4f; border: 1px solid #f48fb1; }
.badge-female   { background: #f3e5f5; color: #4a148c; border: 1px solid #ce93d8; }
.badge-male     { background: #e8eaf6; color: #1a237e; border: 1px solid #9fa8da; }

/* Dashboard stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
@media (min-width: 576px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat-tile { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: 12px; padding: 14px; text-align: center; }
.stat-tile .st-icon { font-size: 1.6rem; margin-bottom: 4px; }
.stat-tile .st-val  { font-size: 1.4rem; font-weight: 700; line-height: 1.1; }
.stat-tile .st-lbl  { font-size: .72rem; color: var(--bs-secondary-color); text-transform: uppercase; letter-spacing: .04em; }

/* Animal card grid */
.animal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.animal-card { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: 12px; padding: 12px; text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: 6px; }
.animal-card:hover { background: var(--bs-secondary-bg); }
.animal-card .ac-tag { font-size: .7rem; color: var(--bs-secondary-color); }
.animal-card .ac-name { font-weight: 700; font-size: .95rem; }
.animal-card .ac-breed { font-size: .78rem; color: var(--bs-secondary-color); }
.animal-card .ac-badges { display: flex; flex-wrap: wrap; gap: 4px; }

/* Health event type colors */
.evt-vaccination { color: #1565c0; }
.evt-treatment   { color: #b71c1c; }
.evt-checkup     { color: #2e7d32; }
.evt-deworming   { color: #6a1b9a; }
.evt-vitamin     { color: #e65100; }

/* Pregnancy tracker */
.preg-bar { height: 6px; border-radius: 3px; background: var(--bs-secondary-bg); overflow: hidden; margin-top: 4px; }
.preg-bar-fill { height: 100%; background: #e91e63; border-radius: 3px; transition: width .3s; }

/* Milk chart bar */
.milk-bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.milk-bar-label { width: 80px; font-size: .78rem; color: var(--bs-secondary-color); text-align: right; flex-shrink: 0; }
[dir="rtl"] .milk-bar-label { text-align: left; }
.milk-bar-track { flex: 1; height: 14px; background: var(--bs-secondary-bg); border-radius: 7px; overflow: hidden; }
.milk-bar-fill { height: 100%; background: #1565c0; border-radius: 7px; }
.milk-bar-val { width: 50px; font-size: .78rem; font-weight: 600; flex-shrink: 0; }

/* Tab nav for animal detail */
.detail-tabs .nav-link { font-size: .85rem; padding: .5rem .75rem; }

/* Timeline for health/breeding events */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline-item { display: flex; gap: 12px; padding-bottom: 16px; position: relative; }
.timeline-item:not(:last-child)::before { content: ''; position: absolute; left: 17px; top: 36px; bottom: 0; width: 2px; background: var(--bs-border-color); }
[dir="rtl"] .timeline-item:not(:last-child)::before { left: auto; right: 17px; }
.timeline-dot { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 1rem; }
.timeline-body { flex: 1; min-width: 0; }
.timeline-body .tl-title { font-weight: 600; }
.timeline-body .tl-meta { font-size: .78rem; color: var(--bs-secondary-color); }

/* Connection badge */
#conn-badge { font-weight: 500; font-size: .72rem; padding: .4em .7em; }
.conn-online { background: var(--bs-success-bg-subtle); color: var(--bs-success-text-emphasis); }
.conn-offline { background: var(--bs-secondary-bg); color: var(--bs-secondary-color); }

#loading-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 2500; display: flex; align-items: center; justify-content: center; }
#loading-overlay.d-none { display: none !important; }
.toast-container { z-index: 2600; }

/* Cards & lists */
.card { border-color: var(--bs-border-color-translucent); }
.stat-card { border: 0; border-radius: 12px; }
.stat-card .stat-label { font-size: .75rem; color: var(--bs-secondary-color); text-transform: uppercase; letter-spacing: .03em; }
.stat-card .stat-value { font-size: 1.25rem; font-weight: 700; }
.quick-action { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 14px 6px; border-radius: 12px; background: var(--bs-body-bg); text-decoration: none; color: var(--bs-body-color); font-size: .8rem; text-align: center; border: 1px solid var(--bs-border-color-translucent); }
.quick-action i { font-size: 1.5rem; color: var(--bs-primary); }
.quick-action:active { transform: scale(.97); }
.list-card { background: var(--bs-body-bg); border-radius: 12px; overflow: hidden; border: 1px solid var(--bs-border-color-translucent); }
.list-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--bs-border-color-translucent); color: inherit; text-decoration: none; }
.list-row:last-child { border-bottom: 0; }
a.list-row:hover, button.list-row:hover { background: var(--bs-secondary-bg); }
button.list-row { width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; }
.list-row .main { flex: 1; min-width: 0; }
.list-row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .sub { font-size: .8rem; color: var(--bs-secondary-color); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .end { text-align: right; white-space: nowrap; }
.thumb { width: 42px; height: 42px; border-radius: 8px; object-fit: cover; background: var(--bs-secondary-bg); display: flex; align-items: center; justify-content: center; color: var(--bs-secondary-color); flex-shrink: 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters > * { flex: 1 1 140px; }
.filters .flex-grow-2 { flex: 2 1 220px; }
.table-report { font-size: .85rem; }
.table-report th { white-space: nowrap; }
.table-report td.num, .table-report th.num { text-align: right; white-space: nowrap; }
.money { font-variant-numeric: tabular-nums; }
.chip { display: inline-block; padding: 6px 12px; border-radius: 20px; background: var(--bs-body-bg); border: 1px solid var(--bs-border-color); white-space: nowrap; font-size: .85rem; cursor: pointer; }
.chip.active { background: var(--bs-primary); color: #fff; border-color: var(--bs-primary); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }

/* POS */
.pos { display: grid; grid-template-columns: 1fr; gap: 12px; margin: -12px -12px 0; }
.pos-left { display: none; }
.pos-right { display: flex; flex-direction: column; min-height: calc(100vh - var(--topbar-h)); background: var(--bs-body-bg); }
@media (min-width: 992px) {
  .pos { grid-template-columns: 1fr 440px; margin: -20px -24px -32px; gap: 0; }
  .pos-left { display: flex; flex-direction: column; height: calc(100vh - var(--topbar-h)); padding: 12px; overflow: hidden; }
  .pos-right { height: calc(100vh - var(--topbar-h)); min-height: 0; border-left: 1px solid var(--bs-border-color); }
}
.pos.show-browse .pos-left { display: flex; flex-direction: column; position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 1040; background: var(--bs-tertiary-bg); padding: 12px; overflow: hidden; }
@media (min-width: 992px) { .pos.show-browse .pos-left { position: static; background: none; } }
.pos-search { position: sticky; top: var(--topbar-h); z-index: 20; padding: 10px 12px; background: var(--bs-body-bg); border-bottom: 1px solid var(--bs-border-color-translucent); }
@media (min-width: 992px) { .pos-search { top: 0; } }
.pos-search .input-group-lg .form-control { font-size: 1.05rem; }
.search-results { position: absolute; left: 12px; right: 12px; top: 100%; z-index: 30; max-height: 55vh; overflow-y: auto; background: var(--bs-body-bg); border: 1px solid var(--bs-border-color); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.15); }
.pos-meta { padding: 8px 12px; display: flex; gap: 8px; border-bottom: 1px solid var(--bs-border-color-translucent); }
.pos-meta .btn { flex: 0 0 auto; }
.pos-meta .btn-party { flex: 1 1 auto; min-width: 0; text-align: left; }
.pos-lines { flex: 1; overflow-y: auto; }
.cart-line { display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--bs-border-color-translucent); align-items: center; }
.cart-line .info { flex: 1; min-width: 0; cursor: pointer; }
.cart-line .name { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cart-line .meta { font-size: .78rem; color: var(--bs-secondary-color); }
.qty-ctl { display: flex; align-items: center; border: 1px solid var(--bs-border-color); border-radius: 8px; overflow: hidden; flex-shrink: 0; }
.qty-ctl button { border: 0; background: var(--bs-secondary-bg); width: 36px; height: 38px; font-size: 1.1rem; color: var(--bs-body-color); }
.qty-ctl input { width: 52px; border: 0; text-align: center; height: 38px; background: var(--bs-body-bg); color: var(--bs-body-color); font-weight: 600; }
.cart-line .amt { width: 84px; text-align: right; font-weight: 600; flex-shrink: 0; }
.pos-footer { position: sticky; bottom: 0; background: var(--bs-body-bg); border-top: 1px solid var(--bs-border-color); padding: 10px 12px calc(10px + var(--safe-b)); box-shadow: 0 -4px 16px rgba(0,0,0,.06); }
.pos-footer .total { font-size: 1.5rem; font-weight: 800; }
.btn-pay { font-size: 1.1rem; font-weight: 700; padding: 12px 18px; }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; overflow-y: auto; padding-bottom: 12px; align-content: start; }
.product-tile { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: 10px; padding: 8px; text-align: left; display: flex; flex-direction: column; gap: 4px; min-height: 96px; }
.product-tile:active { transform: scale(.97); }
.product-tile img, .product-tile .ph { width: 100%; height: 64px; object-fit: cover; border-radius: 6px; background: var(--bs-secondary-bg); display: flex; align-items: center; justify-content: center; color: var(--bs-secondary-color); }
.product-tile .n { font-size: .82rem; font-weight: 600; line-height: 1.15; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.product-tile .p { font-size: .8rem; color: var(--bs-primary); font-weight: 700; }
.product-tile .s { font-size: .7rem; color: var(--bs-secondary-color); }
.pay-quick .btn { flex: 1 1 22%; }
.checkout-total { font-size: 2rem; font-weight: 800; }

/* Scanner */
.scanner-box { position: relative; background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 4 / 3; }
.scanner-box video { width: 100%; height: 100%; object-fit: cover; }
.scanner-box .scan-line { position: absolute; left: 10%; right: 10%; top: 50%; height: 2px; background: #ff3b30; box-shadow: 0 0 8px #ff3b30; }
#html5qr-region video { border-radius: 12px; }

.empty-state i { opacity: .5; }
.form-label { font-size: .85rem; margin-bottom: .25rem; font-weight: 500; }
.modal-fullscreen-sm-down .modal-body { padding-bottom: calc(1rem + var(--safe-b)); }

/* Print */
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  body { background: #fff !important; }
  #print-area { display: block !important; color: #000; }
}
.receipt { font-family: 'Jameel Noori Nastaleeq', 'Courier New', monospace; color: #000; background: #fff; font-size: 12px; line-height: 1.3; margin: 0 auto; }
.receipt.w58 { width: 48mm; }
.receipt.w80 { width: 72mm; }
.receipt .c { text-align: center; }
.receipt .r { text-align: right; }
.receipt .b { font-weight: bold; }
.receipt .big { font-size: 15px; }
.receipt .ur { font-size: 1.6em; line-height: 1.7; unicode-bidi: plaintext; }
.receipt .c .ur, .receipt .r .ur { display: inline-block; }
.receipt hr { border: 0; border-top: 1px dashed #000; margin: 4px 0; opacity: 1; }
.receipt table { width: 100%; border-collapse: collapse; }
.receipt td { vertical-align: top; padding: 0; }
.print-report { color: #000; font-size: 11px; }
.print-report h2 { font-size: 16px; margin: 0 0 4px; }
.print-report table { width: 100%; border-collapse: collapse; }
.print-report th, .print-report td { border: 1px solid #999; padding: 3px 5px; }
.print-report td.num, .print-report th.num { text-align: right; }
.receipt-preview { background: #fff; padding: 12px 6px; border-radius: 8px; border: 1px solid var(--bs-border-color); overflow-x: auto; }

/* Settings page rows */
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--bs-border-color-translucent); }
.settings-row:last-child { border-bottom: 0; }
.settings-label { font-size: .875rem; flex: 0 0 140px; color: var(--bs-body-color); }
.settings-value { flex: 1; min-width: 0; }

/* Section header in list cards */
.list-section-header { padding: 6px 12px; font-size: .73rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--bs-secondary-color); background: var(--bs-secondary-bg); border-bottom: 1px solid var(--bs-border-color-translucent); }

/* Pregnancy progress bar */
.pregnancy-bar .progress-bar { transition: width .4s ease; }

/* Detail page tabs */
.detail-tabs { border-bottom: 1px solid var(--bs-border-color-translucent); }
.detail-tabs .nav-link { border: 0; border-bottom: 2px solid transparent; padding: 8px 14px; color: var(--bs-secondary-color); font-size: .85rem; }
.detail-tabs .nav-link.active { border-bottom-color: var(--bs-primary); color: var(--bs-primary); font-weight: 600; background: none; }

/* Report tabs */
.rpt-tab { font-size: .78rem; padding: 5px 10px; }

/* Text pink for female icon */
.text-pink { color: #e91e63; }
