:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e2e5ea;
  --text: #1c2129;
  --muted: #69707d;
  --brand: #00afef;            /* fiskus plava: logo, oznake, fokus */
  --accent: #0079ad;           /* tamnija nijansa za linkove i gumbe (čitljiv bijeli tekst) */
  --accent-ink: #ffffff;
  --sel: #e4f5fd;
  --novo-bg: #dff4fd;  --novo: #006a96;
  --obrada-bg: #fff2d9; --obrada: #8a5a00;
  --rijeseno-bg: #e1f5e8; --rijeseno: #1d7a3e;
  --high-bg: #fde4e4; --high: #b42318;
  --med-bg: #fff2d9;  --med: #8a5a00;
  --low-bg: #eef0f3;  --low: #4b5563;
  --ai-bg: #e8f7fe;     --ai-border: #b9e5f8;     --ai-ink: #006a96;
  --client-bg: #fff2e6; --client-border: #fbd5b0; --client-ink: #a3470a;
  --danger: #b42318;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1d222a;
    --border: #2a3039;
    --text: #e6e9ee;
    --muted: #949ba6;
    --accent: #3cc4f5;
    --accent-ink: #04212e;
    --sel: #12303f;
    --novo-bg: #0f3345;  --novo: #7fd6f8;
    --obrada-bg: #3a2c0f; --obrada: #f3c46b;
    --rijeseno-bg: #13311f; --rijeseno: #7ad39a;
    --high-bg: #3d1716; --high: #ff8f86;
    --med-bg: #3a2c0f;  --med: #f3c46b;
    --low-bg: #262c35;  --low: #b4bac4;
    --ai-bg: #102c3a;     --ai-border: #1d4a5f;     --ai-ink: #7fd6f8;
    --client-bg: #33210f; --client-border: #5a3a1c; --client-ink: #ffb780;
    --danger: #ff8f86;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
[hidden] { display: none !important; }

/* fokus tipkovnicom */
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
input:focus-visible, textarea:focus-visible {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 25%, transparent);
}

/* ---------- gumbi ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .55; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
.link:hover { text-decoration: underline; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid transparent; background: none; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { border-color: var(--border); }
.icon-btn.on { color: var(--brand); }

/* ---------- bedževi ---------- */
.pill, .badge {
  display: inline-block; border-radius: 999px; padding: 1px 9px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.st-novo { background: var(--novo-bg); color: var(--novo); }
.st-u_obradi { background: var(--obrada-bg); color: var(--obrada); }
.st-rijeseno { background: var(--rijeseno-bg); color: var(--rijeseno); }
.urg-high { background: var(--high-bg); color: var(--high); }
.urg-med { background: var(--med-bg); color: var(--med); }
.urg-low { background: var(--low-bg); color: var(--low); }

/* ---------- gornja traka ---------- */
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; white-space: nowrap; }
.logo { display: block; width: 28px; height: 28px; border-radius: 7px; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface);
  border-top: 3px solid var(--brand); border-bottom: 1px solid var(--border);
}
.tabs { display: flex; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 2px; overflow-x: auto; }
.tabs button {
  border: 0; background: none; padding: 5px 10px; border-radius: 7px; cursor: pointer; white-space: nowrap; color: var(--muted);
}
.tabs button:hover { color: var(--text); }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.tabs .count {
  display: inline-block; min-width: 20px; margin-left: 3px; padding: 0 6px; border-radius: 999px;
  background: var(--border); font-size: 12px; font-weight: 600; text-align: center; font-variant-numeric: tabular-nums;
}
.tabs button.active .count { background: var(--novo-bg); color: var(--novo); }
#search {
  flex: 1; min-width: 180px; max-width: 360px;
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2);
}
.user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.user form { margin: 0; }

/* ---------- raspored ---------- */
body.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.split {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(380px, 1fr) minmax(420px, 1.15fr);
}
.list { overflow-y: auto; border-right: 1px solid var(--border); }
.detail { overflow-y: auto; background: var(--surface); }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.list-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; }

/* ---------- lista ---------- */
.row {
  display: grid; grid-template-columns: 78px minmax(0, 1fr) auto;
  gap: 12px; align-items: start; width: 100%; text-align: left;
  padding: 11px 16px; border: 0; border-bottom: 1px solid var(--border);
  background: var(--surface); cursor: pointer;
}
.row:hover { background: var(--surface-2); }
.row.sel { background: var(--sel); }
.row.hot { box-shadow: inset 3px 0 0 var(--high); }   /* hitan poziv: crvena crta uz rub */
.row:focus-visible { outline-offset: -2px; }
.row.is-novo .firma::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--brand); margin-right: 6px; vertical-align: 1px;
}
.row .time { font-variant-numeric: tabular-nums; }
.row .firma { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.is-novo .firma { font-weight: 700; }
.row .problem { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.row .num { font-size: 13px; }
.row .badges { display: flex; gap: 4px; }
.row.flash { animation: flash 2s ease-out; }
@keyframes flash { from { background: var(--novo-bg); } }

/* ---------- detalji ---------- */
.d-wrap { padding: 18px 22px 40px; max-width: 860px; }
.d-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.d-head h2 { margin: 0 0 2px; font-size: 20px; }
.d-head .badges { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.back { display: none; margin-bottom: 8px; }
.lead { margin: 12px 0 0; font-size: 15.5px; line-height: 1.5; white-space: pre-wrap; }
.card {
  margin-top: 16px; padding: 14px 16px; border: 1px solid var(--border); border-left: 3px solid var(--brand);
  border-radius: var(--radius); background: var(--surface-2);
}
.label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 3px; }
.bignum { font-size: 22px; font-weight: 700; letter-spacing: .3px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 6px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-top: 16px; }
.blk { margin-top: 22px; }
.blk-title { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
h3.blk { margin-top: 22px; }
.blk p { margin: 0; white-space: pre-wrap; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 7px 12px; cursor: pointer; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button:focus-visible { outline-offset: -2px; }
.seg button:not(.on) { color: var(--muted); }
.seg button:not(.on):hover { color: var(--text); background: var(--surface-2); }
.seg button.on { font-weight: 700; }
.seg button.on.st-novo { background: var(--novo-bg); color: var(--novo); }
.seg button.on.st-u_obradi { background: var(--obrada-bg); color: var(--obrada); }
.seg button.on.st-rijeseno { background: var(--rijeseno-bg); color: var(--rijeseno); }
textarea {
  display: block; width: 100%; min-height: 80px; margin-top: 10px; padding: 9px 10px; resize: vertical;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
.save-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }

/* snimak ostaje pri vrhu dok se lista transkript */
.player-bar {
  position: sticky; top: 0; z-index: 2;
  margin: 0 -6px; padding: 6px; background: var(--surface);
}
audio { display: block; width: 100%; height: 40px; }

/* ---------- transkript: AI plavo lijevo, klijent narančasto desno ---------- */
.transcript { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.msg {
  --role: var(--ai-ink);
  max-width: 85%; padding: 8px 12px 9px;
  border: 1px solid var(--ai-border); border-radius: 4px 14px 14px 14px;
  background: var(--ai-bg);
  font-size: 14.5px; line-height: 1.5;
  scroll-margin: 70px 0 16px;
}
.msg.client {
  --role: var(--client-ink);
  align-self: flex-end;
  border-color: var(--client-border); border-radius: 14px 4px 14px 14px;
  background: var(--client-bg);
}
.msg .who {
  display: flex; align-items: center; gap: 8px; margin-bottom: 2px;
  font-size: 12px; font-weight: 700; color: var(--role);
}
.msg .ts {
  border: 0; background: none; padding: 0; cursor: pointer;
  color: var(--role); font-size: 12px; font-weight: 400; font-variant-numeric: tabular-nums;
}
.msg .ts::before {
  content: ""; display: inline-block; margin-right: 4px;
  border-left: 6px solid currentColor; border-top: 4px solid transparent; border-bottom: 4px solid transparent;
}
.msg .ts:hover { text-decoration: underline; }
.msg .ts:disabled { color: var(--muted); cursor: default; text-decoration: none; }
.msg .ts:disabled::before { display: none; }
.msg.playing { box-shadow: 0 0 0 2px var(--role); }   /* rečenica koja se upravo čuje na snimku */

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px; box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
}
.toast.err { background: var(--danger); color: #fff; }

/* ---------- mobitel ---------- */
@media (max-width: 900px) {
  body.app { display: block; height: auto; min-height: 100%; }
  .topbar { gap: 10px; }
  .brand { order: 1; }
  .user { order: 2; margin-left: auto; }
  .tabs { order: 4; max-width: 100%; }
  #search { max-width: none; order: 5; flex-basis: 100%; }
  .split { grid-template-columns: 1fr; }
  .list { border-right: 0; }
  .detail { display: none; }
  body.show-detail .detail { display: block; position: fixed; inset: 0; z-index: 10; }
  body.show-detail { overflow: hidden; }
  .back { display: inline-block; }
  .d-wrap { padding: 14px 16px 40px; }
  .row { grid-template-columns: 64px minmax(0, 1fr) auto; padding: 10px 16px; }
  .msg { max-width: 92%; }
}

/* ---------- prijava ---------- */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-top: 3px solid var(--brand);
  border-radius: 14px; padding: 26px 26px 20px; box-shadow: var(--shadow);
}
.auth-card .brand { margin-bottom: 18px; }
.auth-card h1 { font-size: 20px; margin: 0 0 8px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.auth-card label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; }
.auth-card input {
  font-weight: 400; font-size: 15px; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2);
}
.auth-card .btn { padding: 10px 12px; margin-top: 4px; }
.auth-card .alert {
  background: var(--high-bg); color: var(--high); border-radius: 8px; padding: 9px 12px; margin: 10px 0 0; font-size: 13.5px;
}
.steps { padding-left: 20px; }
.steps li { margin-bottom: 10px; }
.qr { margin: 10px 0 6px; }
.qr img { width: 200px; height: 200px; image-rendering: pixelated; border-radius: 8px; background: #fff; padding: 6px; }
.key { word-break: break-all; font-size: 13px; }
