/* Dhivehi fonts from the device: Faruma / MV Faseyha for normal text, MV Waheed for bold.
   Noto Sans Thaana (Google Fonts) is the fallback on devices without them, e.g. phones.
   unicode-range keeps these fonts to Thaana + Arabic punctuation, so digits and Latin text
   use the system font (Faruma's own digits are italic and it draws ',' as '،'). */
@font-face {
  font-family: 'DV';
  font-weight: 100 500;
  src: local('Faruma'), local('MV Faruma'), local('MV Faseyha'), local('MVFaseyha'), local('A_Faseyha');
  unicode-range: U+0780-07BF, U+060C, U+061B, U+061F, U+FDF2;
}
@font-face {
  font-family: 'DV';
  font-weight: 600 900;
  src: local('MV Waheed'), local('MVWaheed'), local('A_Waheed'), local('Waheed');
  unicode-range: U+0780-07BF, U+060C, U+061B, U+061F, U+FDF2;
}

:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #fcfcfb;
  --surface-2: #efebe1;
  --border: #ddd6c6;
  --text: #22251f;
  --text-2: #565b4f;
  --muted: #7d8275;
  --brand: #2f6b3a;
  --brand-ink: #ffffff;
  --brand-soft: #e1eedc;
  --series-income: #2a78d6;
  --series-expense: #eb6834;
  --good: #0f7a35;
  --good-soft: #dcf0e2;
  --warn: #9a6200;
  --warn-soft: #fbefd2;
  --bad: #c0352b;
  --bad-soft: #fbe1de;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 2px 8px rgb(0 0 0 / .05);
  --radius: 14px;
  --font: 'DV', 'Noto Sans Thaana', system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121311;
    --surface: #1a1a19;
    --surface-2: #242522;
    --border: #34362f;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f9186;
    --brand: #5aa66a;
    --brand-ink: #0d140e;
    --brand-soft: #1f3324;
    --series-income: #3987e5;
    --series-expense: #d95926;
    --good: #5cc07c;
    --good-soft: #17301f;
    --warn: #e2a63b;
    --warn-soft: #34290f;
    --bad: #f0776c;
    --bad-soft: #3a1c19;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121311;
  --surface: #1a1a19;
  --surface-2: #242522;
  --border: #34362f;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #8f9186;
  --brand: #5aa66a;
  --brand-ink: #0d140e;
  --brand-soft: #1f3324;
  --series-income: #3987e5;
  --series-expense: #d95926;
  --good: #5cc07c;
  --good-soft: #17301f;
  --warn: #e2a63b;
  --warn-soft: #34290f;
  --bad: #f0776c;
  --bad-soft: #3a1c19;
  --shadow: 0 1px 2px rgb(0 0 0 / .4);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-tap-highlight-color: transparent; }
button, a, label, select, .row, .chip { touch-action: manipulation; }
.tabs, .topbar, .btn, .chip { -webkit-user-select: none; user-select: none; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.9;
}
button, input, select, textarea { font: inherit; color: inherit; }
bdi, .num { font-variant-numeric: tabular-nums; }
.num { direction: ltr; unicode-bidi: isolate; display: inline-block; }
h1, h2, h3 { line-height: 1.5; margin: 0; }
a { color: var(--brand); }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--brand); color: var(--brand-ink);
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  padding-inline: calc(16px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-left));
  display: flex; align-items: center; gap: 12px;
}
.topbar .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; text-decoration: none; color: inherit; white-space: nowrap; flex-shrink: 0; }
@media (max-width: 420px) { .topbar { gap: 6px; padding-inline: 10px; } .topbar .brand span { font-size: 16px; } }
.topbar .brand img { width: 30px; height: 30px; border-radius: 8px; background: #fff2; }
.topbar .farm-switch {
  margin-inline-start: auto;
  background: rgb(255 255 255 / .16); border: 0; border-radius: 999px;
  color: inherit; padding: 4px 14px; cursor: pointer; max-width: 46vw;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .icon-btn { background: transparent; border: 0; color: inherit; cursor: pointer; padding: 6px; border-radius: 8px; font-size: 14px; }
.topbar .icon-btn:hover, .topbar .farm-switch:hover { background: rgb(255 255 255 / .24); }
.install-btn { font-size: 13px !important; background: rgb(255 255 255 / .2) !important; font-weight: 700; }
.kbd-toggle { font-size: 13px !important; border: 1px solid rgb(255 255 255 / .4) !important; padding: 2px 8px !important; }

main { max-width: 960px; margin: 0 auto; padding: 16px 16px 110px; }

.tabs {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 0;
  padding: 8px 2px 6px; text-decoration: none; color: var(--muted); font-size: 12.5px;
}
.tabs a .ico { font-size: 20px; line-height: 1.3; }
.tabs a.active { color: var(--brand); font-weight: 700; }
@media (min-width: 760px) {
  .tabs {
    position: sticky; top: 50px; bottom: auto; border-top: 0; border-bottom: 1px solid var(--border);
    display: flex; justify-content: center; gap: 4px; padding: 6px;
  }
  .tabs a { flex-direction: row; gap: 6px; padding: 6px 16px; border-radius: 999px; font-size: 15px; }
  .tabs a .ico { font-size: 16px; }
  .tabs a.active { background: var(--brand-soft); }
  main { padding-bottom: 40px; }
}

.page-head { display: flex; align-items: center; gap: 12px; margin: 4px 0 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head .spacer { flex: 1; }

/* ---------- Components ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.card + .card, .section + .section { margin-top: 16px; }
.section-title { font-size: 17px; font-weight: 700; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.section-title .count { color: var(--muted); font-weight: 400; font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 10px; padding: 7px 16px; cursor: pointer;
  background: var(--surface-2); color: var(--text); font-weight: 600; text-decoration: none;
  min-height: 42px;
}
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.small { min-height: 34px; padding: 3px 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }
:focus-visible { outline: 3px solid var(--series-income); outline-offset: 2px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 760px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat .label { color: var(--text-2); font-size: 14px; }
.stat .value { font-size: 22px; font-weight: 700; line-height: 1.6; }
.stat .sub { color: var(--muted); font-size: 13px; }
.value.pos { color: var(--good); }
.value.neg { color: var(--bad); }

.list { display: flex; flex-direction: column; gap: 10px; }
.row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 14px; cursor: pointer; text-align: start; width: 100%;
}
.row:hover { border-color: var(--brand); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .meta { color: var(--muted); font-size: 13.5px; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.row .amount { font-weight: 700; white-space: nowrap; }
.row .amount.inc { color: var(--good); }
.row .amount.exp { color: var(--text); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 0 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.badge.growing { background: var(--good-soft); color: var(--good); }
.badge.harvested { background: var(--surface-2); color: var(--text-2); }
.badge.failed { background: var(--bad-soft); color: var(--bad); }
.badge.overdue { background: var(--bad-soft); color: var(--bad); }
.badge.today { background: var(--warn-soft); color: var(--warn); }
.badge.soon { background: var(--brand-soft); color: var(--brand); }
.badge.done { background: var(--surface-2); color: var(--muted); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 2px 14px; cursor: pointer; font-size: 14px; }
.chip.active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.filters label { display: flex; flex-direction: column; font-size: 13px; color: var(--text-2); }
.filters input, .filters select { min-height: 40px; }
.total-bar { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-radius: 12px; background: var(--brand-soft); margin-bottom: 12px; font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 32px 16px; border: 2px dashed var(--border); border-radius: var(--radius); }
.empty .big { font-size: 40px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; }
.field > span { font-size: 14px; color: var(--text-2); font-weight: 600; }
.field .hint { font-size: 12.5px; color: var(--muted); font-weight: 400; }
.field .req { color: var(--bad); }
input, select, textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); padding: 7px 12px; min-height: 44px;
}
textarea { min-height: 76px; resize: vertical; }
input[type="date"], input[type="month"], input[type="number"], input.ltr { direction: ltr; text-align: right; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-error { background: var(--bad-soft); color: var(--bad); padding: 6px 12px; border-radius: 10px; margin-bottom: 12px; font-size: 14px; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }
.form-actions .spacer { flex: 1; }

dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(520px, calc(100vw - 24px));
  background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgb(0 0 0 / .3);
  max-height: calc(100dvh - 24px);
}
dialog::backdrop { background: rgb(10 15 10 / .5); }
dialog .dlg-head { display: flex; align-items: center; padding: 14px 18px 6px; }
dialog .dlg-head h2 { font-size: 19px; flex: 1; }
dialog .dlg-close { background: none; border: 0; font-size: 24px; cursor: pointer; color: var(--muted); line-height: 1; padding: 4px 8px; }
dialog form { padding: 8px 18px 18px; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: min(420px, 100%); }
.auth-logo { text-align: center; margin-bottom: 16px; }
.auth-logo img { width: 64px; height: 64px; }
.auth-logo h1 { font-size: 26px; color: var(--brand); }
.auth-logo p { color: var(--text-2); margin: 0; }
.auth-switch { text-align: center; margin-top: 12px; font-size: 14px; }
.link-btn { background: none; border: 0; color: var(--brand); cursor: pointer; font-weight: 600; text-decoration: underline; padding: 0; }

/* ---------- Farms ---------- */
.farm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.farm-card { cursor: pointer; display: flex; flex-direction: column; gap: 4px; text-align: start; }
.farm-card:hover { border-color: var(--brand); }
.farm-card h3 { font-size: 18px; display: flex; align-items: center; gap: 8px; }
.farm-logo { width: 32px; height: 32px; object-fit: contain; border-radius: 6px; flex: none; }
.farm-card .meta { color: var(--muted); font-size: 14px; }
.farm-card .actions { display: flex; gap: 8px; margin-top: 8px; }

/* ---------- Fertilization ---------- */
.fert { display: flex; align-items: center; gap: 12px; }
.fert .main { flex: 1; min-width: 0; cursor: pointer; }
@media (max-width: 559px) {
  .fert { flex-wrap: wrap; gap: 8px; }
  .fert .main { flex-basis: 100%; }
  .fert .badge { margin-inline-end: auto; }
}

/* ---------- Chart ---------- */
.chart-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.legend { display: flex; gap: 14px; font-size: 13.5px; color: var(--text-2); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; margin-inline-end: 4px; }
.chart { position: relative; height: 200px; display: flex; align-items: stretch; gap: 4px; padding-top: 6px; }
.chart .grid { position: absolute; inset: 6px 0 26px 0; pointer-events: none; }
.chart .grid div { position: absolute; inset-inline: 0; border-top: 1px solid var(--border); }
.chart .grid span { position: absolute; inset-inline-end: 0; top: -18px; font-size: 11px; color: var(--muted); direction: ltr; }
.chart .col { flex: 1; display: flex; flex-direction: column; position: relative; cursor: default; border-radius: 6px; z-index: 1; }
.chart .col:hover, .chart .col:focus-visible { background: rgb(127 127 127 / .08); }
.chart .bars { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 2px; border-bottom: 1px solid var(--text-2); }
.chart .bar { width: min(22px, 38%); border-radius: 4px 4px 0 0; min-height: 0; }
.chart .bar.inc { background: var(--series-income); }
.chart .bar.exp { background: var(--series-expense); }
.chart .xlabel { height: 26px; text-align: center; font-size: 12px; color: var(--muted); line-height: 26px; white-space: nowrap; }
.tooltip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 150px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 4px 16px rgb(0 0 0 / .15); padding: 6px 10px; font-size: 13.5px; line-height: 1.8;
}
.tooltip .t { font-weight: 700; }
.tooltip .r { display: flex; justify-content: space-between; gap: 12px; }
.tooltip i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-inline-end: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th, td { text-align: start; padding: 6px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--text-2); font-weight: 600; font-size: 13.5px; }
td.n, th.n { text-align: end; white-space: nowrap; }
.table-scroll { overflow-x: auto; }

.hbar { display: grid; grid-template-columns: 110px 1fr auto; gap: 10px; align-items: center; font-size: 14px; margin-bottom: 6px; }
.hbar .track { height: 12px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--series-expense); border-radius: 4px; }

.two-col { display: grid; gap: 16px; }
.two-col > * { min-width: 0; }
@media (min-width: 760px) { .two-col { grid-template-columns: 1fr 1fr; } }

#toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 8px 18px; border-radius: 999px;
  opacity: 0; transition: .2s; pointer-events: none; z-index: 100; font-size: 14.5px;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.loading { text-align: center; color: var(--muted); padding: 40px; }

.calc { margin: -4px 0 12px; padding: 6px 12px; border-radius: 10px; background: var(--brand-soft); font-size: 14.5px; }

/* ---------- Rufiyaa sign (U+20C2) ----------
   No common font has U+20C2 yet, so the sign is drawn from the bundled MVR Currency font (MMA design),
   which has it at U+E900. The real U+20C2 stays in the page, visually hidden, for copy/paste. */
@font-face {
  font-family: 'MVRSign';
  src: url('fonts/MVR-Currency.ttf') format('truetype');
  font-display: block; /* never flash a missing-glyph box */
}
.mvr { position: relative; display: inline-block; }
.mvr-g { font: 400 1em/1 'MVRSign'; }
.mvr-g::before { content: '\E900'; }
.mvr-t {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

/* Left-to-right box so the sign sits on the left of the amount, even inside RTL text */
.money { direction: ltr; unicode-bidi: isolate; display: inline-block; white-space: nowrap; }

/* ---------- Payment status & customers ---------- */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
@media (max-width: 480px) { .seg { grid-template-columns: 1fr; } }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span {
  display: flex; align-items: center; justify-content: center; text-align: center; height: 100%;
  min-height: 44px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); font-size: 14px; line-height: 1.5;
}
.seg input:checked + span { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.seg input:focus-visible + span { outline: 3px solid var(--series-income); outline-offset: 2px; }
.badge.pay-cash { background: var(--good-soft); color: var(--good); }
.badge.pay-transfer { background: var(--brand-soft); color: var(--brand); }
.badge.pay-credit { background: var(--warn-soft); color: var(--warn); }
.owed { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; white-space: nowrap; }
.receivable { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; border-color: var(--warn); background: var(--warn-soft); }
.receivable .big { font-size: 28px; }
.receivable .main { flex: 1; display: flex; flex-direction: column; }
.receivable .label { font-weight: 700; }
.receivable .sub { color: var(--text-2); font-size: 13.5px; }
.receivable .value { font-size: 20px; white-space: nowrap; }

/* ---------- Invoice ---------- */
.notice { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; margin-bottom: 12px;
  border-radius: 12px; background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.invoice {
  position: relative; overflow: hidden; max-width: 760px; margin: 0 auto; padding: 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
@media (max-width: 480px) { .invoice { padding: 16px 12px; } }
.inv-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px 24px; flex-wrap: wrap;
  padding-bottom: 12px; border-bottom: 3px solid var(--brand); }
.inv-farm { font-size: 22px; color: var(--brand); }
.inv-from { display: flex; align-items: center; gap: 14px; }
.inv-logo { width: 72px; height: 72px; object-fit: contain; flex: none; }
.inv-meta { display: flex; flex-wrap: wrap; gap: 2px 14px; color: var(--text-2); font-size: 14px; }
.inv-title { text-align: end; font-size: 14px; }
.inv-title h2 { font-size: 28px; color: var(--brand); }
.inv-to { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin: 16px 0 12px; }
.inv-table th { background: var(--surface-2); }
.inv-table td { padding: 10px 8px; }
.inv-total { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; padding: 10px 14px;
  border-radius: 10px; background: var(--brand-soft); font-size: 19px; font-weight: 700; }
.inv-pay { margin-top: 20px; padding: 12px 16px; border: 1.5px dashed var(--warn); border-radius: 10px;
  background: var(--warn-soft); line-height: 2.2; }
.inv-pay .acc { margin-top: 4px; }
.inv-notes { color: var(--text-2); margin: 16px 0 0; }
.inv-foot { margin-top: 24px; text-align: center; color: var(--muted); font-size: 14px; }
.stamp {
  margin: 20px auto 0; width: max-content; max-width: 100%; transform: rotate(-8deg);
  padding: 6px 22px; text-align: center; color: var(--good); border: 4px solid var(--good); border-radius: 14px;
  box-shadow: inset 0 0 0 3px var(--surface), inset 0 0 0 5px var(--good); opacity: .9; line-height: 1.6;
}
.stamp .big { font-size: 24px; font-weight: 700; }
.stamp .en { direction: ltr; font: 800 22px/1.2 system-ui, sans-serif; letter-spacing: 6px; }
.stamp .d { font-size: 13px; }
@media print {
  .invoice { border: 0; box-shadow: none; padding: 0; max-width: none; }
}

.pending td { white-space: nowrap; }
@media (max-width: 560px) { .pending td .muted { display: none; } .pending td, .pending th { padding-inline: 4px; } .pending table { font-size: 13px; } .pending .badge { padding: 0 6px; font-size: 12px; } }
.group-row td { background: var(--surface-2); font-weight: 700; }
.card.urgent { border: 2px solid var(--warn); }
/* Crop photos */
.photo-field { display: flex; gap: 12px; align-items: center; }
.photo-box { width: 96px; height: 96px; flex: none; border-radius: 12px; overflow: hidden; background: var(--surface-2);
  border: 1px solid var(--border); display: grid; place-items: center; }
.photo-box img { width: 100%; height: 100%; object-fit: cover; }
.logo-box { background: #fff; }
.logo-box img { object-fit: contain; }
.photo-empty { font-size: 30px; opacity: .5; }
.photo-side { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.photo-note { font-size: 13px; line-height: 1.6; }
.photo-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.cicon { width: 1.6em; height: 1.6em; border-radius: 50%; object-fit: cover; vertical-align: middle;
  border: 1px solid var(--border); background: var(--surface-2); }
.title .cicon { width: 1.9em; height: 1.9em; }
.thumb { width: 52px; height: 52px; flex: none; border-radius: 10px; object-fit: cover; background: var(--surface-2); }
.thumb-empty { display: grid; place-items: center; font-size: 22px; opacity: .6; }
.share-opts { display: flex; flex-direction: column; gap: 10px; padding: 8px 18px 20px; }

/* ---------- Dhivehi date picker ---------- */
.dp-btn {
  width: 100%; min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  padding: 7px 12px; cursor: pointer; text-align: start; white-space: nowrap;
}
.dp-btn:hover { border-color: var(--brand); }
.filters .dp-btn { min-width: 170px; min-height: 40px; }
.dp-ico { font-size: 14px; opacity: .7; }
.dp {
  position: fixed; z-index: 200; width: 300px; max-width: calc(100vw - 16px);
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 10px 30px rgb(0 0 0 / .2); padding: 10px;
}
.dp-head { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.dp-head select { min-height: 36px; padding: 2px 8px; flex: 1; }
.dp-head select[data-y] { flex: 0 0 84px; direction: ltr; }
.dp-nav { width: 36px; height: 36px; flex: none; border: 0; border-radius: 8px; background: var(--surface-2); cursor: pointer; font-size: 20px; line-height: 1; }
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.dp-wd { font-size: 11.5px; color: var(--muted); padding: 2px 0; }
.dp-months { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.dp-months .dp-day { aspect-ratio: auto; padding: 8px 2px; font-size: 14px; }
.dp-day {
  aspect-ratio: 1; border: 0; border-radius: 8px; background: transparent; cursor: pointer;
  font-variant-numeric: tabular-nums; font-size: 14.5px;
}
.dp-day:hover { background: var(--brand-soft); }
.dp-day.today { outline: 1.5px solid var(--brand); outline-offset: -1.5px; font-weight: 700; }
.dp-day.sel { background: var(--brand); color: var(--brand-ink); font-weight: 700; }
.dp-foot { display: flex; justify-content: space-between; margin-top: 8px; padding: 0 4px; }

/* ---------- Reports ---------- */
.muted { color: var(--muted); }
p.muted { margin: 0; }
.report-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 8px 16px; flex-wrap: wrap; }
.report-head h2 { font-size: 18px; }
.report-head .meta { color: var(--text-2); font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
tfoot th { border-top: 2px solid var(--text-2); border-bottom: 0; color: var(--text); font-weight: 700; }
.tabs { grid-template-columns: repeat(var(--n, 6), 1fr); }
.tabs a { white-space: nowrap; }
@media (max-width: 420px) { .tabs a { font-size: 11.5px; } }


/* =============================================================
   Added with accounts, multi-item sales, payments, crop pages, tasks, search, settings
   ============================================================= */
a.plain, .plain { color: inherit; text-decoration: none; }
a.row { text-decoration: none; color: inherit; }
.hijri { font-size: .82em; color: var(--muted); white-space: nowrap; }
.badge.role { background: var(--surface-2); color: var(--text-2); }
.value.small { font-size: 17px; line-height: 1.7; }
.muted.num { font-weight: 400; }

/* Phone top bar: logo only, icon-only install button, so the farm name has room */
@media (max-width: 480px) {
  .topbar .brand span, .install-btn .lbl { display: none; }
  .topbar { gap: 4px; }
  .topbar .farm-switch { max-width: none; flex: 1; min-width: 0; }
}

/* Two-column form rows never overflow; long dates (with Hijri) wrap */
.grid-2 > * { min-width: 0; }
.dp-btn { white-space: normal; line-height: 1.5; text-align: start; }
/* Left-to-right languages: number / code inputs follow the reading direction */
[dir="ltr"] input[type="number"], [dir="ltr"] input.ltr, [dir="ltr"] input[type="date"], [dir="ltr"] input[type="month"] { text-align: left; }

/* Toast with an action button (undo) */
#toast { display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 32px); }
#toast.has-action { pointer-events: auto; }
#toast button {
  background: transparent; border: 1px solid currentColor; color: inherit; border-radius: 999px;
  padding: 0 12px; cursor: pointer; font-weight: 700; white-space: nowrap; min-height: 32px;
}

/* Segmented radios: column variants */
.seg.cols-2 { grid-template-columns: repeat(2, 1fr); }
.seg.cols-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 480px) { .seg.cols-3 { grid-template-columns: repeat(2, 1fr); } .seg.cols-2 { grid-template-columns: repeat(2, 1fr); } }
.seg.mini span { min-height: 36px; padding: 2px 10px; }

/* Sale items editor */
.items { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.item-row { border: 1px solid var(--border); border-radius: 12px; padding: 10px; background: var(--surface-2); display: flex; flex-direction: column; gap: 8px; }
.item-top { display: flex; gap: 8px; align-items: center; }
.item-top select { flex: 1; }
.item-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 560px) { .item-grid { grid-template-columns: repeat(2, 1fr); } }
.item-grid label { display: flex; flex-direction: column; font-size: 12.5px; color: var(--text-2); }
.item-grid input { min-height: 40px; padding: 4px 8px; }
.item-del { width: 34px; height: 34px; flex: none; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--bad); font-size: 20px; line-height: 1; cursor: pointer; }

/* Payments on a sale */
.payments { border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px; margin-bottom: 12px; background: var(--surface-2); }
.pay-head { font-weight: 700; margin-bottom: 4px; }
.pay-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; font-size: 14.5px; padding: 3px 0; }
.pay-row span:first-child { flex: 1; }
.pay-row.total { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 6px; }
.inv-paid { margin-top: 8px; padding: 0 14px; }
.inv-paid > div { display: flex; justify-content: space-between; padding: 4px 0; color: var(--text-2); }
.inv-paid .bal { color: var(--warn); font-weight: 700; font-size: 18px; }

/* Crop page */
.crop-head { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.crop-photo { width: 140px; height: 140px; border-radius: 14px; object-fit: cover; flex: none; cursor: zoom-in; background: var(--surface-2); }
.crop-photo.empty { display: grid; place-items: center; font-size: 56px; cursor: default; }
.crop-info { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: 6px; }
.crop-info h1 { font-size: 22px; }
.crop-info .meta { color: var(--muted); font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.crop-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
@media (max-width: 480px) { .crop-photo { width: 100%; height: 200px; } }

/* Field notes timeline */
.timeline { display: flex; flex-direction: column; gap: 10px; }
.note { border-inline-start: 3px solid var(--brand); padding: 6px 12px; background: var(--surface-2); border-radius: 0 10px 10px 0; cursor: pointer; }
[dir="rtl"] .note { border-radius: 10px 0 0 10px; }
.note-date { font-size: 13px; color: var(--text-2); }
.note-text { white-space: pre-wrap; margin: 2px 0; }
.note-photo { display: block; max-width: 220px; max-height: 160px; border-radius: 10px; object-fit: cover; margin-top: 6px; cursor: zoom-in; }
.photo-view img { display: block; max-width: 100%; max-height: 75dvh; margin: 0 auto 16px; border-radius: 10px; }
.photo-view { padding: 0 16px; }
.photo-warn { font-size: 12.5px; color: var(--warn); line-height: 1.6; }

/* Season comparison */
.season-name { font-size: 16px; margin: 14px 0 4px; }
tr.current td { background: var(--brand-soft); font-weight: 600; }
.up { color: var(--good); font-size: 12.5px; white-space: nowrap; }
.down { color: var(--bad); font-size: 12.5px; white-space: nowrap; }

/* Quick add (favourites / recent expenses) */
.quickbar { margin-bottom: 12px; }
.qtitle { font-size: 13px; margin-bottom: 4px; }
.qchips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.qchip { display: inline-flex; align-items: stretch; flex: none; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); overflow: hidden; }
.qchip.fav { border-color: var(--warn); background: var(--warn-soft); }
.qchip button { background: none; border: 0; padding: 4px 12px; cursor: pointer; white-space: nowrap; font-size: 14px; color: inherit; }
.qchip .x { padding: 0 10px; color: var(--muted); border-inline-start: 1px solid var(--border); font-size: 16px; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; }
.more-btn { margin-top: 10px; }
.chips.mini .chip { padding: 0 10px; font-size: 13px; }
.chart-sum { font-size: 13.5px; margin-top: 6px; }

/* Accounts, settings */
.code-box { font: 700 24px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 2px; text-align: center;
  padding: 12px; border: 2px dashed var(--brand); border-radius: 12px; background: var(--brand-soft); margin: 8px 0 12px; user-select: all; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; min-height: 0; flex: none; }
.auth-lang { text-align: center; margin-top: 10px; }
.settings { display: flex; flex-direction: column; gap: 14px; max-width: 640px; }
.settings .card + .card { margin-top: 0; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.set-row:first-of-type { border-top: 0; }
.set-row.check { margin: 0; }
.help { font-size: 14px; line-height: 2; }
.search-box input { font-size: 17px; min-height: 50px; }
a.notice { color: var(--warn); }

@media print {
  :root, :root:not([data-theme="light"]), :root[data-theme="dark"] {
    color-scheme: light;
    --bg: #fff; --surface: #fff; --surface-2: #f1f1ef; --border: #cfcfc9;
    --text: #000; --text-2: #333; --muted: #555;
    --good: #0b6b2e; --bad: #b0281f; --brand: #2f6b3a; --brand-soft: #e6efe3;
    --good-soft: #e3f1e7; --bad-soft: #f8e2df; --warn-soft: #f8edd3; --shadow: none;
  }
  @page { margin: 14mm; }
  body { font-size: 12.5px; }
  .topbar, .tabs, .no-print, #toast { display: none !important; }
  main { max-width: none; padding: 0; }
  .card, .stat { box-shadow: none; break-inside: avoid; padding: 10px 12px; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .two-col { grid-template-columns: 1fr 1fr; }
  .table-scroll { overflow: visible; }
  tr { break-inside: avoid; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
