:root {
  --font: 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  --bg: #f4f6f5; --card: #ffffff; --ink: #14201d; --muted: #5d6b67; --line: #dfe5e3;
  --brand: #0f766e; --brand-ink: #ffffff; --brand-soft: #e3f2ef;
  --danger: #b42318; --warn-bg: #fff4d6; --warn-ink: #6b4a00; --ok: #0a7a3f;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1514; --card: #18201e; --ink: #e8efec; --muted: #9aaaa5; --line: #2a3532;
    --brand: #2bb5a6; --brand-ink: #06201c; --brand-soft: #17302c;
    --danger: #ff8a7a; --warn-bg: #3a2f10; --warn-ink: #ffd98a; --ok: #58d38f;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.6 var(--font); }
#app { max-width: 1100px; margin: 0 auto; padding: 0 12px calc(28px + env(safe-area-inset-bottom)); }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 1.4rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
p { margin: 0; }
small { color: var(--muted); font-weight: 400; }
.muted { color: var(--muted); font-size: .9rem; }
.center { text-align: center; }
.err { color: var(--danger); }
.loading { text-align: center; color: var(--muted); padding: 48px 0; }
.grow { flex: 1; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.banner { background: var(--warn-bg); color: var(--warn-ink); padding: 8px 12px; border-radius: 0 0 var(--radius) var(--radius); font-size: .88rem; text-align: center; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 2px; }
.brand, .who { display: flex; align-items: center; gap: 8px; }
.who span { color: var(--muted); font-size: .9rem; }
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 2px; margin-bottom: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); scrollbar-width: none; }
.tabs a { flex: 1 0 auto; text-align: center; padding: 8px 14px; border-radius: 10px; color: var(--muted); text-decoration: none; font-weight: 500; white-space: nowrap; }
.tabs a.on { background: var(--brand); color: var(--brand-ink); }
.badge { display: inline-block; min-width: 20px; margin-inline-start: 6px; padding: 0 6px; border-radius: 99px; background: #d97706; color: #fff; font-size: .75rem; line-height: 20px; }

main { display: grid; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-head b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }

label { display: grid; gap: 4px; font-size: .9rem; font-weight: 500; color: var(--muted); }
label.inline { display: flex; align-items: center; gap: 8px; }
label.check { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
input, select, textarea, button, .btn { font: inherit; color: var(--ink); }
input, select, textarea { width: 100%; min-height: 46px; padding: 9px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
input[type=checkbox] { width: 20px; min-height: 20px; height: 20px; padding: 0; accent-color: var(--brand); }
input[type=number] { text-align: left; font-variant-numeric: tabular-nums; font-size: 1.05rem; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, tr:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
textarea { resize: vertical; }
button, .btn { min-height: 44px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 500; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
button.big { min-height: 54px; font-size: 1.1rem; }
button.ghost, .btn.ghost { background: transparent; }
button.danger { color: var(--danger); border-color: transparent; }
button.add { border-style: dashed; color: var(--brand); width: 100%; }
button.del { min-height: 44px; width: 44px; padding: 0; font-size: 1.3rem; color: var(--muted); border-color: transparent; }

.grid2, .grid3, .grid4 { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.grid2.top { align-items: start; }
@media (min-width: 720px) { .grid3 { grid-template-columns: repeat(3, 1fr); } .grid4 { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 560px) { .grid2.top, .grid3, .grid4 { grid-template-columns: 1fr; } }

.login { max-width: 380px; margin: 12vh auto 0; text-align: center; justify-items: stretch; }
.login img { justify-self: center; }
.login label { text-align: start; }

.datebar { grid-template-columns: 1fr auto; align-items: end; }
.datebar .btn { grid-column: 1 / -1; }
@media (min-width: 720px) { .datebar { grid-template-columns: 220px 1fr auto; } .datebar .btn { grid-column: auto; } }
.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); font-size: .82rem; color: var(--muted); }
.pill.ok { color: var(--ok); border-color: currentColor; }

.lines { display: grid; gap: 8px; }
.line { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) 44px; gap: 6px; padding-bottom: 8px; border-bottom: 1px dashed var(--line); }
.line .note { grid-column: 1 / -1; min-height: 38px; font-size: .9rem; }
.line:last-child { border-bottom: 0; padding-bottom: 0; }

.photo-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.photo-actions select { width: auto; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.thumbs figure { margin: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--bg); }
.thumbs img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.thumbs figcaption { display: flex; align-items: center; justify-content: space-between; padding: 0 8px; font-size: .8rem; color: var(--muted); min-height: 30px; }
.thumbs .del { min-height: 30px; width: 30px; }

.sticky { position: sticky; bottom: calc(8px + env(safe-area-inset-bottom)); display: grid; z-index: 5; }
.sticky button { box-shadow: 0 6px 24px rgb(0 0 0 / .22); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 10px; }
.summary div { display: grid; }
.summary span { font-size: .75rem; color: var(--muted); }
.summary b { font-variant-numeric: tabular-nums; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 720px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; display: grid; }
.stat span { font-size: .82rem; color: var(--muted); }
.stat b { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.stat.accent { background: var(--brand-soft); border-color: transparent; }
.stat.accent b { color: var(--brand); }

.monthbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.monthbar input[type=month] { width: auto; }
.monthbar select { width: auto; }
.card-head select { width: auto; max-width: 60%; }

.scroll { overflow-x: auto; }
table.sheet { border-collapse: collapse; width: 100%; font-size: .9rem; }
.sheet th, .sheet td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: start; white-space: nowrap; }
.sheet thead th { position: sticky; top: 0; background: var(--card); color: var(--muted); font-weight: 600; font-size: .82rem; }
.sheet tbody th { font-weight: 600; }
.sheet tbody th small { margin-inline-start: 6px; font-size: .75rem; }
.sheet td.n { font-variant-numeric: tabular-nums; direction: ltr; text-align: right; }
.sheet td.strong { font-weight: 600; }
.sheet td.why { white-space: normal; min-width: 150px; color: var(--muted); font-size: .84rem; }
.sheet:not(.plain) tbody tr { cursor: pointer; }
.sheet:not(.plain) tbody tr:hover { background: var(--brand-soft); }
.sheet tr.empty td { font-size: .82rem; }
.sheet tr.future { opacity: .45; }
.sheet tfoot th, .sheet tfoot td { border-top: 2px solid var(--line); border-bottom: 0; font-weight: 700; background: var(--bg); }

.chart { position: relative; height: 280px; }
.chart.tall { height: 420px; }

.catlist { display: grid; gap: 6px; }
.catrow { display: flex; gap: 8px; align-items: center; }
.catrow input[type=text] { min-height: 40px; }
.catrow.off input[type=text] { opacity: .5; text-decoration: line-through; }
.catrow.user { flex-wrap: wrap; }
.catrow select { width: auto; min-height: 40px; flex: 1 1 0; min-width: 0; }
.fresh-box { display: grid; gap: 6px; padding: 8px; border: 1px solid var(--warn-ink); border-radius: 10px; background: var(--warn-bg); }
.pill.warn { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; border-radius: 10px; }
details.merge { border-top: 1px solid var(--line); padding-top: 8px; }
details.merge summary { cursor: pointer; color: var(--brand); font-weight: 500; min-height: 32px; }
details.merge[open] { display: grid; gap: 8px; }
.catrow.user input[type=text] { flex: 1 1 140px; width: auto; }
.catrow.user select { width: auto; min-height: 40px; }

#toast { position: fixed; inset-inline: 12px; bottom: calc(18px + env(safe-area-inset-bottom)); margin: 0 auto; max-width: 420px; padding: 12px 16px; border-radius: 12px; background: var(--ink); color: var(--bg); text-align: center; opacity: 0; transform: translateY(20px); transition: .2s; pointer-events: none; z-index: 20; }
#toast.show { opacity: 1; transform: none; }
#toast.err { background: var(--danger); color: #fff; }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
