:root {
  --green-900: #0b3d2e;
  --green-800: #10513c;
  --green-700: #14684a;
  --green-500: #1f8f63;
  --green-100: #e3f1ea;
  --lime: #7bc043;
  --amber: #e99a0b;
  --amber-100: #fdf1d8;
  --red: #cc3b3b;
  --red-100: #fbe6e6;
  --blue: #2b6cb0;
  --blue-100: #e6effa;
  --bg: #f2f5f2;
  --card: #ffffff;
  --line: #e2e8e3;
  --text: #15241c;
  --muted: #6a7d72;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 40, 30, .06), 0 8px 24px -12px rgba(16, 40, 30, .18);
  --shadow-lg: 0 20px 50px -20px rgba(16, 40, 30, .35);
  --font: "Segoe UI", "Noto Kufi Arabic", "Cairo", Tahoma, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--green-700); text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.35; font-weight: 700; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0; }

/* ---------- layout ---------- */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: linear-gradient(135deg, var(--green-900), var(--green-700));
  color: #fff;
  padding: 12px 16px calc(12px + env(safe-area-inset-top, 0px));
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  display: flex; align-items: center; gap: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,.12);
}
.topbar-inner { display: flex; align-items: center; gap: 12px; width: 100%; max-width: 1080px; margin: 0 auto; }
.topbar .brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo-img { border-radius: 11px; display: block; }
.auth-logo { display: block; margin: 0 auto 12px; border-radius: 18px; }
.ic { display: inline-block; vertical-align: -4px; flex: 0 0 auto; }
.empty-ico { display: inline-flex; color: var(--green-500); margin-bottom: 8px; }
.topbar .logo {
  width: 38px; height: 38px; border-radius: 12px; flex: 0 0 auto;
  background: rgba(255,255,255,.15); display: grid; place-items: center; font-size: 20px;
}
.topbar .titles { min-width: 0; }
.topbar .farm { font-weight: 700; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { font-size: .78rem; opacity: .85; }
.topbar .spacer { flex: 1; }
.topbar .icon-btn {
  background: rgba(255,255,255,.14); border: 0; color: #fff; width: 38px; height: 38px;
  border-radius: 12px; display: grid; place-items: center; cursor: pointer; font-size: 18px;
}
.topbar .icon-btn:hover { background: rgba(255,255,255,.24); }

.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 16px 14px 96px; }
.page-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.tiny { font-size: .74rem; }
.center { text-align: center; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); border: 1px solid var(--line);
}
.card + .card { margin-top: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2 { font-size: 1.02rem; }
.card-tight { padding: 12px; }

/* ---------- KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
@media (min-width: 720px) { .kpi-grid { grid-template-columns: repeat(4, minmax(0,1fr)); } }
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px; box-shadow: var(--shadow); min-width: 0;
}
.kpi .label { font-size: .78rem; color: var(--muted); margin-bottom: 2px; }
.kpi .value { font-size: 1.32rem; font-weight: 700; letter-spacing: -.5px; }
.kpi .value small { font-size: .72rem; font-weight: 600; color: var(--muted); margin-inline-start: 3px; }
.kpi .foot { font-size: .74rem; color: var(--muted); margin-top: 2px; }
.kpi.good .value { color: var(--green-700); }
.kpi.warn .value { color: var(--amber); }
.kpi.bad .value { color: var(--red); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 12px; padding: 10px 16px;
  background: var(--green-700); color: #fff; font-weight: 600; cursor: pointer;
  transition: filter .15s, transform .05s; min-height: 42px;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--green-700); border-color: var(--line); }
.btn.ghost:hover { background: var(--green-100); }
.btn.light { background: #fff; color: var(--green-800); border-color: var(--line); }
.btn.danger { background: var(--red); }
.btn.sm { padding: 6px 10px; min-height: 34px; font-size: .85rem; border-radius: 10px; }
.btn.block { width: 100%; }
.btn.link { background: none; border: 0; color: var(--green-700); padding: 4px; min-height: 0; text-decoration: underline; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #fff;
  width: 100%; min-height: 44px; transition: border-color .15s, box-shadow .15s;
}
.field textarea { min-height: 72px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--green-500); box-shadow: 0 0 0 3px rgba(31,143,99,.15);
}
.field .hint { font-size: .75rem; color: var(--muted); }
.field.invalid input { border-color: var(--red); }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid .full { grid-column: 1 / -1; } }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: 20px; height: 20px; min-height: 0; }

/* ---------- badges & pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: .74rem; font-weight: 700;
  padding: 3px 9px; border-radius: 999px; background: var(--green-100); color: var(--green-800);
}
.badge.demo { background: var(--amber-100); color: #8a5b00; }
.badge.sold { background: #eef1ef; color: var(--muted); }
.badge.danger { background: var(--red-100); color: var(--red); }
.badge.warn { background: var(--amber-100); color: #8a5b00; }
.badge.info { background: var(--blue-100); color: var(--blue); }

/* ---------- alerts ---------- */
.alert-list { display: flex; flex-direction: column; gap: 8px; }
.alert {
  display: flex; gap: 10px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: #fbfcfb; align-items: flex-start;
}
.alert .dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 7px; flex: 0 0 auto; background: var(--muted); }
.alert.danger { background: var(--red-100); border-color: #f3cccc; }
.alert.danger .dot { background: var(--red); }
.alert.warning { background: var(--amber-100); border-color: #f6e2b8; }
.alert.warning .dot { background: var(--amber); }
.alert.info { background: var(--blue-100); border-color: #cfe0f3; }
.alert.info .dot { background: var(--blue); }
.alert .title { font-weight: 600; font-size: .92rem; }
.alert .detail { font-size: .8rem; color: var(--muted); }

/* ---------- batch cards ---------- */
.batch-card { display: block; }
.batch-card .name { font-weight: 700; font-size: 1.05rem; }
.batch-card .meta { font-size: .8rem; color: var(--muted); }
.batch-card .mini-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 12px; }
.batch-card .mini-kpis div { background: #f7f9f7; border-radius: 10px; padding: 6px 8px; }
.batch-card .mini-kpis .k { font-size: .7rem; color: var(--muted); }
.batch-card .mini-kpis .v { font-weight: 700; font-size: .92rem; }

/* ---------- tabs ---------- */
.tabs {
  display: flex; gap: 6px; overflow-x: auto; padding: 4px; background: #e9eeea;
  border-radius: 14px; margin-bottom: 14px; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
@media (max-width: 640px) {
  .tabs { flex-wrap: wrap; overflow: visible; }
  .tab { flex: 1 0 auto; padding: 7px 10px; font-size: .85rem; }
}
.tab {
  border: 0; background: transparent; padding: 8px 14px; border-radius: 10px; cursor: pointer;
  font-weight: 600; color: var(--muted); white-space: nowrap;
}
.tab.active { background: #fff; color: var(--green-800); box-shadow: var(--shadow); }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .86rem; }
table.data th, table.data td { padding: 7px 8px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th { font-size: .76rem; color: var(--muted); font-weight: 700; background: #f8faf8; position: sticky; top: 0; }
table.data tbody tr:hover { background: #f7faf8; }
table.data td.num { font-variant-numeric: tabular-nums; }

/* ---------- charts ---------- */
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .78rem; color: var(--muted); margin-top: 6px; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 5px; }
.chart-empty { padding: 28px 12px; text-align: center; color: var(--muted); font-size: .85rem; background: #f8faf8; border-radius: 12px; }

/* ---------- nav (mobile bottom) ---------- */
.nav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 40;
  background: rgba(255,255,255,.96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  display: flex; padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px; color: var(--muted); font-size: .72rem; border-radius: 10px;
}
.nav a .ico { font-size: 19px; line-height: 1; }
.nav a.active { color: var(--green-700); background: var(--green-100); font-weight: 700; }
@media (min-width: 900px) {
  .nav { position: static; border: 0; background: transparent; justify-content: center; gap: 6px; padding: 0; margin: 0 auto 4px; max-width: 1080px; }
  .nav a { flex: 0 0 auto; flex-direction: row; gap: 8px; padding: 8px 16px; font-size: .88rem; }
}

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(12, 26, 19, .45); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
  animation: fade .15s ease-out;
}
@media (min-width: 640px) { .modal-backdrop { align-items: center; padding: 20px; } }
.modal {
  background: #fff; width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  box-shadow: var(--shadow-lg); animation: slideup .18s ease-out;
}
@media (min-width: 640px) { .modal { border-radius: 20px; padding: 20px; } }
.modal h2 { margin-bottom: 14px; }
.modal .actions { display: flex; gap: 8px; margin-top: 16px; }
.modal .actions .btn { flex: 1; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideup { from { transform: translateY(16px); opacity: .6 } to { transform: none; opacity: 1 } }

/* ---------- toast ---------- */
.toast-root { position: fixed; inset-inline: 0; bottom: calc(72px + env(safe-area-inset-bottom, 0px)); z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: #17352a; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: .88rem;
  box-shadow: var(--shadow-lg); max-width: 90vw; animation: fade .15s;
}
.toast.error { background: #8d2323; }
@media (min-width: 900px) { .toast-root { bottom: 24px; } }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(circle at 20% 10%, #1c7a58 0%, #0b3d2e 45%, #082a20 100%); }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: 22px; padding: 26px 22px; box-shadow: var(--shadow-lg); }
.auth-card .logo { width: 56px; height: 56px; border-radius: 18px; background: var(--green-100); display: grid; place-items: center; font-size: 28px; margin: 0 auto 12px; }
.auth-tabs { display: flex; background: #eef2ef; border-radius: 12px; padding: 4px; margin: 16px 0; }
.auth-tabs button { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 9px; font-weight: 700; color: var(--muted); cursor: pointer; }
.auth-tabs button.active { background: #fff; color: var(--green-800); box-shadow: var(--shadow); }
.form-error { background: var(--red-100); color: #8d2323; border-radius: 10px; padding: 9px 12px; font-size: .85rem; margin-bottom: 12px; }

/* ---------- misc ---------- */
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty .big { font-size: 34px; margin-bottom: 8px; }
.rgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 10px 0 4px; }
@media (min-width: 720px) { .rgrid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.rgrid-item { background: #f7faf8; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.rgrid-item .k { font-size: .72rem; color: var(--muted); }
.rgrid-item .v { font-weight: 700; font-size: .95rem; }
@media (max-width: 640px) { .hide-sm { display: none !important; } }
.section-title { font-size: .82rem; font-weight: 700; color: var(--muted); margin: 18px 2px 8px; }
.divider { height: 1px; background: var(--line); margin: 14px 0; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.task-row { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.task-row:last-child { border-bottom: 0; }
.task-row .tick { width: 38px; height: 38px; border-radius: 50%; border: 1.5px solid var(--line); background: #fff; color: var(--muted); display: grid; place-items: center; cursor: pointer; padding: 0; }
.task-row .tick.done { background: var(--green-100); border-color: var(--green-500); color: var(--green-700); }
.task-row .body { min-width: 0; }
.task-row .body .nm { font-weight: 600; overflow-wrap: anywhere; }
.task-row .side { display: flex; align-items: center; gap: 6px; }
.list-row .grow { flex: 1; min-width: 0; }
.pill-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.pill-toggle button { border: 0; background: #fff; padding: 6px 12px; font-size: .82rem; cursor: pointer; color: var(--muted); }
.pill-toggle button.active { background: var(--green-100); color: var(--green-800); font-weight: 700; }
.ai-box { white-space: pre-wrap; line-height: 1.9; font-size: .93rem; background: #f7faf8; border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.ai-box.loading { color: var(--muted); }
.progress { height: 8px; background: #e9eeea; border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--green-500), var(--lime)); border-radius: 999px; }
.sale-hero { background: linear-gradient(135deg, var(--green-800), var(--green-500)); color: #fff; border-radius: var(--radius); padding: 16px; }
.sale-hero .big { font-size: 1.5rem; font-weight: 800; letter-spacing: -.5px; }
.sale-hero .lbl { font-size: .8rem; opacity: .85; }
.sale-hero .row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.sale-hero .row3 div { background: rgba(255,255,255,.14); border-radius: 10px; padding: 8px; }
.sale-hero .row3 .v { font-weight: 700; font-size: 1rem; }
.sale-hero .row3 .k { font-size: .7rem; opacity: .85; }

/* ---------- report ---------- */
.report { background: #fff; }
.report-head { display: flex; justify-content: space-between; gap: 12px; border-bottom: 2px solid var(--green-700); padding-bottom: 10px; margin-bottom: 14px; }
.report table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.report table th, .report table td { padding: 7px 9px; border-bottom: 1px solid var(--line); text-align: right; }
.report h3 { margin: 16px 0 8px; font-size: .95rem; color: var(--green-800); }

@media print {
  body { background: #fff; font-size: 12px; }
  .topbar, .nav, .tabs, .no-print, .toast-root { display: none !important; }
  .container { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  .report .card { border: 0; padding: 0; }
  a { color: inherit; text-decoration: none; }
}
