:root {
  --primary: #0b2a63;
  --primary-mid: #0056cc;
  --primary-glow: #3b82f6;
  --accent: #20c997;
  --accent-soft: #d7f5ec;
  --bg: #f4f6fb;
  --card: #ffffff;
  --fg: #14213d;
  --muted: #5b6b82;
  --border: #e2e8f0;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --warn: #a15c00;
  --warn-soft: #fff4de;
  --info: #0b5cad;
  --info-soft: #e3f0ff;
  --ok: #0b7a5a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(11, 42, 99, .06), 0 8px 24px -12px rgba(11, 42, 99, .18);
  --sidebar-w: 248px;
  --focus: 0 0 0 3px rgba(59, 130, 246, .45);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.55 "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: "Sora", system-ui, sans-serif; letter-spacing: -.01em; line-height: 1.2; margin: 0; }
h2 { font-size: 1.05rem; } h3 { font-size: .95rem; }
a { color: var(--primary-mid); text-decoration: none; }
a:hover { text-decoration: underline; }
small { display: block; color: var(--muted); font-size: .8rem; }
code { font: .85em ui-monospace, SFMono-Regular, Menlo, monospace; background: #eef2f8; padding: 1px 6px; border-radius: 6px; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: 8px; top: -48px; background: var(--primary); color: #fff; padding: 8px 14px; border-radius: 8px; z-index: 100; }
.skip-link:focus { top: 8px; }
.muted { color: var(--muted); margin: 0; }

/* Shell */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, var(--primary) 0%, #0a2250 100%); color: #dbe6ff;
  display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh;
}
.brand { padding: 0 8px 22px; }
.brand img { display: block; filter: brightness(0) invert(1); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: #c9d8f5; font-weight: 600; text-decoration: none;
}
.nav-link svg, .icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav-link:hover { background: rgba(255, 255, 255, .08); text-decoration: none; }
.nav-link.is-active { background: rgba(32, 201, 151, .16); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.sidebar__foot { display: grid; gap: 10px; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, .12); }
.user-chip { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; padding: 6px; border-radius: 10px; min-width: 0; }
.user-chip:hover { background: rgba(255, 255, 255, .08); text-decoration: none; }
.user-chip strong { display: block; font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip small { color: #9db4e6; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #08302a; display: grid; place-items: center; font-weight: 800; flex: none; }

.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 18px 32px 6px; }
.topbar__title { font-size: 1.5rem; }
.content { padding: 12px 32px 48px; display: grid; gap: 20px; align-content: start; max-width: 1200px; width: 100%; }
.icon-btn { display: none; background: var(--card); border: 1px solid var(--border); border-radius: 10px; width: 42px; height: 42px; place-items: center; color: var(--fg); cursor: pointer; }
.scrim { position: fixed; inset: 0; background: rgba(8, 20, 48, .55); z-index: 40; }

/* Components */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; min-width: 0; }
.card--flush { padding: 0; overflow: hidden; }
.card--danger { border-color: #f0c4be; }
.card__head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.card__head--pad { padding: 18px 20px 0; }
.card__head--sub { margin: 20px 0 8px; padding-top: 16px; border-top: 1px solid var(--border); }
fieldset.card { margin: 0; }
fieldset.card legend { font: 600 1.05rem "Sora", sans-serif; padding: 0 6px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head__actions, .btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row { margin-top: 14px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.stat__label { display: block; color: var(--muted); font-size: .82rem; font-weight: 600; }
.stat__value { display: block; font: 700 1.7rem "Sora", sans-serif; margin: 4px 0 2px; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0 0 14px; }
.kv dt { color: var(--muted); font-size: .85rem; }
.kv dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list a { color: inherit; } .list--compact li { padding: 8px 0; font-size: .88rem; }
.empty { color: var(--muted); padding: 22px 20px; margin: 0; text-align: center; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.badge--ok { background: var(--accent-soft); color: var(--ok); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--info { background: var(--info-soft); color: var(--info); }
.badge--muted { background: #eceff4; color: var(--muted); }

.alert { padding: 12px 16px; border-radius: 10px; border: 1px solid; font-weight: 500; }
.alert--success { background: var(--accent-soft); border-color: #a8e6d2; color: #07553f; }
.alert--error { background: var(--danger-soft); border-color: #f0c4be; color: #8e2418; }
.alert--warning { background: var(--warn-soft); border-color: #f2d49b; color: #7a4600; }
.alert--info { background: var(--info-soft); border-color: #b9d6f7; color: var(--info); }
.alert a { color: inherit; text-decoration: underline; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 18px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--card); color: var(--fg);
  font-weight: 600; font-size: .92rem; font-family: inherit; cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s;
}
.btn:hover { background: #f1f5fb; text-decoration: none; }
.btn--primary { background: var(--primary-mid); border-color: var(--primary-mid); color: #fff; }
.btn--primary:hover { background: #0049ad; }
.btn--warn { background: var(--warn-soft); border-color: #f2d49b; color: var(--warn); }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger:hover { background: #a02e22; }
.btn--ghost { background: transparent; border-color: rgba(255, 255, 255, .25); color: #dbe6ff; }
.btn--ghost:hover { background: rgba(255, 255, 255, .1); }
.auth-card .btn--ghost { color: var(--muted); border-color: var(--border); }
.btn--block { width: 100%; }

/* Forms */
.form { display: grid; gap: 16px; }
.form--wide { gap: 20px; }
.form--inline { grid-template-columns: 1fr auto; align-items: end; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.field { display: grid; gap: 6px; align-content: start; min-width: 0; }
.field label, .check { font-weight: 600; font-size: .88rem; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #c9d3e3; border-radius: 10px;
  background: #fff; color: var(--fg); font: inherit;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary-glow); box-shadow: var(--focus); }
input[readonly] { background: var(--bg); color: var(--muted); }
.field--error input, .field--error select, .field--error textarea { border-color: var(--danger); }
.hint { color: var(--muted); } .error { color: var(--danger); font-weight: 600; }
.input-affix { display: flex; align-items: stretch; }
.input-affix input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-affix span { display: grid; place-items: center; padding: 0 12px; background: var(--bg); border: 1px solid #c9d3e3; border-left: 0; border-radius: 0 10px 10px 0; color: var(--muted); font-size: .88rem; white-space: nowrap; }
.check { display: flex; align-items: center; gap: 10px; margin-top: 16px; }
.check input { width: 18px; min-height: 18px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }
.secret code { display: block; padding: 12px; font-size: 1.05rem; letter-spacing: .08em; text-align: center; overflow-wrap: anywhere; }

.inline-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.inline-actions form { margin: 0; }
.steps { border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; margin: 0 0 14px; background: #fafcff; }
.steps summary { cursor: pointer; font-weight: 700; }
.steps ol { margin: 12px 0; padding-left: 20px; display: grid; gap: 6px; }
.steps .form { margin-top: 12px; }

/* Toolbar, table */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.toolbar__filters { display: flex; gap: 10px; flex-wrap: wrap; flex: 1; }
.toolbar__filters input[type="search"] { flex: 1 1 260px; max-width: 380px; }
.toolbar__filters select, .toolbar__filters input[type="month"] { width: auto; min-width: 170px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 12px 20px; background: #f8fafd; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 14px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafcff; }
.table td a strong { color: var(--fg); }
.table__actions { text-align: right; white-space: nowrap; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 18px; color: var(--muted); }

/* Auth */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; background: linear-gradient(150deg, var(--primary) 0%, var(--primary-mid) 55%, #17a2a2 100%); }
.auth-card { width: 100%; max-width: 420px; background: var(--card); border-radius: 16px; padding: 32px 28px; box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .4); display: grid; gap: 16px; }
.brand--auth { padding: 0; } .brand--auth img { filter: none; }
.auth-title { font-size: 1.4rem; }
.error-code { font: 800 3rem "Sora", sans-serif; color: var(--primary-mid); margin: 0; line-height: 1; }

/* Mobile */
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(82vw, 300px); z-index: 50; transform: translateX(-102%); transition: transform .2s ease; }
  .sidebar.is-open { transform: none; }
  .icon-btn { display: grid; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .topbar__title { font-size: 1.25rem; }
  .grid-2, .form-grid, .form--inline { grid-template-columns: 1fr; }

  .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table, .table tbody, .table tr, .table td { display: block; }
  .table tr { padding: 12px 16px; border-bottom: 1px solid var(--border); }
  .table td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; gap: 16px; text-align: right; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: .78rem; font-weight: 600; text-align: left; }
  .table td:not([data-label])::before { content: none; }
  .table__actions { justify-content: flex-end; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
@media print { .sidebar, .topbar .icon-btn, .btn { display: none; } .shell { display: block; } }
