:root {
    --brand: #1F3864;
    --brand-2: #2E4F8A;
    --accent: #2E7D32;
    --danger: #B3261E;
    --warn: #A15C07;
    --warn-bg: #FFF4E0;
    --ok-bg: #E8F3E8;
    --info-bg: #EAF0F9;
    --text: #1B2430;
    --muted: #5F6B7A;
    --faint: #8A94A3;
    --border: #DCE1E8;
    --surface: #F5F7FA;
    --card: #FFFFFF;
    --radius: 8px;
    --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); font-size: 14px; color: var(--text); background: var(--surface); line-height: 1.45; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; font-weight: 600; margin: 0; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 8px; }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 6px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.mono { font-family: Consolas, "Courier New", monospace; }
.ok { color: var(--accent); }
.bad { color: var(--danger); }
.warn { color: var(--warn); }
hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: 54px 1fr; min-height: 100vh; }
.topbar { grid-column: 1 / 3; display: flex; align-items: center; gap: 14px; padding: 0 18px; background: var(--brand); color: #fff; }
.topbar .logo { font-weight: 600; font-size: 17px; color: #fff; }
.topbar .company { color: #B9C7E0; font-size: 13px; }
.topbar .spacer { flex: 1; }
.topbar .who { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #DDE6F5; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #DCE6F7; color: var(--brand); display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 12px; flex: none; }
.avatar.green { background: #DFF0E0; color: #1F5F22; }
.topbar button.link { background: none; border: none; color: #DDE6F5; cursor: pointer; font: inherit; padding: 4px 6px; }
.topbar button.link:hover { color: #fff; text-decoration: underline; }
.sidebar { background: #fff; border-right: 1px solid var(--border); padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius); color: var(--text); text-decoration: none; }
.sidebar a:hover { background: var(--surface); }
.sidebar a.active { background: var(--info-bg); color: var(--brand); font-weight: 600; }
.sidebar .count { margin-left: auto; background: var(--warn-bg); color: var(--warn); font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 10px; }
.sidebar .section { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; padding: 12px 10px 4px; }
.sidebar svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
main { padding: 20px 24px 40px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }

/* ---------- Cards and tiles ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.card + .card { margin-top: 14px; }
.grid { display: grid; gap: 14px; }
.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)); }
.tile { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.tile .label { color: var(--muted); font-size: 12px; }
.tile .value { font-size: 22px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12px; color: var(--muted); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 460px; gap: 16px; align-items: start; }
.split.wide-right { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.sticky { position: sticky; top: 16px; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: none; }
.list-row .grow { flex: 1; min-width: 0; }

/* ---------- Tables ---------- */
table.data { width: 100%; border-collapse: collapse; background: var(--card); }
table.data th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; }
table.data td { padding: 8px 10px; border-bottom: 1px solid #EEF1F5; vertical-align: top; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: #F7F9FC; }
table.data tr.selected td { background: var(--info-bg); }
table.data tr.total td { font-weight: 600; background: var(--surface); }
table.data tr.heading td { font-weight: 600; color: var(--brand); }
.table-wrap { border: 1px solid var(--border); border-radius: 10px; overflow: auto; max-height: calc(100vh - 230px); background: var(--card); }
.table-wrap table.data th:first-child, .table-wrap table.data td:first-child { padding-left: 14px; }

/* ---------- Forms ---------- */
label.field { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
label.field > input, label.field > select, label.field > textarea { margin-top: 3px; }
input:not([type]), input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
    width: 100%; font: inherit; font-size: 14px; color: var(--text); background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #BFD3F2; border-color: var(--brand-2); }
input[readonly], input:disabled, select:disabled, textarea:disabled { background: var(--surface); color: var(--muted); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 8px 0; }
.check input { width: auto; }
.validation-message, .error { color: var(--danger); font-size: 12px; margin-top: 4px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 13px; font-weight: 500; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--border); background: #fff; color: var(--brand); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface); text-decoration: none; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); }
.btn-success { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-success:hover { background: #276B2A; }
.btn-danger { color: var(--danger); border-color: #E3B4B0; }
.btn-danger:hover { background: #FCEDEC; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Badges, banners ---------- */
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: var(--surface); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: #1F5F22; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.info { background: var(--info-bg); color: var(--brand); }
.badge.bad { background: #FCEDEC; color: var(--danger); }
.banner { border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; }
.banner.warn { background: var(--warn-bg); color: #7A4A08; border: 1px solid #F0D49B; }
.banner.ok { background: var(--ok-bg); color: #1F5F22; border: 1px solid #C6E2C7; }
.banner.info { background: var(--info-bg); color: var(--brand); border: 1px solid #CAD8EE; }
.banner.bad { background: #FCEDEC; color: var(--danger); border: 1px solid #F0C7C3; }
.toast { position: fixed; right: 20px; bottom: 20px; background: var(--text); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; z-index: 50; max-width: 420px; }
.toast.bad { background: var(--danger); }
.presence { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }

/* ---------- Tabs, filters ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs button { background: none; border: none; font: inherit; padding: 8px 14px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.filters select, .filters input { width: auto; }

/* ---------- Dialog ---------- */
.overlay { position: fixed; inset: 0; background: rgba(20, 28, 40, .45); display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; z-index: 40; overflow: auto; }
.dialog { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; padding: 18px 20px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.dialog.wide { max-width: 820px; }
.dialog .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- Document preview ---------- */
.doc-frame { width: 100%; height: calc(100vh - 200px); min-height: 480px; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.doc-img { max-width: 100%; border: 1px solid var(--border); border-radius: 10px; background: #fff; }

/* ---------- Sign-in pages ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--surface); }
.auth-card { background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 28px 30px; width: 100%; max-width: 420px; }
.auth-card .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.auth-card .brand .mark { width: 34px; height: 34px; border-radius: 8px; background: var(--brand); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 13px; }
.auth-card .btn { width: 100%; justify-content: center; padding: 9px; }
.qr { display: block; margin: 8px auto; width: 190px; height: 190px; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; font-family: Consolas, monospace; background: var(--surface); padding: 10px; border-radius: 8px; margin: 10px 0; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty h2 { color: var(--brand); }

#blazor-error-ui { background: #FFF4E0; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2); display: none; left: 0; padding: .6rem 1.25rem .7rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

/* Side-by-side form + panel needs room for the form's tables; stack them on mid-size windows. */
@media (max-width: 1180px) {
    .split, .split.wide-right { grid-template-columns: minmax(0, 1fr); }
    .sticky { position: static; }
}

@media (max-width: 900px) {
    .shell { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; }
    .topbar { grid-column: 1; }
    .sidebar { flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border); padding: 6px; }
    .sidebar .section { display: none; }
    .split, .split.wide-right, .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    main { padding: 14px; }
}
