/* ============ Tokens ============ */
:root {
    --brand: #1a1a5c;
    --brand-strong: #0d0d3d;
    --brand-soft: #e4e4f5;
    --brand-tint: #f4f4fb;
    --accent: #4fc3f7;
    --accent-strong: #29b6f6;
    --ink: #0f172a;
    --ink-2: #334155;
    --muted: #64748b;
    --line: #e2e8f0;
    --line-soft: #f1f5f9;
    --bg: #f5f6fa;
    --card: #ffffff;
    --good: #059669;
    --good-soft: #d1fae5;
    --bad: #dc2626;
    --bad-soft: #fee2e2;
    --warn: #b45309;
    --warn-soft: #fef3c7;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
    --bs-primary: var(--brand);
    --bs-link-color: var(--brand);
    --bs-link-hover-color: var(--brand-strong);
}

html, body {
    font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 14.5px;
}

a { color: var(--brand); }
a:hover { color: var(--brand-strong); }
h1:focus { outline: none; }

/* ============ Bootstrap overrides ============ */
.btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand-strong); --bs-btn-hover-border-color: var(--brand-strong); --bs-btn-active-bg: var(--brand-strong); --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand); }
.btn-outline-primary { --bs-btn-color: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand); --bs-btn-active-bg: var(--brand-strong); }
.btn { font-weight: 500; border-radius: 8px; }
.btn-sm { border-radius: 7px; }
.form-control, .form-select { border-radius: 8px; border-color: #d5dde7; }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem rgba(26, 26, 92, .15); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.form-label { font-weight: 500; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
.valid.modified:not([type=checkbox]) { outline: 1px solid #26b050; }
.invalid { outline: 1px solid #e50000; }
.validation-message { color: #e50000; }

/* ============ Shell ============ */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.app-header { background: #0d0d3d; border-bottom: 3px solid var(--accent); color: #fff; position: sticky; top: 0; z-index: 20; }
.app-header-inner { max-width: 1320px; margin: 0 auto; padding: 0 20px; height: 58px; display: flex; align-items: center; gap: 28px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-size: 15.5px; letter-spacing: .2px; white-space: nowrap; }
.brand:hover { color: #fff; }
.brand img { width: 32px; height: 32px; border-radius: 8px; background: #fff; padding: 3px; }
.brand strong { color: var(--accent); font-weight: 600; }
.app-nav { display: flex; gap: 4px; flex: 1; }
.app-nav a { color: #cbd5e1; text-decoration: none; padding: 7px 12px; border-radius: 8px; font-weight: 500; }
.app-nav a:hover { color: #fff; background: rgba(255, 255, 255, .07); }
.app-nav a.active { color: #fff; background: rgba(79, 195, 247, .15); }
.user-menu { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.user-link { display: flex; align-items: center; gap: 8px; color: #e2e8f0; text-decoration: none; }
.user-link:hover { color: #fff; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 13px; }
.btn-quiet { background: none; border: 1px solid rgba(255, 255, 255, .2); color: #e2e8f0; border-radius: 8px; padding: 5px 12px; font-size: 13px; }
.btn-quiet:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.app-main { flex: 1; width: 100%; max-width: 1320px; margin: 0 auto; padding: 28px 20px 60px; }

@media (max-width: 720px) {
    .user-name { display: none; }
    .app-header-inner { gap: 12px; padding: 0 12px; }
    .brand span { display: none; }
    .app-main { padding: 18px 12px 48px; }
}

/* ============ Page header ============ */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-head h1 { font-size: 26px; font-weight: 700; margin: 0; letter-spacing: -.3px; }
.page-head .sub { color: var(--muted); margin: 4px 0 0; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--brand); }
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ============ Cards ============ */
.card-x { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-x + .card-x { margin-top: 18px; }
.card-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line-soft); }
.card-head h2 { font-size: 16px; font-weight: 600; margin: 0; }
.card-head .hint { color: var(--muted); font-size: 13px; margin: 2px 0 0; }
.card-body-x { padding: 18px 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-2 > .card-x + .card-x { margin-top: 0; }
@media (max-width: 960px) { .grid-2 { grid-template-columns: 1fr; } }
.section-gap { margin-top: 18px; }

/* ============ KPI tiles ============ */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); cursor: pointer; transition: border-color .15s, box-shadow .15s; text-align: left; width: 100%; }
.kpi:hover { border-color: #b9b9e0; }
.kpi.selected { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(26, 26, 92, .12); }
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 500; display: flex; justify-content: space-between; gap: 6px; }
.kpi-value { font-size: 28px; font-weight: 700; letter-spacing: -.5px; margin: 6px 0 4px; line-height: 1.1; }
.kpi-foot { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* ============ Deltas / badges ============ */
.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; font-size: 12px; padding: 1px 7px; border-radius: 999px; white-space: nowrap; }
.delta.up { color: var(--good); background: var(--good-soft); }
.delta.down { color: var(--bad); background: var(--bad-soft); }
.delta.flat { color: var(--muted); background: var(--line-soft); }
.badge-x { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; letter-spacing: .2px; }
.badge-x.draft { background: var(--warn-soft); color: var(--warn); }
.badge-x.published { background: var(--good-soft); color: var(--good); }
.badge-x.muted { background: var(--line-soft); color: var(--muted); }
.badge-x.info { background: #e0e7ff; color: #4338ca; }
.rank-pill { display: inline-block; min-width: 34px; text-align: center; font-weight: 600; padding: 2px 8px; border-radius: 7px; background: var(--line-soft); }
.rank-pill.top3 { background: #fef3c7; color: #92400e; }
.rank-pill.top10 { background: var(--brand-soft); color: var(--brand-strong); }
.rank-pill.none { background: transparent; color: #94a3b8; font-weight: 500; }

/* ============ Toolbar / filters ============ */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar .form-select, .toolbar .form-control { width: auto; min-width: 150px; }
.search-input { position: relative; }
.search-input input { padding-left: 32px; min-width: 220px; }
.search-input::before { content: ""; position: absolute; left: 11px; top: 50%; width: 13px; height: 13px; transform: translateY(-50%); background: no-repeat center/contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%2394a3b8'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z'/%3E%3C/svg%3E"); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: #fff; color: var(--ink-2); border-radius: 999px; padding: 4px 12px; font-size: 13px; font-weight: 500; cursor: pointer; }
.chip:hover { border-color: #b9b9e0; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip .n { opacity: .7; margin-left: 4px; font-weight: 400; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; padding: 2px; background: #fff; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 7px; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.seg button.on { background: var(--brand-tint); color: var(--brand-strong); box-shadow: inset 0 0 0 1px #b9b9e0; }

/* ============ Period bar ============ */
.period-bar { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; box-shadow: var(--shadow); margin-bottom: 18px; }
.period-bar .field { display: flex; flex-direction: column; gap: 4px; }
.period-bar .field label { font-size: 12px; color: var(--muted); font-weight: 500; }
.period-bar .vs { color: var(--muted); padding-bottom: 8px; font-weight: 500; }

/* ============ Tables ============ */
.table-x { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table-x th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fafbfd; white-space: nowrap; }
.table-x th.sortable { cursor: pointer; user-select: none; }
.table-x th.sortable:hover { color: var(--ink); }
.table-x th .arrow { opacity: .6; margin-left: 3px; }
.table-x td { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table-x tbody tr:hover td { background: #fafcfd; }
.table-x tbody tr.clickable { cursor: pointer; }
.table-x tbody tr.selected td { background: var(--brand-tint); }
.table-x .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-x .url { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.table-empty { padding: 28px; text-align: center; color: var(--muted); }
.table-x.edit td { padding: 5px 6px; }
.table-x.edit input, .table-x.edit select { width: 100%; border: 1px solid transparent; border-radius: 6px; padding: 5px 7px; background: transparent; font-size: 13.5px; }
.table-x.edit input:hover, .table-x.edit select:hover { border-color: var(--line); }
.table-x.edit input:focus, .table-x.edit select:focus { border-color: var(--brand); background: #fff; outline: none; }
.table-x.edit input[type=number] { text-align: right; }
.row-del { border: 0; background: none; color: #94a3b8; font-size: 16px; line-height: 1; padding: 4px 8px; border-radius: 6px; }
.row-del:hover { color: var(--bad); background: var(--bad-soft); }
.muted { color: var(--muted); }
.small-x { font-size: 12.5px; }

/* ============ Charts ============ */
.chart-box { position: relative; height: 290px; }
.chart-box.sm { height: 230px; }

/* ============ Alerts / notes ============ */
.note { border-radius: 10px; padding: 12px 16px; font-size: 13.5px; margin-bottom: 16px; border: 1px solid; }
.note.info { background: #eff6ff; border-color: #bfdbfe; color: #1e3a8a; }
.note.warn { background: var(--warn-soft); border-color: #fcd34d; color: #78350f; }
.note.ok { background: var(--good-soft); border-color: #6ee7b7; color: #065f46; }
.note.err { background: var(--bad-soft); border-color: #fca5a5; color: #7f1d1d; }
.note ul { margin: 6px 0 0; padding-left: 18px; }
.summary-card { background: linear-gradient(135deg, #1a1a5c, #0d0d3d); color: #eef4ff; border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 18px 22px; margin-bottom: 18px; }
.summary-card h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--accent); margin: 0 0 6px; font-weight: 600; }
.summary-card p { margin: 0; white-space: pre-line; line-height: 1.6; }

/* ============ Client list ============ */
.client-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.client-card { display: block; text-decoration: none; color: inherit; padding: 18px 20px; }
.client-card:hover { border-color: #b9b9e0; color: inherit; }
.client-card h3 { font-size: 16.5px; margin: 0 0 2px; font-weight: 600; }
.client-card .site { color: var(--muted); font-size: 13px; }
.client-meta { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 14px; font-size: 13px; color: var(--ink-2); }
.client-meta b { font-weight: 600; }

/* ============ Tabs ============ */
.tabs-x { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs-x button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 14px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.tabs-x button:hover { color: var(--ink); }
.tabs-x button.on { color: var(--brand-strong); border-bottom-color: var(--brand); }
.tabs-x .count { background: var(--line-soft); border-radius: 999px; padding: 0 7px; font-size: 12px; margin-left: 5px; }

/* ============ Upload ============ */
.dropzone { border: 2px dashed #cbd5e1; border-radius: var(--radius); padding: 26px; text-align: center; background: #fbfcfe; position: relative; transition: border-color .15s, background .15s; }
.dropzone:hover { border-color: var(--brand); background: var(--brand-tint); }
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone .big { font-weight: 600; font-size: 15px; }
.file-list { list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-direction: column; gap: 8px; }
.file-list li { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff; font-size: 13.5px; }
.file-ico { width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center; font-size: 10.5px; font-weight: 700; color: #fff; flex-shrink: 0; }
.file-ico.pdf { background: #dc2626; }
.file-ico.xls { background: #16a34a; }
.file-ico.oth { background: #64748b; }
.file-list .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============ Editor ============ */
details.ed { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); }
details.ed + details.ed { margin-top: 12px; }
details.ed > summary { list-style: none; cursor: pointer; padding: 14px 18px; display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
details.ed > summary::-webkit-details-marker { display: none; }
details.ed > summary::after { content: "▾"; color: var(--muted); transition: transform .15s; }
details.ed[open] > summary::after { transform: rotate(180deg); }
details.ed > .ed-body { padding: 4px 18px 18px; }
.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.sticky-actions { position: sticky; bottom: 0; background: rgba(246, 248, 251, .92); backdrop-filter: blur(6px); border-top: 1px solid var(--line); padding: 12px 0; margin-top: 20px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; z-index: 5; }

/* ============ Auth pages ============ */
.auth-card { max-width: 420px; margin: 40px auto; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 32px; box-shadow: 0 10px 30px rgba(15, 23, 42, .06); }
.auth-card h1 { font-size: 24px; font-weight: 700; margin: 18px 0 4px; }
.auth-sub { color: var(--muted); margin-bottom: 22px; }
.auth-brand { display: flex; align-items: center; gap: 12px; font-size: 15px; padding-bottom: 14px; margin-bottom: 4px; border-bottom: 3px solid var(--accent); }
.auth-brand img { height: 40px; width: auto; }
.auth-brand span { color: var(--brand); font-weight: 600; letter-spacing: .2px; }
.auth-foot { color: var(--muted); font-size: 13px; text-align: center; margin: 22px 0 0; }

/* ============ Misc ============ */
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty h3 { color: var(--ink); font-size: 18px; margin-bottom: 6px; }
.modal-x { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-x .panel { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal-x .panel-head { padding: 18px 22px; border-bottom: 1px solid var(--line-soft); display: flex; justify-content: space-between; align-items: center; }
.modal-x .panel-head h3 { margin: 0; font-size: 17px; font-weight: 600; }
.modal-x .panel-body { padding: 18px 22px; }
.modal-x .panel-foot { padding: 14px 22px; border-top: 1px solid var(--line-soft); display: flex; justify-content: flex-end; gap: 8px; }
.copy-box { display: flex; gap: 6px; }
.copy-box input { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.spinner-x { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Blazor ============ */
#blazor-error-ui { color-scheme: light only; background: lightyellow; bottom: 0; box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); box-sizing: border-box; display: none; left: 0; padding: 0.6rem 1.25rem 0.7rem 1.25rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
.blazor-error-boundary { background: #b32121; padding: 1rem; color: white; border-radius: 8px; }
.blazor-error-boundary::after { content: "An error has occurred."; }
.darker-border-checkbox.form-check-input { border-color: #929292; }
.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder { color: var(--bs-secondary-color); text-align: end; }
.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder { text-align: start; }
