:root {
  --bg: #f7f8fa;
  --surface: #eef1f4;
  --elevated: #ffffff;
  --variant: #e8ebf0;
  --ink: #1a1f2c;
  --muted: #5c6570;
  --outline: #e3e6ec;
  --primary: #1b4f8a;
  --secondary: #0f2744;
  --success: #1b7a4a;
  --error: #b42318;
  --warning: #9a6700;
  --header: #0f2744;
  --cta: #1b4f8a;
  --radius: 4px;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html, body, button, input, select, textarea {
  font-family: "Montserrat", system-ui, sans-serif;
}
body {
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  font-weight: 400;
}

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

.auth-split {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #fff;
}
.auth-hero {
  background: var(--header);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 48px 56px 32px;
  border-right: 1px solid rgba(255, 255, 255, 0.12);
}
.auth-hero-inner {
  max-width: 440px;
  margin-top: 18vh;
}
.auth-logo {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 28px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  display: inline-block;
}
.auth-hero-title {
  font-size: 26px;
  line-height: 1.35;
  font-weight: 500;
  margin: 0 0 12px;
}
.auth-hero-lede {
  margin: 0;
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  font-weight: 400;
}
.auth-hero-copy {
  margin-top: auto;
  color: rgba(255, 255, 255, 0.45);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.auth-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  background: #fff;
}
.auth-panel-inner {
  width: 100%;
  max-width: 360px;
}
.auth-heading {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 600;
  text-align: left;
}
.auth-sub {
  text-align: left;
  color: var(--muted);
  margin: 0 0 28px;
  font-size: 13px;
}
.auth-form .field label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink);
}
.auth-form .input,
.auth-panel input[type="email"],
.auth-panel input[type="password"] {
  background: #fff;
  border: 1px solid var(--outline);
  border-radius: var(--radius);
  padding: 11px 12px;
}
.auth-form .input:focus,
.auth-panel input:focus {
  outline: none;
  border-color: var(--primary);
}
.btn-auth {
  width: 100%;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-top: 8px;
  background: var(--primary);
  font-weight: 600;
}
.auth-foot {
  text-align: left;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.auth-foot a { font-weight: 600; }

.brand-mark {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fff;
}

@media (max-width: 900px) {
  .auth-split { grid-template-columns: 1fr; }
  .auth-hero { min-height: auto; padding: 28px 24px 24px; border-right: 0; border-bottom: 1px solid rgba(255,255,255,0.12); }
  .auth-hero-inner { margin-top: 8px; }
  .auth-hero-title { font-size: 20px; }
}

.page-title { margin: 0 0 6px; font-size: 20px; font-weight: 600; }
.lede { color: var(--muted); margin: 0 0 20px; font-size: 13px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px; }
.input, select.input, textarea.input, input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="file"], select {
  width: 100%;
  border: 1px solid var(--outline);
  background: #fff;
  border-radius: var(--radius);
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
}
input[type="checkbox"] { width: auto; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: var(--radius);
  padding: 9px 14px;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { text-decoration: none; background: #163f6e; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-cta { background: var(--cta); color: #fff; }
.btn-ghost { background: transparent; color: var(--secondary); border: 1px solid var(--outline); }
.btn-ghost:hover { background: var(--surface); }
.btn-danger { background: var(--error); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 12px; width: auto; }

.errors, .errorlist { color: var(--error); font-size: 13px; padding: 0; margin: 0 0 12px; list-style: none; }
.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li { padding: 10px 12px; border-radius: var(--radius); margin-bottom: 8px; font-size: 13px; border: 1px solid var(--outline); }
.messages .success { background: #e4f5ea; color: var(--success); }
.messages .error { background: #fde8e6; color: var(--error); }
.messages .info { background: #eef3f8; color: var(--secondary); }
.toast-stack li {
  box-shadow: 0 1px 0 rgba(15, 39, 68, 0.04);
  animation: toast-in 0.22s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.banner-readonly {
  margin: 0 0 16px;
  padding: 10px 14px;
  border: 1px solid #d7e0ea;
  border-left: 3px solid var(--primary);
  background: #f3f7fb;
  color: var(--secondary);
  font-size: 13px;
  font-weight: 500;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 100;
  padding: 10px 14px;
  background: var(--header);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  border-radius: var(--radius);
}
.skip-link:focus {
  top: 12px;
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.help { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.credentials-card { border-color: var(--primary); background: #f5f8fc; }
.credentials-card h2 { margin-bottom: 6px; }
.credential-row { margin: 14px 0; }
.credential-row label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 6px;
}
.credential-value {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.credential-value code {
  flex: 1;
  min-width: 160px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--outline);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  word-break: break-all;
}
.code-inline {
  gap: 6px;
}
.code-inline code {
  min-width: 0;
  padding: 6px 8px;
  font-size: 13px;
  flex: 0 1 auto;
}

.app {
  display: grid;
  grid-template-columns: 228px 1fr;
  min-height: 100vh;
  background: var(--bg);
}
.app-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}
.app-navbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
  padding: 10px 36px;
  background: var(--elevated);
  border-bottom: 1px solid var(--outline);
}
.app-navbar-start {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.app-navbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  margin-left: auto;
}
.app-navbar-email {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}
.role-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border: 1px solid var(--outline);
  border-radius: 2px;
  background: var(--surface);
  color: var(--secondary);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.nav-toggle {
  display: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--outline);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.nav-toggle-bar {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--secondary);
}
.sidebar-backdrop {
  display: none;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--header);
  color: #fff;
  padding: 28px 18px 20px;
  z-index: 30;
}
.sidebar .brand-mark {
  font-size: 13px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}
.sidebar nav { margin-top: 22px; display: flex; flex-direction: column; gap: 2px; }
.nav-section-label {
  margin: 14px 12px 6px;
  padding: 0;
  color: rgba(255, 255, 255, 0.45);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.nav-section-admin {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}
.sidebar a {
  color: rgba(255, 255, 255, 0.72);
  padding: 9px 12px;
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  border-left: 2px solid transparent;
}
.sidebar a.active {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-left-color: #fff;
}
.sidebar a:hover { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }
.sidebar .btn-ghost { color: #fff; border-color: rgba(255,255,255,0.28); }
.sidebar .btn-ghost:hover { background: rgba(255,255,255,0.08); }
.main { padding: 28px 36px 48px; flex: 1; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.topbar-actions {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.card-header-row h2 { margin: 0; }
.create-panel {
  border: 1px solid var(--outline);
  border-radius: var(--radius);
  background: var(--elevated);
  overflow: hidden;
  margin-bottom: 16px;
  scroll-margin-top: 72px;
}
.create-panel-summary {
  cursor: pointer;
  list-style: none;
  padding: 14px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--secondary);
  background: #f8fafc;
  border-bottom: 1px solid transparent;
}
.create-panel[open] > .create-panel-summary {
  border-bottom-color: var(--outline);
}
.create-panel-summary::-webkit-details-marker { display: none; }
.create-panel-body {
  padding: 16px 18px 18px;
  margin: 0;
}
.create-panel .tools-grid {
  margin: 0;
  padding: 16px 18px 18px;
}
.create-panel .tools-grid .card {
  margin: 0;
  border: 0;
  padding: 0;
  background: transparent;
}
.period-chips { display: flex; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  padding: 7px 12px;
  border-radius: var(--radius);
  background: #fff;
  border: 1px solid var(--outline);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}
.chip:hover { text-decoration: none; border-color: var(--primary); }
.chip.active { background: var(--header); color: #fff; border-color: var(--header); }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi {
  background: var(--elevated);
  border: 1px solid var(--outline);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.kpi .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.kpi .value { font-size: 26px; font-weight: 600; margin-top: 8px; }
.kpi .delta { font-size: 12px; font-weight: 500; margin-top: 6px; }
.delta-up { color: var(--success); }
.delta-down { color: var(--error); }
.delta-flat { color: var(--muted); }

.card {
  background: var(--elevated);
  border: 1px solid var(--outline);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 14px; font-size: 14px; font-weight: 600; letter-spacing: 0.02em; }
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.filters .field { min-width: 140px; flex: 1; margin-bottom: 0; }
.filters .field-search { flex: 2; min-width: 200px; }
.table-wrap { overflow: auto; max-height: min(70vh, 720px); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--outline); }
th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  background: var(--elevated);
  z-index: 1;
}
tbody tr:hover { background: #f4f6f8; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 2px; font-size: 11px; font-weight: 600; }
.badge-ok { background: #e4f5ea; color: var(--success); }
.badge-off { background: var(--variant); color: var(--muted); }
.badge-warn { background: #eef3f8; color: var(--secondary); }
.muted { color: var(--muted); }
.row-actions { display: flex; gap: 8px; }
.split { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 16px; }
.layout-stack { display: flex; flex-direction: column; gap: 16px; }
.layout-stack .card { margin-bottom: 0; }
.tools-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.csv-import-lede { margin: 0 0 14px; }
.csv-template-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid var(--outline);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius);
  background: #f5f8fc;
  color: var(--ink);
  text-decoration: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.csv-template-btn:hover {
  text-decoration: none;
  background: #eef3f8;
  border-color: #c5d0dc;
}
.csv-template-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  background: var(--primary);
  color: #fff;
}
.csv-template-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.csv-template-copy strong {
  font-size: 13px;
  font-weight: 600;
  color: var(--secondary);
}
.csv-template-copy span {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}
.csv-upload-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
}
.csv-dropzone {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 16px 14px;
  border: 1px dashed #b8c2ce;
  border-radius: var(--radius);
  background: #fafbfc;
  cursor: pointer;
}
.csv-dropzone:hover,
.csv-dropzone.has-file {
  border-color: var(--primary);
  background: #f5f8fc;
}
.csv-dropzone-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--secondary);
}
.csv-dropzone-hint {
  font-size: 12px;
  color: var(--muted);
}
.csv-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}
.bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--outline);
}
.bulk-select-all {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--secondary);
  cursor: pointer;
}
.bulk-assign-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.bulk-assign-controls .input {
  width: auto;
  min-width: 200px;
}
.col-check {
  width: 36px;
  text-align: center;
}
.col-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}
.code-secret.is-masked {
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 500;
}
audio { width: 100%; margin-top: 8px; }
.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--muted);
}
.empty-state p { margin: 0 0 12px; }
.charts-grid { display: grid; grid-template-columns: 1.4fr 0.8fr; gap: 16px; }
.chart-box { position: relative; height: 260px; }
.rank-link { font-weight: 600; }

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .nav-toggle { display: inline-flex; }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgba(15, 39, 68, 0.42);
  }
  .sidebar-backdrop[hidden] { display: none; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(280px, 86vw);
    height: 100vh;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 0;
    overflow-y: auto;
  }
  .app.nav-open .sidebar { transform: translateX(0); }
  .sidebar nav {
    flex-direction: column;
    margin-top: 22px;
    flex-wrap: nowrap;
  }
  .sidebar .brand-mark { border-bottom: 1px solid rgba(255, 255, 255, 0.14); padding-bottom: 16px; }
  .app-navbar { padding: 10px 16px; }
  .app-body { min-height: 0; }
  .kpis, .split, .charts-grid, .tools-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .kpis, .split, .charts-grid, .tools-grid { grid-template-columns: 1fr; }
  .main { padding: 16px; }
  .app-navbar-email { display: none; }
  .role-badge { display: none; }
}
