/* ==========================================================================
   SRP Hub design system
   Tokens, base elements and the shared app shell. Every staff page loads this
   first; page-specific styles build on the tokens below instead of hard-coded
   colours, so the whole hub stays visually consistent.
   ========================================================================== */

:root {
  color-scheme: dark;

  /* Surfaces, darkest to lightest */
  --bg: #0c0e13;
  --surface: #13161d;
  --surface-2: #1a1e27;
  --surface-3: #232834;
  --overlay: rgba(6, 8, 12, 0.72);

  /* Lines */
  --border: #262b36;
  --border-strong: #353c4b;

  /* Text */
  --text: #e7e9ee;
  --text-muted: #9aa3b5;
  --text-subtle: #6b7385;

  /* Brand accent (one accent across the hub) */
  --accent: #6674f4;
  --accent-hover: #5563e6;
  --accent-text: #aab3ff;
  --accent-soft: rgba(102, 116, 244, 0.14);

  /* Status */
  --success: #2fa872;
  --success-hover: #25915f;
  --success-text: #6ee7a8;
  --success-soft: rgba(47, 168, 114, 0.14);
  --warning: #e0a336;
  --warning-hover: #c98e24;
  --warning-text: #fcd27a;
  --warning-soft: rgba(224, 163, 54, 0.14);
  --danger: #e5534b;
  --danger-hover: #cc4038;
  --danger-text: #fca5a0;
  --danger-soft: rgba(229, 83, 75, 0.14);

  /* Text placed on a solid accent/status background */
  --on-accent: #ffffff;
  --on-warning: #1c1405;

  /* Shape & type */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --shell-height: 56px;
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3, h4 { color: var(--text); letter-spacing: -0.01em; line-height: 1.25; }

code, pre, kbd { font-family: var(--font-mono); font-size: 0.9em; }

::selection { background: var(--accent-soft); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input, select, textarea, button { font: inherit; }

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
select,
textarea {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

input::placeholder, textarea::placeholder { color: var(--text-subtle); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

table { border-collapse: collapse; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Reusable components ---------- */

.ui-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.ui-btn:hover { background: var(--accent-hover); color: var(--on-accent); }
.ui-btn--ghost { background: transparent; border-color: var(--border-strong); color: var(--text); }
.ui-btn--ghost:hover { background: var(--surface-3); color: var(--text); }
.ui-btn--danger { background: var(--danger); }
.ui-btn--danger:hover { background: var(--danger-hover); }

.ui-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.ui-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-3);
  color: var(--text-muted);
}

/* ---------- Page layout (new-style pages) ---------- */

.page { max-width: 1320px; margin: 0 auto; padding: 28px 28px 64px; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-header h1 { margin: 0; font-size: 26px; font-weight: 700; }
.page-header p { margin: 4px 0 0; color: var(--text-muted); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 24px; }
.kpi {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}
a.kpi:hover { border-color: var(--border-strong); background: var(--surface-2); color: var(--text); }
.kpi__label { font-size: 12.5px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.kpi__value { font-size: 28px; font-weight: 700; line-height: 1.2; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi__hint { font-size: 12px; color: var(--text-subtle); margin-top: 2px; }
.kpi--warn .kpi__value { color: var(--warning-text); }
.kpi--danger .kpi__value { color: var(--danger-text); }
.kpi--accent .kpi__value { color: var(--accent-text); }
.kpi--success .kpi__value { color: var(--success-text); }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }
.stack { display: grid; gap: 16px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card__head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.card__head a { font-size: 13px; text-decoration: none; }
.card__body { padding: 16px 18px; }
.card__empty { padding: 28px 18px; text-align: center; color: var(--text-subtle); font-size: 14px; }

.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
}
.row:last-child { border-bottom: 0; }
a.row:hover, button.row:hover { background: var(--surface-2); color: var(--text); }
button.row { width: 100%; border-left: 0; border-right: 0; border-top: 0; background: transparent; text-align: left; cursor: pointer; font: inherit; }
.row__main { flex: 1; min-width: 0; }
.row__title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__meta { font-size: 12.5px; color: var(--text-subtle); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__side { font-size: 12.5px; color: var(--text-subtle); white-space: nowrap; }

.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; background: var(--surface-3); color: var(--text-muted); }
.tag--warn { background: var(--warning-soft); color: var(--warning-text); }
.tag--danger { background: var(--danger-soft); color: var(--danger-text); }
.tag--success { background: var(--success-soft); color: var(--success-text); }
.tag--accent { background: var(--accent-soft); color: var(--accent-text); }
.mono { font-family: var(--font-mono); font-size: 0.92em; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tabs a, .tabs button {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px; border: 0; background: transparent; color: var(--text-muted);
  font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover, .tabs button:hover { color: var(--text); }
.tabs .is-active { color: var(--text); border-bottom-color: var(--accent); }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.field input, .field select, .field textarea { width: 100%; padding: 9px 11px; font-size: 14px; }
.field textarea { min-height: 96px; resize: vertical; }
.field__hint { font-size: 12px; color: var(--text-subtle); }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; font-size: 14px; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-subtle); text-transform: uppercase; letter-spacing: 0.05em; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.is-clickable { cursor: pointer; }
.table tbody tr.is-clickable:hover { background: var(--surface-2); }

.notice { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 14px; }
.notice--warn { background: var(--warning-soft); color: var(--warning-text); }
.notice--danger { background: var(--danger-soft); color: var(--danger-text); }
.notice--success { background: var(--success-soft); color: var(--success-text); }
.notice--info { background: var(--accent-soft); color: var(--accent-text); }

.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: skeleton 1.2s infinite; border-radius: 6px; color: transparent !important; }
@keyframes skeleton { to { background-position: -200% 0; } }

@media (max-width: 700px) { .page { padding: 18px 16px 48px; } .page-header h1 { font-size: 22px; } }

/* ---------- App shell (rendered by /js/shell.js) ----------
   Desktop: fixed left sidebar, page content offset by --shell-left.
   Mobile: slim top bar (--shell-top) with a slide-out sidebar. */

:root { --sidebar-width: 248px; --sidebar-collapsed: 68px; --topbar-height: 56px; }

body.has-shell {
  --shell-left: var(--sidebar-width);
  --shell-top: 0px;
  /* Pages that pad <body> set --page-gutter so their content keeps its left padding */
  padding-left: calc(var(--shell-left) + var(--page-gutter, 0px));
}
body.has-shell.shell-collapsed { --shell-left: var(--sidebar-collapsed); }

.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 900;
  width: var(--shell-left);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  font-family: var(--font);
  font-size: 14px;
  transition: width 0.18s ease;
}

.app-sidebar__head {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 64px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.app-sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.app-sidebar__brand:hover { color: var(--text); }
.app-sidebar__brand img { width: 32px; height: 32px; border-radius: 9px; object-fit: cover; flex-shrink: 0; }
.app-sidebar__brand small { display: block; font-weight: 500; font-size: 11px; color: var(--text-subtle); letter-spacing: 0.02em; }

.app-sidebar__scroll { flex: 1; overflow-y: auto; padding: 12px 10px; }

.app-sidebar__section { margin-bottom: 14px; }
.app-sidebar__section-title {
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
  white-space: nowrap;
}

.app-sidebar__link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  height: 38px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
}
.app-sidebar__link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.9; }
.app-sidebar__link:hover { background: var(--surface-3); color: var(--text); }
.app-sidebar__link.is-active { background: var(--accent-soft); color: var(--text); }
.app-sidebar__link.is-active::before {
  content: '';
  position: absolute;
  left: -10px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.app-sidebar__label { overflow: hidden; text-overflow: ellipsis; }
.app-sidebar__badge {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--warning);
  color: var(--on-warning);
  font-size: 11px;
  font-weight: 700;
  display: inline-grid;
  place-items: center;
}
.app-sidebar__badge--accent { background: var(--accent); color: var(--on-accent); }

.app-sidebar__foot {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.app-sidebar__user {
  position: relative;
  flex: 1;
  min-width: 0;
}
.app-sidebar__user > button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.app-sidebar__user > button:hover { background: var(--surface-3); }
.app-sidebar__user-text { min-width: 0; line-height: 1.25; }
.app-sidebar__user-text strong { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-sidebar__user-text span { font-size: 11px; color: var(--text-subtle); }
.app-shell__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-3);
  object-fit: cover;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}
.app-sidebar__menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  right: 0;
  padding: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: none;
}
.app-sidebar__user.is-open .app-sidebar__menu { display: block; }
.app-sidebar__menu a {
  display: block;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
}
.app-sidebar__menu a:hover { background: var(--surface-3); }
.app-sidebar__menu a.app-shell__logout { color: var(--danger-text); }

.app-sidebar__collapse {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.app-sidebar__collapse:hover { background: var(--surface-3); color: var(--text); }
.app-sidebar__collapse svg { width: 16px; height: 16px; transition: transform 0.18s; }

/* Collapsed: icons only */
body.shell-collapsed .app-sidebar__section-title,
body.shell-collapsed .app-sidebar__label,
body.shell-collapsed .app-sidebar__brand span,
body.shell-collapsed .app-sidebar__user-text { display: none; }
body.shell-collapsed .app-sidebar__link { justify-content: center; padding: 0; }
body.shell-collapsed .app-sidebar__badge { position: absolute; top: 2px; right: 4px; min-width: 16px; height: 16px; font-size: 10px; padding: 0 4px; }
body.shell-collapsed .app-sidebar__head { justify-content: center; padding: 0; }
body.shell-collapsed .app-sidebar__foot { flex-direction: column; }
body.shell-collapsed .app-sidebar__collapse svg { transform: rotate(180deg); }
body.shell-collapsed .app-sidebar__menu { left: 0; right: auto; width: 200px; }

/* Mobile top bar */
.app-topbar { display: none; }

@media (max-width: 900px) {
  body.has-shell, body.has-shell.shell-collapsed { --shell-left: 0px; --shell-top: var(--topbar-height); padding-left: var(--page-gutter, 0px); }
  .app-topbar {
    position: sticky;
    top: 0;
    z-index: 900;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    font-family: var(--font);
  }
  .app-topbar a { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; }
  .app-topbar img { width: 30px; height: 30px; border-radius: 8px; }
  .app-topbar button {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
  }
  .app-sidebar {
    width: min(300px, 86vw);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
    z-index: 1000;
  }
  body.shell-nav-open .app-sidebar { transform: none; }
  .app-sidebar__collapse { display: none; }
  body.shell-collapsed .app-sidebar__section-title,
  body.shell-collapsed .app-sidebar__label,
  body.shell-collapsed .app-sidebar__brand span,
  body.shell-collapsed .app-sidebar__user-text { display: revert; }
  body.shell-collapsed .app-sidebar__link { justify-content: flex-start; padding: 0 10px; }
  .app-scrim { position: fixed; inset: 0; background: var(--overlay); z-index: 950; display: none; }
  body.shell-nav-open .app-scrim { display: block; }
}

/* Full-screen panels (detail views) sit beside the sidebar / below the top bar:
   use `inset: var(--shell-top, 0px) 0 0 var(--shell-left, 0px)` instead of `inset: 0`. */

/* Old per-page navbars are replaced by the shell */
body.has-shell > nav.navbar,
body.has-shell > .navbar,
body.has-shell > header.navbar { display: none !important; }
