:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #dfe4ea;
  --text: #1d2733;
  --muted: #64748b;
  --brand: #1f3b57;
  --brand-2: #33566f;
  --accent: #0f7b6c;
  --danger: #b3261e;
  --warn: #a16207;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151c;
    --surface: #171e27;
    --surface-2: #1c242f;
    --border: #2a3542;
    --text: #e6edf5;
    --muted: #93a3b5;
    --brand: #16202b;
    --brand-2: #22303e;
    --accent: #2dd4a7;
    --danger: #ef6b62;
    --warn: #e0a83a;
    --shadow: 0 1px 3px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- shell */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 234px;
  flex: 0 0 234px;
  background: var(--brand);
  color: #dbe4ee;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand {
  padding: 18px 18px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, .1);
}
.sidebar .brand strong { display: block; color: #fff; font-size: 15px; letter-spacing: .02em; }
.sidebar .brand span { font-size: 11.5px; color: #9db2c8; }
.sidebar .brand .logo {
  display: block;
  max-width: 100%;
  max-height: 56px;
  width: auto;
  margin-bottom: 10px;
}

.sidebar nav { padding: 10px 8px; flex: 1; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 11px;
  border-radius: 8px;
  color: #cddae7;
  font-size: 13.5px;
  margin-bottom: 2px;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: rgba(255, 255, 255, .13); color: #fff; font-weight: 600; }
.sidebar nav .group {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: #7f95ac;
  padding: 14px 12px 6px;
}

.sidebar .who {
  padding: 12px 16px;
  border-top: 1px solid rgba(255, 255, 255, .1);
  font-size: 12px;
  color: #a8bccf;
}
.sidebar .who b { display: block; color: #fff; font-size: 13px; }

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

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 22px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; }
.topbar .spacer { flex: 1; }

.content { padding: 20px 22px 46px; }

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  overflow: hidden;
}
.card > h2 {
  margin: 0;
  padding: 12px 16px;
  font-size: 13.5px;
  font-weight: 650;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  gap: 10px;
}
.card > h2 small { font-weight: 400; color: var(--muted); font-size: 12px; }
.card .body { padding: 16px; }
.card .body.tight { padding: 0; }

.grid { display: grid; gap: 18px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid.c3, .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 720px) { .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; } }

/* ----------------------------------------------------------------- KPIs */

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px;
  box-shadow: var(--shadow);
}
.kpi .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.kpi .value { font-size: 23px; font-weight: 680; margin-top: 4px; letter-spacing: -.02em; }
.kpi .value small { font-size: 13px; font-weight: 500; color: var(--muted); }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.kpi .delta { font-size: 12px; font-weight: 600; margin-top: 3px; }
.up { color: var(--danger); }
.down { color: var(--accent); }
.flat { color: var(--muted); }

/* --------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 8px 11px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data thead th {
  background: var(--surface-2);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  position: sticky;
  top: 0;
  z-index: 1;
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tfoot td { font-weight: 650; background: var(--surface-2); border-top: 2px solid var(--border); }
table.data .wrap { white-space: normal; min-width: 190px; }
table.data td.tight { padding: 4px 6px; }

.badge {
  display: inline-block;
  padding: 1.5px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  border: 1px solid transparent;
}
.badge-ok { background: rgba(15, 123, 108, .12); color: var(--accent); border-color: rgba(15, 123, 108, .28); }
.badge-off { background: rgba(179, 38, 30, .1); color: var(--danger); border-color: rgba(179, 38, 30, .25); }
.badge-warn { background: rgba(161, 98, 7, .12); color: var(--warn); border-color: rgba(161, 98, 7, .28); }
.badge-muted { background: var(--surface-2); color: var(--muted); border-color: var(--border); }
.badge-info { background: rgba(31, 59, 87, .1); color: var(--brand-2); border-color: rgba(31, 59, 87, .22); }
@media (prefers-color-scheme: dark) { .badge-info { color: #9dc0e0; } }

/* --------------------------------------------------------------- forms */

label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=file], select, textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15, 123, 108, .35); outline-offset: -1px; border-color: var(--accent); }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
textarea { min-height: 74px; resize: vertical; }
.field { margin-bottom: 13px; }
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 3px; font-weight: 400; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }
.check label { margin: 0; font-weight: 500; color: var(--text); font-size: 13px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters .field { margin: 0; min-width: 140px; flex: 0 1 auto; }
.filters .field.grow { flex: 1 1 220px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: rgba(179, 38, 30, .4); }
.btn-danger:hover { background: rgba(179, 38, 30, .08); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* --------------------------------------------------------------- alerts */

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; border: 1px solid; }
.alert-success { background: rgba(15, 123, 108, .1); border-color: rgba(15, 123, 108, .3); color: var(--accent); }
.alert-error { background: rgba(179, 38, 30, .08); border-color: rgba(179, 38, 30, .3); color: var(--danger); }
.alert-info { background: rgba(31, 59, 87, .07); border-color: rgba(31, 59, 87, .22); color: var(--muted); }
.alert-warn { background: rgba(161, 98, 7, .1); border-color: rgba(161, 98, 7, .3); color: var(--warn); }
.alert ul { margin: 6px 0 0; padding-left: 18px; }

/* --------------------------------------------------------------- charts */

.chart { width: 100%; display: block; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); padding: 0 16px 12px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.bar-row { display: grid; grid-template-columns: minmax(90px, 1.4fr) 3fr minmax(74px, auto); gap: 10px; align-items: center; font-size: 12.5px; padding: 4px 0; }
.bar-row .track { display: block; background: var(--surface-2); border-radius: 5px; height: 15px; overflow: hidden; border: 1px solid var(--border); }
.bar-row .fill { display: block; height: 100%; min-width: 2px; background: linear-gradient(90deg, var(--brand-2), var(--accent)); border-radius: 4px; }
.bar-row .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------ auth page */

.auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(140deg, #1f3b57, #0f2233 70%);
  padding: 20px;
}
.auth .box {
  background: var(--surface);
  border-radius: 14px;
  padding: 30px 30px 26px;
  width: 100%;
  max-width: 390px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .3);
}
.auth h1 { margin: 0 0 4px; font-size: 20px; }
.auth p.sub { margin: 0 0 22px; color: var(--muted); font-size: 13px; }

/* ---------------------------------------------------------- misc / print */

.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 12px; }
.pagination { display: flex; gap: 6px; align-items: center; padding: 12px 16px; font-size: 13px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.empty { padding: 34px 16px; text-align: center; color: var(--muted); }
.inline-form { display: inline; }

.steps { counter-reset: step; margin: 0; padding: 0; list-style: none; }
.steps li { position: relative; padding: 0 0 14px 32px; }
.steps li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

@media print {
  .sidebar, .topbar, .btn, .filters, .pagination { display: none !important; }
  .content { padding: 0; }
  .card { break-inside: avoid; box-shadow: none; }
}
