/* ==========================================================================
   Loko vožnja · službeno vozilo – responzivni izgled (PC + mobitel)
   Bez vanjskih CDN-ova, bez JS frameworka.
   ========================================================================== */
:root {
  --bg: #f2f5f9;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --border: #e1e7ef;
  --text: #17212e;
  --muted: #6b7889;
  --primary: #1f5fbf;
  --primary-600: #194f9f;
  --primary-50: #e9f1fc;
  --brand: #13304f;
  --brand-2: #1d4a78;
  --ok: #1e9e55;
  --ok-50: #e5f6ec;
  --warn: #b7791f;
  --warn-50: #fff5dc;
  --danger: #c63a2d;
  --danger-50: #fde8e5;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .07);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, .10);
  --tap: 44px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1622; --surface: #162130; --surface-2: #1b2838; --border: #2a3a4f;
    --text: #e6edf5; --muted: #95a3b5; --primary: #4b8ef0; --primary-600: #3a7ad8; --primary-50: #1b2f4b;
    --brand: #0b1520; --brand-2: #183251;
    --ok-50: #143524; --warn-50: #3a2e12; --danger-50: #3d1a17;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 8px 24px rgba(0,0,0,.45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; line-height: 1.5; color: var(--text); background: var(--bg);
}
a { color: var(--primary); text-underline-offset: 2px; }
h1 { font-size: 24px; line-height: 1.25; margin: 4px 0 16px; letter-spacing: -.01em; }
h2 { font-size: 18px; margin: 24px 0 12px; }
p { margin: 0 0 12px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }

/* ---------- Gornja traka i navigacija ---------- */
.topbar { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; position: sticky; top: 0; z-index: 50; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.topbar-inner { max-width: 1240px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; min-width: 0; margin-right: auto; }
.brand .logo { width: 38px; height: 38px; border-radius: 10px; background: rgba(255,255,255,.14); display: grid; place-items: center; flex: none; }
.brand .logo svg { width: 24px; height: 24px; }
.brand .bt { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.brand b { font-size: 16px; font-weight: 700; white-space: nowrap; }
.brand small { font-size: 12px; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
.navtoggle { position: absolute; opacity: 0; pointer-events: none; }
.hamburger { display: none; width: var(--tap); height: var(--tap); border-radius: 10px; cursor: pointer; align-items: center; justify-content: center; margin: 0; }
.hamburger:hover { background: rgba(255,255,255,.12); }
.hamburger span, .hamburger span::before, .hamburger span::after { display: block; width: 22px; height: 2px; background: #fff; border-radius: 2px; position: relative; transition: transform .2s, background .2s; }
.hamburger span::before, .hamburger span::after { content: ""; position: absolute; left: 0; }
.hamburger span::before { top: -7px; }
.hamburger span::after { top: 7px; }
.navtoggle:checked + .hamburger span { background: transparent; }
.navtoggle:checked + .hamburger span::before { transform: translateY(7px) rotate(45deg); }
.navtoggle:checked + .hamburger span::after { transform: translateY(-7px) rotate(-45deg); }
.navtoggle:focus-visible + .hamburger { outline: 2px solid #fff; }
.mainnav { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.mainnav a { color: #dce8f6; text-decoration: none; padding: 8px 12px; border-radius: 8px; font-weight: 500; font-size: 14px; display: flex; align-items: center; gap: 7px; min-height: 38px; }
.mainnav a svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.mainnav a:hover { background: rgba(255,255,255,.10); color: #fff; }
.mainnav a.active { background: rgba(255,255,255,.18); color: #fff; }
.mainnav a.cta { background: var(--ok); color: #fff; }
.mainnav a.cta:hover { filter: brightness(1.08); }
.mainnav a.logout { opacity: .8; }

main { width: 100%; max-width: 1240px; margin: 0 auto; padding: 24px 20px 8px; flex: 1; }
footer { text-align: center; color: var(--muted); font-size: 12px; padding: 24px 20px 32px; }

/* ---------- Kartice, naslovi ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow); }
.card > h2:first-child { margin-top: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { margin: 0; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--primary); }
.stat.ok::before { background: var(--ok); }
.stat.warn::before { background: var(--warn); }
.stat.dark::before { background: var(--brand-2); }
.stat .lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.stat .val { font-size: 26px; font-weight: 750; line-height: 1.2; margin-top: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat .val small { font-size: 14px; font-weight: 600; color: var(--muted); }
.stat .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Tablice ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; margin-bottom: 18px; }
.card .table-wrap { box-shadow: none; }
table.list { width: 100%; border-collapse: collapse; background: var(--surface); font-size: 14px; }
table.list th, table.list td { border-bottom: 1px solid var(--border); padding: 11px 12px; text-align: left; vertical-align: top; }
table.list th { background: var(--surface-2); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 650; white-space: nowrap; }
table.list tr:last-child > * { border-bottom: 0; }
table.list tbody tr:hover td, table.list tr:hover td { background: color-mix(in srgb, var(--primary-50) 45%, transparent); }
table.list td.num, table.list th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.list tr.open td { background: var(--warn-50); }
table.list tr.total th { background: var(--surface-2); color: var(--text); font-size: 13.5px; text-transform: none; letter-spacing: 0; }
table.list .rowactions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
table.list td.actions-cell { white-space: nowrap; }

/* ---------- Obrasci ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px 18px; }
.form-grid .wide { grid-column: 1 / -1; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--muted); }
label:has(input[type=checkbox]) { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 14px; min-height: var(--tap); cursor: pointer; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--primary); flex: none; margin: 0; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=month], input[type=email], input[type=password], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; font-size: 16px; color: var(--text); background: var(--surface); transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); }
input:disabled { background: var(--surface-2); color: var(--muted); }
textarea { min-height: 88px; resize: vertical; }

.btn, button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); padding: 10px 18px; border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--primary); color: #fff; font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.2; transition: background .15s, filter .15s, transform .05s; }
.btn:hover, button:hover { background: var(--primary-600); }
.btn:active, button:active { transform: translateY(1px); }
.btn.secondary, button.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover, button.secondary:hover { background: var(--surface-2); }
.btn.danger, button.danger { background: var(--surface); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.btn.danger:hover, button.danger:hover { background: var(--danger-50); }
.btn.success, button.success { background: var(--ok); }
.btn.small, button.small { min-height: 36px; padding: 6px 12px; font-size: 13.5px; }
form.inline { display: inline; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 16px; }

.filters { display: flex; flex-wrap: wrap; gap: 12px 14px; align-items: flex-end; }
.filters > div { min-width: 180px; }
.filters > div:last-child { display: flex; gap: 8px; flex-wrap: wrap; flex: 1 1 auto; }
.filters label { margin-bottom: 6px; }

/* ---------- Poruke, oznake ---------- */
.flash { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 14px; border: 1px solid; border-left-width: 4px; }
.flash.ok { background: var(--ok-50); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.flash.warn { background: var(--warn-50); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.flash.err { background: var(--danger-50); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.muted { color: var(--muted); font-size: 13px; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.badge.open { background: #ffe08a; border-color: #f2c94c; color: #6b4e00; }
.badge.warn { background: var(--danger-50); border-color: color-mix(in srgb, var(--danger) 35%, transparent); color: var(--danger); }
.badge.ok { background: var(--ok-50); border-color: color-mix(in srgb, var(--ok) 35%, transparent); color: var(--ok); }
code.token { word-break: break-all; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); padding: 2px 6px; border-radius: 5px; }
pre.url { white-space: pre-wrap; word-break: break-all; background: var(--surface-2); border: 1px solid var(--border); padding: 12px; border-radius: var(--radius-sm); font-size: 12.5px; }
ol.steps li, ul li { margin-bottom: 8px; }
.route { display: inline; }
.route .arrow { color: var(--muted); margin: 0 4px; }

/* Plutajući gumb „Nova vožnja” (samo mobitel) */
.fab { display: none; }

/* ---------- Prijava ---------- */
body.login { background: radial-gradient(120% 90% at 50% 0%, #245a90 0%, #13304f 55%, #0b1726 100%); background-attachment: fixed; }
body.login .muted { color: var(--muted); }
.login-wrap { width: 100%; max-width: 420px; margin: 0 auto; padding: 12vh 20px 40px; flex: 1; }
.login-wrap .brand { justify-content: center; margin: 0 0 22px; }
.login-wrap .brand small { max-width: none; }
.login-wrap .card { padding: 26px; box-shadow: var(--shadow-lg); }
.login-wrap h1 { font-size: 22px; margin-bottom: 4px; }
.login-wrap .actions button { width: 100%; }

/* ---------- Mobilni zasloni ---------- */
@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .hamburger { display: inline-flex; }
  .topbar-inner { padding: 8px 14px; gap: 8px; }
  .mainnav { display: none; width: 100%; flex-direction: column; align-items: stretch; gap: 2px; padding: 6px 0 10px; border-top: 1px solid rgba(255,255,255,.12); }
  .navtoggle:checked ~ .mainnav { display: flex; }
  .mainnav a { min-height: 48px; font-size: 16px; padding: 10px 12px; }
  .mainnav a svg { width: 20px; height: 20px; }
  .mainnav a.cta { justify-content: center; margin-top: 6px; }
}
@media (max-width: 680px) {
  body { font-size: 15.5px; }
  main { padding: 16px 12px 88px; }
  h1 { font-size: 21px; }
  .card { padding: 16px; border-radius: 14px; }
  .stats { gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat .val { font-size: 21px; }
  .form-grid { grid-template-columns: 1fr; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters > div { min-width: 0; width: 100%; }
  .filters > div:last-child > * { flex: 1 1 auto; }
  .actions > button, .actions > .btn { flex: 1 1 auto; }
  .page-head .btn { display: none; }
  .fab { display: inline-flex; position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 40; height: 56px; padding: 0 22px; border-radius: 28px; background: var(--ok); color: #fff; font-weight: 700; font-size: 16px; align-items: center; gap: 8px; text-decoration: none; box-shadow: 0 6px 18px rgba(0,0,0,.25); }

  /* Tablice -> kartice (oznake stupaca dodaje mala skripta iz zaglavlja tablice) */
  .table-wrap.stack { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  table.list.stack, table.list.stack tbody, table.list.stack tr, table.list.stack td, table.list.stack th { display: block; width: 100%; }
  table.list.stack { background: transparent; }
  table.list.stack tr.head { display: none; }
  table.list.stack tr { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); margin-bottom: 12px; padding: 6px 14px; overflow: hidden; }
  table.list.stack tr.open { background: var(--warn-50); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
  table.list.stack tr.open td, table.list.stack tr:hover td { background: transparent; }
  table.list.stack td { border-bottom: 1px dashed var(--border); padding: 9px 0; text-align: right; display: flex; justify-content: space-between; align-items: baseline; gap: 14px; }
  table.list.stack td::before { content: attr(data-label); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; font-weight: 650; color: var(--muted); text-align: left; flex: none; max-width: 45%; }
  table.list.stack td[data-label=""]::before { display: none; }
  table.list.stack td > * { text-align: right; }
  table.list.stack td.num { white-space: normal; }
  table.list.stack td.lead { display: block; text-align: left; font-size: 16px; font-weight: 650; border-bottom: 1px solid var(--border); padding-top: 10px; }
  table.list.stack td.lead::before { display: none; }
  table.list.stack td.lead > * { text-align: left; }
  table.list.stack td.actions-cell { border-bottom: 0; display: flex; justify-content: stretch; padding: 12px 0 8px; }
  table.list.stack td.actions-cell::before { display: none; }
  table.list.stack td.actions-cell .rowactions { width: 100%; justify-content: stretch; }
  table.list.stack td.actions-cell .rowactions > * { flex: 1 1 0; }
  table.list.stack td.actions-cell .btn, table.list.stack td.actions-cell button { width: 100%; min-height: var(--tap); }
  table.list.stack td.actions-cell form.inline { display: flex; }
  table.list.stack td:last-child { border-bottom: 0; }
  table.list.stack td.empty { text-align: center; display: block; }
  table.list.stack td.empty::before { display: none; }
  table.list.stack tr.total { background: var(--brand-2); color: #fff; border: 0; }
  table.list.stack tr.total th { background: transparent; color: #fff; border: 0; padding: 8px 0; text-align: left !important; display: flex; justify-content: space-between; }
  table.list.stack tr.total th:empty { display: none; }
  table.list.stack input[type=text] { width: 100% !important; }
  table.list.stack td form.inline { display: flex; gap: 8px; align-items: center; }

  .brand small { max-width: 52vw; }
}

/* ---------- Mobilne stranice START / KRAJ ---------- */
body.mobile { background: radial-gradient(120% 80% at 50% 0%, #1d4a78 0%, #12263d 60%, #0b1726 100%); color: #fff; }
.mobile-wrap { width: 100%; max-width: 480px; margin: 0 auto; padding: 28px 18px calc(28px + env(safe-area-inset-bottom)); text-align: center; }
.mobile-wrap h1 { font-size: 26px; }
.mobile-wrap .veh { opacity: .85; margin-bottom: 18px; }
.bigbtn { display: block; width: 100%; padding: 34px 10px; font-size: 34px; font-weight: 800; border-radius: 22px; border: 0; color: #fff; margin: 16px 0; cursor: pointer; letter-spacing: 1px; box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.bigbtn.start { background: linear-gradient(180deg, #25b864, #1a8f4c); }
.bigbtn.end { background: linear-gradient(180deg, #e04a3c, #b52f23); }
.bigbtn:hover { filter: brightness(1.06); }
.bigbtn:disabled { opacity: .5; }
.mobile-wrap input[type=text] { font-size: 18px; padding: 14px; color: #1d2733; background: #fff; border: 0; }
.mobile-wrap label { color: #dce8f6; }
.mobile-wrap .result { background: #fff; color: #1d2733; border-radius: 16px; padding: 16px; text-align: left; margin: 12px 0; }
.mobile-wrap .result.err { background: #fde4e1; }
.mobile-wrap .result dt { font-size: 12px; color: #7a8796; margin-top: 8px; }
.mobile-wrap .result dd { margin: 0; font-size: 17px; font-weight: 600; }
.mobile-wrap a { color: #9cc6ff; }
.mobile-wrap .muted { color: #b5c4d6; }
.mobile-wrap #status { min-height: 24px; }

/* ---------- Izvješće za ispis (A4) – uvijek svijetlo ---------- */
.report-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); box-shadow: var(--shadow); }
.report { background: #fff; color: #111; padding: 14mm 12mm; max-width: 297mm; min-width: 900px; margin: 0 auto; border: 1px solid #dde3ea; font-size: 12px; color-scheme: light; }
.report h1 { text-align: center; font-size: 17px; margin: 6px 0 2px; text-transform: uppercase; }
.report .subtitle { text-align: center; margin-bottom: 12px; }
.report .head { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 24px; margin-bottom: 10px; }
.report .head div span { color: #555; display: inline-block; min-width: 125px; }
.report table { width: 100%; border-collapse: collapse; }
.report th, .report td { border: 1px solid #555; padding: 3px 4px; vertical-align: top; }
.report th { background: #e9edf2; font-size: 11px; }
.report td.num { text-align: right; white-space: nowrap; }
.report tfoot td { font-weight: 700; background: #f3f5f8; }
.report .sum { margin-top: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 24px; }
.report .signs { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 30px; margin-top: 34px; text-align: center; }
.report .signs div { border-top: 1px solid #000; padding-top: 4px; }
.report .legal { margin-top: 18px; font-size: 10px; color: #333; border-top: 1px solid #aaa; padding-top: 6px; }
.scroll-hint { display: none; }
@media (max-width: 680px) { .scroll-hint { display: block; margin: -4px 0 10px; } }

@page { size: A4 landscape; margin: 10mm; }
@media print {
  :root { color-scheme: light; }
  body { background: #fff; color: #000; font-size: 11px; display: block; }
  .no-print, .topbar, footer, .flash, .fab, .scroll-hint { display: none !important; }
  main { margin: 0; padding: 0; max-width: none; }
  .report-scroll { overflow: visible; box-shadow: none; }
  .report { border: 0; padding: 0; max-width: none; min-width: 0; }
  .report tr { page-break-inside: avoid; }
  .report th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Dodatno: ćelija tokena u postavkama */
.tokencell { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.tokencell form.inline { display: inline-flex; }
@media (max-width: 680px) {
  table.list.stack td .cv { min-width: 0; overflow-wrap: anywhere; }
  table.list.stack .tokencell { align-items: stretch; }
  table.list.stack .tokencell .btn, table.list.stack .tokencell button { width: 100%; }
}
table.list .rowactions { flex-wrap: nowrap; }
@media (max-width: 680px) {
  table.list.stack td.block { display: block; text-align: left; }
  table.list.stack td.block::before { display: block; max-width: none; margin-bottom: 3px; }
  table.list.stack td.block > * { text-align: left; }
}
