:root {
    --navy: #0B2A4A;
    --navy-2: #12406e;
    --teal: #1FB6A6;
    --teal-dark: #159488;
    --blue: #2f6fed;
    --green: #22a06b;
    --ink: #1c2733;
    --muted: #5b6b7b;
    --line: #e6ebf1;
    --bg: #eef2f7;
    --bg-soft: #f6f9fc;
    --card: #ffffff;
    --danger: #d9534f;
    --warn: #e0a800;
    --shadow: 0 8px 30px rgba(11, 42, 74, 0.08);
    --shadow-lg: 0 18px 50px rgba(11, 42, 74, 0.16);
    --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    font-size: 15px;
}

h1, h2, h3 { margin: 0; font-weight: 800; letter-spacing: -0.01em; }
a { color: var(--teal-dark); text-decoration: none; }

/* ---------------- App shell ---------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 258px;
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--navy) 0%, #0a2340 100%);
    color: #cfe0ee;
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 20px; }
.brand-word { font-size: 19px; font-weight: 800; color: #fff; }
.brand-word span { color: var(--teal); }
.brand-sub { font-size: 11px; color: #8fb0cc; letter-spacing: .5px; text-transform: uppercase; }

.nav-label {
    font-size: 10.5px; letter-spacing: .8px; text-transform: uppercase;
    color: #6f93b4; margin: 18px 12px 6px;
}
.nav-group { display: flex; flex-direction: column; gap: 3px; }

.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px; border-radius: 10px;
    color: #c3d6e8; font-weight: 600; font-size: 14px;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: linear-gradient(90deg, rgba(31,182,166,.22), rgba(31,182,166,.05)); color: #fff; box-shadow: inset 3px 0 0 var(--teal); }
.ni-icon { width: 18px; text-align: center; opacity: .85; font-size: 13px; }
.nav-badge {
    margin-left: auto; background: var(--teal); color: #04231f;
    font-size: 11px; font-weight: 800; min-width: 20px; height: 20px; padding: 0 6px;
    border-radius: 11px; display: inline-flex; align-items: center; justify-content: center;
}

.sidebar-foot {
    margin-top: auto; padding: 12px; font-size: 12px; color: #8fb0cc;
    display: flex; align-items: center; gap: 8px;
    border-top: 1px solid rgba(255,255,255,0.08);
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-live { background: var(--teal); box-shadow: 0 0 0 0 rgba(31,182,166,.6); animation: pulse 2s infinite; }
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(31,182,166,.5); }
    70% { box-shadow: 0 0 0 7px rgba(31,182,166,0); }
    100% { box-shadow: 0 0 0 0 rgba(31,182,166,0); }
}

.app-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    height: 62px; display: flex; align-items: center; justify-content: space-between;
    padding: 0 30px; background: rgba(255,255,255,0.72); backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.hello { font-size: 13px; color: var(--muted); }
.hello b { color: var(--ink); }

.app-content { padding: 28px 30px 48px; max-width: 1240px; width: 100%; }

/* ---------------- Page header ---------------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 25px; color: var(--navy); }
.page-sub { margin: 5px 0 0; color: var(--muted); font-size: 14px; }
.page-head-actions { display: flex; gap: 10px; }

/* ---------------- Stat cards ---------------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 22px; }
.stat-grid.two { grid-template-columns: repeat(2, 1fr); }
.linkcard { text-decoration: none; color: inherit; transition: transform .08s, box-shadow .15s; }
.linkcard:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-card {
    background: var(--card); border-radius: var(--radius); padding: 20px 22px;
    box-shadow: var(--shadow); position: relative; overflow: hidden;
    border: 1px solid var(--line);
}
.stat-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; }
.stat-card.accent-teal::before { background: var(--teal); }
.stat-card.accent-navy::before { background: var(--navy); }
.stat-card.accent-blue::before { background: var(--blue); }
.stat-card.accent-green::before { background: var(--green); }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.stat-value { font-size: 30px; font-weight: 800; color: var(--navy); margin: 8px 0 4px; line-height: 1.05; letter-spacing: -0.02em; }
.stat-foot { font-size: 12.5px; color: var(--muted); }

/* ---------------- Cards ---------------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); gap: 12px; }
.card-head h2 { font-size: 15px; color: var(--navy); }
.card-body { padding: 20px; }
.card-body.no-pad { padding: 0; }
.card-body .pad, .pad { padding: 18px 20px; }
.card-foot { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--bg-soft); gap: 12px; }

/* ---------------- Charts ---------------- */
.chart { width: 100%; height: auto; }
.chart-val { font-size: 10px; fill: var(--navy); font-weight: 700; }
.chart-axis { font-size: 9px; fill: var(--muted); }

/* horizontal bars */
.hbars { display: flex; flex-direction: column; gap: 12px; }
.hbar-row { display: grid; grid-template-columns: 1fr 130px 34px; align-items: center; gap: 10px; }
.hbar-label { font-size: 13px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { background: var(--bg); height: 10px; border-radius: 6px; overflow: hidden; }
.hbar-fill { height: 100%; background: linear-gradient(90deg, var(--teal), var(--blue)); border-radius: 6px; }
.hbar-value { font-size: 13px; font-weight: 700; color: var(--navy); text-align: right; }

/* ---------------- Key-value list ---------------- */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 9px 18px; margin: 0; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; font-weight: 600; font-size: 13.5px; text-align: right; color: var(--ink); }
.kv dd.small, .small { font-weight: 500; font-size: 12.5px; }

/* ---------------- Tables ---------------- */
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table thead th {
    text-align: left; padding: 11px 16px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
    color: var(--muted); background: var(--bg-soft); border-bottom: 1px solid var(--line); font-weight: 700; white-space: nowrap;
}
.table tbody td { padding: 11px 16px; border-bottom: 1px solid var(--line); color: var(--ink); }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--bg-soft); }
.table.compact tbody td, .table.compact thead th { padding: 8px 14px; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.num-bad { color: var(--danger); font-weight: 700; }
.mono { font-family: Consolas, Menlo, monospace; font-size: 12.5px; }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); }
.link { color: var(--teal-dark); cursor: pointer; text-decoration: underline dotted; }

/* ---------------- Badges & pills ---------------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.badge-ok { background: rgba(34,160,107,.12); color: var(--green); }
.badge-warn { background: rgba(224,168,0,.15); color: #a9790a; }
.badge-error { background: rgba(217,83,79,.12); color: var(--danger); }
.badge-muted { background: #eef2f7; color: var(--muted); }
.badge-navy { background: rgba(11,42,74,.1); color: var(--navy); }

.pill { padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.pill-live { background: rgba(31,182,166,.14); color: var(--teal-dark); }
.pill-idle { background: #eef2f7; color: var(--muted); }

.now-processing { margin-top: 14px; font-size: 13px; color: var(--teal-dark); }

/* ---------------- Buttons ---------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 9px 18px; border-radius: 10px; border: 1px solid var(--line);
    background: #fff; color: var(--ink); font-weight: 700; font-size: 13.5px; cursor: pointer;
    transition: transform .05s, box-shadow .15s, background .15s;
}
.btn:hover { box-shadow: var(--shadow); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; box-shadow: none; }
.btn-primary { background: linear-gradient(135deg, var(--teal), var(--teal-dark)); color: #fff; border-color: transparent; }
.btn-primary:hover { box-shadow: 0 8px 20px rgba(31,182,166,.35); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 13px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-row, .page-head-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row { margin-top: 16px; }

/* ---------------- Forms ---------------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.input {
    width: 100%; padding: 10px 13px; border: 1px solid var(--line); border-radius: 10px;
    font-size: 14px; color: var(--ink); background: #fff; transition: border .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(31,182,166,.15); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-bottom: 16px; }
.search { display: flex; gap: 8px; flex: 1; max-width: 460px; }
.search .input { flex: 1; }

/* ---------------- Alerts ---------------- */
.alert { padding: 11px 14px; border-radius: 10px; font-size: 13.5px; }
.alert-error { background: rgba(217,83,79,.1); color: #a63631; border: 1px solid rgba(217,83,79,.25); }
.alert-ok { background: rgba(34,160,107,.1); color: #197a51; border: 1px solid rgba(34,160,107,.25); }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }

.cred-reveal { background: var(--bg-soft); border: 1px dashed var(--teal); border-radius: 10px; padding: 12px 14px; }
.cred-reveal code { font-size: 15px; font-weight: 700; color: var(--navy); }

/* ---------------- Skeletons ---------------- */
.skeleton-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 22px; }
.skeleton { height: 108px; background: linear-gradient(90deg, #eef2f7 25%, #f6f9fc 50%, #eef2f7 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.page-loading { padding: 40px; text-align: center; color: var(--muted); }

/* ---------------- Login ---------------- */
.login-shell {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: radial-gradient(1200px 600px at 15% -10%, #12406e 0%, transparent 55%),
                radial-gradient(900px 500px at 110% 120%, rgba(31,182,166,.45) 0%, transparent 55%),
                linear-gradient(135deg, #0B2A4A 0%, #0a2340 100%);
    padding: 20px;
}
.login-card {
    background: #fff; width: 100%; max-width: 410px; border-radius: 20px;
    padding: 34px 34px 26px; box-shadow: var(--shadow-lg);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-wordmark { font-size: 20px; font-weight: 800; color: var(--navy); }
.login-wordmark span { color: var(--teal); }
.login-sub { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.login-card h1 { font-size: 23px; color: var(--navy); }
.login-lead { color: var(--muted); font-size: 14px; margin: 6px 0 20px; }
.login-footer { margin-top: 20px; text-align: center; font-size: 11px; color: var(--muted); }
.validation-message { color: var(--danger); font-size: 12px; }

/* ---------------- Blazor error UI ---------------- */
#blazor-error-ui {
    display: none; position: fixed; bottom: 0; left: 0; right: 0;
    background: #fff3cd; color: #664d03; padding: 10px 18px; box-shadow: 0 -2px 12px rgba(0,0,0,.1);
    z-index: 1000; font-size: 13px;
}
#blazor-error-ui .reload { color: #664d03; text-decoration: underline; margin-left: 8px; }
#blazor-error-ui .dismiss { cursor: pointer; float: right; }

/* ---------------- Responsive ---------------- */
@media (max-width: 1000px) {
    .stat-grid, .skeleton-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
    .sidebar { position: fixed; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
    .app-content { padding: 18px; }
    .stat-grid, .skeleton-grid { grid-template-columns: 1fr; }
}
