:root {
  color-scheme: light;
  --accent: #0f766e;
  --on-accent: #fff;
  --danger: #b91c1c;
  --text: #111827;
  --label: #374151;
  --muted: #6b7280;
  --border: #e5e7eb;
  --input-border: #d1d5db;
  --bg: #f9fafb;
  --surface: #fff;
  --stripe: #e6f2f1;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
}

/* Dark palette: follows the system unless the toggle chose light; the toggle can also force dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --accent: #2dd4bf;
    --on-accent: #042f2e;
    --danger: #f87171;
    --text: #e5e7eb;
    --label: #cbd5e1;
    --muted: #9ca3af;
    --border: #374151;
    --input-border: #4b5563;
    --bg: #0b1120;
    --surface: #111827;
    --stripe: #16302f;
    --error-bg: #3b1212;
    --error-border: #7f1d1d;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --accent: #2dd4bf;
  --on-accent: #042f2e;
  --danger: #f87171;
  --text: #e5e7eb;
  --label: #cbd5e1;
  --muted: #9ca3af;
  --border: #374151;
  --input-border: #4b5563;
  --bg: #0b1120;
  --surface: #111827;
  --stripe: #16302f;
  --error-bg: #3b1212;
  --error-border: #7f1d1d;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  /* Georgian fallbacks: Android/Linux ship Noto Sans Georgian, Windows has Sylfaen. */
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Georgian", "BPG Arial", Sylfaen, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

main { max-width: 720px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.5rem; margin: 0 0 12px; padding-right: 48px; }
h2 { font-size: 1.15rem; margin: 24px 0 8px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
a { color: var(--accent); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
label { display: block; margin-bottom: 10px; font-size: 0.9rem; color: var(--label); }
input, select, button { font: inherit; }
input, select { display: block; width: 100%; margin-top: 4px; padding: 10px; border: 1px solid var(--input-border); border-radius: 8px; background: var(--surface); color: var(--text); }
input, select { font-size: 16px; }
button { padding: 10px 16px; border: 0; border-radius: 8px; background: var(--accent); color: var(--on-accent); cursor: pointer; }
button.danger { background: var(--danger); color: #fff; }
button.small { padding: 4px 10px; font-size: 0.85rem; }
button.link { background: none; color: var(--accent); padding: 0; text-decoration: underline; }

.theme-toggle {
  position: absolute; top: 12px; right: 12px;
  width: 40px; height: 40px; padding: 0;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 50%;
  font-size: 1.1rem; line-height: 1;
}

.tabs { display: flex; gap: 4px; padding: 4px; margin-bottom: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.tab { flex: 1; padding: 10px 8px; border-radius: 8px; text-align: center; text-decoration: none; color: var(--text); font-weight: 600; }
:root[data-tab="add"] .tab[href="#add"],
:root[data-tab="expenses"] .tab[href="#expenses"],
:root[data-tab="summary"] .tab[href="#summary"] { background: var(--accent); color: var(--on-accent); }
:root[data-tab] .tab-panel { display: none; }
:root[data-tab="add"] #add,
:root[data-tab="expenses"] #expenses,
:root[data-tab="summary"] #summary { display: block; }
.notice { background: var(--stripe); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 10px; }

.row { display: flex; gap: 8px; }
.row > label { flex: 1; }
.row > label:first-child { flex: 2; }
.inline { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 8px; }
.inline > input, .inline > label { flex: 1; min-width: 0; margin-bottom: 0; }

.error { background: var(--error-bg); color: var(--danger); border: 1px solid var(--error-border); border-radius: 8px; padding: 10px; }
.muted { color: var(--muted); font-size: 0.9rem; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); }
tfoot th { border-bottom: 0; }
.num { text-align: right; white-space: nowrap; }
tr[data-href] { cursor: pointer; }
tr.day-even > td { background: var(--surface); }
tr.day-odd > td { background: var(--stripe); }
.pay { color: var(--danger); font-weight: 600; }
.receive { color: var(--accent); font-weight: 600; }

.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.list { list-style: none; padding: 0; margin: 0 0 12px; }
.list li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.member { display: flex; gap: 8px; align-items: flex-end; }
.member form:first-child { flex: 1; margin-bottom: 0; }
.admin-header { display: flex; justify-content: space-between; align-items: center; padding-right: 48px; }
.admin-header h1 { padding-right: 0; }
.admin-header h1 a { color: inherit; text-decoration: none; }
