/* Boje su definirane kao varijable - tamna tema samo mijenja vrijednosti */
:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --border: #e4e3df;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #8a8984;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --grid: #ecebe7;
  /* Boje serija na grafovima (faze L1, L2, L3) - provjereno za daltonizam */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --border: #2e2e2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e88;
    --accent: #3987e5;
    --grid: #2a2a28;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); }
code { font-size: 0.9em; background: var(--grid); padding: 1px 5px; border-radius: 4px; }
h1 { font-size: 1.4rem; margin: 0 0 16px; }
h2 { font-size: 1.1rem; margin: 28px 0 12px; }
.muted { color: var(--muted); }
.error { color: var(--critical); min-height: 1.2em; }

/* ---------- Gornja traka ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; color: var(--text); text-decoration: none; }
.brand svg { width: 22px; height: 22px; fill: var(--accent); }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a { padding: 6px 9px; border-radius: 6px; color: var(--text-2); text-decoration: none; }
nav a:hover { background: var(--grid); }
nav a.active { background: var(--accent); color: var(--accent-ink); }
.who { margin-left: auto; display: flex; gap: 12px; align-items: center; color: var(--text-2); }

main { max-width: 1200px; margin: 0 auto; padding: 24px; }

/* ---------- Kartice s brojkama ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.tile .label { color: var(--text-2); font-size: 0.85rem; }
.tile .value { font-size: 1.7rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile .unit { font-size: 0.95rem; color: var(--text-2); font-weight: 400; margin-left: 4px; }

/* ---------- Punjači ---------- */
.stations { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.station { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.station h3 { margin: 0 0 2px; font-size: 1rem; }
.station .meta { color: var(--muted); font-size: 0.85rem; }
.station .row { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }

.station form.limit { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); display: grid; gap: 6px; }
.station form.limit label { display: flex; justify-content: space-between; }
.limit-row { display: flex; gap: 6px; }
.limit-row input { width: 90px; flex: 1; }

/* Status uvijek ima ikonu + tekst, nikad samo boju */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; font-weight: 550; }
.status::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.status.good { color: var(--good); }
.status.busy { color: var(--accent); }
.status.bad { color: var(--critical); }
.status.off { color: var(--muted); }

/* ---------- Tablice ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-2); font-weight: 550; font-size: 0.85rem; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--grid); }
tfoot td { font-weight: 650; border-top: 2px solid var(--border); }
.empty { padding: 24px; text-align: center; color: var(--muted); }

/* ---------- Forme ---------- */
.toolbar { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
form.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; margin-bottom: 16px; }
label { display: grid; gap: 4px; font-size: 0.85rem; color: var(--text-2); }
input, select {
  font: inherit; padding: 7px 10px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button {
  font: inherit; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
}
button:hover { background: var(--grid); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--critical); }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
button:disabled { opacity: 0.5; cursor: default; }

/* ---------- Graf ---------- */
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; position: relative; }
.chart-card h3 { margin: 0 0 8px; font-size: 1rem; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 280px; overflow: visible; }
.chart .grid line { stroke: var(--grid); }
.chart .axis text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart .line.s1 { stroke: var(--series-1); }
/* Isprekidane linije: kad su struje po fazama jednake, linije se preklapaju pa se i dalje vide sve tri */
.chart .line.s2 { stroke: var(--series-2); stroke-dasharray: 8 6; }
.chart .line.s3 { stroke: var(--series-3); stroke-dasharray: 3 11; }
.chart .dot.s1 { fill: var(--series-1); }
.chart .dot.s2 { fill: var(--series-2); }
.chart .dot.s3 { fill: var(--series-3); }
.chart .end-label { fill: var(--text-2); font-size: 11px; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 16px; border-top: 3px solid; display: inline-block; }
.swatch.s1 { border-color: var(--series-1); }
.swatch.s2 { border-color: var(--series-2); border-top-style: dashed; }
.swatch.s3 { border-color: var(--series-3); border-top-style: dotted; }
.chart .area { fill: var(--accent); opacity: 0.08; }
.chart .cross { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--text); color: var(--surface);
  padding: 6px 10px; border-radius: 6px; font-size: 0.8rem; white-space: nowrap; transform: translate(-50%, -110%);
}
details { margin-top: 12px; }
summary { cursor: pointer; color: var(--accent); }

/* ---------- Prijava i obavijesti ---------- */
dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); width: min(420px, 92vw); }
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
dialog form { display: grid; gap: 12px; }
dialog h2 { margin: 0; }
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface);
  padding: 10px 18px; border-radius: 8px; opacity: 0; transition: opacity 0.2s; pointer-events: none;
}
#toast.show { opacity: 1; }
#toast.err { background: var(--critical); color: #fff; }

@media (max-width: 640px) {
  main { padding: 16px; }
  .topbar { padding: 10px 16px; gap: 10px; }
  .who { margin-left: 0; }
}
.phases { font-size: 13px; color: var(--text-2); margin-top: 6px; font-variant-numeric: tabular-nums; }
h2 .meta { font-size: 13px; font-weight: normal; color: var(--muted); margin-left: 8px; }
.price-preview { grid-column: 1 / -1; font-size: 0.9rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.tile .meta { font-size: 0.8rem; color: var(--muted); }
.meta { color: var(--muted); font-size: 0.85rem; }
td.breakdown { white-space: normal; line-height: 1.4; font-variant-numeric: tabular-nums; }
.tiles + .table-wrap { margin-top: 12px; }
label.check { grid-auto-flow: column; justify-content: start; align-items: center; gap: 8px; }
.form-note { grid-column: 1 / -1; margin: 0; font-size: 0.85rem; }
.limit-progress { margin: 0 0 12px; max-width: 640px; }
.limit-progress .bar { height: 6px; border-radius: 3px; background: var(--grid); margin-top: 6px; overflow: hidden; }
.limit-progress .bar span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
input.narrow { width: 80px; }
a.button { display: inline-block; padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); text-decoration: none; background: var(--surface); white-space: nowrap; }
.profiles { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
td.config-value { font-family: ui-monospace, monospace; font-size: 0.85rem; word-break: break-all; white-space: normal; min-width: 120px; max-width: 360px; }
td.config-value .meta { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
td.breakdown code { word-break: break-all; }
a.plain { color: inherit; text-decoration: none; }
a.plain:hover { text-decoration: underline; }
form.config-edit { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
form.config-edit input, form.config-edit select { font-family: ui-monospace, monospace; font-size: 0.85rem; min-width: 110px; flex: 1; }
form.config-edit button { padding: 4px 10px; }
/* Na mobitelu postavke jedna ispod druge: naziv pa vrijednost */
@media (max-width: 600px) {
  table.config thead { display: none; }
  table.config tr, table.config td { display: block; width: 100%; }
  table.config td.config-value { max-width: none; padding-top: 0; }
}
label.inline { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
label.inline select { width: auto; }
.tiles + .tiles { margin-top: 12px; }

/* ---------- Prijava, korisnici, upute ---------- */
.who .role { font-size: 0.8rem; color: var(--muted); }
.who a { color: var(--text); text-decoration: none; }
.who select { width: auto; }
dialog .login-key { margin-top: 12px; font-size: 0.85rem; color: var(--text-2); }
dialog .login-key form { margin-top: 8px; }
button.wide { width: 100%; margin-top: 8px; }
.link-box { background: var(--surface); border: 1px solid var(--accent); border-radius: 10px; padding: 14px 16px; margin: 12px 0 16px; display: grid; gap: 8px; }
.link-box input { width: 100%; font-family: ui-monospace, monospace; font-size: 0.8rem; }
.link-box .limit-row { display: flex; gap: 8px; flex-wrap: wrap; }
.link-box .limit-row input { flex: 1; min-width: 200px; }
form.stack, .stack { display: grid; gap: 8px; }
.invite-locations { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; }
.invite-locations .label { font-size: 0.85rem; color: var(--text-2); width: 100%; }
td.actions { white-space: nowrap; }
td.actions button + button { margin-left: 6px; }
.public-card { max-width: 480px; margin: 24px auto; }
.public-card form { grid-template-columns: 1fr; }

.guide { display: grid; grid-template-columns: 220px 1fr; gap: 24px; align-items: start; }
.guide-toc { position: sticky; top: 72px; display: grid; gap: 2px; }
.guide-toc button { text-align: left; padding: 4px 0; }
.guide-body section { border-bottom: 1px solid var(--border); padding-bottom: 16px; margin-bottom: 8px; }
.guide-body h2 { margin-top: 8px; }
.guide-body li { margin: 4px 0; }
.guide-body figure { margin: 12px 0; }
.guide-body figure img { max-width: 100%; border: 1px solid var(--border); border-radius: 8px; display: block; }
.guide-body figcaption { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }
table.matrix td:not(:first-child), table.matrix th:not(:first-child) { text-align: center; }
table.matrix .mine { background: color-mix(in srgb, var(--accent) 12%, transparent); font-weight: 600; }
@media (max-width: 800px) {
  .guide { grid-template-columns: 1fr; }
  .guide-toc { position: static; }
}
@media print {
  .topbar, .guide-toc, .toolbar button, #toast { display: none !important; }
  body { background: #fff; color: #000; }
  .guide { grid-template-columns: 1fr; }
  .guide-body section { break-inside: avoid-page; }
}
.who .me { display: flex; flex-direction: column; line-height: 1.2; text-align: right; }
.invite-locations[hidden] { display: none; }
