/* Rehnut — disainisüsteem. Ainus stiilileht; asendab Pico.css-i.
   Põhimõtted: navi tumesinine külgriba, sisu hele; tihedad 14px tabelid ilma triibustuseta;
   rahasummad tabelnumbritega paremale; olekud värvimärgistega heledal taustal. */

:root {
    --primary: #1D4ED8;
    --primary-hover: #1E40AF;
    --primary-light: #EFF6FF;
    --sidebar-bg: #0F1D33;
    --sidebar-text: #94A3B8;
    --sidebar-text-active: #FFFFFF;
    --sidebar-active-bg: rgba(255, 255, 255, 0.08);
    --bg: #F6F8FA;
    --surface: #FFFFFF;
    --border: #E2E8F0;
    --border-strong: #CBD5E1;
    --text: #0F172A;
    --text-muted: #64748B;
    --negative: #DC2626;
    --positive: #15803D;
    --radius: 6px;
    --radius-lg: 10px;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; font-weight: 600; margin: 0; display: flex; align-items: center; gap: 10px; }
h1 small { font-weight: 400; }
code { background: var(--primary-light); padding: 1px 5px; border-radius: 4px; font-size: 13px; }

/* ── Rakenduse kest ─────────────────────────────────────────── */
.app { min-height: 100vh; }
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 216px;
    background: var(--sidebar-bg);
    display: flex; flex-direction: column;
    padding: 16px 10px;
    overflow-y: auto;
}
.sidebar .logo {
    color: #fff; font-size: 19px; font-weight: 700; letter-spacing: 0.2px;
    padding: 4px 10px 16px; text-decoration: none;
}
.sidebar .nav-group { margin-top: 14px; }
.sidebar .nav-group-label {
    font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px;
    color: #475569; padding: 0 10px 4px;
}
.sidebar .nav-item {
    display: block; color: var(--sidebar-text); font-size: 13.5px;
    padding: 6px 10px; border-radius: var(--radius); text-decoration: none;
    margin-bottom: 1px;
}
.sidebar .nav-item:hover { color: var(--sidebar-text-active); background: var(--sidebar-active-bg); text-decoration: none; }
.sidebar .nav-item.active { color: var(--sidebar-text-active); background: var(--sidebar-active-bg); font-weight: 600; }
.nav-badge {
    float: right; min-width: 18px; text-align: center;
    background: #F59E0B; color: #1F1300; font-size: 11px; font-weight: 700;
    border-radius: 999px; padding: 1px 6px; line-height: 1.4;
}
.nav-badge-muted { background: rgba(255, 255, 255, 0.16); color: #E2E8F0; }
.nav-badge.badge-zero { display: none; }   /* loendur 0 → peidus, aga element olemas (taustavärskendus) */
.sidebar .spacer { flex: 1; }
.sidebar .bottom { border-top: 1px solid rgba(255, 255, 255, 0.08); padding-top: 8px; margin-top: 8px; }

.main { margin-left: 216px; display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
    height: 48px; background: var(--surface); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; position: sticky; top: 0; z-index: 10;
}
.topbar .company { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.topbar .user { display: flex; align-items: center; gap: 12px; color: var(--text-muted); font-size: 13px; }
.content { padding: 24px; max-width: 1240px; width: 100%; }

/* ── Menüütulba kokkuklapp (lisaruum, nt ostuarve kõrvutivaates) ──────────── */
.topbar-left { display: flex; align-items: center; gap: 10px; }
.sidebar-toggle {
    background: none; border: none; color: var(--text-muted); cursor: pointer;
    font-size: 17px; line-height: 1; padding: 4px 9px; border-radius: var(--radius);
}
.sidebar-toggle:hover { background: rgba(15, 23, 42, 0.05); color: var(--text); }
.sidebar { transition: transform .18s ease; }
.main { transition: margin-left .18s ease; }
html.sidebar-collapsed .sidebar { transform: translateX(-100%); }
html.sidebar-collapsed .main { margin-left: 0; }
html.sidebar-collapsed .content { max-width: none; }   /* vabanenud ruum kasutusse */
@media (max-width: 1000px) { html.sidebar-collapsed .sidebar { display: none; } }

/* ── Lehe päis ──────────────────────────────────────────────── */
.page-header {
    display: flex; align-items: flex-end; justify-content: space-between;
    gap: 16px; margin-bottom: 18px; flex-wrap: wrap;
}
.page-header .actions { display: flex; align-items: center; gap: 8px; }
.page-header .actions form { margin: 0; }
.breadcrumb { font-size: 12.5px; color: var(--text-muted); margin-bottom: 2px; }
.breadcrumb a { color: var(--text-muted); }
.section-title {
    font-size: 15px; font-weight: 600; margin: 26px 0 10px;
    display: flex; align-items: center; gap: 8px;
}

/* ── Nupud ──────────────────────────────────────────────────── */
button, .btn, .btn-secondary, .btn-ghost {
    font-family: inherit; font-size: 13.5px; font-weight: 500;
    border-radius: var(--radius); cursor: pointer; line-height: 1.2;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    text-decoration: none; white-space: nowrap;
}
button, .btn {
    background: var(--primary); color: #fff; border: 1px solid var(--primary);
    padding: 8px 14px;
}
button:hover, .btn:hover { background: var(--primary-hover); border-color: var(--primary-hover); text-decoration: none; color: #fff; }
button.btn-secondary, .btn-secondary {
    background: var(--surface); color: var(--text); border: 1px solid var(--border-strong);
    padding: 8px 14px;
}
button.btn-secondary:hover, .btn-secondary:hover { background: var(--bg); text-decoration: none; color: var(--text); }
button.btn-ghost, .btn-ghost {
    background: transparent; color: var(--text-muted); border: 1px solid transparent;
    padding: 8px 10px;
}
button.btn-ghost:hover, .btn-ghost:hover { background: rgba(15, 23, 42, 0.05); color: var(--text); text-decoration: none; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
button.btn-danger, .btn-danger { color: var(--negative); }
button.btn-danger:hover, .btn-danger:hover { background: #FEF2F2; color: var(--negative); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Vormid ─────────────────────────────────────────────────── */
form { margin: 0 0 8px; }
label { display: block; font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 10px; }
input, select, textarea {
    font-family: inherit; font-size: 13.5px; color: var(--text);
    background: var(--surface); border: 1px solid var(--border-strong);
    border-radius: var(--radius); padding: 7px 10px; width: 100%;
    margin-top: 3px;
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary);
}
/* lukus väljad (funktsioon veel ühendamata): hall taust, muudetamatu */
input[readonly], textarea[readonly], input:disabled, select:disabled {
    background: #F1F5F9; color: var(--text-muted); cursor: not-allowed; border-color: var(--border);
}
input[type="checkbox"] { width: auto; margin: 0 6px 0 0; vertical-align: -2px; }
input[type="file"] { padding: 5px; background: transparent; border: none; }
label.check { display: flex; align-items: center; font-weight: 400; margin-bottom: 10px; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 4px; }
.form-row > label, .form-row > input, .form-row > select { flex: 1; min-width: 140px; }
.form-actions {
    display: flex; gap: 10px; align-items: center;
    padding: 14px 0 0; margin-top: 10px; border-top: 1px solid var(--border);
}
.filter-bar {
    display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: 12px 14px; margin-bottom: 18px;
}
.filter-bar label { margin-bottom: 0; }
.filter-bar > input, .filter-bar > select { width: auto; flex: 1; min-width: 130px; margin-top: 0; }
.input-sm { padding: 4px 8px; font-size: 12.5px; width: auto; margin-top: 0; }

/* ── Tabelid ────────────────────────────────────────────────── */
.table-wrap {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow); overflow-x: auto; margin-bottom: 18px;
}
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th {
    text-align: left; font-size: 11.5px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.5px; color: var(--text-muted);
    padding: 9px 12px; border-bottom: 1px solid var(--border);
    background: #FBFCFD; white-space: nowrap;
}
td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #F8FAFC; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
td small { display: block; color: var(--text-muted); font-size: 12px; }
tfoot td { border-top: 1px solid var(--border); border-bottom: none; font-weight: 500; }
tfoot tr.grand td { font-weight: 700; border-top: 2px solid var(--border-strong); font-size: 14px; }
.edit-table input, .edit-table select { margin-top: 0; }
.edit-table td { padding: 4px 6px; }
.edit-table input.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Kõrvutivaade: PDF | redigeeritav mustand ──────────────────── */
.review-split { display: grid; grid-template-columns: 1fr; gap: 20px; align-items: start; }
.review-split.has-pdf { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.review-pdf { position: sticky; top: 16px; align-self: start; }
.review-pdf-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.review-pdf iframe {
    width: 100%; height: 82vh; border: 1px solid var(--border);
    border-radius: var(--radius-lg); background: #fff; display: block;
}
.review-form { min-width: 0; }
.posted-pdf { margin-top: 18px; }
/* kinnitatud arve PDF: suletud olekus üherealine klõpsatav riba, avatuna vaatur */
.posted-pdf > summary {
    cursor: pointer; user-select: none; padding: 8px 10px; margin-bottom: 6px;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface-alt, #F8FAFC); font-size: 14px;
}
.posted-pdf > summary:hover { border-color: var(--primary); }
/* klaviatuur: Tab toob fookuse siia, Enter/Tühik avab-sulgeb — fookus peab olema selgelt näha */
.posted-pdf > summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.posted-pdf[open] > summary { margin-bottom: 8px; }
.posted-pdf iframe {
    width: 100%; height: 80vh; border: 1px solid var(--border);
    border-radius: var(--radius-lg); background: #fff; display: block;
}
.party-bar {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
    padding: 10px 14px; background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-lg); margin-bottom: 16px;
}
.party-info strong { font-size: 14px; }
.party-info .hint { display: block; margin-top: 2px; }
.party-saldo { text-align: right; white-space: nowrap; }
.party-saldo label { display: block; font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.party-saldo .num { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.review-totals { margin-top: 12px; margin-left: auto; max-width: 320px; }
.review-totals > div { display: flex; justify-content: space-between; padding: 3px 0; font-variant-numeric: tabular-nums; }
.review-totals .grand { border-top: 2px solid var(--border-strong); font-weight: 700; font-size: 14px; margin-top: 2px; padding-top: 5px; }
.review-totals .delta { font-size: 12.5px; margin-top: 6px; display: block; }
.review-totals .delta.warn { color: var(--negative); font-weight: 600; }
.review-totals .delta.ok { color: var(--text-muted); }
.doc-meta { margin-top: 28px; padding-top: 14px; border-top: 1px solid var(--border); }
@media (max-width: 1000px) {
    .review-split.has-pdf { grid-template-columns: 1fr; }
    .review-pdf { position: static; }
    .review-pdf iframe { height: 60vh; }
}
.report-table td { padding: 7px 12px; }
.report-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 1000px) { .report-cols { grid-template-columns: 1fr; } }
.row-actions { display: flex; gap: 6px; align-items: center; justify-content: flex-end; flex-wrap: wrap; margin: 0; }
.row-actions form { margin: 0; display: flex; gap: 6px; align-items: center; }

/* ── Olekumärgised ──────────────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center;
    font-size: 11.5px; font-weight: 600; letter-spacing: 0.2px;
    padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.badge-draft     { background: #F1F5F9; color: #475569; }
.badge-confirmed { background: #EFF6FF; color: #1D4ED8; }
.badge-sent      { background: #EEF2FF; color: #4338CA; }
.badge-paid      { background: #F0FDF4; color: #15803D; }
.badge-partial   { background: #FFFBEB; color: #B45309; }
.badge-overdue   { background: #FEF2F2; color: #DC2626; }
.badge-void      { background: #F8FAFC; color: #94A3B8; text-decoration: line-through; }
.badge-neutral   { background: #F1F5F9; color: #475569; }

/* ── Teated ─────────────────────────────────────────────────── */
.flash {
    border-radius: var(--radius-lg); padding: 10px 14px; margin-bottom: 14px;
    font-size: 13.5px; border: 1px solid;
}
.flash-ok   { background: #F0FDF4; border-color: #BBF7D0; color: #166534; }
.flash-err  { background: #FEF2F2; border-color: #FECACA; color: #991B1B; }
.flash-warn { background: #FFFBEB; border-color: #FDE68A; color: #92400E; }
.flash form { margin: 0; }

/* ── Kaardid ja paneelid ────────────────────────────────────── */
.stat-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px; margin-bottom: 22px;
}
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow); padding: 14px 16px;
}
.card header {
    font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--text-muted); margin-bottom: 6px;
}
.card p { margin: 0; color: var(--text-muted); font-size: 13px; }
.stat-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.card small { color: var(--text-muted); font-size: 12px; }
.report-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px; margin-bottom: 10px;
}
.card-link { display: block; color: var(--text); text-decoration: none; }
.card-link:hover { border-color: var(--primary); text-decoration: none; color: var(--text); }
.card-link:hover header { color: var(--primary); }
.panel {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 18px;
}
.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; margin-bottom: 18px; }
@media (max-width: 1000px) { .panel-grid { grid-template-columns: 1fr; } }
details.panel summary {
    cursor: pointer; font-weight: 600; font-size: 14px; user-select: none;
}
details.panel[open] summary { margin-bottom: 12px; }

/* ── Vajab tegutsemist (töölaud) ────────────────────────────── */
.todo-panel {
    background: #FFFBEB; border: 1px solid #FDE68A; border-radius: var(--radius-lg);
    padding: 12px 16px; margin-bottom: 18px;
}
.todo-title { font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px;
    color: #92400E; margin-bottom: 8px; }
.todo-item {
    display: flex; align-items: center; gap: 8px;
    color: var(--text); padding: 5px 0; text-decoration: none; font-size: 13.5px;
}
.todo-item:hover { color: var(--primary); text-decoration: none; }
.todo-item .nav-badge { float: none; }

/* ── Muu ────────────────────────────────────────────────────── */
.hint { color: var(--text-muted); font-size: 12.5px; font-weight: 400; }
p.hint { margin: 0 0 14px; }
.num-neg { color: var(--negative); }
.empty {
    background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius-lg);
    padding: 28px; text-align: center; color: var(--text-muted); margin-bottom: 18px;
}
.empty .btn { margin-top: 10px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar form { margin: 0; }
.detail-grid {
    display: flex; gap: 32px; flex-wrap: wrap;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: 12px 18px; margin-bottom: 18px;
}
.detail-item label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--text-muted); margin-bottom: 1px; }
.detail-item div { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ── Sisselogimine ──────────────────────────────────────────── */
.auth-page {
    min-height: 100vh; display: flex; align-items: flex-start; justify-content: center;
    background: var(--bg); padding: 10vh 16px 40px;
}
.auth-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
    width: 100%; max-width: 380px; padding: 32px 32px 26px;
}
.auth-logo { font-size: 24px; font-weight: 700; color: var(--sidebar-bg); display: flex; align-items: center; gap: 8px; }
.auth-sub { color: var(--text-muted); margin: 2px 0 20px; font-size: 13.5px; }
.auth-divider {
    display: flex; align-items: center; gap: 10px; color: var(--text-muted);
    font-size: 12px; margin: 18px 0;
}
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.auth-error { color: var(--negative); font-size: 13px; min-height: 1em; margin: 10px 0 0; }
/* Neutraalne olekutekst (nt "See võib võtta mõne sekundi…") — erineb punasest veast */
.auth-note { color: var(--text-muted); font-size: 13px; min-height: 1em; margin: 10px 0 0; }

/* Nupu laadimisolek: pöörlev spinner + sildivahetus (Web eID sisselogimine jm) */
@keyframes rehnut-spin { to { transform: rotate(360deg); } }
.spin {
    display: inline-block; width: 0.95em; height: 0.95em; vertical-align: -0.1em; margin-right: 0.5em;
    border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
    animation: rehnut-spin 0.6s linear infinite;
}
/* laadides jää täisnähtavaks (mitte 0.5 nagu :disabled) — signaal "töötab", mitte "keelatud" */
.btn.loading, .btn-secondary.loading { opacity: 1; cursor: progress; pointer-events: none; }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 1.6s; } }

/* ── Mobiil ─────────────────────────────────────────────────── */
@media (max-width: 820px) {
    .sidebar { position: static; width: 100%; height: auto; flex-direction: row; flex-wrap: wrap;
        align-items: center; gap: 2px; padding: 8px; }
    .sidebar .logo { padding: 4px 10px; font-size: 16px; }
    .sidebar .nav-group { margin: 0; display: contents; }
    .sidebar .nav-group-label { display: none; }
    .sidebar .spacer { display: none; }
    .sidebar .bottom { border: none; margin: 0; padding: 0; }
    .main { margin-left: 0; }
    .content { padding: 14px; }
    .app { display: flex; flex-direction: column; }
}

@media print {
    .sidebar, .topbar, .filter-bar, .form-actions, .row-actions, .toolbar { display: none !important; }
    .main { margin-left: 0; }
    body { background: #fff; }
    .table-wrap, .panel, .card { box-shadow: none; border-color: #999; }
}

/* ── Kelluke (teavituskeskus) ─────────────────────────────────────────────── */
.bell { position: relative; text-decoration: none; font-size: 16px; padding: 4px 6px; border-radius: var(--radius); }
.bell:hover { background: rgba(15, 23, 42, 0.05); }
.bell-count {
    position: absolute; top: -2px; right: -4px; background: #DC2626; color: #fff;
    font-size: 10px; font-weight: 700; line-height: 1; padding: 2px 5px; border-radius: 999px;
}
.bell-count.bell-zero { display: none; }
.notif-list { display: flex; flex-direction: column; gap: 8px; }
.notif {
    background: var(--surface, #fff); border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: var(--radius); padding: 12px 14px; display: flex; gap: 12px; align-items: flex-start;
}
.notif.notif-read { opacity: 0.55; }
.notif.notif-error { border-left: 3px solid #DC2626; }
.notif.notif-success { border-left: 3px solid #16A34A; }
.notif.notif-warn { border-left: 3px solid #D97706; }
.notif-main { flex: 1; }
.notif-title { font-weight: 600; }
.notif-body { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.notif-time { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.notif-actions { display: flex; gap: 8px; margin-top: 8px; align-items: center; }

/* ── Hamburgeri tähelepanutäpp (külgriba peideti automaatselt) ───────────── */
.sidebar-toggle { position: relative; }
.sidebar-toggle.sidebar-attn::after {
    content: ''; position: absolute; top: 3px; right: 3px;
    width: 8px; height: 8px; border-radius: 50%; background: #DC2626;
    animation: sidebar-attn-pulse 1.4s ease-in-out infinite;
}
@keyframes sidebar-attn-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.35; transform: scale(0.75); }
}

/* ── Tenandivahetaja (mitme firma kasutaja) ──────────────────────────────── */
.tenant-switch {
    font-weight: 600; font-size: 14px; border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: var(--radius); padding: 4px 8px; background: var(--surface, #fff);
    cursor: pointer;
}
