/* Design tokens ------------------------------------------------------------------ */
:root {
  --brand: #1f6feb;
  --brand-dark: #1a5fd0;
  --brand-soft: #e8f0fe;

  --ok: #1a7f4b;
  --ok-soft: #e6f5ec;
  --warn: #b56b00;
  --warn-soft: #fdf3e2;
  --bad: #c0392b;
  --bad-soft: #fdeceb;
  --info: #5a4fcf;
  --info-soft: #eeecfb;

  --ink: #14181f;
  --ink-2: #46505f;
  --ink-3: #6b7686;
  --line: #e2e6ec;
  --bg: #f5f7fa;
  --surface: #ffffff;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px rgba(16, 24, 40, 0.05);
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }

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

h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .75rem; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
small, .small { font-size: .84rem; }
.muted { color: var(--ink-3); }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

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

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: #101725;
  color: #c8d0dd;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar__brand {
  padding: 1.1rem 1.15rem;
  font-weight: 700;
  color: #fff;
  font-size: 1rem;
  letter-spacing: -0.01em;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.sidebar__brand small { display: block; font-weight: 400; color: #8b97a8; font-size: .78rem; }
.sidebar__nav { padding: .6rem 0; overflow-y: auto; flex: 1; }
.sidebar__group { padding: .9rem 1.15rem .3rem; font-size: .7rem; text-transform: uppercase; letter-spacing: .07em; color: #6c7889; }
.sidebar a.navlink {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem 1.15rem; color: #c8d0dd; font-size: .92rem;
  border-left: 3px solid transparent;
}
.sidebar a.navlink:hover { background: rgba(255, 255, 255, .05); color: #fff; text-decoration: none; }
.sidebar a.navlink.active { background: rgba(31, 111, 235, .16); color: #fff; border-left-color: var(--brand); font-weight: 550; }
.sidebar__foot { padding: .8rem 1.15rem; border-top: 1px solid rgba(255,255,255,.08); font-size: .84rem; }
.sidebar__foot a { color: #8b97a8; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: .8rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  position: sticky; top: 0; z-index: 10;
}
.topbar h1 { margin: 0; font-size: 1.15rem; }
.content { padding: 1.5rem; max-width: 1400px; width: 100%; }

/* Cards & tables ------------------------------------------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem;
  margin-bottom: 1.15rem;
}
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .9rem; }
.card__head h2, .card__head h3 { margin: 0; }

.grid { display: grid; gap: 1.15rem; }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid--4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: .6rem .7rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 600; background: #fafbfc; }
tbody tr:hover { background: #fafbfc; }
tbody tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; margin: 0 -1.15rem -1.15rem; padding: 0 0 0; }
.table-wrap table { min-width: 640px; }

/* Forms --------------------------------------------------------------------------- */
label { display: block; font-size: .86rem; font-weight: 550; color: var(--ink-2); margin-bottom: .28rem; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=time], input[type=search], select, textarea {
  width: 100%; padding: .52rem .68rem; font-size: .94rem; font-family: inherit;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
input[disabled], select[disabled] { background: #f3f5f8; color: var(--ink-3); }
.field { margin-bottom: .9rem; }
.field__hint { font-size: .8rem; color: var(--ink-3); margin-top: .25rem; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 450; margin-bottom: .4rem; }
.check input { width: auto; margin: 0; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 1rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .52rem .95rem; font-size: .92rem; font-weight: 550; font-family: inherit;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: #fff; color: var(--ink); cursor: pointer; text-decoration: none;
}
.btn:hover { background: #f5f7fa; text-decoration: none; }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-dark); }
.btn--danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn--danger:hover { filter: brightness(.94); }
.btn--sm { padding: .3rem .6rem; font-size: .84rem; }
.btn--block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: .55rem; flex-wrap: wrap; align-items: center; }

/* Badges & alerts ------------------------------------------------------------------ */
.badge {
  display: inline-block; padding: .16rem .5rem; border-radius: 999px;
  font-size: .76rem; font-weight: 600; white-space: nowrap;
  background: #eef1f5; color: var(--ink-2);
}
.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--bad { background: var(--bad-soft); color: var(--bad); }
.badge--info { background: var(--info-soft); color: var(--info); }
.badge--brand { background: var(--brand-soft); color: var(--brand-dark); }

.alert { padding: .75rem .9rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: .92rem; border: 1px solid transparent; }
.alert--ok { background: var(--ok-soft); color: var(--ok); border-color: #bfe3cd; }
.alert--warn { background: var(--warn-soft); color: var(--warn); border-color: #f0d9ac; }
.alert--bad { background: var(--bad-soft); color: var(--bad); border-color: #f2c6c1; }
.alert--info { background: var(--brand-soft); color: var(--brand-dark); border-color: #c6d9f8; }

.empty { text-align: center; padding: 2.5rem 1rem; color: var(--ink-3); }
.empty__icon { font-size: 2rem; display: block; margin-bottom: .5rem; opacity: .6; }

/* Stat tiles ----------------------------------------------------------------------- */
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.stat__label { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 600; }
.stat__value { font-size: 1.85rem; font-weight: 680; line-height: 1.15; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.stat__hint { font-size: .82rem; color: var(--ink-3); }
.stat--ok .stat__value { color: var(--ok); }
.stat--warn .stat__value { color: var(--warn); }
.stat--bad .stat__value { color: var(--bad); }

/* Login ---------------------------------------------------------------------------- */
.auth {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 1.5rem; background: linear-gradient(160deg, #101725 0%, #1c2b45 100%);
}
.auth__card { background: #fff; border-radius: 14px; padding: 2rem; width: 100%; max-width: 380px; box-shadow: 0 18px 40px rgba(0, 0, 0, .28); }
.auth__brand { text-align: center; margin-bottom: 1.4rem; }
.auth__brand h1 { font-size: 1.25rem; margin-bottom: .2rem; }
.auth__brand p { color: var(--ink-3); font-size: .88rem; margin: 0; }

/* Utilities ------------------------------------------------------------------------ */
.flex { display: flex; }
.flex--between { justify-content: space-between; }
.flex--center { align-items: center; }
.flex--wrap { flex-wrap: wrap; }
.gap { gap: .75rem; }
.gap-sm { gap: .4rem; }
.mt { margin-top: 1rem; }
.mt-sm { margin-top: .5rem; }
.mb { margin-bottom: 1rem; }
.mb-0 { margin-bottom: 0; }
.hidden { display: none !important; }
.filters { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin-bottom: 0; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; object-fit: cover;
  background: var(--brand-soft); color: var(--brand-dark);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 650; font-size: .8rem; flex: 0 0 auto;
}
.person { display: flex; align-items: center; gap: .6rem; }
.person__name { font-weight: 550; }
.person__meta { font-size: .8rem; color: var(--ink-3); }

@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; }
  .sidebar__nav { display: flex; overflow-x: auto; padding: .3rem; }
  .sidebar__group, .sidebar__foot { display: none; }
  .sidebar a.navlink { border-left: none; border-bottom: 3px solid transparent; white-space: nowrap; }
  .sidebar a.navlink.active { border-left: none; border-bottom-color: var(--brand); }
  .content { padding: 1rem; }
}

/* Print / "Save as PDF": the browser's own print dialog produces the report PDF, so the
   server needs no PDF engine. Everything chrome-like disappears; tables stay readable. */
@media print {
  .sidebar, .topbar, .btn, .btn-row, .filters, .no-print, .empty__icon { display: none !important; }
  body { background: #fff; font-size: 11pt; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; margin-bottom: .8rem; }
  .table-wrap { overflow: visible; margin: 0; }
  .table-wrap table { min-width: 0; }
  table { font-size: 9.5pt; }
  th { background: #f2f2f2 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .badge, .heat td.cell, .stat { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  thead { display: table-header-group; }
  tr { break-inside: avoid; }
  canvas { max-height: 260px; }
  a[href]::after { content: ""; }
}

/* Printed header: only visible on paper, so the report says what it is and when it ran. */
.print-only { display: none; }
@media print { .print-only { display: block; margin-bottom: .8rem; } }
