/* ============================================================
   ZKS Copilot · CyberAid - design system
   Paleta: navy #1B365D, teal #2E86AB, accent #4DA8CF
   Ritam razmaka: 4px mreža. Radijus kartica: 14px.
   ============================================================ */

:root {
  --navy: #1B365D;
  --navy-2: #2E5780;
  --teal: #2E86AB;
  --teal-dark: #23698a;
  --accent: #4DA8CF;

  --bg: #F4F6FA;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --border: #E2E8F0;
  --border-strong: #CBD5E1;
  --text: #1E2A3E;
  --text-muted: #5B6B82;
  --text-faint: #8494AB;

  --ok: #1E7F4F;
  --ok-bg: #E7F5EE;
  --warn: #9A6700;
  --warn-bg: #FFF4DC;
  --danger: #B42318;
  --danger-bg: #FCEBEA;
  --info-bg: #EAF4F9;

  --badge-a: #B42318;
  --badge-a-bg: #FCEBEA;
  --badge-b: #9A6700;
  --badge-b-bg: #FFF4DC;
  --badge-c: #47586E;
  --badge-c-bg: #EDF1F6;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(27, 54, 93, .04);
  --shadow-lg: 0 8px 30px rgba(27, 54, 93, .12);
  --gradient-hero: linear-gradient(135deg, #1B365D 0%, #2E5780 100%);

  --sidebar-w: 264px;
  --sidebar-w-min: 76px;
  --sources-w: 304px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;
}

html[data-theme="dark"] {
  --bg: #0D1626;
  --surface: #152238;
  --surface-2: #1B2A44;
  --border: #263A58;
  --border-strong: #35496A;
  --text: #E7EDF6;
  --text-muted: #A3B2C8;
  --text-faint: #75869F;

  --ok: #4CC38A;
  --ok-bg: #123626;
  --warn: #E5B454;
  --warn-bg: #35290F;
  --danger: #F2726A;
  --danger-bg: #3A1815;
  --info-bg: #16304A;

  --badge-a: #F2726A;
  --badge-a-bg: #3A1815;
  --badge-b: #E5B454;
  --badge-b-bg: #35290F;
  --badge-c: #A9B8CE;
  --badge-c-bg: #223450;

  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, .45);
  --gradient-hero: linear-gradient(135deg, #10233F 0%, #1B365D 100%);
}

/* ---------- Reset i osnove ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; color: var(--text); }
p { margin: 0 0 8px; }
p:last-child { margin-bottom: 0; }
a { color: var(--teal); }
code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; }
[hidden] { display: none !important; }

/* samo za čitače zaslona */
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

button { font-family: inherit; }
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---------- Gumbi, polja ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 10px 16px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
  text-decoration: none;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--teal-dark); }
.btn-primary:active:not(:disabled) { background: var(--navy); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { border-color: var(--teal); color: var(--teal); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { color: var(--teal); border-color: var(--teal); background: var(--info-bg); }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border: none; border-radius: 8px;
  background: transparent; color: var(--text-muted); cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.input {
  width: 100%; padding: 10px 14px; font-size: 15px; font-family: inherit;
  color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input::placeholder { color: var(--text-faint); }
.input:focus-visible { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(46, 134, 171, .18); }
.input-inline { max-width: 280px; }

.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); margin: 0 0 6px; }
.check-row { display: flex; align-items: center; gap: 8px; margin: 12px 0 4px; font-size: 14px; color: var(--text-muted); cursor: pointer; }
.check-row input { width: 16px; height: 16px; accent-color: var(--teal); cursor: pointer; }

/* ---------- Kartice ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px;
}
.card-title { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 700; margin-bottom: 4px; color: var(--text); }
.card-title svg { color: var(--teal); flex: none; }
.card-sub { font-size: 13.5px; color: var(--text-muted); margin-bottom: 12px; }

/* ============================================================
   PRISTUPNI ZASLON
   ============================================================ */
.gate {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.gate-bg {
  position: absolute; inset: 0; background: var(--gradient-hero);
}
.gate-bg::before, .gate-bg::after {
  content: ""; position: absolute; border-radius: 50%; filter: blur(2px); opacity: .35;
}
.gate-bg::before { width: 480px; height: 480px; top: -160px; right: -120px; background: radial-gradient(circle, rgba(77,168,207,.5), transparent 70%); }
.gate-bg::after { width: 420px; height: 420px; bottom: -140px; left: -100px; background: radial-gradient(circle, rgba(46,134,171,.45), transparent 70%); }

.gate-card {
  position: relative; z-index: 1; width: 100%; max-width: 400px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow-lg);
  padding: 36px 32px 28px; text-align: center;
  animation: gate-in .35s ease both;
}
@keyframes gate-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.gate-logo { margin-bottom: 14px; }
.gate-title { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.gate-brand { font-size: 13px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: var(--teal); margin: 2px 0 14px; }
.gate-sub { font-size: 14px; color: var(--text-muted); margin-bottom: 22px; }
.gate-card form { text-align: left; }
.gate-card .btn-block { margin-top: 14px; padding: 12px 16px; font-size: 15px; }
.gate-error { color: var(--danger); font-size: 13.5px; margin: 10px 0 0; }
.gate-foot { margin-top: 22px; font-size: 12.5px; color: var(--text-faint); }
.gate-version { font-size: 11.5px; }

/* ============================================================
   RASPORED APLIKACIJE
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) auto;
  height: 100dvh;
}

/* ---------- Bočna traka ---------- */
.sidebar {
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
  overflow: hidden;
  transition: width .2s ease;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 16px 14px 12px 16px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); min-width: 0; }
.brand-mark { flex: none; display: inline-flex; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text strong { font-size: 15px; font-weight: 800; letter-spacing: -.01em; white-space: nowrap; }
.brand-text small { font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--teal); }
.sidebar-collapse-btn svg { transition: transform .2s ease; }

.main-nav { display: flex; flex-direction: column; gap: 2px; padding: 8px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 14px; font-weight: 600; text-decoration: none;
  transition: background-color .15s ease, color .15s ease;
  white-space: nowrap;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--info-bg); color: var(--navy); }
html[data-theme="dark"] .nav-item[aria-current="page"] { color: var(--accent); }
.nav-item[aria-current="page"] .nav-icon { color: var(--teal); }
.nav-icon { flex: none; display: inline-flex; color: var(--text-faint); }
.nav-item:hover .nav-icon { color: var(--teal); }

.sidebar-foot { padding: 10px 8px 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.foot-btn {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 9px 12px; border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-muted); font-size: 13.5px; font-weight: 600; cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
  white-space: nowrap;
}
.foot-btn:hover { background: var(--surface-2); color: var(--text); }
.version-row { padding: 8px 12px 0; font-size: 12px; color: var(--text-faint); white-space: nowrap; }

/* kompaktni prikaz potrošnje tokena u podnožju bočne trake */
.usage-row { padding: 6px 12px 0; font-size: 11.5px; color: var(--text-faint); }
.usage-line { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; white-space: nowrap; }
.usage-tier { font-weight: 700; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; }
.usage-mini-text { flex: none; font-variant-numeric: tabular-nums; }
.usage-bar {
  display: block; height: 6px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  overflow: hidden; margin: 8px 0 4px;
}
.usage-bar-mini { height: 4px; margin: 5px 0 0; }
.usage-fill { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--teal); transition: width .3s ease; }
.usage-fill.usage-warn { background: var(--warn); }
.usage-fill.usage-crit { background: var(--danger); }
/* ---------- Nedavni razgovori u bočnoj traci (v1.4.0) ---------- */
.history-section { margin: 2px 0 6px; min-width: 0; }
.history-toggle {
  display: flex; align-items: center; gap: 6px; width: 100%;
  padding: 6px 12px 4px; border: none; background: transparent; cursor: pointer;
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-faint); border-radius: var(--radius-sm); text-align: left;
  transition: color .15s ease;
}
.history-toggle:hover { color: var(--text-muted); }
.history-chevron { display: inline-flex; transition: transform .15s ease; }
.history-section.collapsed .history-chevron { transform: rotate(-90deg); }
.history-section.collapsed .history-list,
.history-section.collapsed .history-more { display: none; }
.history-list { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.history-item { position: relative; display: flex; align-items: center; min-width: 0; }
.history-open {
  display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0;
  padding: 7px 10px 7px 12px; border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-muted);
  font-size: 13px; font-weight: 500; text-align: left; cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
}
.history-item:hover .history-open, .history-open:focus-visible { background: var(--surface-2); color: var(--text); }
.history-item.active .history-open { background: var(--info-bg); color: var(--navy); font-weight: 600; }
html[data-theme="dark"] .history-item.active .history-open { color: var(--accent); }
.history-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-time { flex: none; font-size: 11px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.history-del {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; padding: 0; border: none; border-radius: 6px;
  background: transparent; color: var(--text-faint); cursor: pointer;
  opacity: 0;
  transition: opacity .12s ease, color .12s ease, background-color .12s ease;
}
.history-item:hover .history-del, .history-del:focus-visible { opacity: 1; }
.history-del:hover, .history-del:focus-visible { color: var(--danger); background: var(--danger-bg); }
/* kanta prekriva vrijeme - sakrij ga dok je kanta vidljiva */
.history-item:hover .history-time, .history-item:focus-within .history-time { visibility: hidden; }
.history-more {
  display: block; width: 100%; margin-top: 1px; padding: 6px 12px;
  border: none; border-radius: var(--radius-sm); background: transparent;
  color: var(--teal); font-size: 12.5px; font-weight: 600; text-align: left; cursor: pointer;
  transition: background-color .15s ease;
}
.history-more:hover { background: var(--surface-2); }

html[data-theme="light"] .theme-icon-dark, html:not([data-theme="dark"]) .theme-icon-dark { display: inline-flex; }
html:not([data-theme="dark"]) .theme-icon-light { display: none; }
html[data-theme="dark"] .theme-icon-light { display: inline-flex; }
html[data-theme="dark"] .theme-icon-dark { display: none; }

/* Skupljena bočna traka (ikone) */
.app.sidebar-mini { grid-template-columns: var(--sidebar-w-min) minmax(0, 1fr) auto; }
.app.sidebar-mini .brand-text, .app.sidebar-mini .nav-label, .app.sidebar-mini .version-row, .app.sidebar-mini .usage-row, .app.sidebar-mini .history-section { display: none; }
.app.sidebar-mini .sidebar-head { justify-content: center; padding-left: 8px; padding-right: 8px; flex-direction: column; gap: 10px; }
.app.sidebar-mini .nav-item, .app.sidebar-mini .foot-btn { justify-content: center; padding-left: 0; padding-right: 0; }
.app.sidebar-mini .sidebar-collapse-btn svg { transform: rotate(180deg); }

/* ---------- Središnji dio ---------- */
.content { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: none; align-items: center; gap: 10px;
  padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 16px; font-weight: 700; }
.backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(13, 22, 38, .5); }

.data-error-banner {
  margin: 12px 16px 0; padding: 12px 16px;
  background: var(--danger-bg); border: 1px solid var(--danger);
  border-radius: var(--radius-sm); color: var(--text); font-size: 13.5px;
  display: flex; flex-direction: column; gap: 2px;
}
.data-error-banner strong { color: var(--danger); }

.main { flex: 1; min-height: 0; display: flex; }
.view { flex: 1; min-width: 0; overflow-y: auto; }
.view-inner { max-width: 880px; margin: 0 auto; padding: 28px 24px 48px; }
.view-narrow { max-width: 720px; }
.view-header { margin-bottom: 24px; }
.view-header h2 { font-size: 24px; font-weight: 800; letter-spacing: -.02em; margin-bottom: 6px; }
.view-header p { color: var(--text-muted); font-size: 14.5px; max-width: 64ch; }
.section-title { font-size: 17px; font-weight: 700; margin: 28px 0 12px; }
.section-title:first-of-type { margin-top: 0; }

/* Prazna stanja */
.empty-state {
  padding: 32px 24px; text-align: center; color: var(--text-muted);
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius);
  font-size: 14px;
}
.empty-state strong { display: block; color: var(--text); margin-bottom: 4px; }

/* ============================================================
   CHAT
   ============================================================ */
.view-chat { display: flex; flex-direction: column; overflow: hidden; }
.chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 24px 12px; border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.chat-head-title h2 { font-size: 17px; font-weight: 800; }
.chat-head-sub { font-size: 12.5px; color: var(--text-muted); }
.chat-head-actions { display: flex; gap: 8px; }

.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.chat-messages { max-width: 760px; margin: 0 auto; padding: 24px 20px 12px; display: flex; flex-direction: column; gap: 14px; }

.msg { display: flex; flex-direction: column; max-width: 86%; }
.msg-user { align-self: flex-end; align-items: flex-end; }
.msg-assistant { align-self: flex-start; align-items: flex-start; }
.msg-bubble {
  padding: 12px 16px; border-radius: var(--radius);
  font-size: var(--msg-size, 14.5px); line-height: 1.6; overflow-wrap: break-word;
}
.msg-user .msg-bubble {
  background: linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 100%);
  color: #fff; border-bottom-right-radius: 5px;
  white-space: pre-wrap;
}
.msg-assistant .msg-bubble {
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow); border-bottom-left-radius: 5px;
}
.msg-error .msg-bubble { background: var(--danger-bg); border: 1px solid var(--danger); }
.msg-meta { font-size: 11px; color: var(--text-faint); margin-top: 4px; padding: 0 4px; }

/* akcije na porukama (Kopiraj / Ponovi / Pokušaj ponovno) */
.msg-actions { display: flex; gap: 6px; margin-top: 6px; opacity: 0; transition: opacity .15s ease; }
.msg-assistant:hover .msg-actions,
.msg-assistant:focus-within .msg-actions { opacity: 1; }
@media (hover: none) { .msg-actions { opacity: 1; } }
.msg-action-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 11px; min-height: 28px; font-size: 12px; font-weight: 600;
  color: var(--text-muted); background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; cursor: pointer;
  transition: color .15s ease, border-color .15s ease, background-color .15s ease;
}
.msg-action-btn:hover { color: var(--teal); border-color: var(--teal); }
.msg-action-btn.copied { color: var(--ok); border-color: var(--ok); }
.msg-action-retry { color: var(--danger); }
.msg-action-retry:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-bg); }

/* napomena o skraćenom/prekinutom odgovoru */
.msg-note {
  margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--border);
  font-size: 12px; color: var(--warn);
}

/* FAB: povratak na dno razgovora */
.scroll-fab {
  position: sticky; bottom: 14px;
  display: flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; margin: 8px 18px 0 auto;
  border-radius: 50%; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--teal); cursor: pointer;
  box-shadow: var(--shadow-lg); z-index: 5;
  transition: background-color .15s ease, color .15s ease;
}
.scroll-fab:hover { background: var(--info-bg); }

/* markdown unutar odgovora */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3, .msg-bubble h4 { font-size: 15px; margin: 12px 0 6px; }
.msg-bubble h1:first-child, .msg-bubble h2:first-child, .msg-bubble h3:first-child { margin-top: 0; }
.msg-bubble ul, .msg-bubble ol { margin: 6px 0; padding-left: 22px; }
.msg-bubble li { margin: 3px 0; }
.msg-bubble pre {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; overflow-x: auto; font-size: 13px; margin: 8px 0;
}
.msg-bubble pre code { background: none; border: none; padding: 0; }
.msg-bubble table { border-collapse: collapse; margin: 8px 0; width: 100%; font-size: 13.5px; }
.msg-bubble th, .msg-bubble td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.msg-bubble th { background: var(--surface-2); font-weight: 700; }
.msg-bubble blockquote { margin: 8px 0; padding: 4px 14px; border-left: 3px solid var(--accent); color: var(--text-muted); }
.msg-bubble hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }

/* indikator tipkanja */
.typing { display: inline-flex; gap: 5px; padding: 4px 2px; align-items: center; }
.typing-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); animation: typing-bounce 1.2s infinite ease-in-out; }
.typing-dot:nth-child(2) { animation-delay: .15s; }
.typing-dot:nth-child(3) { animation-delay: .3s; }
@keyframes typing-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* pozdravni (prazni) zaslon */
.chat-welcome { text-align: center; padding: 40px 20px 24px; color: var(--text-muted); }
.chat-welcome-icon { margin-bottom: 12px; }
.chat-welcome h3 { font-size: 20px; font-weight: 800; color: var(--text); margin-bottom: 6px; }
.chat-welcome p { font-size: 14px; max-width: 52ch; margin: 0 auto; }
.welcome-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px;
  max-width: 580px; margin: 22px auto 0; text-align: left;
}
.welcome-card {
  display: block; width: 100%; min-height: 44px; text-align: left;
  padding: 13px 16px; font-size: 13.5px; font-weight: 600; line-height: 1.45;
  color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; box-shadow: var(--shadow);
  transition: border-color .15s ease, background-color .15s ease;
}
.welcome-card:hover { border-color: var(--teal); background: var(--info-bg); }

/* donji dio chata - composer po uzoru na claude.ai */
.chat-bottom { padding: 10px 20px calc(14px + env(safe-area-inset-bottom)); }
.chat-form {
  max-width: 760px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 10px;
  padding: 10px 10px 10px 18px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 18px;
  box-shadow: 0 4px 18px rgba(27, 54, 93, .08), var(--shadow);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.chat-form:focus-within {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(46, 134, 171, .18), 0 4px 18px rgba(27, 54, 93, .08);
}
html[data-theme="dark"] .chat-form { box-shadow: 0 4px 18px rgba(0, 0, 0, .35); }
html[data-theme="dark"] .chat-form:focus-within { box-shadow: 0 0 0 3px rgba(77, 168, 207, .25), 0 4px 18px rgba(0, 0, 0, .35); }
.chat-input {
  flex: 1; resize: none; min-height: 24px; max-height: 260px;
  padding: 6px 0; font-size: 16px; font-family: inherit; line-height: 1.5;
  color: var(--text); background: transparent; border: none;
  overflow-y: hidden;
}
.chat-input:focus, .chat-input:focus-visible { outline: none; border: none; box-shadow: none; }
.chat-send { flex: none; width: 36px; height: 36px; padding: 0; border-radius: 50%; }
.chat-send:disabled { background: var(--border-strong); color: #fff; opacity: 1; }
.chat-disclaimer { max-width: 760px; margin: 8px auto 0; text-align: center; font-size: 11.5px; color: var(--text-faint); }

/* prazni razgovor (.is-empty): welcome blok + composer vertikalno centrirani,
   s prvom porukom composer se "usidri" na dno */
.view-chat.is-empty .chat-scroll { flex: 0 1 auto; margin-top: auto; }
.view-chat.is-empty .chat-bottom { margin-bottom: auto; padding-top: 0; }
.view-chat.is-empty .chat-welcome { padding-bottom: 8px; }

/* ---------- Panel Izvori ---------- */
.sources-panel {
  width: var(--sources-w); border-left: 1px solid var(--border);
  background: var(--surface); display: none; flex-direction: column;
  overflow-y: auto; padding: 18px 16px;
}
.sources-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 2px; }
.sources-title { font-size: 15px; font-weight: 800; }
.sources-sub { font-size: 12px; color: var(--text-muted); margin-bottom: 14px; }
.sources-list { display: flex; flex-direction: column; gap: 8px; }
.source-item {
  position: relative;
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.source-ref { font-size: 13.5px; font-weight: 700; color: var(--navy); }
html[data-theme="dark"] .source-ref { color: var(--accent); }
.source-doc { font-size: 12px; color: var(--text-muted); }

/* kartica izvora kao poveznica (NN / zsis.hr) */
a.source-item-link { text-decoration: none; color: inherit; cursor: pointer; transition: border-color .15s ease, background-color .15s ease; }
a.source-item-link:hover { border-color: var(--teal); background: var(--info-bg); }
a.source-item-link .source-ref { padding-right: 20px; }
.source-ext { position: absolute; top: 11px; right: 11px; color: var(--text-faint); transition: color .15s ease; }
a.source-item-link:hover .source-ext { color: var(--teal); }
.sources-empty { font-size: 13px; color: var(--text-faint); padding: 14px 4px; }
.sources-more {
  align-self: flex-start; padding: 6px 12px; margin-top: 2px;
  font-size: 12.5px; font-weight: 600; color: var(--teal);
  background: transparent; border: 1px dashed var(--border-strong); border-radius: 999px; cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease;
}
.sources-more:hover { border-color: var(--teal); background: var(--info-bg); }

body.sources-open .sources-panel { display: flex; }
@media (max-width: 1279.98px) { .sources-panel, .sources-toggle { display: none !important; } }
body:not(.route-chat) .sources-panel { display: none !important; }

/* ============================================================
   KATEGORIZACIJA - čarobnjak
   ============================================================ */
.wizard-steps { display: flex; gap: 4px; margin-bottom: 20px; flex-wrap: wrap; }
.wizard-step-tab {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 13px; border-radius: 999px; font-size: 13px; font-weight: 600;
  color: var(--text-faint); background: transparent; border: 1px solid transparent;
}
.wizard-step-tab .step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%; font-size: 11.5px; font-weight: 700;
  background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text-muted);
}
.wizard-step-tab.active { color: var(--navy); background: var(--info-bg); }
html[data-theme="dark"] .wizard-step-tab.active { color: var(--accent); }
.wizard-step-tab.active .step-num { background: var(--teal); border-color: var(--teal); color: #fff; }
.wizard-step-tab.done { color: var(--text-muted); }
.wizard-step-tab.done .step-num { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }

.wizard-body { margin-bottom: 16px; }
.wizard-q { font-size: 17px; font-weight: 700; margin-bottom: 4px; }
.wizard-hint { font-size: 13.5px; color: var(--text-muted); margin-bottom: 16px; }
.wizard-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 20px; }

.option-list { display: flex; flex-direction: column; gap: 8px; }
.option-group-label { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-faint); margin: 14px 0 6px; }
.option-group-label:first-child { margin-top: 0; }
.option-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; text-align: left; padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14.5px; font-weight: 600; color: var(--text); cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease;
}
.option-btn:hover { border-color: var(--teal); }
.option-btn.selected { border-color: var(--teal); background: var(--info-bg); }
.option-btn .option-sub { display: block; font-size: 12.5px; font-weight: 500; color: var(--text-muted); margin-top: 2px; }
.option-check { flex: none; color: var(--teal); opacity: 0; }
.option-btn.selected .option-check { opacity: 1; }

.size-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.size-grid .field { display: flex; flex-direction: column; }
.radio-row { display: flex; flex-wrap: wrap; gap: 8px; }
.radio-chip {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  padding: 9px 15px; border: 1px solid var(--border-strong); border-radius: 999px;
  font-size: 13.5px; font-weight: 600; color: var(--text-muted); background: var(--surface);
  transition: border-color .15s ease, background-color .15s ease, color .15s ease;
}
.radio-chip:hover { border-color: var(--teal); }
.radio-chip input { position: absolute; opacity: 0; pointer-events: none; }
.radio-chip.selected { border-color: var(--teal); background: var(--info-bg); color: var(--navy); }
html[data-theme="dark"] .radio-chip.selected { color: var(--accent); }
.radio-chip:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.check-list { display: flex; flex-direction: column; gap: 8px; }
.check-item {
  display: flex; align-items: flex-start; gap: 10px; cursor: pointer;
  padding: 11px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; background: var(--surface);
  transition: border-color .15s ease, background-color .15s ease;
}
.check-item:hover { border-color: var(--teal); }
.check-item input { margin-top: 3px; width: 15px; height: 15px; accent-color: var(--teal); flex: none; }
.check-item.selected { border-color: var(--teal); background: var(--info-bg); }

.callout {
  display: flex; gap: 10px; padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 13.5px; margin: 12px 0;
  background: var(--info-bg); border: 1px solid var(--accent); color: var(--text);
}
.callout-warn { background: var(--warn-bg); border-color: var(--warn); }
.callout-danger { background: var(--danger-bg); border-color: var(--danger); }
.callout strong { display: block; margin-bottom: 2px; }

/* rezultat */
.result-hero {
  background: var(--gradient-hero); color: #fff; border-radius: var(--radius);
  padding: 26px 24px; margin-bottom: 16px; box-shadow: var(--shadow-lg);
}
.result-label { font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; opacity: .75; margin-bottom: 6px; }
.result-category { font-size: 27px; font-weight: 800; letter-spacing: -.02em; margin-bottom: 8px; }
.result-explain { font-size: 14px; opacity: .9; max-width: 60ch; }
.result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin: 16px 0; }
.result-fact { padding: 14px 16px; }
.result-fact .fact-label { font-size: 11.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--text-faint); margin-bottom: 4px; }
.result-fact .fact-value { font-size: 14.5px; font-weight: 600; }
.result-citations { margin: 14px 0; }
.result-citations li { font-size: 13.5px; color: var(--text-muted); margin: 3px 0; }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }

/* ============================================================
   MJERE I OBVEZE
   ============================================================ */
.razina-select { margin-bottom: 20px; }
.razina-tabs { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 12px; }
.razina-tab {
  padding: 8px 18px; border: none; border-radius: 9px; cursor: pointer;
  font-size: 14px; font-weight: 700; color: var(--text-muted); background: transparent;
  transition: background-color .15s ease, color .15s ease;
}
.razina-tab:hover { color: var(--text); }
.razina-tab.active { background: var(--navy); color: #fff; }
html[data-theme="dark"] .razina-tab.active { background: var(--teal); }

.mjere-list { display: flex; flex-direction: column; gap: 10px; }
.mjera-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.mjera-toggle {
  display: flex; align-items: flex-start; gap: 14px; width: 100%; text-align: left;
  padding: 16px 18px; background: none; border: none; cursor: pointer; color: var(--text);
}
.mjera-toggle:hover { background: var(--surface-2); }
.mjera-num {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 10px; font-size: 14px; font-weight: 800;
  background: var(--info-bg); color: var(--navy);
}
html[data-theme="dark"] .mjera-num { color: var(--accent); }
.mjera-main { flex: 1; min-width: 0; }
/* naziv i opis su blok-elementi: bez toga se tekst naziva i opisa vizualno "lijepi" */
.mjera-name { display: block; font-size: 14.5px; font-weight: 700; line-height: 1.4; }
.mjera-desc { display: block; font-size: 13px; color: var(--text-muted); margin-top: 4px; line-height: 1.5; }
.mjera-badges { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.mjera-chevron { flex: none; color: var(--text-faint); transition: transform .2s ease; margin-top: 6px; }
.mjera-card.open .mjera-chevron { transform: rotate(180deg); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  white-space: nowrap;
}
.badge-a { background: var(--badge-a-bg); color: var(--badge-a); }
.badge-b { background: var(--badge-b-bg); color: var(--badge-b); }
.badge-c { background: var(--badge-c-bg); color: var(--badge-c); }
.badge-na { background: var(--surface-2); color: var(--text-faint); }

.mjera-body { border-top: 1px solid var(--border); padding: 6px 18px 16px; }
.podmjera { padding: 14px 0; border-bottom: 1px solid var(--border); }
.podmjera:last-child { border-bottom: none; }
.podmjera-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.podmjera-id { font-family: var(--mono); font-size: 12.5px; font-weight: 700; color: var(--teal); }
.podmjera-name { font-size: 14px; font-weight: 700; flex: 1; min-width: 200px; }
.podmjera-text { font-size: 13.5px; color: var(--text-muted); line-height: 1.6; }
.uvjet-callout {
  margin-top: 10px; padding: 10px 14px; border-radius: var(--radius-sm);
  background: var(--warn-bg); border: 1px solid var(--warn);
  font-size: 13px; color: var(--text);
}
.uvjet-callout strong { color: var(--warn); }
.mjere-legend { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: 12.5px; color: var(--text-muted); margin-bottom: 16px; }

/* ============================================================
   ROKOVI I INCIDENTI
   ============================================================ */
.incident-timeline { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 12px; margin-bottom: 24px; }
.deadline-card { padding: 18px; position: relative; overflow: hidden; }
.deadline-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--teal); border-radius: 4px 0 0 4px; }
.deadline-when { font-size: 21px; font-weight: 800; color: var(--navy); letter-spacing: -.02em; }
html[data-theme="dark"] .deadline-when { color: var(--accent); }
.deadline-name { font-size: 14px; font-weight: 700; margin: 4px 0 6px; }
.deadline-desc { font-size: 13px; color: var(--text-muted); }
.deadline-ref { display: inline-block; margin-top: 10px; font-size: 11.5px; font-weight: 700; color: var(--teal); background: var(--info-bg); border-radius: 999px; padding: 3px 10px; }

.calc-card { margin-bottom: 8px; }
.calc-row { margin: 14px 0; }
.deadline-results { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.deadline-result-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 14px;
  padding: 10px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; flex-wrap: wrap;
}
.deadline-result-row .dr-name { font-weight: 600; }
.deadline-result-row .dr-date { font-weight: 800; color: var(--navy); font-variant-numeric: tabular-nums; }
html[data-theme="dark"] .deadline-result-row .dr-date { color: var(--accent); }
.calc-empty { font-size: 13.5px; color: var(--text-faint); padding: 6px 2px; }

.table-card { padding: 6px 0; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td { text-align: left; padding: 11px 18px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table th { font-size: 12px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--text-faint); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table .ref-cell { font-size: 12.5px; color: var(--teal); font-weight: 600; white-space: nowrap; }

.kazne-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.kazna-card { padding: 18px; }
.kazna-title { font-size: 14px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--danger); margin-bottom: 8px; }
.kazna-amount { font-size: 20px; font-weight: 800; color: var(--text); margin-bottom: 6px; letter-spacing: -.01em; }
.kazna-desc { font-size: 13px; color: var(--text-muted); }
.kazna-desc dt { font-weight: 700; color: var(--text); margin-top: 8px; }
.kazna-desc dd { margin: 2px 0 0; }
.kazna-desc dl { margin: 0; }
.kazna-note .kazna-title { color: var(--text-muted); }

/* ---------- O aplikaciji ---------- */
.about-card { margin-bottom: 12px; }
.about-card p { font-size: 14px; color: var(--text-muted); }
.about-card p strong { color: var(--text); }
.about-list { margin: 4px 0 0; padding-left: 20px; font-size: 14px; color: var(--text-muted); }
.about-list li { margin: 5px 0; }

/* ---------- Modal: Postavke ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 120;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(13, 22, 38, .55);
}
.modal {
  width: 100%; max-width: 460px; max-height: 90dvh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  animation: gate-in .25s ease both;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 8px; }
.modal-head h2 { font-size: 18px; font-weight: 800; letter-spacing: -.01em; }
.modal-body { padding: 0 20px 20px; }
.settings-group { padding: 14px 0; border-bottom: 1px solid var(--border); }
.settings-group:last-child { border-bottom: none; padding-bottom: 4px; }
.settings-label {
  font-size: 11.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--text-faint); margin-bottom: 10px;
}
.settings-key-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.settings-key-row code { font-size: 13px; padding: 5px 10px; }

/* uloga i potrošnja tokena u Postavkama */
.settings-usage { margin-top: 12px; }
.usage-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 2px; }
.usage-name { font-size: 14px; font-weight: 700; color: var(--text); }
.tier-badge {
  display: inline-flex; align-items: center;
  font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 2px 9px; border-radius: 999px;
  background: var(--info-bg); color: var(--teal); border: 1px solid var(--accent);
}
.usage-numbers { font-size: 12.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.usage-expires { font-size: 12px; color: var(--text-faint); margin-top: 2px; }
.usage-loading { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-faint); }
.usage-unavailable { font-size: 12.5px; color: var(--text-faint); font-style: italic; }
.spinner {
  display: inline-block; width: 14px; height: 14px; flex: none;
  border: 2px solid var(--border-strong); border-top-color: var(--teal);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.settings-meta { font-size: 13px; color: var(--text-muted); }
.settings-meta a { font-weight: 600; }

/* ---------- Obavijesti (toast) ---------- */
.toast-container {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: min(440px, calc(100vw - 32px));
}
.toast {
  width: 100%; padding: 12px 18px; border-radius: var(--radius-sm);
  background: var(--navy); color: #fff; font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: toast-in .25s ease both;
}
.toast-error { background: var(--danger); }
.toast-warn { background: #7A5600; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ============================================================
   RESPONZIVNOST
   ============================================================ */

/* >=1280px: panel Izvori dopušten (upravljan klasom body.sources-open) */

@media (max-width: 1439.98px) {
  .view-inner { max-width: 800px; }
}

/* < 960px: bočna traka automatski mini */
@media (max-width: 959.98px) {
  .app { grid-template-columns: var(--sidebar-w-min) minmax(0, 1fr); }
  .app .brand-text, .app .nav-label, .app .version-row, .app .usage-row, .app .history-section { display: none; }
  .app .sidebar-head { justify-content: center; padding-left: 8px; padding-right: 8px; }
  .app .sidebar-collapse-btn { display: none; }
  .app .nav-item, .app .foot-btn { justify-content: center; padding-left: 0; padding-right: 0; }
  .view-inner { padding: 22px 18px 40px; }
}

/* < 640px: bočna traka postaje ladica, gornja traka s hamburgerom */
@media (max-width: 639.98px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; z-index: 50; top: 0; bottom: 0; left: 0;
    width: min(300px, 84vw); transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  .app.sidebar-open .sidebar { transform: translateX(0); }
  /* u ladici uvijek prikaži pune oznake */
  .app .sidebar .brand-text, .app .sidebar .nav-label, .app .sidebar .version-row { display: flex; }
  .app .sidebar .nav-label { display: inline; }
  .app .sidebar .usage-row { display: block; }
  /* povijest razgovora vidljiva u mobilnoj ladici (ali ne kad je [hidden]) */
  .app .sidebar .history-section:not([hidden]) { display: block; }
  /* na dodirnim uređajima nema hovera - kanta uvijek vidljiva, vrijeme ostaje */
  .app .sidebar .history-del { opacity: 1; }
  .app .sidebar .history-open { padding-right: 36px; }
  .app .sidebar .history-item .history-time { visibility: visible; }
  .app .sidebar-head { justify-content: space-between; padding: 16px 14px 12px 16px; }
  .app .nav-item, .app .foot-btn { justify-content: flex-start; padding: 11px 12px; }
  .topbar { display: flex; }
  .chat-head { padding: 12px 16px 10px; }
  .chat-head-sub { display: none; }
  .chat-messages { padding: 16px 14px 8px; }
  .msg { max-width: 94%; }
  .chat-bottom { padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); } /* puna širina minus 12px margine */
  .chat-form { padding: 8px 8px 8px 14px; border-radius: 16px; }
  /* 16px fonta composera sprječava iOS zoom (naslijeđeno iz osnovnog pravila) */
  .welcome-grid { grid-template-columns: 1fr; }
  .scroll-fab { margin-right: 12px; }
  .modal-overlay { padding: 12px; align-items: flex-end; }
  .modal { max-height: 86dvh; }
  .view-inner { padding: 18px 14px 36px; }
  .view-header h2 { font-size: 21px; }
  .size-grid { grid-template-columns: 1fr; }
  .wizard-nav { flex-direction: column-reverse; }
  .wizard-nav .btn { width: 100%; }
  .result-category { font-size: 23px; }
  .gate-card { padding: 28px 22px 22px; }
}

/* Ispis */
@media print {
  .sidebar, .topbar, .chat-bottom, .sources-panel, .toast-container { display: none !important; }
}
