:root {
    --bg: #faf8f5;
    --panel: #ffffff;
    --ink: #2b1f14;
    --muted: #7a6e65;
    --line: #e5ddd6;
    --brand: #0f766e;
    --brand-dark: #115e59;
    --accent: #b45309;
    --danger: #b91c1c;
    --sidebar-bg: #1e1a16;
    --sidebar-hover: #2d2620;
    --sidebar-text: #d4ccc5;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
}

a {
    color: var(--brand-dark);
    text-decoration: none;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 220px;
    background: var(--sidebar-bg);
    color: #fff;
    padding: 18px 12px;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    letter-spacing: 0;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    background: #c0392b;
    color: #fff;
    font-size: 15px;
    font-weight: 900;
    letter-spacing: -1px;
    overflow: hidden;
    flex-shrink: 0;
}

.brand-logo {
    height: 40px;
    width: auto;
    max-width: 120px;
    object-fit: contain;
    flex-shrink: 0;
}

.brand-name {
    font-size: 15px;
    letter-spacing: .5px;
    color: #fff;
}

.menu {
    display: grid;
    gap: 2px;
    margin-top: 22px;
}

.menu a {
    color: var(--sidebar-text);
    padding: 13px 14px;
    border-radius: 8px;
    font-size: 14.5px;
    font-weight: 500;
    letter-spacing: 0.1px;
    transition: background .12s, color .12s;
    line-height: 1.2;
}

.menu a:hover {
    background: var(--sidebar-hover);
    color: #fff;
    padding-left: 18px;
    transition: background .12s, color .12s, padding-left .12s;
}

.menu a.active {
    background: var(--sidebar-hover);
    color: #fff;
    font-weight: 700;
}

.app {
    margin-left: 220px;
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    height: 64px;
    padding: 12px 24px;
    background: #fff;
    border-bottom: 1px solid var(--line);
}

.quick-search {
    flex: 1;
}

input,
select,
textarea {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 9px 11px;
    background: #fff;
    color: var(--ink);
}

textarea {
    min-height: 86px;
    resize: vertical;
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.content {
    padding: 24px;
}

.page-head,
.panel-head,
.userbar,
.form-actions,
.page-actions,
.inline-form,
.filters {
    display: flex;
    align-items: center;
    gap: 12px;
}

.page-head {
    justify-content: space-between;
    margin-bottom: 18px;
}

.page-head h1,
.panel h2,
.doc-card h2 {
    margin: 0;
}

.page-head p,
.doc-card p {
    margin: 6px 0 0;
    color: var(--muted);
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 14px;
    border: 0;
    border-radius: 6px;
    background: var(--brand);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}

.button:hover {
    background: var(--brand-dark);
    color: #fff;
}

.button-light {
    background: #eef3f5;
    color: var(--ink);
}

.button-light:hover {
    background: #dfe8ec;
    color: var(--ink);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat-card,
.panel,
.doc-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.stat-card {
    display: grid;
    gap: 10px;
    padding: 16px;
}

.stat-card span {
    color: var(--muted);
}

.stat-card strong {
    font-size: 28px;
}

.panel {
    padding: 18px;
    margin-bottom: 18px;
}

.panel-head {
    justify-content: space-between;
    margin-bottom: 14px;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 11px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.badge {
    display: inline-flex;
    padding: 4px 8px;
    border-radius: 999px;
    background: #e7f5f3;
    color: var(--brand-dark);
    font-weight: 700;
    font-size: 12px;
}

.empty {
    color: var(--muted);
    text-align: center;
}

.muted {
    color: var(--muted);
}

.filters {
    margin-bottom: 18px;
}

.filters input,
.filters select {
    max-width: 320px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.form-section {
    display: grid;
    gap: 14px;
}

.form-section.compact {
    display: block;
}

.form-actions {
    grid-column: 1 / -1;
}

.input-action {
    display: flex;
    gap: 6px;
    align-items: center;
}

.input-action input {
    flex: 1;
    min-width: 0;
}

.ur-result {
    font-size: 12px;
    margin-top: 4px;
    min-height: 20px;
}

.inline-form {
    align-items: end;
    flex-wrap: wrap;
}

.inline-form input,
.inline-form select {
    max-width: 260px;
}

.doc-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.doc-card {
    padding: 18px;
}

.details-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}

.details-grid div {
    min-height: 64px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f8fafb;
}

.details-grid span {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.details-grid strong {
    display: block;
    overflow-wrap: anywhere;
}

.alert {
    padding: 12px 14px;
    margin-bottom: 16px;
    border-radius: 6px;
    border: 1px solid var(--line);
}

.alert.success {
    background: #ecfdf5;
    border-color: #a7f3d0;
}

.alert.error {
    background: #fef2f2;
    border-color: #fecaca;
    color: var(--danger);
}

.login-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
    background: #eef3f5;
}

.login-card {
    width: min(420px, calc(100vw - 32px));
    padding: 28px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.login-card form {
    display: grid;
    gap: 14px;
}

.login-brand {
    margin-bottom: 18px;
}

/* ─── INPUT GROUP (inline button) ─── */
.input-group {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.input-group input {
    flex: 1;
}

.input-group .button {
    white-space: nowrap;
    flex-shrink: 0;
}

/* ─── UR RESULT STATES ─── */
.ur-ok {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-top: 6px;
    padding: 10px 12px;
    border: 1px solid #16a34a;
    border-radius: 8px;
    background: #f0fdf4;
    font-size: 13px;
}

.ur-ok strong { color: #16a34a; }
.ur-type { color: var(--muted); font-size: 11px; }

.ur-warn {
    display: inline-block;
    margin-top: 6px;
    padding: 5px 10px;
    border: 1px solid orange;
    border-radius: 6px;
    background: #fff7ed;
    color: #92400e;
    font-size: 12px;
}

.ur-error {
    display: inline-block;
    margin-top: 6px;
    padding: 5px 10px;
    border: 1px solid var(--danger);
    border-radius: 6px;
    background: #fef2f2;
    color: var(--danger);
    font-size: 12px;
}

.ur-loading {
    display: inline-block;
    margin-top: 6px;
    color: #0ea5e9;
    font-size: 12px;
}

/* ─── CLIENT FILTER INPUT ─── */
.client-filter {
    margin-bottom: 4px;
}

/* ─── GLOBAL SEARCH DROPDOWN ─── */
.global-search-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 100;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0,0,0,.1);
    overflow: hidden;
}

.gs-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    border-bottom: 1px solid var(--line);
    font-size: 13px;
    color: var(--ink);
}

.gs-item:last-child { border-bottom: 0; }
.gs-item:hover { background: var(--bg); }
.gs-icon { font-size: 16px; flex-shrink: 0; }
.gs-label { font-weight: 600; flex: 1; }
.gs-sub { color: var(--muted); font-size: 11px; }
.gs-empty { padding: 10px 14px; color: var(--muted); font-size: 13px; }

/* ─── ALERTS / WARNINGS ─── */
.alert {
    padding: 10px 16px;
    border-radius: 8px;
    margin-bottom: 14px;
    font-size: 13px;
    font-weight: 600;
}

.alert.success { background: #f0fdf4; border: 1px solid #16a34a; color: #166534; }
.alert.error   { background: #fef2f2; border: 1px solid var(--danger); color: var(--danger); }
.alert.warn    { background: #fff7ed; border: 1px solid orange; color: #92400e; }

/* ─── TABLE ROW URGENCY ─── */
tr.danger td { background: #fef2f2; }
tr.warn   td { background: #fff7ed; }

/* ─── BADGES ─── */
.badge-danger { background: #fef2f2; color: var(--danger); border: 1px solid var(--danger); padding: 2px 7px; border-radius: 12px; font-size: 11px; font-weight: 700; }
.badge-warn   { background: #fff7ed; color: #92400e; border: 1px solid orange; padding: 2px 7px; border-radius: 12px; font-size: 11px; font-weight: 700; }

.print-document {
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto;
    padding: 16mm;
    background: #fff;
    color: #000;
}

.print-document h1 {
    text-align: center;
    font-size: 18px;
    margin: 0 0 16px;
}

.doc-meta,
.signature-grid,
.seal-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.doc-line {
    border-bottom: 1px solid #000;
    min-height: 26px;
    padding: 5px 0;
}

.seal-box {
    min-height: 36px;
    border: 1px solid #000;
    padding: 8px;
}

.signature-box {
    min-height: 76px;
    border-top: 1px solid #000;
    padding-top: 8px;
    margin-top: 42px;
}

.excel-print {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 11px;
}

.excel-act-copy {
    min-height: 134mm;
    padding-bottom: 8mm;
    border-bottom: 1px dashed #777;
    page-break-inside: avoid;
}

.excel-act-copy + .excel-act-copy {
    padding-top: 8mm;
}

.excel-act-head {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
}

.excel-act-copy h1 {
    margin: 4px 0 10px;
    text-align: left;
    font-size: 15px;
}

.excel-row {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 8px;
    margin-bottom: 8px;
}

.excel-row strong {
    border-bottom: 1px solid #000;
}

.excel-act-table,
.excel-info-table {
    width: 100%;
    margin-bottom: 10px;
    border-collapse: collapse;
}

.excel-act-table th,
.excel-act-table td,
.excel-info-table th,
.excel-info-table td {
    border: 1px solid #000;
    padding: 5px 6px;
    text-align: left;
    vertical-align: top;
}

.excel-act-table th {
    width: 110px;
}

.excel-act-table td {
    min-width: 70px;
    text-align: center;
}

.excel-info-table th {
    width: 120px;
    background: #f3f3f3;
    font-weight: 700;
}

.excel-signatures {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-top: 18px;
}

.excel-seal-place {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 36px;
    margin-top: 22px;
}

.excel-seal-place span {
    display: block;
    min-height: 52px;
    border: 1px solid #000;
    padding: 8px;
}

.contract-letterhead {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    margin-bottom: 6px;
    font-size: 12px;
    line-height: 1.5;
}

.contract-letterhead-text {
    grid-column: 2;
    text-align: center;
}

.letterhead-logo {
    grid-column: 3;
    justify-self: end;
    height: 40px;
}

.eds-page .letterhead-logo {
    margin-right: -58px;
}

.letterhead-divider {
    border-top: 3px double #000;
    margin: 4px 0 16px;
}

.eds-highlight {
    border: 3px solid #000;
    padding: 18px 20px;
    margin: 18px 0;
    text-align: center;
    font-weight: 800;
    font-size: 21px;
    line-height: 1.45;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.eds-intro {
    text-align: center;
    font-weight: 700;
    font-size: 16px;
    margin: 24px 0 14px;
}

.eds-steps {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin: 14px 0 24px;
}

.eds-step {
    border-radius: 10px;
    background: linear-gradient(180deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: #fff;
    padding: 18px 20px;
    text-align: center;
    font-weight: 800;
    font-size: 18px;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    box-shadow: 0 3px 0 rgba(0, 0, 0, .3), 0 8px 16px rgba(15, 118, 110, .28);
}

.eds-substeps {
    margin-top: 10px;
    font-weight: 700;
    font-size: 14px;
    text-transform: none;
    letter-spacing: normal;
}

.eds-substeps div {
    padding: 3px 0;
}

.contract-doc h3 {
    font-size: 12px;
    margin: 10px 0 4px;
}

.contract-fine,
.contract-doc p {
    font-size: 9.5px;
    line-height: 1.35;
    margin: 4px 0;
    text-align: justify;
}

.reg-form th,
.reg-form td {
    font-size: 10px;
}

.reg-form th:first-child {
    width: 26px;
    text-align: center;
}

.mini-table {
    width: 100%;
    border-collapse: collapse;
}

.mini-table th,
.mini-table td {
    border: 1px solid #000;
    padding: 2px 5px;
    font-size: 9.5px;
    text-align: center;
}

.two-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.page-break {
    break-after: page;
    page-break-after: always;
}

@media (max-width: 980px) {
    .sidebar {
        position: static;
        width: auto;
    }

    .app {
        margin-left: 0;
    }

    .stat-grid,
    .form-grid,
    .doc-grid,
    .details-grid {
        grid-template-columns: 1fr;
    }

    .two-columns,
    .topbar,
    .page-head {
        align-items: stretch;
        flex-direction: column;
        height: auto;
    }
}

@media print {
    body {
        background: #fff;
    }

    .sidebar,
    .topbar,
    .no-print {
        display: none !important;
    }

    .app,
    .content {
        margin: 0;
        padding: 0;
    }

    .print-document {
        width: auto;
        min-height: auto;
        padding: 0;
    }

    @page {
        size: A4;
        margin: 10mm 12mm;
    }

    .print-document {
        font-size: 10.5px;
    }

    .excel-act-copy {
        min-height: 0;
        border-bottom: none;
    }

    .excel-act-copy + .excel-act-copy {
        page-break-before: avoid;
        border-top: 1px dashed #777;
    }

    h1, h2, h3 {
        margin: 6px 0 4px !important;
    }

    table {
        page-break-inside: avoid;
    }

    /* Экономія тонера/чернил: на печати нет заливок/теней, только чёрный контур */
    .eds-step {
        background: none !important;
        color: #000 !important;
        border: 1.6px solid #000 !important;
        box-shadow: none !important;
    }

    .excel-info-table th,
    .doc-meta,
    .contract-letterhead-text {
        background: none !important;
    }

    .letterhead-logo {
        filter: grayscale(1) contrast(1.3);
        height: 35px;
    }

    /* Компактнее, чтобы EDS-instrukcija помещалась на 1 stranicu, bet aizpilda lapu */
    .contract-letterhead {
        margin-bottom: 3px;
    }

    .letterhead-divider {
        margin: 2px 0 11px;
    }

    .eds-highlight {
        font-size: 15px;
        padding: 7px 13px;
        margin: 7px 0;
    }

    .eds-intro {
        font-size: 13px;
        margin: 10px 0 7px;
    }

    .eds-steps {
        gap: 7px;
        margin: 6px 0 12px;
    }

    .eds-step {
        font-size: 12.5px;
        padding: 7px 15px;
    }

    .eds-substeps {
        font-size: 11.5px;
        margin-top: 6px;
    }

    /* Šapka ar logo pievieno augstumu — kompensējam ar -20% pārējos excel-print dokumentos */
    .excel-print {
        font-size: 8.4px;
    }

    .excel-print .excel-info-table th,
    .excel-print .excel-info-table td,
    .excel-print .excel-act-table th,
    .excel-print .excel-act-table td {
        padding: 4px 5px !important;
    }

    .excel-print .excel-row {
        margin-bottom: 6px !important;
    }

    .excel-print .excel-signatures {
        margin-top: 14px !important;
        gap: 19px !important;
    }

    .excel-print .excel-seal-place {
        margin-top: 17px !important;
        gap: 29px !important;
    }

    .excel-print .excel-act-copy {
        padding-bottom: 6mm !important;
    }

    .excel-print .contract-fine,
    .excel-print .contract-doc p {
        font-size: 7.6px !important;
        margin: 3px 0 !important;
    }

    .excel-print .reg-form th,
    .excel-print .reg-form td {
        font-size: 8px !important;
    }

    .excel-print .mini-table th,
    .excel-print .mini-table td {
        font-size: 7.6px !important;
        padding: 1.6px 4px !important;
    }

    /* excel-act-copy dokumenti (plombu akti) — šapka atkārtojas 2x lapā, jāsaspiež stiprāk */
    .excel-act-copy .contract-letterhead {
        font-size: 7.5px !important;
        margin-bottom: 1px !important;
    }

    .excel-act-copy .letterhead-logo {
        height: 20px !important;
    }

    .excel-act-copy .letterhead-divider {
        margin: 1px 0 4px !important;
        border-top-width: 2px !important;
    }

    .excel-act-copy h1 {
        font-size: 11px !important;
        margin: 2px 0 4px !important;
    }

    .excel-act-head {
        font-size: 9px !important;
    }

    .excel-act-copy .excel-row {
        margin-bottom: 4px !important;
    }

    .excel-act-copy .excel-info-table th,
    .excel-act-copy .excel-info-table td,
    .excel-act-copy .excel-act-table th,
    .excel-act-copy .excel-act-table td {
        padding: 3px 4px !important;
    }

    .excel-act-copy .excel-signatures {
        margin-top: 8px !important;
        gap: 14px !important;
    }

    .excel-act-copy .excel-seal-place {
        margin-top: 10px !important;
        gap: 16px !important;
    }

    .excel-act-copy .excel-seal-place span {
        min-height: 28px !important;
        padding: 4px !important;
    }

    .excel-act-copy {
        padding-bottom: 3mm !important;
    }
}

/* ══════════════════════════════════════════════════
   DARK MODE
══════════════════════════════════════════════════ */
[data-theme="dark"] {
    --bg: #0f172a;
    --panel: #1e293b;
    --ink: #e2e8f0;
    --muted: #94a3b8;
    --line: #334155;
    --brand: #14b8a6;
    --brand-dark: #0d9488;
    --accent: #f59e0b;
    --danger: #f87171;
}

[data-theme="dark"] body { background: var(--bg); color: var(--ink); }
[data-theme="dark"] .topbar { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .panel,
[data-theme="dark"] .stat-card,
[data-theme="dark"] .doc-card { background: #1e293b; border-color: #334155; }
[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea { background: #0f172a; color: #e2e8f0; border-color: #334155; }
[data-theme="dark"] thead th { background: #1e293b; color: #94a3b8; }
[data-theme="dark"] th, [data-theme="dark"] td { border-color: #334155; }
[data-theme="dark"] .details-grid div { background: #0f172a; border-color: #334155; }
[data-theme="dark"] .button-light { background: #334155; color: #e2e8f0; }
[data-theme="dark"] .button-light:hover { background: #475569; color: #e2e8f0; }
[data-theme="dark"] .badge { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] tr.danger td { background: #3b1a1a; }
[data-theme="dark"] tr.warn td { background: #2d1f0a; }
[data-theme="dark"] .alert.success { background: #052e16; border-color: #166534; color: #4ade80; }
[data-theme="dark"] .alert.error { background: #3b1a1a; border-color: #f87171; }
[data-theme="dark"] .alert.warn { background: #2d1f0a; border-color: #f59e0b; }
[data-theme="dark"] .session-modal { background: #1e293b; color: #e2e8f0; }
[data-theme="dark"] .toast { background: #1e293b; border-color: #334155; color: #e2e8f0; }
[data-theme="dark"] .toast.toast-success { background: #052e16; color: #4ade80; }
[data-theme="dark"] .toast.toast-error { background: #3b1a1a; color: #f87171; }
[data-theme="dark"] .login-card { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .ur-ok { background: #052e16; border-color: #166534; }
[data-theme="dark"] .global-search-dropdown { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .gs-item { color: #e2e8f0; border-color: #334155; }
[data-theme="dark"] .gs-item:hover { background: #0f172a; }

/* ══════════════════════════════════════════════════
   STATUS BADGES (colored)
══════════════════════════════════════════════════ */
.badge-jauns      { background: #dbeafe; color: #1d4ed8; }
.badge-darba      { background: #dcfce7; color: #166534; }
.badge-gaida-kl   { background: #fef9c3; color: #854d0e; }
.badge-gaida-vid  { background: #ffedd5; color: #9a3412; }
.badge-pabeigts   { background: #f0fdf4; color: #166534; border: 1px solid #86efac; }
.badge-arhivets   { background: #f1f5f9; color: #475569; }

[data-theme="dark"] .badge-jauns     { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .badge-darba     { background: #14532d; color: #86efac; }
[data-theme="dark"] .badge-gaida-kl  { background: #422006; color: #fde047; }
[data-theme="dark"] .badge-gaida-vid { background: #431407; color: #fdba74; }
[data-theme="dark"] .badge-pabeigts  { background: #052e16; color: #4ade80; border-color: #166534; }
[data-theme="dark"] .badge-arhivets  { background: #1e293b; color: #64748b; }

/* ══════════════════════════════════════════════════
   STICKY TABLE HEADERS
══════════════════════════════════════════════════ */
thead th {
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 2;
    border-bottom: 2px solid var(--line);
}

[data-theme="dark"] thead th { background: #1e293b; }

/* ══════════════════════════════════════════════════
   SORTABLE COLUMNS
══════════════════════════════════════════════════ */
th[data-sortable] { cursor: pointer; user-select: none; white-space: nowrap; }
th[data-sortable]::after { content: ' ↕'; color: var(--muted); font-size: 10px; }
th[data-sortable].sort-asc::after  { content: ' ↑'; color: var(--brand); }
th[data-sortable].sort-desc::after { content: ' ↓'; color: var(--brand); }

/* ══════════════════════════════════════════════════
   LOADING BUTTON
══════════════════════════════════════════════════ */
.button.loading { opacity: .72; pointer-events: none; }
.button.loading::after { content: ' ⟳'; display: inline-block; animation: btn-spin .7s linear infinite; }
@keyframes btn-spin { 100% { transform: rotate(360deg); } }

/* ══════════════════════════════════════════════════
   BREADCRUMBS
══════════════════════════════════════════════════ */
.breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 14px;
}
.breadcrumbs a { color: var(--brand-dark); }
.breadcrumbs .sep { color: var(--line); margin: 0 2px; }
.breadcrumbs .current { color: var(--ink); font-weight: 600; }

/* ══════════════════════════════════════════════════
   PROGRESS BAR (contract duration)
══════════════════════════════════════════════════ */
.progress-wrap { min-width: 90px; }
.progress-bar { width: 100%; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-bottom: 3px; }
.progress-fill { height: 100%; border-radius: 3px; transition: width .3s; background: var(--brand); }
.progress-fill.warn   { background: orange; }
.progress-fill.danger { background: var(--danger); }
.progress-pct { font-size: 11px; color: var(--muted); }

/* ══════════════════════════════════════════════════
   DEADLINE BADGES
══════════════════════════════════════════════════ */
.due-overdue { background: #fef2f2; color: var(--danger); padding: 2px 7px; border-radius: 6px; font-size: 11px; font-weight: 700; display: inline-block; }
.due-soon    { background: #fff7ed; color: #92400e; padding: 2px 7px; border-radius: 6px; font-size: 11px; font-weight: 700; display: inline-block; }
.due-ok      { background: #f0fdf4; color: #166534; padding: 2px 7px; border-radius: 6px; font-size: 11px; font-weight: 700; display: inline-block; }
[data-theme="dark"] .due-overdue { background: #3b1a1a; }
[data-theme="dark"] .due-soon    { background: #2d1f0a; }
[data-theme="dark"] .due-ok      { background: #052e16; }

/* ══════════════════════════════════════════════════
   PAGINATION
══════════════════════════════════════════════════ */
.pagination { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 14px 0 4px; }
.pagination a,
.pagination span {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 36px; height: 36px; padding: 0 10px;
    border: 1px solid var(--line); border-radius: 6px;
    font-size: 13px; color: var(--ink); text-decoration: none;
}
.pagination a:hover { background: var(--bg); }
.pagination .pag-current { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 700; }
.pagination .pag-dots { border: none; color: var(--muted); min-width: auto; }
.pagination .pag-info { border: none; font-size: 12px; color: var(--muted); min-width: auto; }

/* ══════════════════════════════════════════════════
   SESSION TIMEOUT MODAL
══════════════════════════════════════════════════ */
.session-overlay {
    display: none; position: fixed; inset: 0; z-index: 9999;
    background: rgba(0,0,0,.55); align-items: center; justify-content: center;
}
.session-overlay.active { display: flex; }
.session-modal {
    background: #fff; border-radius: 12px; padding: 32px;
    max-width: 360px; width: calc(100vw - 32px);
    text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.session-modal h3 { margin: 0 0 10px; font-size: 20px; }
.session-modal p  { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.session-modal-actions { display: flex; gap: 10px; justify-content: center; }
#session-countdown { font-weight: 700; color: var(--danger); font-size: 26px; display: block; margin: 0 0 16px; }

/* ══════════════════════════════════════════════════
   TOAST NOTIFICATIONS
══════════════════════════════════════════════════ */
.toast-wrap {
    position: fixed; top: 76px; right: 20px; z-index: 9998;
    display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
    padding: 12px 16px; border-radius: 8px; background: #fff;
    border: 1px solid var(--line); box-shadow: 0 4px 16px rgba(0,0,0,.12);
    font-size: 13px; max-width: 320px; pointer-events: auto;
    animation: toast-in .2s ease; cursor: pointer;
}
.toast.toast-success { border-color: #16a34a; background: #f0fdf4; color: #166534; }
.toast.toast-error   { border-color: #ef4444; background: #fef2f2; color: #b91c1c; }
.toast.toast-info    { border-color: #0ea5e9; background: #e0f2fe; color: #075985; }
@keyframes toast-in { from { transform: translateX(110%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ══════════════════════════════════════════════════
   DARK MODE TOGGLE BUTTON
══════════════════════════════════════════════════ */
.dark-toggle {
    background: none; border: 1px solid var(--line); border-radius: 6px;
    padding: 7px 10px; cursor: pointer; font-size: 15px;
    line-height: 1; color: var(--ink); flex-shrink: 0;
}
.dark-toggle:hover { background: var(--bg); }

/* ══════════════════════════════════════════════════
   TIMELINE (change history)
══════════════════════════════════════════════════ */
.timeline { display: flex; flex-direction: column; }
.tl-item { display: grid; grid-template-columns: 20px 1fr; gap: 10px; padding-bottom: 14px; position: relative; }
.tl-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand); margin-top: 4px; flex-shrink: 0; }
.tl-item::before { content: ''; position: absolute; left: 4px; top: 14px; bottom: 0; width: 1px; background: var(--line); }
.tl-item:last-child::before { display: none; }
.tl-meta  { font-size: 11px; color: var(--muted); }
.tl-text  { font-size: 13px; margin-top: 3px; }

/* ══════════════════════════════════════════════════
   INLINE STATUS SELECT
══════════════════════════════════════════════════ */
.status-select {
    appearance: none; border-radius: 999px; border: 1px solid transparent;
    padding: 3px 22px 3px 9px; font-size: 12px; font-weight: 700;
    cursor: pointer; outline: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b7785'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 7px center;
    background-size: 8px; min-height: auto; width: auto;
}
.status-select.badge-jauns     { background-color: #dbeafe; color: #1d4ed8; }
.status-select.badge-darba     { background-color: #dcfce7; color: #166534; }
.status-select.badge-gaida-kl  { background-color: #fef9c3; color: #854d0e; }
.status-select.badge-gaida-vid { background-color: #ffedd5; color: #9a3412; }
.status-select.badge-pabeigts  { background-color: #f0fdf4; color: #166534; }
.status-select.badge-arhivets  { background-color: #f1f5f9; color: #475569; }

/* ══════════════════════════════════════════════════
   EKA PHOTO
══════════════════════════════════════════════════ */
.eka-thumb { width: 72px; height: 50px; object-fit: cover; border-radius: 5px; border: 1px solid var(--line); vertical-align: middle; }
.eka-photo-lg { max-width: 260px; border-radius: 8px; border: 1px solid var(--line); display: block; margin-bottom: 12px; }
.eka-no-photo { display: inline-flex; align-items: center; justify-content: center; width: 72px; height: 50px; border: 1px dashed var(--line); border-radius: 5px; color: var(--muted); font-size: 11px; }

/* ══════════════════════════════════════════════════
   MAPS LINK
══════════════════════════════════════════════════ */
.maps-link { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; color: var(--brand-dark); margin-left: 4px; white-space: nowrap; }

/* ══════════════════════════════════════════════════
   TECH STATS WIDGET
══════════════════════════════════════════════════ */
.tech-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tech-card { padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; text-align: center; }
.tech-card .name  { font-weight: 700; margin-bottom: 4px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tech-card .count { font-size: 30px; font-weight: 700; color: var(--brand); line-height: 1; }
.tech-card .sub   { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ══════════════════════════════════════════════════
   CHART LEGEND
══════════════════════════════════════════════════ */
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 12px; padding: 0 4px; }
.chart-legend-item { display: flex; align-items: center; gap: 5px; }
.chart-dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }

/* ══════════════════════════════════════════════════
   HEATMAP
══════════════════════════════════════════════════ */
.heatmap-wrap { overflow-x: auto; padding: 4px 0; }

/* ══════════════════════════════════════════════════
   AUDIT LOG
══════════════════════════════════════════════════ */
.audit-action { padding: 2px 7px; border-radius: 4px; font-size: 11px; font-weight: 700; }
.audit-create { background: #dcfce7; color: #166534; }
.audit-update { background: #dbeafe; color: #1d4ed8; }
.audit-delete { background: #fef2f2; color: #b91c1c; }
.audit-print  { background: #f3e8ff; color: #7c3aed; }

/* ══════════════════════════════════════════════════
   IMPORT CSV
══════════════════════════════════════════════════ */
.import-zone {
    border: 2px dashed var(--line); border-radius: 10px; padding: 32px;
    text-align: center; cursor: pointer; transition: background .2s;
}
.import-zone:hover, .import-zone.drag-over { background: var(--bg); border-color: var(--brand); }
.import-zone p { margin: 8px 0 0; color: var(--muted); font-size: 13px; }

/* ══════════════════════════════════════════════════
   NEXT-SERVICE BADGE
══════════════════════════════════════════════════ */
.service-due    { background: #fff7ed; color: #92400e; padding: 2px 7px; border-radius: 6px; font-size: 11px; font-weight: 700; }
.service-overdue { background: #fef2f2; color: var(--danger); padding: 2px 7px; border-radius: 6px; font-size: 11px; font-weight: 700; }

@media (max-width: 980px) {
    .tech-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ══════════════════════════════════════════════════
   TIMELINE LIST
══════════════════════════════════════════════════ */
.tl-list { display: flex; flex-direction: column; }
.tl-dot.audit-create { background: #166534; }
.tl-dot.audit-update { background: #1d4ed8; }
.tl-dot.audit-delete { background: #b91c1c; }
.tl-dot.audit-print  { background: #7c3aed; }

/* ══════════════════════════════════════════════════
   CHART LEGEND
══════════════════════════════════════════════════ */
.chart-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.chart-legend-item { display: flex; align-items: center; gap: 5px; font-size: 12px; }
.chart-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.heatmap-wrap { overflow-x: auto; }

/* ══════════════════════════════════════════════════
   GLOBAL SEARCH DROPDOWN
══════════════════════════════════════════════════ */
.global-search-dropdown { position: absolute; top: 100%; left: 0; right: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); z-index: 200; max-height: 360px; overflow-y: auto; display: none; }
.gs-item { display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 6px; padding: 9px 14px; text-decoration: none; color: var(--ink); border-bottom: 1px solid var(--line); transition: background .12s; }
.gs-item:last-child { border-bottom: none; }
.gs-item:hover { background: var(--bg); }
.gs-icon { font-size: 14px; text-align: center; }
.gs-label { font-size: 13px; font-weight: 500; }
.gs-sub { font-size: 11px; color: var(--muted); }
.gs-empty { padding: 12px 14px; font-size: 13px; color: var(--muted); }

/* ══════════════════════════════════════════════════
   DARK TOGGLE BUTTON
══════════════════════════════════════════════════ */
.dark-toggle { background: none; border: 1px solid var(--line); border-radius: 6px; padding: 4px 9px; cursor: pointer; font-size: 15px; color: var(--ink); transition: background .15s; }
.dark-toggle:hover { background: var(--bg); }

/* ══════════════════════════════════════════════════
   INLINE-FORM (filters)
══════════════════════════════════════════════════ */
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.reason-chips { display:flex; flex-wrap:wrap; gap:6px; margin:4px 0; }
.reason-chips .chip {
    font-size:11px; padding:3px 9px; border-radius:999px;
    border:1px solid var(--border, #ccc); background:var(--panel, #f4f4f4);
    cursor:pointer; color:var(--muted, #555);
}
.reason-chips .chip:hover { background:var(--accent-light, #e0ebff); color:var(--accent, #2563eb); }

.tl-detail-card { margin-top:6px; padding:8px 10px; background:var(--panel-2,#f7f7f9); border:1px solid var(--border,#e3e3e8); border-radius:8px; font-size:12px; }
.tl-detail-card.hidden { display:none; }
.tl-detail-table { width:100%; border-collapse:collapse; }
.tl-detail-table td { padding:2px 6px; border-bottom:1px dashed var(--border,#e3e3e8); vertical-align:top; }
.tl-detail-table td:first-child { color:var(--muted,#777); white-space:nowrap; font-weight:600; width:35%; }

/* ══════════════════════════════════════════════════
   OPERATION TYPE BADGES (Pieteikumu bāze)
══════════════════════════════════════════════════ */
.type-badge {
    display:inline-flex; align-items:center; gap:4px;
    font-size:11px; font-weight:600; padding:3px 9px; border-radius:999px; white-space:nowrap;
}
.type-instalacija { background:#e3f6e9; color:#1a7f5a; }
.type-remonts     { background:#fdeee0; color:#b5530f; }
.type-nonemsana   { background:#fde2e2; color:#b42318; }
.type-ligums      { background:#e6ecff; color:#3548c4; }
.type-plombas     { background:#f1e6ff; color:#7a3ec4; }
.type-noma        { background:#e0f4f7; color:#157e8c; }
.type-other       { background:#eef0f2; color:#5b6470; }

/* ══════════════════════════════════════════════════
   REMINDERS (Atgādinājumi) — modern card layout
══════════════════════════════════════════════════ */
.reminder-card {
    display:flex; gap:14px; align-items:flex-start; padding:14px 16px;
    border:1px solid var(--border,#e3e3e8); border-radius:12px; background:var(--panel,#fff);
    margin-bottom:10px; transition:box-shadow .15s, border-color .15s;
}
.reminder-card:hover { box-shadow:0 2px 10px rgba(0,0,0,.06); border-color:var(--accent,#2563eb); }
@media (max-width: 640px) {
    .reminder-card { flex-wrap:wrap; padding:10px 12px; gap:8px; }
    .reminder-icon { font-size:18px; }
    .reminder-title { font-size:13px; }
    .reminder-meta { font-size:11px; gap:6px; }
    .page-head { flex-direction:column; align-items:flex-start; gap:10px; }
    .page-head .page-actions { flex-wrap:wrap; }
    .form-grid { grid-template-columns:1fr !important; }
    .panel-head { flex-direction:column; align-items:flex-start; gap:6px; }
}
.reminder-card.is-overdue { border-left:4px solid #b42318; background:#fff7f7; }
.reminder-card.is-soon    { border-left:4px solid #b5530f; background:#fffaf3; }
.reminder-card.is-done    { opacity:.55; }
.reminder-icon { font-size:22px; line-height:1; padding-top:2px; }
.reminder-body { flex:1; min-width:0; }
.reminder-title { font-weight:700; font-size:14px; margin-bottom:2px; }
.reminder-meta { font-size:12px; color:var(--muted,#777); display:flex; flex-wrap:wrap; gap:8px; }
.reminder-pill {
    font-size:10px; font-weight:700; text-transform:uppercase; letter-spacing:.03em;
    padding:2px 8px; border-radius:999px; display:inline-block;
}
.reminder-pill.prio-Zema     { background:#eef0f2; color:#5b6470; }
.reminder-pill.prio-Normāla  { background:#e6ecff; color:#3548c4; }
.reminder-pill.prio-Augsta   { background:#fdeee0; color:#b5530f; }
.reminder-pill.prio-Kritiska { background:#fde2e2; color:#b42318; }
.reminder-due { font-weight:600; }
.reminder-due.is-overdue { color:#b42318; }
.reminder-due.is-soon    { color:#b5530f; }

.reason-chips .chip-cnt {
    display:inline-block; font-size:10px; font-weight:700; color:#fff;
    background:var(--accent,#2563eb); border-radius:999px; padding:0 5px; margin-right:3px;
}

/* ══════════════════════════════════════════════════
   ROW ACTIONS (table inline buttons — bigger targets)
══════════════════════════════════════════════════ */
.row-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.row-actions a,
.row-actions button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 5px 12px;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    transition: background .13s, border-color .13s;
}

.row-actions a.ra-open {
    background: #eef7f5;
    color: var(--brand-dark);
    border-color: #c5e8e3;
}
.row-actions a.ra-open:hover { background: #d5ede8; color: var(--brand-dark); }

.row-actions button.ra-icon,
.row-actions a.ra-icon {
    background: #f4f0ea;
    color: var(--ink);
    border-color: var(--line);
    padding: 5px 9px;
    font-size: 15px;
}
.row-actions button.ra-icon:hover,
.row-actions a.ra-icon:hover { background: #ede8e0; }

.row-actions a.ra-del {
    background: #fdf2f2;
    color: #b91c1c;
    border-color: #f5c5c5;
    padding: 5px 9px;
    font-size: 15px;
}
.row-actions a.ra-del:hover { background: #fce4e4; }

/* ══════════════════════════════════════════════════
   WARM PANEL & STAT OVERRIDES
══════════════════════════════════════════════════ */
.stat-card { border-color: var(--line); }
.topbar { border-bottom-color: var(--line); background: #fffcfa; }
thead th { background: #fffcfa; }
.details-grid div { background: #fdf9f5; }
.login-page { background: #f4ede4; }
.login-card { border-color: var(--line); }
