:root {
  /* Detrack brand — navy wordmark + red "a" accent */
  --brand: #233E54;
  --brand-dark: #1a2f40;
  --brand-darker: #122230;
  --brand-light: #e8eef3;
  --accent: #E31E3E;
  --accent-hover: #c41834;
  --accent-light: #fde8eb;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --border: #d8e0e8;
  --text: #1a212b;
  --text-muted: #5c6b7a;
  --danger: #E31E3E;
  --danger-bg: #fde8eb;
  --warning: #b45309;
  --warning-bg: #fef3c7;
  --success: #15803d;
  --success-bg: #dcfce7;
  --info: #233E54;
  --info-bg: #e8eef3;
  --sidebar-bg: #233E54;
  --sidebar-text: #b8c5d1;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(35, 62, 84, 0.08), 0 1px 2px rgba(35, 62, 84, 0.04);
  --shadow-lg: 0 12px 32px rgba(35, 62, 84, 0.16);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.mono { font-family: 'JetBrains Mono', monospace; }

/* ---------- Loading ---------- */
.app-loading {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: var(--bg);
  color: var(--text-muted);
  z-index: 100;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Auth ---------- */
.auth-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background:
    radial-gradient(900px 500px at 90% -5%, rgba(227, 30, 62, 0.08), transparent),
    radial-gradient(700px 420px at -5% 105%, rgba(35, 62, 84, 0.12), transparent),
    linear-gradient(180deg, #eef2f6 0%, var(--bg) 100%);
}

.auth-panel { width: 100%; max-width: 760px; }

.auth-brand {
  text-align: center;
  margin-bottom: 1.5rem;
}

.auth-brand p { color: var(--text-muted); }
.auth-tagline {
  margin-top: 0.65rem;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--brand) !important;
}

.brand-logo {
  display: block;
  width: min(280px, 85vw);
  height: auto;
  margin: 0 auto;
}

.brand-logo-sidebar {
  display: block;
  width: 148px;
  height: auto;
}

.sidebar-portal-label {
  display: block;
  margin-top: 0.45rem;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 1.75rem;
  max-width: 420px;
  margin: 0 auto;
}

.auth-card-wide { max-width: 760px; }
.auth-card h2 { font-size: 1.15rem; margin-bottom: 1rem; }

.auth-links { font-size: 0.9rem; color: var(--text-muted); margin-top: 0.5rem; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.link-btn:hover { text-decoration: underline; }

/* ---------- Forms ---------- */
label { display: block; font-size: 0.85rem; font-weight: 600; margin: 0.85rem 0 0.3rem; }

input, select, textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(35, 62, 84, 0.14);
}

input[type="file"] { padding: 0.45rem; background: var(--bg); }
input[type="radio"], input[type="checkbox"] { width: auto; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}

.form-span-2 { grid-column: span 2; }

.form-error {
  margin-top: 0.75rem;
  padding: 0.6rem 0.8rem;
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 8px;
  font-size: 0.88rem;
}

.form-success {
  margin-top: 0.75rem;
  padding: 0.6rem 0.8rem;
  background: var(--success-bg);
  color: var(--success);
  border-radius: 8px;
  font-size: 0.88rem;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--brand); }
.btn-secondary:hover:not(:disabled) { background: var(--brand-light); }
.btn-danger { background: var(--accent); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--accent-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-ghost { background: transparent; color: inherit; border-color: rgba(255, 255, 255, 0.25); }
.btn-block { width: 100%; margin-top: 1.25rem; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.82rem; }

.btn-icon {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
}

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

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 1rem 1rem 1.1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
}

.sidebar-brand .brand-logo-wrap {
  background: #fff;
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-nav { flex: 1; padding: 0.75rem 0.6rem; }

.nav-section {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.4);
  padding: 0.9rem 0.65rem 0.35rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.92rem;
  margin-bottom: 2px;
}

.nav-link svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-link:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav-link.active {
  background: rgba(227, 30, 62, 0.22);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--accent);
}

.nav-badge {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 99px;
  padding: 0.05rem 0.45rem;
}

.sidebar-footer {
  padding: 1rem 1.2rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.operator-info { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.8rem; overflow: hidden; }
.operator-info span:last-child { white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }

.role-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 6px;
  padding: 0.1rem 0.45rem;
  width: fit-content;
  font-family: 'JetBrains Mono', monospace;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar-left { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.topbar-titles h2 { font-size: 1.15rem; }
.topbar-titles p { font-size: 0.82rem; }
.topbar-actions { display: flex; align-items: center; gap: 0.75rem; }
.last-updated { font-size: 0.78rem; color: var(--text-muted); }

.menu-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
  cursor: pointer;
  color: var(--text);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 18, 0.5);
  z-index: 19;
}

.page-content { padding: 1.5rem; flex: 1; }

/* ---------- Cards & stats ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.card h3 { font-size: 1rem; margin-bottom: 0.9rem; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
}

.stat-card .stat-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-card .stat-value { font-size: 1.55rem; font-weight: 700; margin-top: 0.3rem; }

/* Commission Due — SRS Module 8: bold, 300% of body font */
.commission-due-card {
  background: linear-gradient(135deg, var(--brand-darker) 0%, var(--brand) 55%, #2c4d66 100%);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 1.5rem 1.75rem;
  margin-bottom: 1.25rem;
  position: relative;
  overflow: hidden;
}

.commission-due-card::after {
  content: '';
  position: absolute;
  right: -20px;
  top: -30px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: rgba(227, 30, 62, 0.18);
  pointer-events: none;
}

.commission-due-card .stat-label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  opacity: 0.85;
}

.commission-due-value {
  font-size: 300%;
  font-weight: 700;
  line-height: 1.15;
  margin-top: 0.25rem;
  font-variant-numeric: tabular-nums;
}

.welcome-banner { margin-bottom: 1.25rem; }
.welcome-banner h2 { font-size: 1.3rem; }
.welcome-banner p { color: var(--text-muted); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  background: var(--surface);
}

.data-table th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0.6rem 0.75rem;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:hover td { background: #f8fafb; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 700;
  border-radius: 99px;
  padding: 0.15rem 0.6rem;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-info { background: var(--brand-light); color: var(--brand); }
.badge-danger { background: var(--accent-light); color: var(--accent); }
.badge-muted { background: var(--bg); color: var(--text-muted); }

/* ---------- Toolbars ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.toolbar .search-input { max-width: 280px; }
.export-toolbar { display: flex; gap: 0.5rem; margin-left: auto; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 18, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-body { padding: 1.25rem; overflow-y: auto; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

/* ---------- Toasts ---------- */
.toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  z-index: 90;
}

.toast {
  background: var(--brand);
  color: #fff;
  padding: 0.7rem 1.1rem;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s, transform 0.25s;
  max-width: 340px;
}

.toast.visible { opacity: 1; transform: translateY(0); }
.toast-error { background: var(--accent); }

/* ---------- Claim form ---------- */
.radio-row { display: flex; gap: 1.5rem; margin: 0.4rem 0 0.6rem; }
.radio-row label { display: flex; align-items: center; gap: 0.45rem; margin: 0; font-weight: 500; }

.readonly-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem 1.25rem;
  background: var(--bg);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.readonly-grid .ro-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}

/* ---------- Notifications ---------- */
.notif-item {
  display: flex;
  gap: 0.9rem;
  padding: 0.85rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.notif-item.unread { background: var(--brand-light); }
.notif-dot {
  width: 9px;
  height: 9px;
  margin-top: 7px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent);
}

.notif-item.read .notif-dot { background: var(--border); }
.notif-item strong { display: block; font-size: 0.92rem; }
.notif-item p { font-size: 0.86rem; color: var(--text-muted); }
.notif-item time { margin-left: auto; font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .menu-toggle { display: inline-flex; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .sidebar.is-open { transform: translateX(0); }
  .sidebar-overlay.is-visible { display: block; }
  body.menu-open { overflow: hidden; }

  .page-content { padding: 1rem; }
  .form-grid { grid-template-columns: 1fr; }
  .form-span-2 { grid-column: span 1; }
  .commission-due-value { font-size: 220%; }
  .export-toolbar { margin-left: 0; }
}
