:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --text: #1d232b;
    --muted: #5d6673;
    --line: #dde2e8;
    --accent: #1f5fa8;
    --accent-dark: #174a84;
    --ok: #1e7f4f;
    --ok-bg: #e4f4ea;
    --warn: #8a5a00;
    --warn-bg: #fff3d6;
    --bad: #a12b2b;
    --bad-bg: #fde7e7;
    --gray-bg: #eef0f3;
    color-scheme: light;
}

* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
h1 { font-size: 1.4rem; margin: 0 0 0.75rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 0.5rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); font-size: 0.9rem; }

.topbar { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; padding: 0.6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar__brand { font-weight: 700; letter-spacing: 0.08em; color: var(--accent); }
.topbar__company { display: flex; flex-direction: column; line-height: 1.25; }
.topbar__label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.topbar__meta { font-size: 0.8rem; color: var(--muted); }
.topbar__nav { display: flex; gap: 1rem; }
.topbar__nav a { text-decoration: none; font-weight: 600; }
.topbar__user { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.topbar__user form { margin: 0; display: flex; gap: 0.4rem; align-items: center; }
.switcher select { padding: 0.3rem 0.5rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }

.page { max-width: 1280px; margin: 0 auto; padding: 1.25rem; }
.footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 1.5rem; }
.crumbs { margin-bottom: 0.75rem; color: var(--muted); display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

.flash { padding: 0.6rem 0.9rem; border-radius: 6px; margin-bottom: 0.9rem; border: 1px solid var(--line); background: var(--surface); }
.flash--ok { background: var(--ok-bg); border-color: #b7dfc6; color: var(--ok); }
.flash--info { background: #e8f0fb; border-color: #bcd2ef; color: var(--accent-dark); }
.flash--error { background: var(--bad-bg); border-color: #f0bcbc; color: var(--bad); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 1rem 1.1rem; margin-bottom: 1rem; }
.panel--narrow { max-width: 460px; margin: 3rem auto; }
.two-col { display: grid; grid-template-columns: minmax(280px, 420px) 1fr; gap: 1rem; align-items: start; }
.two-col--wide { grid-template-columns: minmax(360px, 1fr) minmax(360px, 1fr); }

.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.summary--inline { margin-bottom: 0.75rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 0.7rem 0.9rem; display: flex; flex-direction: column; }
.stat__label { font-size: 0.78rem; color: var(--muted); }
.stat__value { font-size: 1.45rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat__value--text { font-size: 1.05rem; }
.stat--warn .stat__value { color: var(--warn); }

.form .field { margin-bottom: 0.7rem; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem 0.8rem; }
.fields--four { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.field--wide { grid-column: 1 / -1; }
label { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 0.25rem; }
input, select, textarea { width: 100%; padding: 0.5rem 0.6rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); font: inherit; color: var(--text); }
input[readonly] { background: var(--gray-bg); }
input[type="file"] { padding: 0.35rem; }
.check { display: flex; gap: 0.5rem; align-items: center; font-size: 0.95rem; color: var(--text); }
.check input { width: auto; }
.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.8rem; }
.inline-form { display: flex; gap: 0.6rem; align-items: end; flex-wrap: wrap; }
.inline-form label { margin: 0; }
.inline-form input { width: auto; }

.btn { display: inline-flex; align-items: center; gap: 0.4rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); padding: 0.5rem 0.85rem; text-decoration: none; font: inherit; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-dark); }
.btn--small { padding: 0.3rem 0.6rem; font-size: 0.85rem; }
.btn--danger { border-color: #e2a3a3; color: var(--bad); background: var(--bad-bg); }
.danger-zone { margin-top: 1.5rem; padding: 0.6rem 0.8rem; border: 1px dashed #e2a3a3; border-radius: 6px; }
.danger-zone summary { cursor: pointer; color: var(--bad); }

.months { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 1rem 0; align-items: center; }
.months__item { text-decoration: none; padding: 0.3rem 0.7rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text); }
.months__item.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.months__count { font-size: 0.8rem; opacity: 0.8; }
.months__empty { color: var(--muted); }

.filters { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.8rem; }
.chip { text-decoration: none; padding: 0.25rem 0.65rem; border-radius: 999px; border: 1px solid var(--line); color: var(--text); font-size: 0.9rem; background: var(--surface); }
.chip span { color: var(--muted); font-size: 0.8rem; }
.chip.is-active { border-color: var(--accent); background: #e8f0fb; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.docs { width: 100%; border-collapse: collapse; }
.docs th, .docs td { padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.docs th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: var(--gray-bg); }
.docs .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.docs .empty { text-align: center; color: var(--muted); padding: 2rem; }
.docs--compact th, .docs--compact td { padding: 0.35rem 0.5rem; font-size: 0.9rem; }
.tag { font-size: 0.7rem; border: 1px solid var(--line); border-radius: 4px; padding: 0 0.3rem; color: var(--muted); white-space: nowrap; }

.status { display: inline-block; font-size: 0.8rem; padding: 0.15rem 0.5rem; border-radius: 4px; margin: 0 0.25rem 0.25rem 0; white-space: nowrap; }
.status--ok { background: var(--ok-bg); color: var(--ok); }
.status--warn { background: var(--warn-bg); color: var(--warn); }
.status--bad { background: var(--bad-bg); color: var(--bad); }
.status--muted { background: var(--gray-bg); color: var(--muted); }

.details summary { cursor: pointer; color: var(--accent); font-size: 0.9rem; }
.bank-line { margin: 0.2rem 0; font-size: 0.82rem; color: var(--muted); }
.plain-list { padding-left: 1.2rem; }
.plain-list li { margin-bottom: 0.3rem; }
.copybox { min-height: 200px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.8rem; white-space: pre; }
.copybox--tall { min-height: 360px; }

.preview { border: 1px solid var(--line); border-radius: 8px; background: var(--gray-bg); max-height: 75vh; overflow: auto; }
.preview img { display: block; max-width: 100%; height: auto; margin: 0 auto; background: #fff; }
.ocr { white-space: pre-wrap; background: var(--gray-bg); border: 1px solid var(--line); padding: 0.7rem; border-radius: 6px; max-height: 420px; overflow: auto; font-size: 0.82rem; }

.error-box { max-width: 560px; margin: 3rem auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 1.5rem; }
.error-box__id { color: var(--muted); font-size: 0.85rem; }

@media (max-width: 860px) {
    .two-col, .two-col--wide { grid-template-columns: 1fr; }
    .fields { grid-template-columns: 1fr; }
    .topbar { gap: 0.5rem; }
    .topbar__user { margin-left: 0; }
}
@media (max-width: 720px) {
    .docs thead { display: none; }
    .docs tr { display: block; padding: 0.5rem 0; }
    .docs td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: 0.2rem 0.75rem; }
    .docs td::before { content: attr(data-label); color: var(--muted); font-size: 0.8rem; flex-shrink: 0; }
    .docs td.num { text-align: right; }
    .docs tr + tr { border-top: 1px solid var(--line); }
}

/* ---- dokumenta lapa (vecās sistēmas izkārtojums) ---- */
.page--full { max-width: none; padding: 22px; background: #fff; }
.doc-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin: -22px -22px 22px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.doc-head h1 { font-size: 22px; margin: 0; }
.doc-grid { display: grid; grid-template-columns: minmax(420px, 560px) minmax(620px, 1fr); gap: 22px; align-items: start; }
.doc-form, .doc-source { padding: 18px; margin: 0; }
.doc-form h2, .doc-source h2 { font-size: 18px; margin: 0 0 12px; }
.doc-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.doc-fields .wide { grid-column: 1 / -1; }
.doc-fields label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.doc-fields input, .doc-fields select { padding: 9px; font-size: 14px; }
.doc-fields .check { font-size: 14px; }
.doc-form .actions { margin-top: 14px; }
.doc-form .btn--primary { background: #0f766e; border-color: #0f766e; }
.doc-form .btn--primary:hover { background: #0b5f59; }
.doc-source { position: sticky; top: 14px; border-width: 2px; }
.doc-meta { font-size: 13px; line-height: 1.5; margin: 0 0 12px; }
.doc-preview { height: calc(100vh - 205px); min-height: 660px; border: 1px solid var(--line); border-radius: 8px; background: #f8fafc; overflow: auto; }
.doc-preview img { display: block; width: 100%; height: auto; background: #fff; }
.doc-preview--empty { display: flex; align-items: center; justify-content: center; padding: 22px; text-align: center; }
.doc-source .docs { border: 1px solid var(--line); border-radius: 6px; }
.doc-source .ocr { max-height: 520px; }
@media (max-width: 1100px) {
    .doc-grid { grid-template-columns: 1fr; }
    .doc-fields { grid-template-columns: 1fr; }
    .doc-source { position: static; }
    .doc-preview { height: 70vh; min-height: 420px; }
}

/* ---- telefona pievienošanas lapa ---- */
.page--minimal { max-width: 560px; padding: 1rem; }
.add__company { margin: 0 0 1rem; text-align: center; color: var(--muted); }
.add__form { display: flex; flex-direction: column; gap: 0.9rem; }
.add__button { display: flex; align-items: center; gap: 0.9rem; padding: 1.1rem 1.2rem; border: 2px solid var(--line); border-radius: 12px; background: var(--surface); font-size: 1.1rem; font-weight: 600; color: var(--text); cursor: pointer; }
.add__button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.add__button--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.add__button.is-busy { opacity: 0.6; pointer-events: none; }
.add__icon { font-size: 1.8rem; }
.add__status { text-align: center; font-weight: 600; color: var(--accent-dark); }
.add__hint { text-align: center; margin-top: 1.2rem; }
.add__result { text-align: center; background: var(--ok-bg); border: 1px solid #b7dfc6; border-radius: 12px; padding: 1rem; margin-bottom: 1.2rem; }
.add__check { font-size: 2.2rem; color: var(--ok); }
