/* SEF fakture — Apple stil: sistemski font (SF Pro), Apple sistemske boje (svetli + tamni režim),
   grupisane zaobljene kartice, „frosted” zaglavlje, segmentirane kontrole. Akcent: zlatna 15 Milja. */

:root {
    color-scheme: light dark;
    /* svetli režim (iOS/macOS system colors) */
    --bg: #f2f2f7;                       /* systemGroupedBackground */
    --card: #ffffff;                     /* secondarySystemGroupedBackground */
    --card-2: #f2f2f7;                   /* tertiary */
    --label: #000000;
    --label-2: rgba(60, 60, 67, 0.62);   /* secondaryLabel */
    --label-3: rgba(60, 60, 67, 0.32);   /* tertiaryLabel */
    --sep: rgba(60, 60, 67, 0.16);       /* separator */
    --fill: rgba(118, 118, 128, 0.12);   /* tertiarySystemFill */
    --fill-2: rgba(118, 118, 128, 0.2);
    --material: rgba(249, 249, 251, 0.78);
    --accent: #9a7433;                   /* zlatna, tamnija radi kontrasta */
    --accent-text: #ffffff;
    --accent-soft: rgba(154, 116, 51, 0.14);
    --green: #248a3d;  --green-soft: rgba(52, 199, 89, 0.15);
    --red: #d70015;    --red-soft: rgba(255, 59, 48, 0.12);
    --orange: #c93400; --orange-soft: rgba(255, 149, 0, 0.15);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
    --seg-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 3px 1px rgba(0, 0, 0, 0.04);
    --r: 12px;
    --r-sm: 9px;
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro", "Helvetica Neue", system-ui, "Segoe UI", sans-serif;
    --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro", "Helvetica Neue", system-ui, sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #000000;
        --card: #1c1c1e;
        --card-2: #2c2c2e;
        --label: #ffffff;
        --label-2: rgba(235, 235, 245, 0.62);
        --label-3: rgba(235, 235, 245, 0.3);
        --sep: rgba(84, 84, 88, 0.6);
        --fill: rgba(118, 118, 128, 0.24);
        --fill-2: rgba(118, 118, 128, 0.32);
        --material: rgba(28, 28, 30, 0.72);
        --accent: #d6b26e;
        --accent-text: #1c1c1e;
        --accent-soft: rgba(214, 178, 110, 0.16);
        --green: #30d158;  --green-soft: rgba(48, 209, 88, 0.16);
        --red: #ff453a;    --red-soft: rgba(255, 69, 58, 0.16);
        --orange: #ff9f0a; --orange-soft: rgba(255, 159, 10, 0.16);
        --shadow: none;
        --seg-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
    }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--label);
    font: 15px/1.47 var(--font);
    letter-spacing: -0.01em;
    -webkit-font-smoothing: antialiased;
}

h1 {
    margin: 0 0 0.25rem;
    font: 700 clamp(1.75rem, 4vw, 2.125rem)/1.15 var(--font-display);
    letter-spacing: -0.025em;
}

code { background: var(--fill); border-radius: 5px; padding: 0.05em 0.35em; font: 0.88em var(--mono); }
a { color: var(--accent); }
.muted { color: var(--label-2); }
.small { font-size: 0.82rem; }
.block { display: block; }
.nowrap { white-space: nowrap; }
.link { color: var(--accent); text-decoration: none; }
.link:hover { text-decoration: underline; }

/* ---------- Zaglavlje (frosted) ---------- */
.top {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 0.6rem clamp(1rem, 4vw, 2rem);
    background: var(--material);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 0.5px solid var(--sep);
}
.brand { display: flex; flex-direction: column; line-height: 1.15; color: var(--label); text-decoration: none; }
.brand-mark { font: 600 1.06rem var(--font-display); letter-spacing: -0.02em; }
.brand-sub { font-size: 0.72rem; color: var(--label-2); }

/* segmentirana kontrola */
.tabs {
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    background: var(--fill);
    border-radius: var(--r-sm);
    margin-right: auto;
}
.tabs a {
    padding: 0.32rem 1rem;
    border-radius: 7px;
    color: var(--label);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: background 0.15s ease;
}
.tabs a:hover { background: var(--fill); }
.tabs a.is-active { background: var(--card); box-shadow: var(--seg-shadow); font-weight: 600; }
@media (prefers-color-scheme: dark) { .tabs a.is-active { background: #636366; } }

.who { display: flex; align-items: center; gap: 1rem; margin: 0; }
.who-link, .who-name { color: var(--accent); text-decoration: none; font-size: 0.88rem; }
.who-name { color: var(--label-2); }
.who-link:hover, .who-name:hover, .who-link.is-active, .who-name.is-active { color: var(--accent); text-decoration: none; opacity: 0.8; }

/* ---------- Raspored ---------- */
.page { max-width: 1180px; margin: 0 auto; padding: 2rem clamp(1rem, 4vw, 2rem) 4rem; }
.center { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem 1rem; }
.page-head { margin-bottom: 1.5rem; }
.page-head p { margin: 0; max-width: 60rem; }

.card {
    background: var(--card);
    border-radius: var(--r);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}
.auth { width: 100%; max-width: 380px; padding: 2rem; }
.auth-wide { max-width: 440px; }
.auth h1 { font-size: 1.75rem; }
.eyebrow { margin: 0 0 0.35rem; color: var(--label-2); font-size: 0.8rem; font-weight: 500; }

.empty { text-align: center; padding: 3rem 1.5rem; }
.empty-title { margin: 0 0 0.25rem; font: 600 1.06rem var(--font-display); }
.empty p { margin: 0; }

/* naslovi sekcija, kao iOS grupisane liste */
.sub { margin: 1.75rem 0 0.5rem; font: 600 1.06rem var(--font-display); letter-spacing: -0.015em; color: var(--label); }
h2.sub:first-child, .inv-grid .sub { margin-top: 0; }
.sub-sm { margin: 1.25rem 0 0.5rem 0.25rem; font-size: 0.78rem; font-weight: 400; color: var(--label-2); text-transform: uppercase; letter-spacing: 0.02em; }

/* ---------- Forme ---------- */
.form { display: grid; gap: 0.9rem; margin-top: 1.25rem; }
.form label { display: grid; gap: 0.3rem; font-size: 0.82rem; color: var(--label-2); }
input, select, button { font: inherit; letter-spacing: inherit; }
.form input, .filters input, .filters select {
    display: block;
    width: 100%;
    min-width: 0;
    height: 2.4rem;
    padding: 0 0.75rem;
    background: var(--fill);
    border: 0;
    border-radius: var(--r-sm);
    color: var(--label);
    font-size: 0.94rem;
    outline: none;
    transition: box-shadow 0.15s ease;
}
.form input::placeholder, .filters input::placeholder { color: var(--label-3); }
.form input:focus, .filters input:focus, .filters select:focus { box-shadow: 0 0 0 3.5px var(--accent-soft), 0 0 0 1px var(--accent); }
.form .code-input { height: 3rem; font: 600 1.5rem var(--mono); letter-spacing: 0.4em; text-align: center; }
.form .check { display: flex; align-items: center; gap: 0.55rem; color: var(--label); font-size: 0.92rem; }
.form .check input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
select {
    -webkit-appearance: none;
    appearance: none;
    padding-right: 2rem !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none' stroke='%238e8e93' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
}
input[type="date"] { -webkit-appearance: none; appearance: none; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
input[type="date"] { line-height: 2.4rem; }
input[type="date"]::-webkit-datetime-edit, input[type="date"]::-webkit-datetime-edit-fields-wrapper { padding: 0; }
input[type="date"]::-webkit-calendar-picker-indicator { opacity: 0.55; }
input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; }

/* ---------- Dugmad ---------- */
.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 0.35rem;
    height: 2.4rem;
    padding: 0 1.1rem;
    border: 0;
    border-radius: var(--r-sm);
    font-size: 0.94rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: opacity 0.15s ease, background 0.15s ease;
}
a.btn { text-decoration: none; }
.btn:active { opacity: 0.7; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3.5px var(--accent-soft), 0 0 0 1px var(--accent); }
.btn-gold { background: var(--accent); color: var(--accent-text); }
.btn-gold:hover { opacity: 0.88; }
.btn-ghost { background: var(--fill); color: var(--accent); }
.btn-ghost:hover { background: var(--fill-2); }
.btn-sm { height: 1.85rem; padding: 0 0.75rem; font-size: 0.8rem; border-radius: 7px; }
.btn-danger { color: var(--red); }

/* ---------- Poruke ---------- */
.alert { margin: 1rem 0 0; padding: 0.75rem 1rem; border-radius: var(--r-sm); font-size: 0.9rem; }
.alert-error { background: var(--red-soft); color: var(--red); }
.alert-ok { background: var(--green-soft); color: var(--green); }
.alert-warn { background: var(--orange-soft); color: var(--orange); }
.flash { margin: 0 0 1.25rem; }

/* ---------- 2FA ---------- */
.steps { margin: 0.75rem 0 1.25rem; padding-left: 1.2rem; font-size: 0.9rem; color: var(--label-2); }
.steps li { margin-bottom: 0.3rem; }
.steps strong, .muted strong { color: var(--label); font-weight: 600; }
.qr { width: fit-content; margin: 0 auto 1rem; padding: 12px; background: #fff; border-radius: var(--r); line-height: 0; box-shadow: var(--shadow); }
.qr svg { display: block; max-width: 100%; height: auto; }
.secret {
    margin: 0 0 0.5rem;
    padding: 0.65rem 0.85rem;
    background: var(--fill);
    border-radius: var(--r-sm);
    font: 600 0.92rem/1.4 var(--mono);
    letter-spacing: 0.06em;
    word-break: break-all;
    color: var(--label);
}

/* ---------- Sinhronizacija ---------- */
.sync-panel {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1rem;
    margin-bottom: 1rem;
    padding: 0.7rem 0.75rem 0.7rem 1rem;
    background: var(--card);
    border-radius: var(--r);
    box-shadow: var(--shadow);
}
.sync-panel form { margin: 0; }
.sync-info { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 0.55rem; font-size: 0.88rem; }
.sync-info strong { font-weight: 600; }
.sync-details { margin: -0.25rem 0 1rem; font-size: 0.82rem; color: var(--label-2); }
.sync-details summary { cursor: pointer; }
.sync-details pre { white-space: pre-wrap; word-break: break-word; background: var(--card); padding: 0.75rem 1rem; border-radius: var(--r-sm); font: 0.8rem/1.5 var(--mono); }

/* ---------- Bedževi i oznake ---------- */
.badge {
    display: inline-block;
    padding: 0.12rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-ok { background: var(--green-soft); color: var(--green); }
.badge-warn { background: var(--orange-soft); color: var(--orange); }
.badge-bad { background: var(--red-soft); color: var(--red); }
.badge-neutral { background: var(--fill); color: var(--label-2); }
.badge-lg { font-size: 0.82rem; padding: 0.22rem 0.75rem; }
.tag {
    display: inline-block;
    margin-left: 0.35rem;
    padding: 0.02rem 0.4rem;
    background: var(--fill);
    border-radius: 5px;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--label-2);
    vertical-align: 0.1em;
}

/* ---------- Filteri ---------- */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--card);
    border-radius: var(--r);
    box-shadow: var(--shadow);
}
.filters label { display: grid; gap: 0.3rem; min-width: 0; font-size: 0.75rem; font-weight: 500; color: var(--label-2); }
.filters label { flex: 1 1 150px; }
.filters .f-q { flex: 2 1 260px; }
.filters .f-q input {
    padding-left: 2rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='none' stroke='%238e8e93' stroke-width='1.8' stroke-linecap='round'%3E%3Ccircle cx='6' cy='6' r='4.8'/%3E%3Cpath d='M9.6 9.6L13 13'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 0.7rem center;
}
.f-actions { display: flex; gap: 0.5rem; flex: 0 0 auto; }
.list-count { margin: 0 0 0.6rem 0.25rem; font-size: 0.88rem; }
.list-count strong { font-weight: 600; }
.pager { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 1.25rem; font-size: 0.88rem; }

/* ---------- Tabele (grupisane liste) ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); }
.table-plain { margin: 0 0 1.5rem; }
.inv, .plain { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.inv th, .plain th {
    text-align: left;
    padding: 0.65rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--label-2);
    border-bottom: 0.5px solid var(--sep);
    white-space: nowrap;
}
.inv td, .plain td { padding: 0.7rem 1rem; border-bottom: 0.5px solid var(--sep); vertical-align: top; }
.inv tbody tr:last-child td, .plain tbody tr:last-child td { border-bottom: 0; }
.inv tbody tr { transition: background 0.1s ease; }
.inv tbody tr:hover { background: var(--fill); }
.inv .num, .plain .num { text-align: right; font-variant-numeric: tabular-nums; }
.inv-no { color: var(--label); font-weight: 600; text-decoration: none; white-space: nowrap; }
.inv-no:hover { color: var(--accent); }
/* ceo red je klikabilan: link broja fakture se proteže preko reda (Cmd+klik → novi tab radi) */
.inv tbody tr { position: relative; cursor: pointer; }
.inv-no::after { content: ""; position: absolute; inset: 0; }
.inv tbody tr:hover .inv-no { color: var(--accent); }
.inv-no:focus-visible { outline: none; }
.inv tbody tr:has(.inv-no:focus-visible) { box-shadow: inset 0 0 0 2px var(--accent); }
.sm-label { display: none; }

/* ---------- Detalj fakture ---------- */
.crumbs { margin: 0 0 1rem; font-size: 0.9rem; }
.crumbs .link { font-weight: 500; }
.inv-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 1rem 2rem; margin-bottom: 1.5rem; }
.inv-partner { margin: 0; font-size: 1rem; color: var(--label-2); }
.inv-head-right { display: grid; justify-items: end; gap: 0.5rem; }
.inv-total { margin: 0; font: 700 1.9rem/1.1 var(--font-display); letter-spacing: -0.025em; font-variant-numeric: tabular-nums; }
.inv-total .muted { font-weight: 500; font-size: 1.1rem; }
.inv-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.inv-actions .dl { font-size: 0.82rem; }
.inv-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.inv-grid .card { padding: 1.1rem 1.25rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.45rem 1rem; margin: 0.6rem 0 0; font-size: 0.9rem; }
.kv dt { color: var(--label-2); }
.kv dd { margin: 0; }
.kv-num dd { text-align: right; font-variant-numeric: tabular-nums; }
.inv-meta { margin-top: 1.5rem; }

.attachments { list-style: none; margin: 0 0 1.5rem; padding: 0; background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.attachments li { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.75rem; padding: 0.65rem 1rem; border-bottom: 0.5px solid var(--sep); }
.attachments li:last-child { border-bottom: 0; }

/* ---------- Korisnici ---------- */
.row-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.35rem; }
.row-actions form { margin: 0; }
.users td { vertical-align: middle; }
.add-user { margin-top: 1.5rem; }

/* ---------- Zbirovi ---------- */
.year-tabs { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 2px; margin-bottom: 1rem; background: var(--fill); border-radius: var(--r-sm); }
.year-tabs a { padding: 0.3rem 1rem; border-radius: 7px; color: var(--label); text-decoration: none; font-size: 0.85rem; font-weight: 500; }
.year-tabs a:hover { background: var(--fill); }
.year-tabs a.is-active { background: var(--card); box-shadow: var(--seg-shadow); font-weight: 600; }
@media (prefers-color-scheme: dark) { .year-tabs a.is-active { background: #636366; } }
.report th.grp { text-align: center; border-left: 0.5px solid var(--sep); }
.report tfoot th { color: var(--label); font-size: 0.88rem; font-weight: 600; border-top: 0.5px solid var(--sep); border-bottom: 0; background: var(--card-2); }
.report tfoot th.num { text-align: right; font-variant-numeric: tabular-nums; }
.report tr.is-empty td { color: var(--label-3); }
.report tr.is-selected td { background: var(--accent-soft); }
.neg { color: var(--red); }
.period-head { display: flex; align-items: baseline; gap: 1rem; }
.report-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1.5rem; }

/* ---------- Srednji ekrani ---------- */
@media (max-width: 1000px) {
    .f-actions { flex: 1 1 100%; }
    .f-actions .btn { flex: 1; }
    .inv-grid { grid-template-columns: 1fr; }
    .report-grid { grid-template-columns: 1fr; }
}

/* ---------- Telefon ---------- */
@media (max-width: 720px) {
    body { font-size: 16px; }
    .top { flex-wrap: wrap; gap: 0.6rem 1rem; padding: 0.6rem 1rem 0.7rem; }
    .brand { flex: 1; }
    .tabs { order: 3; flex-basis: 100%; margin-right: 0; }
    .tabs a { flex: 1; text-align: center; }
    .who { gap: 0.75rem; }
    .who-name { display: inline-block; max-width: 6.5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
    .hide-sm { display: none; }
    .page { padding-top: 1.25rem; }
    .card { padding: 1.25rem; }
    .inv-head-right { justify-items: start; }

    /* lista faktura → ćelije kao u iOS listi */
    .table-wrap { overflow: hidden; }
    .inv thead { display: none; }
    .inv, .inv tbody { display: block; }
    .inv tr {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas: "no amount" "partner status" "date date";
        gap: 0.15rem 0.75rem;
        padding: 0.75rem 1rem;
        border-bottom: 0.5px solid var(--sep);
    }
    .inv tbody tr:last-child { border-bottom: 0; }
    .inv td { padding: 0; border: 0; }
    .inv .c-no { grid-area: no; }
    .inv .c-amount { grid-area: amount; font-weight: 600; }
    .inv .c-partner { grid-area: partner; color: var(--label-2); }
    .inv .c-status { grid-area: status; text-align: right; }
    .sm-label { display: inline; }
    .inv .c-date { grid-area: date; font-size: 0.8rem; color: var(--label-3); }
    .inv .c-partner .block { display: inline; margin-left: 0.3rem; white-space: nowrap; }
    .table-wrap.table-plain { overflow-x: auto; }
}
