:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e7ecf3;
    --text: #17202e;
    --muted: #667085;
    --primary: #0b6bcb;
    --primary-dark: #095297;
    --accent: #0ea5e9;
    --success: #12a150;
    --warning: #d97706;
    --danger: #dc2626;
    --sidebar: #0d1b2f;
    --sidebar-2: #13263f;
    --radius: 12px;
    --shadow: 0 12px 32px rgba(15, 35, 70, .08);
    --shadow-sm: 0 2px 8px rgba(15, 35, 70, .06);
}

* { box-sizing: border-box; }

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

h1, h2, h3 { color: #0d2542; letter-spacing: -.01em; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.app-sidebar {
    width: 250px;
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
    color: #cdd8e8;
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 12px;
    color: #fff; font-weight: 700; font-size: 1.15rem;
    padding: 6px 8px 22px; text-decoration: none;
}
.sidebar-brand:hover { text-decoration: none; }
.brand-logo {
    width: 36px; height: 36px; border-radius: 9px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: grid; place-items: center; font-size: .9rem; font-weight: 800; color: #fff;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.side-link {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 14px; border-radius: 9px;
    color: #b9c6da; font-weight: 500; text-decoration: none;
    transition: background .15s, color .15s;
}
.side-link:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.side-link.active { background: var(--primary); color: #fff; }
.side-ico { font-size: 1rem; width: 20px; text-align: center; }
.sidebar-foot { font-size: .75rem; color: #6b7d95; padding: 12px 8px 0; border-top: 1px solid rgba(255,255,255,.07); }

.app-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.app-topbar {
    height: 60px; display: flex; align-items: center; justify-content: space-between;
    padding: 0 28px; background: var(--surface); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 5;
}
.topbar-spacer { flex: 1; }
.topbar-user { display: flex; align-items: center; gap: 14px; }
.user-name { font-weight: 600; color: var(--text); }
.app-content { padding: 28px; max-width: 1200px; width: 100%; }

/* ---------- Buttons ---------- */
.btn-primary, .btn-secondary, .btn-danger, .btn-ghost, .btn-sm {
    display: inline-flex; align-items: center; gap: 8px;
    border: 1px solid transparent; border-radius: 9px;
    padding: 10px 18px; font-size: .92rem; font-weight: 600;
    cursor: pointer; transition: all .15s; text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); text-decoration: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; text-decoration: none; }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); padding: 8px 14px; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: .82rem; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Cards & surfaces ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-pad { padding: 22px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0 0 4px; font-size: 1.55rem; }
.page-head p { margin: 0; color: var(--muted); }

/* ---------- Stat cards ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 18px; margin-bottom: 26px; }
.stat-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm);
}
.stat-card .label { color: var(--muted); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat-card .value { font-size: 2rem; font-weight: 800; color: #0d2542; margin-top: 6px; }
.stat-card .sub { color: var(--muted); font-size: .82rem; margin-top: 2px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); }
table.grid th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--surface-2); }
table.grid tbody tr:hover { background: var(--surface-2); }
table.grid td.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .85rem; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge-green { background: #e7f7ee; color: var(--success); }
.badge-gray { background: #eef1f5; color: var(--muted); }
.badge-amber { background: #fdf2e3; color: var(--warning); }
.badge-red { background: #fdecec; color: var(--danger); }

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 16px; }
.field > span, .field-label { display: block; font-weight: 600; margin-bottom: 6px; font-size: .88rem; color: #2c3a4d; }
.field .hint { font-weight: 400; color: var(--muted); font-size: .8rem; margin-top: 4px; }
.input, .textarea, select.input {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px;
    font-size: .95rem; font-family: inherit; background: #fff; color: var(--text); transition: border .15s, box-shadow .15s;
}
.input:focus, .textarea:focus, select.input:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(11,107,203,.12);
}
.textarea { min-height: 120px; resize: vertical; }
.textarea.code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .85rem; line-height: 1.5; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 4px 24px; }
.checkbox-row { display: flex; align-items: center; gap: 10px; margin: 12px 0; }
.validation-message { color: var(--danger); font-size: .82rem; }

.form-section { margin-top: 8px; }
.form-section h3 { font-size: 1rem; margin: 22px 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar .grow { flex: 1; min-width: 180px; }
.search-input { max-width: 320px; }

/* ---------- Pagination ---------- */
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 16px; color: var(--muted); }

/* ---------- Login ---------- */
.login-viewport {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: radial-gradient(1000px 500px at 50% -20%, #dce9fb, var(--bg)); padding: 24px;
}
.login-card { background: #fff; width: 100%; max-width: 400px; border-radius: 16px; padding: 34px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.login-logo { width: 46px; height: 46px; border-radius: 12px; background: linear-gradient(135deg, var(--primary), var(--accent)); color: #fff; display: grid; place-items: center; font-weight: 800; }
.login-brand h1 { margin: 0; font-size: 1.25rem; }
.login-brand p { margin: 0; color: var(--muted); font-size: .85rem; }
.login-error { background: #fdecec; color: var(--danger); padding: 10px 14px; border-radius: 9px; font-size: .88rem; margin-bottom: 16px; }
.login-card .btn-primary { width: 100%; justify-content: center; margin-top: 8px; }

/* ---------- Misc ---------- */
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state .big { font-size: 2.4rem; margin-bottom: 10px; }
.flash { padding: 12px 16px; border-radius: 9px; margin-bottom: 18px; font-size: .9rem; }
.flash-success { background: #e7f7ee; color: var(--success); }
.flash-error { background: #fdecec; color: var(--danger); }
.code-inline { font-family: ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 2px 7px; border-radius: 6px; font-size: .85rem; border: 1px solid var(--border); }
.row-gap { display: flex; gap: 10px; flex-wrap: wrap; }

/* Blazor error UI */
#blazor-error-ui {
    color-scheme: light only; background: #fff5f5; border-top: 3px solid var(--danger);
    bottom: 0; box-shadow: 0 -1px 8px rgba(0,0,0,.1); display: none;
    padding: 12px 20px; position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 16px; top: 12px; }

@media (max-width: 760px) {
    .app-sidebar { position: fixed; z-index: 30; transform: translateX(-100%); }
    .app-content { padding: 18px; }
}
