:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1c2622;
  --muted: #6b7a74;
  --line: #e3e8e6;
  --brand: #1f6f5c;
  --brand-soft: #e3f1ed;
  --income: #1c8a4f;
  --expense: #c6423a;
  --warn: #d48a12;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --input: #ffffff;
  --danger-line: #f0c9c6;
  --child-bg: #fdf0d9; --child-fg: #a2650a;
  --admin-bg: #e5e9fb; --admin-fg: #3a4cb0;
  --warn-bg: #fff6e5;
  color-scheme: light;
}
/* 🌙 tamni režim */
:root[data-theme="dark"] {
  --bg: #111614;
  --card: #1b2320;
  --input: #141a18;
  --text: #e6ece9;
  --muted: #93a29c;
  --line: #2b3632;
  --brand: #27866d;
  --brand-soft: #1d3a32;
  --income: #4cc483;
  --expense: #f0716a;
  --warn: #e9a23b;
  --danger-line: #5a2b28;
  --child-bg: #3b2e14; --child-fg: #f0c56e;
  --admin-bg: #232a4a; --admin-fg: #9fb0ff;
  --warn-bg: #2e2614;
  --shadow: 0 1px 2px rgba(0,0,0,.3);
  color-scheme: dark;
}
:root[data-theme="dark"] #tabbar { background: var(--card); }
:root[data-theme="dark"] .toast { background: #e6ece9; color: #111; }
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 16px; line-height: 1.4;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
.hidden { display: none !important; }

/* ---------- gornja traka ---------- */
#topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--brand); color: #fff;
}
.brand { font-weight: 700; font-size: 17px; }
.who { font-size: 13px; opacity: .9; }

main { max-width: 760px; margin: 0 auto; padding: 16px; }
.center-msg { text-align: center; color: var(--muted); padding: 60px 0; }

/* ---------- donja navigacija ---------- */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
#tabbar button {
  flex: 1; background: none; border: 0; color: var(--muted);
  font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 4px 0; cursor: pointer;
}
#tabbar button span { font-size: 20px; line-height: 1; }
#tabbar button.active { color: var(--brand); font-weight: 600; }
#tabbar button.add span {
  background: var(--brand); color: #fff; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-size: 24px; margin-top: -14px;
  box-shadow: 0 2px 8px rgba(31,111,92,.4);
}

/* ---------- kartice i elementi ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.card h2, .card h3 { margin: 0 0 12px; font-size: 16px; }
h1 { font-size: 22px; margin: 4px 0 16px; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.total { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; }
.total .lbl { font-size: 12px; color: var(--muted); }
.total .val { font-size: 18px; font-weight: 700; margin-top: 2px; white-space: nowrap; }
@media (max-width: 420px) { .total .val { font-size: 15px; } }
.income { color: var(--income); }
.expense { color: var(--expense); }

.monthnav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.monthnav .m { font-weight: 700; font-size: 18px; }
.iconbtn {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  width: 40px; height: 40px; font-size: 18px; cursor: pointer;
}

/* trake po kategorijama */
.bar-item { margin-bottom: 12px; }
.bar-item .top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; gap: 8px; }
.bar-item .sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.bar { height: 8px; background: var(--line); border-radius: 6px; overflow: hidden; }
.bar > div { height: 100%; background: var(--expense); border-radius: 6px; }
.bar.inc > div { background: var(--income); }
.bar.limit > div { background: var(--brand); }
.bar.limit.over > div { background: var(--expense); }
.bar.limit.near > div { background: var(--warn); }

/* grafikon po mjesecima */
.chart { display: flex; align-items: flex-end; gap: 8px; height: 140px; padding-top: 8px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.chart .bars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 3px; }
.chart .bars div { width: 40%; max-width: 18px; border-radius: 4px 4px 0 0; min-height: 2px; }
.chart .bi { background: var(--income); }
.chart .be { background: var(--expense); }
.chart .lbl { font-size: 11px; color: var(--muted); margin-top: 4px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

/* lista transakcija */
.daygroup { font-size: 13px; color: var(--muted); margin: 14px 4px 6px; font-weight: 600; }
.tx {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  background: var(--card); border-radius: 12px; margin-bottom: 6px; box-shadow: var(--shadow); cursor: pointer;
}
.tx .ic { width: 38px; height: 38px; border-radius: 10px; background: var(--brand-soft); display: grid; place-items: center; font-size: 18px; flex-shrink: 0; }
.tx .t1 { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .t2 { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .amt { font-weight: 700; white-space: nowrap; }

/* forme */
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
input, select, textarea {
  width: 100%; padding: 12px; font-size: 16px; font-family: inherit;
  border: 1px solid var(--line); border-radius: 10px; background: var(--input); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: transparent; }
textarea { min-height: 70px; resize: vertical; }
input.amount { font-size: 28px; font-weight: 700; text-align: right; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 16px; font-size: 15px; font-weight: 600; font-family: inherit;
  border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { color: var(--expense); border-color: var(--danger-line); }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: default; }
.btns { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.btns .btn { flex: 1; }

.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; }
.seg button {
  flex: 1; border: 0; background: none; padding: 10px; border-radius: 10px;
  font-size: 15px; font-weight: 600; color: var(--muted); cursor: pointer; font-family: inherit;
}
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.seg button.on.e { color: var(--expense); }
.seg button.on.i { color: var(--income); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { padding: 7px 12px; border-radius: 20px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 14px; cursor: pointer; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

.receipt-box { border: 2px dashed var(--line); border-radius: 12px; padding: 12px; text-align: center; }
.receipt-box img { max-width: 100%; max-height: 260px; border-radius: 8px; margin-top: 8px; }
.progress { height: 6px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; background: var(--brand); width: 0; transition: width .2s; }
details { margin-top: 10px; font-size: 13px; }
details pre { white-space: pre-wrap; background: var(--bg); padding: 8px; border-radius: 8px; max-height: 200px; overflow: auto; }

/* kategorije */
.cat { border-bottom: 1px solid var(--line); padding: 10px 0; }
.cat:last-child { border-bottom: 0; }
.cat .name { font-weight: 600; }
.cat .subs { margin: 6px 0 0 30px; }
.cat .subrow { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 15px; }
.cat.archived, .subrow.archived { opacity: .45; }
.linkbtn { background: none; border: 0; color: var(--brand); font-size: 13px; cursor: pointer; padding: 4px 6px; font-family: inherit; }
.linkbtn.red { color: var(--expense); }
.toggle { width: auto; transform: scale(1.2); }

.badge { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.badge.child { background: var(--child-bg); color: var(--child-fg); }
.badge.admin { background: var(--admin-bg); color: var(--admin-fg); }

.code { font-family: ui-monospace, monospace; font-size: 26px; letter-spacing: 3px; font-weight: 700; text-align: center; padding: 12px; background: var(--brand-soft); border-radius: 10px; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 50;
  max-width: 90vw; box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.toast.err { background: var(--expense); }

.auth { max-width: 400px; margin: 30px auto; }
.auth .logo { font-size: 48px; text-align: center; }
.auth h1 { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* prozorčić (dijalog) */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--card); color: var(--text); border-radius: 16px; padding: 20px; width: 100%; max-width: 400px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal h3 { margin: 0 0 8px; font-size: 18px; }
.modal p { margin: 0 0 8px; color: var(--muted); word-break: break-word; }

/* gornje dugme za profil/podešavanja */
button.who { background: rgba(255,255,255,.15); border: 0; color: #fff; border-radius: 20px; padding: 6px 12px; font-size: 13px; font-family: inherit; cursor: pointer; }

/* prostor za Netlify oznaku dolje desno */
body.netlify-badge { padding-bottom: calc(140px + env(safe-area-inset-bottom)); }
body.netlify-badge #tabbar { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
body.netlify-badge .toast { bottom: calc(150px + env(safe-area-inset-bottom)); }

/* v1.3 */
.alert { background: var(--warn-bg); border-left: 4px solid var(--warn); }
.pay { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.pay:last-child { border-bottom: 0; }
.pay.late .due { color: var(--expense); font-weight: 600; }
.tag { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); margin: 2px 4px 2px 0; cursor: pointer; }
:root[data-theme="dark"] .tag, :root[data-theme="dark"] .badge { color: #7fd8bd; }
table.rep { width: 100%; border-collapse: collapse; font-size: 13px; }
table.rep th, table.rep td { padding: 7px 3px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.rep th:first-child, table.rep td:first-child { text-align: left; white-space: normal; }
table.rep th { font-size: 12px; color: var(--muted); font-weight: 600; }
.tablewrap { overflow-x: auto; }
.up { color: var(--expense); } .down { color: var(--income); }
.toolgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.toolgrid .btn { flex-direction: column; padding: 14px 8px; font-size: 14px; }
.toolgrid .btn span { font-size: 24px; }
.opt { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0 0; color: var(--text); font-size: 15px; }

/* v1.5 – na računaru donja i gornja traka iste širine kao aplikacija */
@media (min-width: 800px) {
  #tabbar {
    left: 50%; right: auto; width: 760px; transform: translateX(-50%);
    border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0;
    box-shadow: 0 -2px 12px rgba(0,0,0,.06);
  }
  #topbar { padding-left: calc((100% - 760px) / 2 + 16px); padding-right: calc((100% - 760px) / 2 + 16px); }
  .toast { bottom: 100px; }
}
