:root {
  /* Background gradient — soft sky-blue to near-white, kept light across
     its whole range on purpose: every glass surface below is translucent,
     so the backdrop must never get dark enough to break text contrast. */
  --bg-grad: linear-gradient(135deg, #8fcbec 0%, #a9c3ee 32%, #cfd9f4 62%, #eef3fb 100%);

  /* Glass surfaces */
  --glass: rgba(255, 255, 255, 0.60);
  --glass-strong: rgba(255, 255, 255, 0.80);
  --glass-border: rgba(255, 255, 255, 0.75);
  --glass-shadow: 0 10px 34px rgba(30, 41, 82, 0.12), 0 1px 2px rgba(30, 41, 82, 0.06);
  --frame-bg: rgba(255, 255, 255, 0.22);
  --frame-border: rgba(255, 255, 255, 0.55);

  --sidebar-bg: rgba(255, 255, 255, 0.55);
  --sidebar-border: rgba(255, 255, 255, 0.65);

  --text: #10182d;
  --text-muted: #5b6a8c;
  --text-faint: #8b96b3;

  --accent: #2f6fed;
  --accent-dark: #1d4fc7;
  --accent-grad: linear-gradient(135deg, #4c8bf5 0%, #2457d6 100%);
  --accent-contrast: #ffffff;
  --accent-soft: rgba(47, 111, 237, 0.10);

  /* Semantic pastel chips — reused for stat tiles and status badges so
     the two systems read as one language (see stat-tile / badge rules). */
  --indigo-bg: #eaebfc; --indigo-fg: #6366f1;
  --teal-bg:   #e1f8f2; --teal-fg:   #10b394;
  --purple-bg: #f4e9ff; --purple-fg: #a855f7;
  --rose-bg:   #ffe7ee; --rose-fg:   #f43f5e;
  --amber-bg:  #fef3d9; --amber-fg:  #d99012;

  --ok: #0f9d72;
  --ok-bg: #e1f8f2;
  --warn: #b4740b;
  --warn-bg: #fef3d9;
  --error: #e0284f;
  --error-bg: #ffe7ee;
  --muted-badge-bg: rgba(91, 106, 140, 0.10);

  --radius-lg: 22px;
  --radius: 16px;
  --radius-sm: 12px;
  --radius-pill: 999px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
}

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

/* ---------- Outer frame + shell ---------- */
/* Locked to exactly 100vh on purpose -- .content below is the only part
   that scrolls, so the sidebar/topbar/frame never move. */

.app-frame {
  height: 100vh;
  padding: 12px;
}

.app-shell {
  display: flex;
  height: 100%;
  background: var(--frame-bg);
  border: 1px solid var(--frame-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--glass-shadow);
  overflow: hidden;
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 700;
  font-size: 1.05rem;
  padding: 2px 10px 18px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 9px;
  background: var(--accent-grad);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 10px rgba(47, 111, 237, 0.35);
}

.brand-mark svg { width: 18px; height: 18px; stroke: currentColor; }

.nav-section-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  font-weight: 700;
  padding: 10px 12px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.87rem;
  font-weight: 600;
  margin-bottom: 2px;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-item:hover {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.nav-item.active {
  background: var(--accent-grad);
  color: #fff;
  box-shadow: 0 6px 16px rgba(47, 111, 237, 0.32);
}

.nav-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nav-icon svg { width: 18px; height: 18px; stroke: currentColor; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(91, 106, 140, 0.16);
}

.sidebar-footer button {
  width: 100%;
  background: transparent;
  border: 1px solid rgba(91, 106, 140, 0.25);
  color: var(--text-muted);
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  margin-top: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.sidebar-footer button:hover {
  background: var(--rose-bg);
  color: var(--error);
  border-color: transparent;
}

/* ---------- Main content ---------- */

.content {
  flex: 1;
  /* min-height: 0 overrides flexbox's default min-height:auto, which
     otherwise lets this item grow to fit its content instead of clipping
     -- without it, overflow-y:auto never actually engages and the whole
     .app-shell grows past 100vh (page-level scroll) instead of scrolling
     internally here. */
  min-height: 0;
  padding: 20px 28px 24px;
  overflow-y: auto;
  min-width: 0;
}

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.topbar .greeting {
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  margin: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--glass-strong);
  border: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: default;
}

.icon-btn svg { width: 17px; height: 17px; stroke: currentColor; }

.topbar-divider {
  width: 1px;
  height: 26px;
  background: rgba(91, 106, 140, 0.2);
  margin: 0 2px;
}

.avatar-block {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent-grad);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  box-shadow: 0 4px 10px rgba(47, 111, 237, 0.3);
  flex-shrink: 0;
}

.avatar-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.avatar-role {
  font-size: 0.72rem;
  color: var(--text-faint);
}

.topbar-titles h1 {
  margin: 1px 0 0;
  font-size: 1.35rem;
  letter-spacing: -0.01em;
}

.page-subtitle {
  margin: -2px 0 14px;
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* ---------- Stat tiles ---------- */

.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.stat-tile {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-icon svg { width: 18px; height: 18px; stroke: currentColor; }

.stat-icon.indigo { background: var(--indigo-bg); color: var(--indigo-fg); }
.stat-icon.teal   { background: var(--teal-bg);   color: var(--teal-fg); }
.stat-icon.purple { background: var(--purple-bg); color: var(--purple-fg); }
.stat-icon.rose   { background: var(--rose-bg);   color: var(--rose-fg); }

.stat-tile .stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.stat-tile .stat-label {
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: -4px;
}

/* ---------- Cards & panels ---------- */

.card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 12px;
  flex-wrap: wrap;
}

.card h2 {
  margin: 0;
  font-size: 1rem;
}

.card-header .card-link {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
}

.card-header .card-link:hover { text-decoration: underline; }

/* ---------- Filter bar ---------- */

.filter-bar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.filter-bar .field { margin: 0; }
.filter-bar label { margin-top: 0; }
.filter-bar input, .filter-bar select { margin-top: 4px; }

/* Filters auto-apply via filters.js (GET, on change/debounced input) --
   the manual submit button is a no-JS fallback only, hidden once wired. */
.filter-bar.js-autosubmit .js-manual-submit { display: none; }

.search-input {
  min-width: 220px;
}

/* ---------- Custom dropdown (replaces native <select> popup) ---------- */

.dd { position: relative; }

.dd-enhanced select {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.dd-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 220px;
  padding: 8px 12px;
  margin-top: 4px;
  border: 1px solid rgba(91, 106, 140, 0.22);
  background: var(--glass-strong);
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.dd-trigger:hover { border-color: rgba(47, 111, 237, 0.4); }

.dd.open .dd-trigger {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.dd-trigger-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dd-chevron {
  width: 14px;
  height: 14px;
  color: var(--text-faint);
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.dd.open .dd-chevron { transform: rotate(180deg); }

.dd-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 100%;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--glass-shadow);
  padding: 6px;
  z-index: 30;
  max-height: 260px;
  overflow-y: auto;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.dd-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.dd-option:hover { background: var(--accent-soft); }

.dd-option .dd-check {
  width: 14px;
  height: 14px;
  color: var(--accent);
  opacity: 0;
  flex-shrink: 0;
}

.dd-option.selected { color: var(--accent-dark); font-weight: 700; }
.dd-option.selected .dd-check { opacity: 1; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 8px 12px;
  font-size: 0.84rem;
  border-bottom: 1px solid rgba(91, 106, 140, 0.14);
  white-space: nowrap;
}

th {
  color: var(--text-faint);
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(47, 111, 237, 0.05); }

/* ---------- Pagination ---------- */

.pagination-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.pagination-count {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.pagination {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pagination a, .pagination span {
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--text-muted);
}

.pagination a:hover { background: var(--accent-soft); color: var(--accent-dark); }
.pagination .page-current { background: var(--accent-grad); color: #fff; }
.pagination .page-disabled { color: var(--text-faint); opacity: 0.5; }

/* ---------- Badges ---------- */

.badge {
  display: inline-block;
  padding: 4px 11px;
  border-radius: var(--radius-pill);
  font-size: 0.74rem;
  font-weight: 700;
  background: var(--muted-badge-bg);
  color: var(--text-muted);
}

.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-error { background: var(--error-bg); color: var(--error); }
.badge-purple { background: var(--purple-bg); color: var(--purple-fg); }
.badge-indigo { background: var(--indigo-bg); color: var(--indigo-fg); }

/* ---------- Forms ---------- */

label { display: block; margin-top: 10px; font-weight: 700; font-size: 0.82rem; color: var(--text); }

input, select {
  padding: 8px 12px;
  margin-top: 4px;
  width: 220px;
  border: 1px solid rgba(91, 106, 140, 0.22);
  background: var(--glass-strong);
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  color: var(--text);
  font-family: inherit;
}

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

button, .btn {
  margin-top: 12px;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent-grad);
  color: var(--accent-contrast);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(47, 111, 237, 0.28);
}

button:hover, .btn:hover { filter: brightness(1.05); }

.btn-ghost {
  background: var(--glass-strong);
  color: var(--text);
  box-shadow: none;
  border: 1px solid rgba(91, 106, 140, 0.22);
}

form.inline { display: inline; }

/* ---------- Notices ---------- */

.notice {
  background: var(--ok-bg);
  border: 1px solid rgba(15, 157, 114, 0.25);
  color: var(--ok);
  padding: 11px 15px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.86rem;
  font-weight: 600;
}

.error {
  background: var(--error-bg);
  border: 1px solid rgba(224, 40, 79, 0.25);
  color: var(--error);
  padding: 11px 15px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.86rem;
  font-weight: 600;
}

.stage-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--glass-strong);
  border: 1px dashed rgba(91, 106, 140, 0.3);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
}

/* ---------- Login page ---------- */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-grad);
  background-attachment: fixed;
}

.login-card {
  background: var(--glass-strong);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  width: 100%;
  max-width: 350px;
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
}

.login-card .brand { color: var(--text); padding: 0 0 20px; }
.login-card p.subtitle { margin: -12px 0 4px; color: var(--text-muted); font-size: 0.85rem; }
.login-card input { width: 100%; }
.login-card button { width: 100%; }

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 720px) {
  .app-frame { padding: 0; }
  .app-shell { border-radius: 0; flex-direction: column; min-height: 100vh; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--sidebar-border); }
  .content { padding: 22px 18px 32px; }
}
