:root {
    --bg: #f4f5f3;
    --surface: #ffffff;
    --ink: #1c2321;
    --muted: #66706c;
    --line: #dfe3e0;
    --accent: #0f5f52;
    --accent-ink: #ffffff;
    --accent-soft: #e3f1ee;
    --warn: #8a5a00;
    --warn-soft: #fff4d6;
    --bad: #a12626;
    --bad-soft: #fde8e8;
    --ok: #1d6b3a;
    --ok-soft: #e3f4e8;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(20, 30, 28, .06), 0 4px 14px rgba(20, 30, 28, .04);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #131816;
        --surface: #1b2220;
        --ink: #e8eeeb;
        --muted: #98a39e;
        --line: #2c3532;
        --accent: #4cc2ad;
        --accent-ink: #0b1815;
        --accent-soft: #1d3a34;
        --warn: #f0c36a;
        --warn-soft: #3a2f14;
        --bad: #f09a9a;
        --bad-soft: #3d1f1f;
        --ok: #7bd69a;
        --ok-soft: #1c3526;
        --shadow: none;
    }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1 { font-size: 1.5rem; margin: 0 0 .75rem; line-height: 1.2; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; background: var(--accent-soft); padding: .05em .35em; border-radius: 4px; }
pre { margin: .25rem 0; padding: .5rem; background: var(--bg); border-radius: 6px; overflow-x: auto; white-space: pre-wrap; word-break: break-word; font-size: .8rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hidden-form { display: none; }

/* ---- рамка ---- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: .75rem;
    padding: .55rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--ink); text-decoration: none; letter-spacing: .01em; }
.brand-sub { font-weight: 500; color: var(--accent); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; justify-content: flex-end; }
.user-link { color: var(--ink); text-decoration: none; font-weight: 600; }
.nav-toggle { display: none; background: none; border: 1px solid var(--line); color: var(--ink); border-radius: 8px; padding: .25rem .6rem; font-size: 1.1rem; cursor: pointer; }
.bell { position: relative; text-decoration: none; font-size: 1.15rem; padding: 0 .25rem; }
.bell-count {
    position: absolute; top: -.45rem; right: -.45rem;
    min-width: 1.15rem; height: 1.15rem; padding: 0 .25rem;
    border-radius: 999px; background: var(--bad); color: #fff;
    font-size: .7rem; line-height: 1.15rem; text-align: center; font-weight: 700;
}
.inline-form { display: inline; margin: 0; }

.shell { display: flex; min-height: calc(100vh - 3.2rem); }
.sidebar {
    width: 15.5rem; flex: none;
    padding: 1rem .75rem;
    background: var(--surface);
    border-right: 1px solid var(--line);
    display: flex; flex-direction: column; gap: .15rem;
}
.nav-link {
    display: flex; justify-content: space-between; align-items: center;
    padding: .5rem .7rem; border-radius: 8px;
    color: var(--ink); text-decoration: none;
}
.nav-link:hover { background: var(--accent-soft); }
.nav-link.is-active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.nav-group { margin: 1rem .7rem .25rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.nav-foot { margin-top: auto; padding: .75rem .7rem 0; font-size: .75rem; color: var(--muted); }
.badge { background: var(--bad); color: #fff; border-radius: 999px; font-size: .72rem; padding: 0 .45rem; font-weight: 700; }
.content { flex: 1; min-width: 0; padding: 1.25rem 1.5rem 3rem; max-width: 78rem; }

/* ---- компоненти ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem 1.1rem;
    margin: 0 0 1rem;
}
.card.flush { padding: 0; overflow: hidden; }
.card .pad { padding: 1rem 1.1rem 0; }
.card.narrow { max-width: 26rem; }
.card.narrow-lg { max-width: 36rem; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); gap: 1rem; align-items: start; }
.form-row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; }
.form-row > label { flex: 1 1 12rem; }
.actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .75rem; }
td.actions { margin-top: 0; flex-wrap: nowrap; }

label { display: block; margin: 0 0 .75rem; font-weight: 500; }
label.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 .75rem; padding: .5rem .75rem; }
legend { padding: 0 .35rem; font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select {
    display: block; width: 100%; margin-top: .25rem;
    padding: .5rem .6rem; font: inherit; color: var(--ink);
    background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 2px;
}
input[type=checkbox] { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }
input:disabled, select:disabled { opacity: .6; }
.w-sm { width: 6rem; }
td input[type=text], td input[type=number] { margin-top: 0; }

.btn {
    display: inline-block; padding: .5rem .95rem; border-radius: 8px;
    border: 1px solid var(--line); background: var(--surface); color: var(--ink);
    font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-sm { padding: .3rem .65rem; font-size: .85rem; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }

.flash { padding: .65rem .9rem; border-radius: 8px; margin: 0 0 1rem; border: 1px solid transparent; word-break: break-word; }
.flash-ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.flash-error { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); }
.flash-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }

.chip { display: inline-block; padding: 0 .5rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); font-size: .75rem; color: var(--muted); }
.chip-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--bg); }
.table tr:last-child td { border-bottom: 0; }
.table.compact th, .table.compact td { padding: .35rem .6rem; }
.table tr.is-off td { opacity: .55; }
.matrix th.center, .matrix td.center { text-align: center; min-width: 6.5rem; }
.matrix .group-row td { background: var(--accent-soft); font-weight: 600; }

/* ---- dashboard ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: .85rem; margin: 0 0 1rem; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); }
.tile-label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.tile-value { font-size: 1.7rem; font-weight: 700; margin: .15rem 0 .35rem; font-variant-numeric: tabular-nums; }
.tile-meta { font-size: .8rem; color: var(--muted); }
.tile-src { font-size: .72rem; color: var(--muted); margin-top: .4rem; border-top: 1px dashed var(--line); padding-top: .35rem; }

.note-list { list-style: none; margin: 0; padding: 0; }
.note-list li { padding: .7rem 1rem; border-bottom: 1px solid var(--line); }
.note-list li:last-child { border-bottom: 0; }
.note-list li.is-unread { background: var(--accent-soft); }
.card:not(.flush) .note-list li { padding-left: 0; padding-right: 0; }
.card:not(.flush) .note-list li.is-unread { padding-left: .6rem; padding-right: .6rem; border-radius: 8px; }

.flow { display: flex; flex-wrap: wrap; gap: .4rem .25rem; list-style: none; padding: 0; margin: 0 0 .5rem; counter-reset: step; }
.flow li { counter-increment: step; background: var(--accent-soft); border-radius: 999px; padding: .2rem .75rem .2rem .45rem; font-size: .85rem; }
.flow li::before { content: counter(step); display: inline-block; width: 1.3rem; height: 1.3rem; line-height: 1.3rem; text-align: center; margin-right: .4rem; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: .72rem; font-weight: 700; }

/* ---- поставки ---- */
.setting { padding: .85rem 0; border-top: 1px solid var(--line); }
.setting:first-of-type { border-top: 0; }
.setting-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.setting-now .value { font-weight: 700; margin-right: .35rem; }
.setting-form { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; align-items: center; }
.setting-form input[type=text], .setting-form select { width: auto; min-width: 9rem; margin-top: 0; }
.setting-form input[type=date] { width: auto; margin-top: 0; }
.filters { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; }
.filters label { margin: 0; }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; margin: 1rem 0; }

.checks { list-style: none; margin: 0; padding: 0; }
.checks li { padding: .2rem 0; }
.checks .ok { color: var(--ok); }
.checks .bad { color: var(--bad); font-weight: 600; }

/* ---- проста страна (најава) ---- */
body.plain { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.plain-wrap { width: 100%; max-width: 26rem; }
.plain-wrap.wide { max-width: 46rem; }
.plain-brand { text-align: center; font-size: 1.6rem; font-weight: 700; margin-bottom: 1rem; }

/* ---- мобилно ---- */
@media (max-width: 860px) {
    .nav-toggle { display: inline-block; }
    .sidebar { display: none; position: fixed; top: 3.2rem; left: 0; bottom: 0; z-index: 15; box-shadow: 4px 0 20px rgba(0,0,0,.2); overflow-y: auto; }
    .sidebar.is-open { display: flex; }
    .content { padding: 1rem .9rem 3rem; }
    .user-link .muted { display: none; }
    .tiles { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
    .tiles { grid-template-columns: 1fr; }
    .topbar-right { gap: .5rem; }
}

/* ---- печатење на нарачка ---- */
.print-page { background: #fff; color: #111; }
.print-doc { max-width: 56rem; margin: 1.5rem auto; padding: 0 1rem; }
.print-bar { margin-bottom: 1rem; display: flex; gap: .5rem; }
.print-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.print-doc h1 { margin-bottom: .2rem; }
@media print {
    .print-bar { display: none; }
    .print-doc { margin: 0; max-width: none; padding: 0; }
    body { background: #fff; color: #000; }
}
code { white-space: nowrap; }
