:root {
    --ink: #0f172a;
    --ink-soft: #64748b;
    --paper: #f3f5f8;
    --paper-2: #e8ecf2;
    --card: #ffffff;
    --line: #e6e9ef;
    --sidebar: #0b1220;
    --sidebar-2: #141c2e;
    --accent: #0f766e;
    --accent-ink: #f0fdfa;
    --ok: #047857;
    --ok-bg: #ecfdf5;
    --danger: #be123c;
    --danger-bg: #fff1f2;
    --warn: #c2410c;
    --warn-bg: #fff7ed;
    --info: #1d4ed8;
    --info-bg: #eff6ff;
    --pending: #c2410c;
    --pending-bg: #fff7ed;
    --pending-line: #fdba74;
    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 12px 32px rgba(15, 23, 42, .05);
    --radius: 18px;
    --sans: "Plus Jakarta Sans", ui-sans-serif, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: var(--sans);
    color: var(--ink);
    background:
        radial-gradient(900px 420px at 88% -10%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 55%),
        var(--paper);
    letter-spacing: -.018em;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); border: 0;
}

.app { display: grid; grid-template-columns: 272px 1fr; min-height: 100vh; }
.sidebar {
    background: linear-gradient(180deg, #101828 0%, var(--sidebar) 100%);
    color: #e8eef8;
    display: flex;
    flex-direction: column;
    padding: 22px 14px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand {
    display: flex; align-items: center; gap: 10px;
    text-decoration: none; color: #fff; font-weight: 800;
    font-size: 1.12rem; padding: 4px 8px 18px; letter-spacing: -.03em;
}
.brand-mark {
    width: 34px; height: 34px; border-radius: 11px;
    display: grid; place-items: center;
    background: var(--accent); color: var(--accent-ink);
}
.company-switch { padding: 0 8px 18px; }
.company-switch select {
    width: 100%; background: var(--sidebar-2); color: #fff;
    border: 1px solid #243044; border-radius: 12px; padding: 10px 12px;
}
.nav { display: flex; flex-direction: column; gap: 3px; overflow: auto; flex: 1; padding: 0 4px; }
.nav-label {
    margin: 18px 10px 7px; font-size: .68rem; letter-spacing: .16em;
    text-transform: uppercase; color: #7d8ba3; font-weight: 700;
}
.nav-link {
    display: flex; align-items: center; gap: 10px;
    text-decoration: none; color: #c5d0e0;
    padding: 9px 11px; border-radius: 12px; font-weight: 600; font-size: .93rem;
}
.nav-link:hover { background: #1a2436; color: #fff; }
.nav-link.active {
    background: color-mix(in srgb, var(--accent) 18%, #162033);
    color: #fff;
}
.nav-ico { display: grid; place-items: center; opacity: .88; }
.sidebar-foot { padding: 16px 8px 4px; border-top: 1px solid #243044; margin-top: 12px; }
.sidebar .btn-ghost {
    background: #fff;
    color: #0b1220;
    border-color: #fff;
}
.sidebar .btn-ghost:hover {
    background: #e2e8f0;
    color: #0b1220;
    filter: none;
}
.who { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.who-meta { min-width: 0; }
.who-meta strong { display: block; font-size: .9rem; }
.who-meta span { display: block; font-size: .75rem; color: #8b97ab; word-break: break-all; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    flex-shrink: 0;
    background: #0b1220;
    color: #fff;
    display: grid; place-items: center; font-weight: 800;
    font-size: 0.95rem;
    object-fit: cover;
    border: 1px solid #243044;
}

.main { min-width: 0; }
.topbar {
    display: flex; align-items: flex-start; gap: 14px;
    padding: 24px 32px 6px; position: sticky; top: 0; z-index: 5;
    background: color-mix(in srgb, var(--paper) 86%, transparent);
    backdrop-filter: blur(14px);
}
.topbar-title { flex: 1; min-width: 0; }
.topbar h1 { margin: 0; font-size: 1.65rem; letter-spacing: -.04em; font-weight: 800; }
.page-lead { margin: 6px 0 0; color: var(--ink-soft); font-size: .98rem; line-height: 1.5; max-width: 62ch; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 4px; }
.menu-btn {
    display: none; background: transparent; border: 0; padding: 6px; cursor: pointer;
}
.content { padding: 18px 32px 64px; max-width: 1220px; }
.stack { display: grid; gap: 22px; }
.switch-label { display: block; font-size: .68rem; letter-spacing: .14em; text-transform: uppercase; color: #7d8ba3; margin: 0 0 6px; font-weight: 700; }

.flash {
    border-radius: 14px; padding: 12px 14px; margin-bottom: 16px; font-weight: 600;
}
.flash-success { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--danger-bg); color: var(--danger); }
.flash-info { background: var(--info-bg); color: var(--info); }

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

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}
.card h2, .card h3 { margin: 0 0 14px; letter-spacing: -.03em; font-weight: 700; }
.card-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 14px;
}
.card-head h2, .card-head h3 { margin: 0; }

.stat {
    padding: 20px 20px 16px;
    position: relative;
    overflow: hidden;
}
.stat .label { color: var(--ink-soft); font-weight: 700; font-size: .74rem; letter-spacing: .08em; text-transform: uppercase; }
.stat .value {
    font-size: 1.72rem; font-weight: 700;
    margin: 10px 0 6px; letter-spacing: -.045em;
    font-variant-numeric: tabular-nums;
}
.stat .hint { color: var(--ink-soft); font-size: .82rem; font-weight: 600; }
.stat.up { background: linear-gradient(180deg, #f0fdf7, #fff); border-color: #bbf7d0; }
.stat.up .value, .stat.up .hint { color: var(--ok); }
.stat.down { background: linear-gradient(180deg, #fff1f2, #fff); border-color: #fecdd3; }
.stat.down .value, .stat.down .hint { color: var(--danger); }
.stat.pending {
    background: linear-gradient(180deg, #fff7ed, #fff);
    border-color: var(--pending-line);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--pending) 12%, transparent), var(--shadow);
}
.stat.pending .label { color: #9a3412; }
.stat.pending .value,
.stat.pending .hint { color: var(--pending); }
a.stat-link { text-decoration: none; display: block; }
a.stat-link:hover { transform: translateY(-1px); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border-radius: 12px; padding: 10px 14px; text-decoration: none;
    border: 1px solid transparent; font-weight: 700; cursor: pointer;
    background: #fff; color: var(--ink);
    transition: transform .12s ease, filter .12s ease, background .12s ease;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: #fff; border-color: var(--line); }
.btn-sm { padding: 7px 10px; font-size: .85rem; }
.btn-wide { width: 100%; }
.btn:hover { filter: brightness(1.04); }

.badge {
    display: inline-flex; align-items: center; border-radius: 999px;
    padding: 4px 9px; font-size: .74rem; font-weight: 700;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-muted { background: var(--paper-2); color: var(--ink-soft); }

.table-wrap { overflow: auto; }
table.data {
    width: 100%; border-collapse: collapse; font-size: .92rem;
}
table.data th, table.data td {
    text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
table.data th {
    font-size: .72rem; letter-spacing: .07em; text-transform: uppercase;
    color: var(--ink-soft); font-weight: 700;
}
table.data tr:hover td { background: #f8fafc; }
table.data .num, .num {
    font-variant-numeric: tabular-nums;
    text-align: right; white-space: nowrap; font-weight: 600;
}
table.data td.num, table.data th.num { text-align: right; }
table.data tr.is-open td { background: var(--pending-bg); }
table.data tr.is-overdue td { background: var(--danger-bg); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-weight: 700; font-size: .86rem; }
.field input, .field select, .field textarea {
    border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
    background: #fff;
}
.field textarea { min-height: 90px; resize: vertical; }
.help { color: var(--ink-soft); font-size: .8rem; }

.toolbar {
    display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
    margin-bottom: 16px;
}
.toolbar input, .toolbar select {
    border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #fff;
}
.search { min-width: 220px; flex: 1; }

.progress {
    height: 8px; background: var(--paper-2); border-radius: 99px; overflow: hidden;
}
.progress > span { display: block; height: 100%; background: var(--accent); }
.progress.over > span { background: var(--danger); }

.muted { color: var(--ink-soft); }
.empty {
    text-align: center; padding: 36px 16px; color: var(--ink-soft);
}
.empty h3 { color: var(--ink); margin: 0 0 8px; }

.company-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.company-card {
    display: block; text-decoration: none; padding: 20px; border-radius: var(--radius);
    border: 1px solid var(--line); background: var(--card); box-shadow: var(--shadow);
}
.company-card.active { outline: 2px solid var(--accent); }
.company-card .type { color: var(--ink-soft); font-size: .82rem; font-weight: 700; margin-bottom: 6px; }
.company-card h3 { margin: 0 0 8px; }
.logo-preview { width: 48px; height: 48px; object-fit: contain; border-radius: 8px; background: #fff; border: 1px solid var(--line); }

.split { display: grid; grid-template-columns: 1.4fr .8fr; gap: 16px; }
.invoice-stage {
    display: grid;
    grid-template-columns: minmax(0, 210mm) minmax(240px, 1fr);
    gap: 16px;
    align-items: start;
}
.invoice-paper {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 14mm 14mm 10mm;
    box-shadow: var(--shadow);
}

.items-table input, .items-table select { width: 100%; padding: 8px 9px; }

.auth-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.1fr .9fr;
    background: var(--sidebar);
}
.auth-visual {
    color: #eef4ff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between;
    background:
        radial-gradient(900px 480px at 18% 8%, color-mix(in srgb, var(--accent) 42%, transparent), transparent 62%),
        linear-gradient(180deg, #101828, #0b1220);
}
.auth-visual h1 { font-size: 3rem; margin: 12px 0 10px; letter-spacing: -.055em; max-width: 12ch; font-weight: 800; }
.auth-visual p { color: #b7c3d6; max-width: 40ch; line-height: 1.5; font-size: 1.05rem; }
.auth-points { display: grid; gap: 10px; margin-top: 28px; }
.auth-points div {
    background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.06);
    border-radius: 14px; padding: 12px 14px; font-weight: 600;
}
.auth-card {
    background: var(--paper); display: grid; place-items: center; padding: 32px;
}
.auth-box { width: min(420px, 100%); }
.auth-box h2 { margin: 0 0 6px; font-size: 1.8rem; }
.auth-box .sub { margin: 0 0 22px; color: var(--ink-soft); }

.checks { display: flex; align-items: center; gap: 8px; font-weight: 600; }

.steps { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; counter-reset: step; }
.steps li {
    display: grid; grid-template-columns: 32px 1fr; gap: 12px; align-items: start;
    padding: 12px 0; border-bottom: 1px solid var(--line);
}
.steps li:last-child { border-bottom: 0; }
.steps li::before {
    counter-increment: step; content: counter(step);
    width: 32px; height: 32px; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--paper-2); font-weight: 800; font-size: .85rem;
}
.drop {
    border: 1.5px dashed var(--line); border-radius: 16px; padding: 28px;
    text-align: center; background: #fff;
}

.hidden { display: none !important; }
.req { color: #2563eb; font-weight: 800; }

.content:has(.receipt-layout),
.content:has(.receipt-strip) { max-width: 1360px; }

.receipt-layout {
    display: grid;
    grid-template-columns: minmax(300px, .92fr) minmax(380px, 1.18fr);
    gap: 16px;
    align-items: start;
}
.receipt-upload {
    position: sticky;
    top: 88px;
    padding: 16px;
}
.dropzone {
    border: 1.6px dashed #d4dbe6;
    border-radius: 16px;
    background: #f7f8fb;
    min-height: 520px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    transition: border-color .15s ease, background .15s ease;
}
.dropzone.is-over,
.dropzone.has-file { border-color: color-mix(in srgb, var(--accent) 45%, #d4dbe6); background: #fff; }
.receipt-preview {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
    display: grid;
    grid-template-rows: minmax(220px, 320px) auto;
}
.receipt-preview img,
.receipt-preview iframe {
    width: 100%;
    height: 320px;
    border: 0;
    object-fit: contain;
    background: #eef1f6;
}
.receipt-preview-meta { padding: 12px 14px 14px; }
.receipt-preview-meta strong { display: block; font-size: .92rem; }
.receipt-preview-meta p { margin: 4px 0 10px; word-break: break-all; }
.dropzone-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 14px;
    padding: 12px 8px 18px;
}
.dropzone-kicker { margin: 0; font-weight: 700; color: var(--ink-soft); }
.dropzone-icons { display: flex; gap: 10px; }
.ftype {
    width: 54px; height: 62px; border-radius: 10px;
    display: grid; place-items: center;
    font-size: .68rem; font-weight: 800; letter-spacing: .04em;
    box-shadow: 0 8px 18px rgba(15, 23, 42, .08);
}
.ftype-pdf { background: linear-gradient(180deg, #fff, #fee2e2); color: #b91c1c; border: 1px solid #fecaca; }
.ftype-png { background: linear-gradient(180deg, #fff, #dbeafe); color: #1d4ed8; border: 1px solid #bfdbfe; }
.ftype-jpg { background: linear-gradient(180deg, #fff, #ffedd5); color: #c2410c; border: 1px solid #fed7aa; }
.dropzone-box {
    width: min(100%, 340px);
    background: #eef4ff;
    border: 1px solid #dbe7ff;
    border-radius: 12px;
    padding: 14px 16px;
    text-align: left;
    color: #1e3a8a;
}
.dropzone-box strong { display: block; margin-bottom: 8px; }
.dropzone-box ul { margin: 0 0 8px; padding-left: 18px; }
.dropzone-box p { margin: 0; font-size: .82rem; color: #3b4f7a; }

.receipt-form { padding: 22px; }
.scan-status {
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 16px;
    font-weight: 700;
    font-size: .9rem;
}
.scan-status.is-busy { background: #eff6ff; color: #1d4ed8; }
.scan-status.is-ok { background: var(--ok-bg); color: var(--ok); }
.scan-status.is-warn { background: var(--warn-bg); color: var(--warn); }
.positions-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin: 22px 0 12px;
}
.positions-head > span {
    background: #eef1f6; color: #475569;
    font-size: .68rem; font-weight: 800; letter-spacing: .14em;
    text-transform: uppercase; border-radius: 8px; padding: 6px 10px;
}
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg-opt { cursor: pointer; }
.seg-opt input { position: absolute; opacity: 0; pointer-events: none; }
.seg-opt span {
    display: block; padding: 7px 14px; font-size: .86rem; font-weight: 700; color: var(--ink-soft);
}
.seg-opt:has(input:checked) span {
    background: #eff6ff; color: #1d4ed8; box-shadow: inset 0 0 0 1px #93c5fd;
}
.position-row {
    display: grid;
    grid-template-columns: minmax(140px, .9fr) minmax(160px, 1.4fr) minmax(140px, .8fr);
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fbfcfe;
}
.amount-wrap { display: flex; }
.amount-wrap input { border-top-right-radius: 0; border-bottom-right-radius: 0; flex: 1; min-width: 0; }
.amount-wrap .ccy {
    display: grid; place-items: center;
    padding: 0 12px; border: 1px solid var(--line); border-left: 0;
    border-radius: 0 12px 12px 0; background: #fff; font-weight: 800; color: var(--ink-soft);
}
.receipt-foot {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap; margin-top: 18px; padding-top: 16px;
    border-top: 1px solid var(--line);
}
.receipt-total { font-weight: 700; color: var(--ink-soft); }
.receipt-total strong { color: var(--ink); font-size: 1.15rem; margin-left: 4px; }
.receipt-actions { display: flex; gap: 8px; }

.receipt-strip { margin-bottom: 16px; }
.receipt-strip-row {
    display: flex; gap: 12px; overflow-x: auto; padding-bottom: 6px;
    scroll-snap-type: x proximity;
}
.receipt-tile {
    flex: 0 0 148px; text-decoration: none; color: inherit;
    border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
    background: #f8fafc; scroll-snap-align: start;
}
.receipt-tile img, .receipt-pdf-thumb {
    width: 100%; height: 110px; object-fit: cover; display: block; background: #e2e8f0;
}
.receipt-pdf-thumb { display: grid; place-items: center; font-weight: 800; color: #b91c1c; background: #fee2e2; }
.receipt-tile span, .receipt-tile small {
    display: block; padding: 0 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.receipt-tile span { padding-top: 8px; font-weight: 700; font-size: .8rem; }
.receipt-tile small { padding-bottom: 10px; color: var(--ink-soft); font-size: .72rem; }
.file-chip {
    width: 42px; height: 42px; border-radius: 10px; overflow: hidden;
    display: grid; place-items: center; border: 1px solid var(--line); background: #f8fafc;
}
.file-chip img { width: 100%; height: 100%; object-fit: cover; }
.file-chip-pdf { font-size: .62rem; font-weight: 800; color: #b91c1c; }

.tax-meter {
    height: 12px;
    background: #e8ecf2;
    border-radius: 99px;
    overflow: hidden;
    margin: 12px 0 8px;
}
.tax-meter > span { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.tax-meter.tax-tight > span { background: var(--warn); }
.tax-meter.tax-warn > span, .tax-meter.tax-over > span, .tax-meter.tax-lost > span { background: var(--danger); }
.tax-meter-labels {
    display: flex; justify-content: space-between;
    font-size: .8rem; font-weight: 700; color: var(--ink-soft);
}
.tax-hero h3 { margin: 0 0 8px; font-size: 1rem; }

.tax-card h2 { margin-bottom: 6px; }
.tax-lead { margin: 0 0 14px; color: var(--ink-soft); font-size: .88rem; line-height: 1.45; font-weight: 600; }
.tax-foot { margin: 12px 0 0; color: var(--ink-soft); font-size: .78rem; line-height: 1.4; font-weight: 600; }
.tax-gfb { background: linear-gradient(180deg, #ecfdf5, #fff); border-color: #a7f3d0; }
.tax-gfb h2 { color: #047857; }
.tax-svs { background: linear-gradient(180deg, #fff7ed, #fff); border-color: #fed7aa; }
.tax-svs h2 { color: #c2410c; }
.tax-est { background: linear-gradient(180deg, #eef2ff, #fff); border-color: #c7d2fe; }
.tax-est h2 { color: #3730a3; }
.tax-rows { display: grid; gap: 0; }
.tax-rows > div {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
    padding: 10px 0; border-bottom: 1px solid color-mix(in srgb, currentColor 8%, var(--line));
}
.tax-rows > div:last-child { border-bottom: 0; padding-bottom: 0; }
.tax-rows strong { display: block; font-size: .86rem; }
.tax-rows small { display: block; margin-top: 3px; color: var(--ink-soft); font-size: .74rem; font-weight: 600; line-height: 1.35; }
.tax-rows span {
    font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap;
    padding: 4px 9px; border-radius: 8px; background: var(--paper);
}
.tax-rows .is-ok span { color: var(--ok); background: var(--ok-bg); }
.tax-rows .is-due span { color: var(--danger); background: var(--danger-bg); }
.tax-rows .is-cost span { color: var(--warn); background: var(--warn-bg); }
.tax-rows .is-info span { color: var(--info); background: var(--info-bg); }
.tax-rows .is-mute span { color: var(--ink-soft); background: var(--paper-2); }

@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .split, .invoice-stage, .auth-shell, .receipt-layout { grid-template-columns: 1fr; }
    .auth-visual { display: none; }
    .receipt-upload { position: static; }
}
@media (max-width: 860px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; inset: 0 auto 0 0; width: min(84vw, 300px);
        transform: translateX(-105%); transition: transform .2s ease; z-index: 20;
    }
    .sidebar.open { transform: none; }
    .menu-btn { display: grid; }
    .grid-2, .grid-3, .form-grid, .receipt-layout, .position-row { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .content, .topbar { padding-left: 16px; padding-right: 16px; }
    .topbar h1 { font-size: 1.2rem; }
    .receipt-upload { position: static; }
    .dropzone { min-height: 0; }
}

@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .app { display: block; }
    .content { padding: 0; }
    body { background: #fff; }
}
