/* =========================================================================
   AI KNJIGOVOĐA — dizajn sistem
   Estetika: "kontrolna soba / knjiga" — precizno, mirno, poverljivo.
   Novac i konta uvek u monospace fontu (potpis interfejsa).
   ========================================================================= */

:root {
  /* Struktura */
  --ink:        #14202C;   /* sidebar / zaglavlje */
  --ink-2:      #1C2B3A;
  --ink-line:   #2A3B4D;

  /* Površine */
  --bg:         #EAEEF2;   /* hladna svetla podloga (ne krem) */
  --surface:    #FFFFFF;
  --surface-2:  #F5F7F9;

  /* Tekst */
  --text:       #16232F;
  --text-muted: #5C6B7A;
  --text-dim:   #8494A2;
  --on-ink:     #DCE6F0;
  --on-ink-dim: #8CA0B4;

  /* Akcenat (jedini brend akcenat) */
  --accent:     #2C6E9B;
  --accent-700: #22597E;
  --accent-050: #E7F0F7;

  /* Semantika statusa */
  --ok:      #1F7A54;  --ok-bg:   #E4F1EB;
  --warn:    #B0761A;  --warn-bg: #FBF0DC;
  --err:     #B23B32;  --err-bg:  #F8E4E2;
  --info:    #2C6E9B;  --info-bg: #E7F0F7;
  --neutral: #64748B;  --neutral-bg:#EDF1F4;

  --line:    #D8DFE6;
  --line-2:  #E7ECF0;

  --radius:  10px;
  --radius-s: 7px;
  --shadow:  0 1px 2px rgba(20,32,44,.06), 0 4px 16px rgba(20,32,44,.05);
  --shadow-lg: 0 8px 40px rgba(20,32,44,.16);

  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Space Grotesk", var(--font-ui);
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", "Cascadia Code", monospace;

  --sidebar-w: 232px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; letter-spacing: -.01em; margin: 0; }
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* numbers / accounts / money — potpis */
.mono, .amount, .acct { font-family: var(--font-mono); font-feature-settings: "tnum" 1; }
.amount { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------------------------------------------------------------- Layout */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--ink);
  color: var(--on-ink);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  padding: 20px 20px 18px;
  border-bottom: 1px solid var(--ink-line);
  display: flex; align-items: center; gap: 11px;
}
.brand__mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: linear-gradient(150deg, var(--accent), #3E8FC4);
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; color: #fff; font-size: 15px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.15);
}
.brand__name { font-family: var(--font-display); font-weight: 600; font-size: 15px; color: #fff; line-height: 1.15; }
.brand__sub { font-size: 11px; color: var(--on-ink-dim); }

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav__label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--on-ink-dim); padding: 14px 12px 6px; }
.nav__item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 8px;
  color: var(--on-ink); font-size: 13.5px; font-weight: 500;
  border: none; background: none; width: 100%; text-align: left;
  transition: background .12s, color .12s;
}
.nav__item:hover { background: var(--ink-2); }
.nav__item.is-active { background: var(--accent); color: #fff; }
.nav__item .ico { width: 17px; height: 17px; flex: none; opacity: .9; }
.nav__badge {
  margin-left: auto; font-family: var(--font-mono); font-size: 11px;
  background: rgba(255,255,255,.14); padding: 1px 7px; border-radius: 20px; min-width: 20px; text-align: center;
}
.nav__item.is-active .nav__badge { background: rgba(255,255,255,.24); }
.nav__badge.is-alert { background: var(--err); color: #fff; }

.userbox { padding: 12px 14px; border-top: 1px solid var(--ink-line); display: flex; align-items: center; gap: 10px; }
.userbox__avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-700); display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 12px; }
.userbox__name { font-size: 13px; font-weight: 600; color: #fff; }
.userbox__role { font-size: 11px; color: var(--on-ink-dim); text-transform: capitalize; }
.userbox__logout { margin-left: auto; background: none; border: none; color: var(--on-ink-dim); font-size: 12px; padding: 4px; }
.userbox__logout:hover { color: #fff; }

/* ---------------------------------------------------------------- Main */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 60px; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px; padding: 0 26px; position: sticky; top: 0; z-index: 20;
}
.topbar__title { font-size: 18px; }
.topbar__spacer { flex: 1; }
.provider-chip {
  font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted);
  background: var(--surface-2); border: 1px solid var(--line); padding: 4px 10px; border-radius: 20px;
  display: inline-flex; gap: 7px; align-items: center;
}
.provider-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }

.content { padding: 26px; max-width: 1240px; width: 100%; }
.view-head { margin-bottom: 18px; }
.view-head h2 { font-size: 15px; color: var(--text); }
.view-head p { margin: 3px 0 0; color: var(--text-muted); font-size: 13px; }

/* ---------------------------------------------------------------- Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  padding: 8px 14px; border-radius: var(--radius-s); font-size: 13px; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  transition: all .12s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-700); border-color: var(--accent-700); color: #fff; }
.btn--ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn--ok:hover { filter: brightness(.94); color: #fff; }
.btn--danger { background: var(--surface); border-color: var(--err); color: var(--err); }
.btn--danger:hover { background: var(--err); color: #fff; }
.btn--ghost { background: none; border-color: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); border-color: transparent; }
.btn--sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card__pad { padding: 18px; }

/* KPI grid */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 16px 14px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--neutral); }
.kpi.is-ok::before { background: var(--ok); }
.kpi.is-warn::before { background: var(--warn); }
.kpi.is-err::before { background: var(--err); }
.kpi.is-info::before { background: var(--accent); }
.kpi__label { font-size: 12px; color: var(--text-muted); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi__value { font-family: var(--font-display); font-size: 26px; font-weight: 600; margin-top: 8px; letter-spacing: -.02em; }
.kpi__value .amount { font-family: var(--font-mono); font-size: 20px; }
.kpi__sub { font-size: 11.5px; color: var(--text-dim); margin-top: 4px; }
.kpi__sub .amount { font-size: 12px; color: var(--text-muted); }

/* ---------------------------------------------------------------- Tables */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl thead th {
  background: var(--surface-2); text-align: left; font-weight: 600; color: var(--text-muted);
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em;
  padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.tbl tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover { background: var(--surface-2); cursor: default; }
.tbl .num { text-align: right; }
.tbl .clickable { cursor: pointer; }
.tbl .clickable:hover { background: var(--accent-050); }

/* ---------------------------------------------------------------- Chips */
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--neutral-bg); color: var(--neutral);
}
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.err { background: var(--err-bg); color: var(--err); }
.chip.info { background: var(--info-bg); color: var(--info); }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Risk nivoi (poreski inspektor) */
.chip.risk-nizak { background: var(--ok-bg); color: var(--ok); }
.chip.risk-srednji { background: var(--warn-bg); color: var(--warn); }
.chip.risk-visok { background: #FDE7DC; color: #C2410C; }
.chip.risk-kritican { background: var(--err-bg); color: var(--err); }
.kpi.is-crit::before { background: var(--err); }
.risk-bar { display: inline-block; height: 6px; border-radius: 3px; background: var(--line); vertical-align: middle; }
.finding { border-left: 3px solid var(--line); }
.finding.risk-nizak { border-left-color: var(--ok); }
.finding.risk-srednji { border-left-color: var(--warn); }
.finding.risk-visok { border-left-color: #C2410C; }
.finding.risk-kritican { border-left-color: var(--err); }
.legal-basis { font-size: 12px; color: var(--accent-700); background: var(--accent-050); padding: 6px 10px; border-radius: 6px; margin-top: 6px; }
.legal-basis.none { color: var(--warn); background: var(--warn-bg); }

/* ---------------------------------------------------------------- Ledger card (potpis) */
.ledger {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 14px; overflow: hidden;
}
.ledger__head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.ledger__title { font-family: var(--font-display); font-weight: 600; font-size: 14px; }
.ledger__meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.ledger__meta .acct { color: var(--accent); }
.ledger__conf { margin-left: auto; text-align: right; }
.ledger__conf small { display: block; font-size: 10.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.ledger__conf b { font-family: var(--font-mono); font-size: 15px; }

.ledger__entries { padding: 6px 16px 12px; }
.ledger-row {
  display: grid; grid-template-columns: 64px 1fr 120px 120px; gap: 8px; align-items: center;
  padding: 7px 0; border-bottom: 1px dashed var(--line-2);
}
.ledger-row:last-child { border-bottom: none; }
.ledger-row .acct { font-family: var(--font-mono); font-weight: 600; color: var(--ink); }
.ledger-row .desc { color: var(--text-muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; }
.ledger-row .amount { text-align: right; font-family: var(--font-mono); font-size: 13px; }
.ledger-row .amount.d { color: var(--text); }
.ledger-row .amount.k { color: var(--text); }
.ledger-row .amount.empty { color: var(--line); }
.ledger-cols { display: grid; grid-template-columns: 64px 1fr 120px 120px; gap: 8px; padding: 4px 0 2px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); border-bottom: 1px solid var(--line); }
.ledger-cols .r { text-align: right; }
.ledger__total { display: grid; grid-template-columns: 1fr 120px 120px; gap: 8px; padding: 9px 0 2px; border-top: 2px solid var(--ink); margin-top: 4px; font-weight: 700; }
.ledger__total .amount { text-align: right; font-family: var(--font-mono); }
.ledger__foot { padding: 12px 16px; background: var(--surface-2); border-top: 1px solid var(--line); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ledger__expl { font-size: 12px; color: var(--text-muted); flex: 1; min-width: 200px; }
.balance-flag { font-size: 11.5px; font-weight: 600; }
.balance-flag.ok { color: var(--ok); }
.balance-flag.bad { color: var(--err); }

/* ---------------------------------------------------------------- Issues */
.issue-group { margin-bottom: 16px; }
.issue-group__head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.issue-group__head h3 { font-size: 13.5px; }
.issue-list { display: flex; flex-direction: column; gap: 6px; }
.issue {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px;
  background: var(--surface); border: 1px solid var(--line); border-left-width: 3px; border-radius: var(--radius-s);
}
.issue.sev-error { border-left-color: var(--err); }
.issue.sev-warning { border-left-color: var(--warn); }
.issue.sev-info { border-left-color: var(--accent); }
.issue__msg { flex: 1; font-size: 13px; }
.issue__amount { font-family: var(--font-mono); font-size: 13px; font-weight: 600; }

/* ---------------------------------------------------------------- Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background:
  radial-gradient(1200px 600px at 20% -10%, #1E3247 0%, transparent 60%), var(--ink); padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden; }
.login-card__head { padding: 28px 28px 8px; text-align: center; }
.login-card__head .brand__mark { width: 44px; height: 44px; margin: 0 auto 14px; font-size: 20px; }
.login-card__head h1 { font-size: 20px; }
.login-card__head p { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.login-card__body { padding: 20px 28px 26px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-s);
  font-size: 14px; font-family: inherit; background: var(--surface-2); color: var(--text);
}
.input:focus { outline: none; border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px var(--accent-050); }
select.input { cursor: pointer; }
.login-hint { margin-top: 14px; font-size: 11.5px; color: var(--text-dim); text-align: center; line-height: 1.6; }
.login-hint code { font-family: var(--font-mono); background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.login-error { background: var(--err-bg); color: var(--err); padding: 9px 12px; border-radius: var(--radius-s); font-size: 12.5px; margin-bottom: 14px; }

/* ---------------------------------------------------------------- Modal / drawer */
.overlay { position: fixed; inset: 0; background: rgba(20,32,44,.42); z-index: 60; display: grid; place-items: center; padding: 20px; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 460px; overflow: hidden; }
.modal--wide { max-width: 720px; max-height: 92vh; display: flex; flex-direction: column; }
.modal--wide .modal__body { overflow-y: auto; flex: 1; }
.modal__head { padding: 18px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal__head h3 { font-size: 15px; }
.modal__head .x { margin-left: auto; background: none; border: none; font-size: 20px; color: var(--text-dim); line-height: 1; }
.modal__body { padding: 20px; }
.modal__foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; background: var(--surface-2); }

.company-bar { display: flex; align-items: center; gap: 8px; margin-right: 8px; }
.company-bar #company-switcher { max-width: 240px; min-width: 160px; }

.onboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.onboard-span-2 { grid-column: 1 / -1; }
.onboard-section { margin-bottom: 8px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.onboard-section:last-of-type { border-bottom: none; }
.onboard-section h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: 0 0 10px; }
.ob-check { display: flex !important; align-items: center; gap: 8px; margin-top: 28px; font-weight: 500 !important; color: var(--text) !important; cursor: pointer; }
.ob-check input { width: auto; }
.onboard-preview {
  margin: 4px 0 10px; padding: 10px 12px; border-radius: 10px;
  background: var(--surface-2); font-size: 12.5px; color: var(--text-muted); line-height: 1.5;
}
.onboard-preview strong { color: var(--text); }
.onboard-preview .chip { margin: 2px 4px 2px 0; }
@media (max-width: 640px) {
  .onboard-grid { grid-template-columns: 1fr; }
  .onboard-span-2 { grid-column: auto; }
  .company-bar { flex-wrap: wrap; }
}

.drawer-overlay { position: fixed; inset: 0; background: rgba(20,32,44,.42); z-index: 60; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: 520px; max-width: 92vw; background: var(--surface); box-shadow: var(--shadow-lg); z-index: 61; display: flex; flex-direction: column; }
.drawer__head { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.drawer__head h3 { font-size: 16px; }
.drawer__head .x { margin-left: auto; background: none; border: none; font-size: 22px; color: var(--text-dim); }
.drawer__body { padding: 22px; overflow-y: auto; flex: 1; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13px; margin-bottom: 18px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; font-weight: 500; }

/* ---------------------------------------------------------------- Utils */
.muted { color: var(--text-muted); }
.dim { color: var(--text-dim); }
.right { text-align: right; }
.mt-0 { margin-top: 0; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; align-items: center; gap: 10px; }
.flex-wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.empty { text-align: center; padding: 44px 20px; color: var(--text-dim); }
.empty__icon { font-size: 30px; margin-bottom: 10px; opacity: .5; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); margin: 22px 0 10px; font-weight: 600; }
.toast-zone { position: fixed; bottom: 22px; right: 22px; z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: var(--radius-s); font-size: 13px; box-shadow: var(--shadow-lg); animation: slideup .2s ease; max-width: 340px; }
.toast.ok { background: var(--ok); } .toast.err { background: var(--err); }
@keyframes slideup { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.spin { width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: rot .7s linear infinite; margin: 40px auto; }
@keyframes rot { to { transform: rotate(360deg); } }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -260px; transition: left .2s; z-index: 80; width: 240px; }
  .sidebar.open { left: 0; }
  .ledger-row, .ledger-cols { grid-template-columns: 52px 1fr 92px 92px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
