:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eceef2;
  --text: #1c1f26;
  --muted: #5d6573;
  --border: #d9dde4;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --da: #1f8f4d;
  --da-bg: #dff5e7;
  --ne: #c92a2a;
  --ne-bg: #fde3e3;
  --mz: #9a5b00;
  --mz-bg: #fff0cc;
  --shadow: 0 1px 3px rgba(0, 0, 0, .12);
  --header-h: 52px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1e2127;
    --surface-2: #2a2e36;
    --text: #e9ebef;
    --muted: #9aa2b1;
    --border: #363b45;
    --accent: #748ffc;
    --accent-text: #10131a;
    --da: #5fd08a;
    --da-bg: #163b25;
    --ne: #ff8787;
    --ne-bg: #451d1d;
    --mz: #ffd166;
    --mz-bg: #4a3a12;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

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

[hidden] { display: none !important; }

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

button { cursor: pointer; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

a { color: var(--accent); }

/* ---------- gornja traka ---------- */

.topbar {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 1.1rem;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  white-space: nowrap;
}

.btn:hover { background: var(--surface-2); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.btn:disabled { opacity: .45; cursor: default; }

/* ---------- prijava ---------- */

.login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}

.login-card h1 { margin: 0 0 4px; font-size: 1.6rem; }
.login-card p { margin: 0 0 20px; color: var(--muted); }
.login-card label { display: block; font-weight: 600; margin: 16px 0 8px; }

.voter-pick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }

.voter-pick button {
  min-height: 56px;
  font-size: 1.4rem;
  font-weight: 700;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.voter-pick button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

.login-card input[type="password"] {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.login-card .btn.primary { width: 100%; min-height: 50px; margin-top: 20px; font-size: 1.05rem; }

.error { color: var(--ne); min-height: 1.5em; margin: 12px 0 0; font-weight: 500; }

/* ---------- glasanje: raspored ---------- */

.layout {
  height: calc(100dvh - var(--header-h));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.pane { min-height: 0; min-width: 0; display: flex; flex-direction: column; background: var(--surface); }

.list-pane { border-right: 1px solid var(--border); }

.layout[data-view="list"] .detail-pane { display: none; }
.layout[data-view="detail"] .list-pane { display: none; }

@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(320px, 400px) 1fr; }
  .layout[data-view="list"] .detail-pane,
  .layout[data-view="detail"] .list-pane { display: flex; }
  .only-narrow { display: none !important; }
}

/* ---------- lista ---------- */

.list-head { padding: 12px 16px; border-bottom: 1px solid var(--border); display: grid; gap: 10px; }

.progress-line { display: flex; justify-content: space-between; font-size: .9rem; color: var(--muted); }

.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--da); width: 0; transition: width .25s; }

.list-head input[type="search"] {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.chips { display: flex; gap: 8px; }

.chip {
  min-height: 36px;
  padding: 0 14px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: .9rem;
}

.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

#items { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; overscroll-behavior: contain; }

#items li button {
  width: 100%;
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
}

#items li button:hover { background: var(--surface-2); }
#items li button[aria-current="true"] { background: var(--surface-2); box-shadow: inset 4px 0 0 var(--accent); }

.num { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 2.2em; font-size: .9rem; }
.ititle { flex: 1; min-width: 0; overflow-wrap: anywhere; }

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

/* ---------- značke glasova ---------- */

.pill {
  display: inline-block;
  min-width: 3.6em;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: .78rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: .02em;
  white-space: nowrap;
}

.pill.DA { background: var(--da-bg); color: var(--da); }
.pill.NE { background: var(--ne-bg); color: var(--ne); }
.pill.MOZDA { background: var(--mz-bg); color: var(--mz); }
.pill.none { background: var(--surface-2); color: var(--muted); font-weight: 500; }

/* ---------- detalj ---------- */

.detail-top { padding: 8px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.detail-top .counter { color: var(--muted); font-size: .9rem; margin-left: auto; }

.doc { flex: 1; overflow-y: auto; padding: 20px 16px; overscroll-behavior: contain; }

.doc-inner { max-width: 720px; margin: 0 auto; }
.doc h2 { margin: 0 0 16px; font-size: 1.5rem; line-height: 1.25; overflow-wrap: anywhere; }
.doc .text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 1.05rem; line-height: 1.65; }
.doc .placeholder { color: var(--muted); text-align: center; margin-top: 20vh; }

.votebar {
  border-top: 1px solid var(--border);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface);
  display: grid;
  gap: 10px;
}

.votes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; max-width: 720px; width: 100%; margin: 0 auto; }

.vote {
  min-height: 56px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-weight: 700;
  font-size: 1.05rem;
}

.vote[data-v="DA"] { color: var(--da); }
.vote[data-v="NE"] { color: var(--ne); }
.vote[data-v="MOZDA"] { color: var(--mz); }
.vote[aria-pressed="true"][data-v="DA"] { background: var(--da); border-color: var(--da); color: #fff; }
.vote[aria-pressed="true"][data-v="NE"] { background: var(--ne); border-color: var(--ne); color: #fff; }
.vote[aria-pressed="true"][data-v="MOZDA"] { background: var(--mz); border-color: var(--mz); color: #fff; }

@media (prefers-color-scheme: dark) {
  .vote[aria-pressed="true"] { color: #10131a !important; }
}

.nav { display: flex; gap: 8px; max-width: 720px; width: 100%; margin: 0 auto; }
.nav .btn { flex: 1 1 0; min-width: 0; padding: 4px 6px; font-size: .9rem; white-space: normal; text-align: center; line-height: 1.2; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ne);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  z-index: 10;
  max-width: 90vw;
}

/* ---------- rezultati ---------- */

.results-page { max-width: 1000px; margin: 0 auto; padding: 16px; }

.progress-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }

.pcard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.pcard b { display: block; font-size: 1.15rem; }
.pcard small { color: var(--muted); }
.pcard .bar { margin-top: 6px; }

@media (max-width: 560px) {
  .progress-cards { grid-template-columns: repeat(2, 1fr); }
}

.toolbar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-bottom: 12px; }
.toolbar input[type="search"] {
  flex: 1 1 200px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.toolbar .updated { color: var(--muted); font-size: .85rem; }

.table-wrap {
  overflow: auto;
  max-height: calc(100dvh - 250px);
  min-height: 240px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

table.results { border-collapse: separate; border-spacing: 0; width: 100%; }

table.results th, table.results td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  background: var(--surface);
}

table.results thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  font-size: .85rem;
}

table.results th:first-child, table.results td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  text-align: left;
  min-width: 160px;
  max-width: 320px;
  border-right: 1px solid var(--border);
}

table.results thead th:first-child { z-index: 3; }

table.results td:first-child { overflow-wrap: anywhere; }
table.results td:first-child .num { margin-right: 6px; }

table.results tbody tr:hover td { background: var(--surface-2); }

.tally { display: inline-flex; gap: 6px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tally .da { color: var(--da); }
.tally .ne { color: var(--ne); }
.tally .mz { color: var(--mz); }

.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); margin-top: 10px; align-items: center; }

.toast.ok { background: var(--da); }

@media (max-width: 480px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .results-page { padding: 10px; }
  table.results th, table.results td { padding: 8px 5px; }
  table.results th:first-child, table.results td:first-child { min-width: 118px; max-width: 130px; font-size: .88rem; }
  table.results .pill { min-width: 0; padding: 2px 7px; font-size: .72rem; }
}

/* ---------- napomene ---------- */

.notes-dialog {
  width: min(640px, calc(100vw - 24px));
  max-height: min(80dvh, 720px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  flex-direction: column;
}

.notes-dialog[open] { display: flex; }
.notes-dialog::backdrop { background: rgba(0, 0, 0, .55); }

.notes-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 1.1rem;
}

.notes-body { padding: 8px 20px 20px; overflow-y: auto; overflow-wrap: anywhere; }

.md h1, .md h2, .md h3, .md h4 { line-height: 1.25; margin: 1.2em 0 .5em; }
.md h1 { font-size: 1.5rem; }
.md h2 { font-size: 1.3rem; }
.md h3 { font-size: 1.1rem; }
.md p, .md ul, .md ol, .md blockquote, .md pre { margin: 0 0 1em; }
.md ul, .md ol { padding-left: 1.4em; }
.md blockquote { padding: 2px 14px; border-left: 4px solid var(--border); color: var(--muted); }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.md pre { background: var(--surface-2); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.md pre code { padding: 0; background: none; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.2em 0; }

@media (max-width: 480px) {
  .topbar .btn { padding: 0 10px; }
}

/* ---------- napomena uz pesmu ---------- */

.note-row { max-width: 720px; width: 100%; margin: 0 auto; }
.note-row .btn { width: 100%; }
.note-row .btn.has-note { border-color: var(--accent); color: var(--accent); font-weight: 600; }

.note-form { display: flex; flex-direction: column; gap: 12px; padding: 12px 20px 20px; }
.note-form textarea {
  width: 100%;
  min-height: 160px;
  resize: vertical;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.note-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- pregled u rezultatima ---------- */

.overview { margin-bottom: 16px; }
.overview h2 { font-size: 1.05rem; margin: 0 0 8px; }
.overview-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ocard { border-radius: 10px; padding: 12px; background: var(--surface-2); text-align: center; }
.ocard b { display: block; font-size: 1.6rem; }
.ocard small { font-weight: 600; }
.ocard.DA { background: var(--da-bg); color: var(--da); }
.ocard.NE { background: var(--ne-bg); color: var(--ne); }
.ocard.OPEN { color: var(--muted); }
.overview-note { margin: 8px 0 0; color: var(--muted); font-size: .85rem; }

/* ---------- crteži: dropzone, galerija, potvrda brisanja ---------- */

.uploader-page, .drawings-page { max-width: 960px; margin: 0 auto; padding: 16px; display: grid; gap: 28px; }
.uploader-page h2 { font-size: 1.05rem; margin: 0 0 10px; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  background: var(--surface);
}
.dropzone.dragover { border-color: var(--accent); color: var(--accent); background: var(--surface-2); }
.dropzone p { margin: 0; }
.dropzone .hint { font-size: .85rem; margin-top: 4px; }
.upload-status { margin: 10px 0 0; color: var(--muted); font-size: .9rem; }

.drawing-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-top: 14px; }
.drawing-grid .empty { color: var(--muted); grid-column: 1 / -1; }

.dcard { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); display: flex; flex-direction: column; }
.dthumb { aspect-ratio: 1; background: var(--surface-2); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.dthumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dicon { font-weight: 700; color: var(--muted); }
.dmeta { padding: 8px 10px 0; display: grid; gap: 2px; min-width: 0; }
.dname { font-size: .88rem; font-weight: 600; overflow-wrap: anywhere; }
.dmeta small { color: var(--muted); font-size: .78rem; }
.dactions { display: flex; gap: 6px; padding: 8px 10px 10px; }
.dactions .btn { flex: 1; padding: 6px 8px; font-size: .85rem; }
.dactions .btn.danger { flex: 0 0 auto; }

.btn.danger { border-color: var(--ne); color: var(--ne); }
.btn.danger:hover { background: var(--ne-bg); }

.song-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.song-list .empty { color: var(--muted); }
.song-list button {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.song-list button:hover { background: var(--surface-2); }

.notes-body .text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; margin-bottom: 16px; }

.confirm-dialog {
  border: none;
  border-radius: 14px;
  padding: 20px;
  max-width: 420px;
  width: calc(100% - 32px);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.confirm-dialog[open] { display: flex; flex-direction: column; gap: 16px; }
.confirm-dialog::backdrop { background: rgba(0, 0, 0, .55); }
.confirm-dialog p { margin: 0; overflow-wrap: anywhere; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 480px) {
  .uploader-page, .drawings-page { padding: 10px; }
  .drawing-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}

/* ---------- pregled fajla (crteži) ---------- */

.preview-dialog {
  width: min(96vw, 1100px);
  height: min(92dvh, 900px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
}
.preview-dialog[open] { display: flex; flex-direction: column; }
.preview-dialog::backdrop { background: rgba(0, 0, 0, .55); }

.preview-body { flex: 1; min-height: 0; }
.preview-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }

@media (max-width: 480px) {
  .preview-dialog { width: 100vw; height: 100dvh; max-width: 100vw; border-radius: 0; }
}
