:root {
  --bg: #f4f1ea;
  --card: #fffdf8;
  --ink: #1d2a24;
  --muted: #6b756f;
  --line: #e3ddd0;
  --accent: #1f6b4f;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe2;
  --late: #b4412d;
  --soon: #b7791f;
  --pos: #1f7a4f;
  --neg: #b4412d;
  --shadow: 0 1px 2px rgb(40 30 10 / 6%), 0 4px 14px rgb(40 30 10 / 5%);
  --radius: 16px;
  --tabs-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --card: #1b211e;
    --ink: #e8ece9;
    --muted: #94a19a;
    --line: #2b3430;
    --accent: #4fb38a;
    --accent-ink: #0d1a14;
    --accent-soft: #1f3a2e;
    --late: #ef7c66;
    --soon: #e0a84a;
    --pos: #5cc796;
    --neg: #ef7c66;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
a { color: var(--accent); }
svg { width: 22px; height: 22px; flex: none; }

.splash { display: grid; place-items: center; min-height: 100dvh; color: var(--muted); }

/* fejléc */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top) + 10px) max(16px, (100% - 608px) / 2) 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.top h1 { flex: 1; margin: 0; font-size: 26px; letter-spacing: -0.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: grid; place-items: center; width: 36px; height: 36px; margin-left: -8px; color: var(--accent); }
.back svg { width: 26px; height: 26px; }

main {
  max-width: 640px; margin: 0 auto;
  padding: 4px 16px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 96px);
}
h2 { display: flex; justify-content: space-between; margin: 22px 4px 8px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
h2 span { text-transform: none; letter-spacing: 0; }
h3 { margin: 0 0 10px; font-size: 17px; }
.muted { color: var(--muted); }
.hint { margin: 6px 2px; font-size: 13px; color: var(--muted); }
.hint.err { color: var(--late); }
.ok { color: var(--pos); font-weight: 600; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 16px; margin: 12px 0; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }

/* szegmens-váltó */
.seg { display: flex; padding: 3px; background: var(--line); border-radius: 11px; margin: 6px 0 4px; }
.seg a { flex: 1; text-align: center; padding: 7px; border-radius: 9px; color: var(--ink); text-decoration: none; font-size: 14px; font-weight: 500; }
.seg a.on { background: var(--card); box-shadow: 0 1px 3px rgb(0 0 0 / 12%); font-weight: 600; }

.summary { display: flex; gap: 12px; }
.summary > div { flex: 1; display: flex; flex-direction: column; }
.summary small { color: var(--muted); font-size: 12px; }
.summary b { font-size: 20px; letter-spacing: -0.01em; }

/* listaelemek */
.list { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); overflow: hidden; }
.bill { display: flex; align-items: center; gap: 12px; padding: 12px 14px; color: inherit; text-decoration: none; border-top: 1px solid var(--line); }
.bill:first-child { border-top: 0; }
.bill:active { background: var(--accent-soft); }
.bill.dim { opacity: 0.55; }
.badge {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; flex: none;
  background: hsl(var(--h) 45% 88%); color: hsl(var(--h) 45% 28%); font-weight: 700; font-size: 17px;
}
@media (prefers-color-scheme: dark) { .badge { background: hsl(var(--h) 30% 24%); color: hsl(var(--h) 55% 78%); } }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.main b, .amt b { font-weight: 600; }
.main small, .amt small { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.amt { display: flex; flex-direction: column; align-items: flex-end; text-align: right; max-width: 48%; }
.amt b { white-space: nowrap; font-variant-numeric: tabular-nums; }
.bill.late .due { color: var(--late); font-weight: 600; }
.bill.soon .due { color: var(--soon); font-weight: 600; }

/* űrlapok */
.form label, form label { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; font-size: 13px; font-weight: 500; color: var(--muted); }
input, select, textarea {
  font: inherit; font-size: 17px; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 11px;
  padding: 11px 12px; width: 100%; min-height: 46px; appearance: none; -webkit-appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
input[type='date'] { min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; }
.row { display: flex; gap: 10px; }
.row label { flex: 1; min-width: 0; }
label.check { flex-direction: row; align-items: center; gap: 10px; font-size: 15px; color: var(--ink); }
label.check input { width: 22px; height: 22px; min-height: 0; padding: 0; appearance: auto; -webkit-appearance: checkbox; }

details { margin: 0 0 14px; }
details summary { cursor: pointer; padding: 6px 0; font-size: 14px; color: var(--accent); font-weight: 500; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary::after { content: ' ›'; }
details[open] summary::after { content: ' ⌄'; }
details.split summary { color: var(--muted); }
details.split summary span { color: var(--ink); }
details[open] > :not(summary) { margin-top: 10px; }

button, .button {
  font: inherit; font-weight: 600; font-size: 16px; border: 0; border-radius: 12px; padding: 12px 18px; min-height: 46px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
}
button:disabled { opacity: 0.5; }
.primary { background: var(--accent); color: var(--accent-ink); }
.primary:active { filter: brightness(0.92); }
.ghost { background: var(--accent-soft); color: var(--accent); }
.block, form > .primary { width: 100%; }
.button.block { margin-top: 16px; }
.danger-link { display: block; margin: 18px auto; background: none; color: var(--late); font-weight: 500; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; }

/* számla állapota */
.status { display: flex; align-items: center; gap: 12px; }
.status > div { flex: 1; display: flex; flex-direction: column; }
.status b { font-size: 22px; letter-spacing: -0.01em; }
.status small { color: var(--muted); }
.status.late small { color: var(--late); font-weight: 600; }
.status.paid { background: var(--accent-soft); border-color: transparent; }
.status.paid b { color: var(--accent); font-size: 18px; }
.breakdown { list-style: none; padding: 6px 16px; }
.breakdown li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.breakdown li:first-child { border-top: 0; }
.breakdown li span { flex: 1; }
.breakdown small { color: var(--muted); }
.breakdown em { font-style: normal; font-size: 12px; color: var(--pos); }

/* elszámolás */
.bal-head { display: flex; flex-direction: column; margin-bottom: 8px; }
.bal-head small { color: var(--muted); }
.bal-head b { font-size: 28px; letter-spacing: -0.02em; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.items { list-style: none; margin: 0 0 14px; padding: 0; }
.items li { display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--line); }
.items li input { width: 22px; height: 22px; min-height: 0; padding: 0; flex: none; appearance: auto; -webkit-appearance: checkbox; accent-color: var(--accent); }
.items a { flex: 1; display: flex; align-items: center; gap: 8px; padding: 9px 0; color: inherit; text-decoration: none; }
.items span { flex: 1; display: flex; flex-direction: column; }
.items small { color: var(--muted); font-size: 12px; }
.items b { font-variant-numeric: tabular-nums; }

/* tételek */
.items-edit { margin-bottom: 14px; }
.items-edit .lbl { display: block; margin-bottom: 5px; font-size: 13px; font-weight: 500; color: var(--muted); }
.item-row { display: flex; gap: 8px; margin-bottom: 8px; }
.item-row input { flex: 1; font-variant-numeric: tabular-nums; }
.item-del { min-height: 46px; width: 46px; padding: 0; flex: none; background: var(--bg); color: var(--muted); border: 1px solid var(--line); font-size: 22px; font-weight: 400; }
.item-del[hidden] { display: none; }
.items-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.items-foot span { font-weight: 600; font-variant-numeric: tabular-nums; }
.items-sum { margin: -4px 4px 8px; }
button.link { background: none; color: var(--accent); padding: 4px 0; min-height: 0; font-weight: 500; font-size: 15px; }
button.link.danger { color: var(--late); font-size: 13px; margin-left: 6px; }
.err { color: var(--late); }

/* Gmail */
.badge.mail { background: var(--accent-soft); color: var(--accent); }
.bill.import { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.mailinfo { display: flex; flex-direction: column; gap: 3px; }
.mailinfo small { color: var(--muted); }
.mailinfo p { margin: 6px 0 0; }

.users { list-style: none; padding: 0; margin: 0 0 8px; }
.users li { padding: 6px 0; }
.users small { color: var(--muted); }

/* lebegő gomb és alsó fülsor */
.fab {
  position: fixed; right: 20px; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 18px); z-index: 6;
  width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 18px rgb(31 107 79 / 35%);
}
.fab svg { width: 28px; height: 28px; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabs a { flex: 1; height: var(--tabs-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 500; }
.tabs a.on { color: var(--accent); }

/* belépés */
.auth { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; max-width: 420px; padding-bottom: 40px; }
.auth h1 { text-align: center; margin: 8px 0 4px; font-size: 30px; letter-spacing: -0.02em; }
.auth > p { text-align: center; }
.auth .logo { display: block; width: 96px; height: 96px; margin: 0 auto 4px; border-radius: 22px; box-shadow: 0 8px 24px rgb(22 77 58 / 25%); }

/* új verzió sáv */
#update-bar {
  position: fixed; left: 0; right: 0; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 8px) max(16px, (100% - 608px) / 2) 8px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
  box-shadow: 0 2px 10px rgb(0 0 0 / 20%);
}
#update-bar button { min-height: 36px; padding: 6px 16px; border-radius: 999px; background: var(--accent-ink); color: var(--accent); }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 90px); z-index: 20;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: 0.25s;
  max-width: min(92vw, 440px); padding: 12px 16px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-size: 15px; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--late); color: #fff; }
