:root {
  --bg: #f4f2ee;
  --card: #ffffff;
  --text: #1d2422;
  --muted: #66706c;
  --line: #e2ded6;
  --brand: #1f6f5c;
  --brand-soft: #e3f0ec;
  --plus: #1f6f5c;
  --minus: #b4432f;
  --minus-soft: #f8e7e3;
  --warn-soft: #fbf1d9;
  --p0: #2f6fb5; --p0-soft: #e2edf8;
  --p1: #b0670f; --p1-soft: #fbeedb;
  --p2: #8a46b0; --p2-soft: #f1e6f7;
  --p3: #66706c; --p3-soft: #eceae5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141917;
    --card: #1d2421;
    --text: #e9eeec;
    --muted: #9aa5a1;
    --line: #2d3733;
    --brand: #5cc1a5;
    --brand-soft: #1d3a32;
    --plus: #5cc1a5;
    --minus: #ef8a76;
    --minus-soft: #3a2420;
    --warn-soft: #3a3220;
    --p0: #7fb0ea; --p0-soft: #1f2e40;
    --p1: #e7a85a; --p1-soft: #3a2c1a;
    --p2: #c99ae6; --p2-soft: #33233d;
    --p3: #9aa5a1; --p3-soft: #2a302d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }

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

/* ---------- rozvržení ---------- */

.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 12px) 16px 8px;
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
}
.top h1 { font-size: 22px; margin: 0; }
.top .who { color: var(--muted); font-size: 14px; }

main {
  max-width: 640px; margin: 0 auto;
  padding: 4px 16px calc(env(safe-area-inset-bottom) + 150px);
}

nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs button {
  border: 0; background: none; padding: 9px 2px 8px;
  font-size: 12px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
nav.tabs button svg { width: 22px; height: 22px; }
nav.tabs button.on { color: var(--brand); font-weight: 600; }
nav.tabs .badge {
  position: absolute; margin-left: 18px; margin-top: -2px;
  background: var(--minus); color: #fff; border-radius: 9px;
  font-size: 11px; min-width: 17px; padding: 0 4px; line-height: 17px;
}

.fabs {
  position: fixed; right: 16px; z-index: 11; display: flex; gap: 8px;
  bottom: calc(env(safe-area-inset-bottom) + 72px);
}
.fab {
  border: 0; border-radius: 28px; padding: 14px 20px;
  background: var(--brand); color: #fff; font-weight: 600; font-size: 16px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .2);
}
@media (prefers-color-scheme: dark) { .fab { color: #0f1a16; } }
.fab.alt { background: var(--card); color: var(--brand); border: 1px solid var(--line); }

/* ---------- karty a seznamy ---------- */

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin: 0 0 12px;
}
.card h2 { font-size: 15px; margin: 0 0 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.card.todo { background: var(--warn-soft); }
.card.ok { background: var(--brand-soft); }

.big { font-size: 28px; font-weight: 700; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.plus { color: var(--plus); }
.minus { color: var(--minus); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

.people { width: 100%; border-collapse: collapse; font-size: 15px; }
.people th { text-align: right; font-weight: 500; color: var(--muted); font-size: 13px; padding: 0 0 6px; }
.people th:first-child { text-align: left; }
.people td { padding: 7px 0; border-top: 1px solid var(--line); text-align: right; }
.people td:first-child { text-align: left; }
.people th + th, .people td + td { padding-left: 8px; }
.people.wide { font-size: 13.5px; }
.people tfoot td { font-weight: 700; }

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 0; border-top: 1px solid var(--line);
}
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; }
.list .sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li.tap { cursor: pointer; }
.cat {
  width: 38px; height: 38px; border-radius: 10px; flex: none;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
  background: var(--brand-soft); color: var(--brand);
}

/* barva člověka: Miro, Honza, Sárka */
.av {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 16px; font-weight: 700;
}
.pname { font-weight: 600; }
.p0 { --pc: var(--p0); --pcs: var(--p0-soft); }
.p1 { --pc: var(--p1); --pcs: var(--p1-soft); }
.p2 { --pc: var(--p2); --pcs: var(--p2-soft); }
.p3 { --pc: var(--p3); --pcs: var(--p3-soft); }
.av, .pname { color: var(--pc); }
.av { background: var(--pcs); }
.list li.rejected .num, .list li.rejected .title { text-decoration: line-through; opacity: .6; }
.list li.rejected .pill { text-decoration: none; }

.transfer { padding: 12px 0; border-top: 1px solid var(--line); }
.transfer:first-of-type { border-top: 0; padding-top: 0; }
.transfer .line { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.transfer .who { font-weight: 600; }
.transfer .amt { font-size: 20px; font-weight: 700; }
.transfer .split { font-size: 13px; color: var(--muted); }
.transfer .acts { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.pill {
  display: inline-block; font-size: 12px; font-weight: 600; border-radius: 10px; padding: 2px 8px;
  background: var(--line); color: var(--muted);
}
.pill.ceka { background: var(--minus-soft); color: var(--minus); }
.pill.odeslano { background: var(--warn-soft); color: #8a6512; }
.pill.zaplaceno, .pill.prevedeno { background: var(--brand-soft); color: var(--brand); }
@media (prefers-color-scheme: dark) { .pill.odeslano { color: #e5c06a; } }

details.period { padding: 0; }
details.period summary { list-style: none; cursor: pointer; padding: 16px; display: flex; justify-content: space-between; gap: 12px; }
details.period summary::-webkit-details-marker { display: none; }
details.period .inner { padding: 0 16px 16px; }

.empty { color: var(--muted); text-align: center; padding: 16px 0; }

/* ---------- tlačítka a formuláře ---------- */

.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 9px 14px; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0f1a16; } }
.btn.danger { color: var(--minus); }
.btn.block { width: 100%; padding: 13px; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

label { display: block; font-size: 14px; color: var(--muted); margin: 12px 0 4px; }
input:not([type]), input[type=text], input[type=password], input[type=email], input[type=date], input[type=number], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  padding: 11px 12px; font-size: 16px;
}
input.amount { font-size: 30px; font-weight: 700; padding: 10px 12px; }
.amountwrap { position: relative; }
.amountwrap span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-size: 30px; font-weight: 700; color: var(--muted); }
.amountwrap input { padding-left: 34px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  border: 1px solid var(--line); background: var(--card); border-radius: 18px;
  padding: 7px 12px; font-size: 14px;
}
.chips button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .chips button.on { color: #0f1a16; } }

.photo { margin-top: 6px; }
.photo img { max-width: 100%; max-height: 220px; border-radius: 10px; display: block; margin-bottom: 8px; }

.err { color: var(--minus); font-size: 14px; margin-top: 10px; min-height: 1em; }

/* ---------- dialog ---------- */

dialog {
  border: 0; padding: 0; background: var(--card); color: var(--text);
  width: 100%; max-width: 560px; max-height: 92vh;
  border-radius: 18px 18px 0 0; margin: auto auto 0;
}
@media (min-width: 600px) { dialog { border-radius: 18px; margin: auto; } }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
dialog .dhead { display: flex; justify-content: space-between; align-items: center; padding: 16px 16px 0; }
dialog .dhead h3 { margin: 0; font-size: 19px; }
dialog .dhead button { border: 0; background: none; font-size: 26px; line-height: 1; color: var(--muted); padding: 0 4px; }
dialog .dbody { padding: 0 16px calc(env(safe-area-inset-bottom) + 16px); }
dialog .dacts { display: flex; gap: 8px; margin-top: 18px; }
dialog .dacts > * { flex: 1; }
dialog img.full { width: 100%; border-radius: 10px; margin-top: 12px; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 140px); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s;
  max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; }

/* ---------- přihlášení ---------- */

.auth { max-width: 380px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 12vh) 16px 40px; }
.auth h1 { margin: 0 0 4px; }
.auth form { margin-top: 18px; }
.auth .btn { margin-top: 18px; }
