:root {
  /* CabRate light theme: CoreQ-style neutral surfaces, neutral black accent (yellow only inside the logo) */
  --bg: #faf9f4;
  --surface: #ffffff;
  --surface-elevated: #f7f8fa;
  --bezel: #e4e7ec;
  --bezel-strong: #d0d5dd;
  --accent: #111111;
  --accent-hover: #000000;
  --accent-ink: #ffffff;
  --orange: #3f3f46;
  --orange-soft: rgba(24, 24, 27, 0.07);
  --green: #27272a;
  --green-soft: rgba(16, 24, 40, 0.07);
  --cyan: #27272a;
  --cyan-soft: rgba(24, 24, 27, 0.07);
  --amber: #52525b;
  --amber-soft: rgba(24, 24, 27, 0.07);
  --coral: #d92d20;
  --coral-soft: rgba(217, 45, 32, 0.08);
  --text: #101828;
  --text-sub: #475467;
  --muted: #667085;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Inter", "Space Grotesk", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

/* Auth Screen */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 500px;
  background: var(--surface);
  border: 1px solid var(--bezel);
  border-radius: 16px;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--orange-soft);
  border: 1px solid rgba(249, 115, 22, 0.35);
  color: var(--orange);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  width: fit-content;
}

.auth-card h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: -0.02em;
}

.auth-card p {
  margin: 0;
  color: var(--text-sub);
  line-height: 1.5;
  font-size: 14px;
}

.meta-box {
  background: var(--surface-elevated);
  border: 1px solid var(--bezel);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-sub);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:hover {
  opacity: 0.92;
}

.btn-orange {
  background: var(--orange);
  color: #0a0c10;
}

.btn-green {
  background: var(--green);
  color: #0a0c10;
}

.btn-outline {
  background: var(--surface-elevated);
  border-color: var(--bezel);
  color: var(--text);
}

.btn-outline:hover {
  border-color: var(--bezel-strong);
}

.btn-danger {
  background: var(--coral-soft);
  border-color: rgba(239, 68, 68, 0.45);
  color: var(--coral);
}

/* Linear / Attio Enterprise App Shell */
.app-shell {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--bezel);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-logo {
  padding: 2px 8px 10px;
  border-bottom: 1px solid var(--bezel);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-logo strong {
  font-size: 18px;
  letter-spacing: -0.02em;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.09em;
  color: var(--muted);
  text-transform: uppercase;
  padding: 10px 10px 4px;
}

.nav-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-sub);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}

.nav-btn:hover {
  background: var(--surface-elevated);
  color: var(--text);
}

.nav-btn.active {
  background: var(--orange-soft);
  border-color: #d4d4d8;
  color: var(--text);
  font-weight: 600;
}

.nav-badge {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--surface-elevated);
  color: var(--text-sub);
}

.nav-btn.active .nav-badge {
  background: var(--orange);
  color: #0a0c10;
  font-weight: 700;
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--bezel);
}

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

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

.topbar-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.select, .input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--bezel);
  border-radius: 8px;
  padding: 8px 11px;
  font-family: var(--sans);
  font-size: 13px;
}

.input:focus, .select:focus {
  outline: 1px solid var(--orange);
  border-color: var(--orange);
}

.content {
  padding: 22px 24px 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 1480px;
  width: 100%;
}

.banner {
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--green);
  background: var(--green-soft);
  color: var(--green);
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.banner.error {
  border-color: var(--coral);
  background: var(--coral-soft);
  color: var(--coral);
}

/* Cards & Grids */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--bezel);
  border-radius: 12px;
  padding: 16px 18px;
}

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-sub);
  text-transform: uppercase;
}

.kpi-value {
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

.kpi-sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr));
  gap: 14px;
}

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

.section-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.07em;
  color: var(--orange);
  text-transform: uppercase;
}

.section-subtitle {
  font-size: 13px;
  color: var(--text-sub);
  margin-top: 2px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  padding: 10px 10px;
  text-align: left;
  border-bottom: 1px solid var(--bezel);
}

th {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

tr.clickable-row {
  cursor: pointer;
}

tr:hover td {
  background: rgba(16, 24, 40, 0.03);
}

.tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--mono);
}

.tag-orange { background: var(--orange-soft); color: var(--orange); border: 1px solid rgba(249, 115, 22, 0.35); }
.tag-green { background: var(--green-soft); color: var(--green); }
.tag-cyan { background: var(--cyan-soft); color: var(--cyan); }
.tag-amber { background: var(--amber-soft); color: var(--amber); }
.tag-coral { background: var(--coral-soft); color: var(--coral); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 12px;
  color: var(--text-sub);
}

.bar-track {
  height: 8px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--bezel);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 4px;
}

canvas.chart-canvas {
  width: 100%;
  height: 210px;
  display: block;
}

/* Workflow Stepper */
.stage-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.stage-pill {
  font-family: var(--mono);
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--bezel);
  color: var(--text-sub);
  background: var(--bg);
}

.stage-pill.done {
  border-color: var(--bezel-strong);
  color: var(--green);
  background: var(--green-soft);
}

.stage-pill.current {
  border-color: var(--orange);
  color: var(--orange);
  background: var(--orange-soft);
}

/* Contextual Right-Hand Detail Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.45);
  z-index: 60;
  display: flex;
  justify-content: flex-end;
}

.drawer-panel {
  width: 100%;
  max-width: 480px;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--bezel-strong);
  display: flex;
  flex-direction: column;
  box-shadow: -16px 0 48px rgba(16, 24, 40, 0.18);
}

.drawer-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--bezel);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.drawer-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.kv-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  font-size: 13px;
}

.kv-row span:first-child {
  color: var(--text-sub);
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--bezel);
  }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .nav-section-label {
    display: none;
  }
  .nav-btn {
    width: auto;
  }
}

/* CabRate brand logo */
.brand-logo { display: block; height: auto; }
.auth-logo { width: 200px; max-width: 70%; margin-bottom: 2px; }
.side-logo { width: 130px; margin: 2px 0 6px; }

/* ---- Light theme refinements ---- */
.auth-card, .card, .panel { box-shadow: var(--shadow-sm); }
.auth-card { border-radius: 16px; box-shadow: var(--shadow-md); }
.auth-logo { width: 220px; max-width: 70%; margin: 0 auto 6px; }
.auth-card h1 { font-size: 24px; }
.brand-pill { background: var(--orange-soft); border: 1px solid rgba(24, 24, 27, 0.22); color: var(--orange); }
.btn { border-radius: 10px; min-height: 42px; }
.btn-orange { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-sm); }
.btn-orange:hover { background: var(--accent-hover); opacity: 1; }
.btn-green { background: #27272a; color: #fff; }
.btn-green:hover { background: #09090b; opacity: 1; }
.banner { background: var(--surface); border-color: var(--bezel-strong); border-left: 4px solid var(--accent); color: var(--text); box-shadow: var(--shadow-sm); }
.banner.error { background: var(--coral-soft); border-color: rgba(217, 45, 32, 0.35); border-left: 4px solid var(--coral); color: var(--coral); }
.tag-green { background: var(--surface-elevated); color: var(--text-sub); border: 1px solid var(--bezel-strong); }
.btn-outline { background: var(--surface); border-color: var(--bezel-strong); color: var(--text); box-shadow: var(--shadow-sm); }
.btn-outline:hover { background: var(--surface-elevated); }
.btn-danger { background: var(--surface); border-color: rgba(217, 45, 32, 0.35); color: var(--coral); }
.btn-danger:hover { background: var(--coral-soft); opacity: 1; }
.sidebar { background: var(--surface); box-shadow: 1px 0 0 var(--bezel); }
.side-logo { width: 140px; }
.nav-btn { color: var(--text-sub); }
.nav-btn:hover { background: var(--surface-elevated); color: var(--text); }
.nav-btn.active { background: #eeeeef; border-color: #d4d4d8; color: var(--text); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.nav-btn.active .nav-badge { background: var(--accent); color: var(--accent-ink); }
.nav-badge { background: var(--surface-elevated); border: 1px solid var(--bezel); }
.topbar { background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(8px); box-shadow: var(--shadow-sm); }
.select, .input { background: var(--surface); border-color: var(--bezel-strong); border-radius: 10px; box-shadow: var(--shadow-sm); }
.input:focus, .select:focus { outline: 3px solid rgba(24, 24, 27, 0.18); border-color: var(--accent); }
.card { border-radius: 12px; }
.bar-fill { background: var(--accent) !important; }
.tag-orange { background: var(--orange-soft); color: var(--orange); border: 1px solid rgba(24, 24, 27, 0.22); }
.meta-box { background: var(--surface-elevated); }
th { background: var(--surface-elevated); }
tbody tr:hover { background: rgba(16, 24, 40, 0.025); }
::selection { background: rgba(24, 24, 27, 0.18); }

/* ---- Mobile: off-canvas menu, compact cards, stacked tables ---- */
.nav-toggle, .nav-backdrop { display: none; }
@media (max-width: 960px) {
  .app-shell { display: block; }
  .nav-toggle { display: inline-flex; flex-direction: column; justify-content: center; gap: 4px; width: 42px; height: 42px; padding: 0 11px; border-radius: 10px; border: 1px solid var(--bezel-strong); background: var(--surface); cursor: pointer; flex: none; }
  .nav-toggle span { display: block; height: 2px; background: var(--text); border-radius: 2px; }
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: min(84vw, 300px); height: 100%; z-index: 80; transform: translateX(-102%); transition: transform .2s ease; border-right: 1px solid var(--bezel); box-shadow: var(--shadow-md); overflow-y: auto; }
  .nav-open .sidebar { transform: none; }
  .nav-open .nav-backdrop { display: block; position: fixed; inset: 0; background: rgba(16, 24, 40, 0.45); z-index: 70; }
  .sidebar-nav { flex-direction: column; flex-wrap: nowrap; overflow: visible; }
  .nav-section-label { display: block; }
  .nav-btn { width: 100%; min-height: 44px; }
  .topbar { padding: 10px 14px; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 10px 12px; }
  .topbar-titles { min-width: 0; }
  .topbar h2 { font-size: 17px !important; }
  .topbar-controls { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .topbar-controls .select { width: 100%; min-width: 0; }
  .topbar-controls .btn { grid-column: 1 / -1; width: 100%; }
  .content { padding: 14px 14px 32px; gap: 14px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-value { font-size: 22px; }
  .card { padding: 14px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .drawer-panel { max-width: 100%; }
  .btn { min-height: 44px; }
  /* tables -> stacked cards */
  table.stackable, table.stackable tbody, table.stackable tr, table.stackable td { display: block; width: 100%; }
  table.stackable thead { display: none; }
  table.stackable tbody tr { background: var(--surface); border: 1px solid var(--bezel); border-radius: 12px; padding: 6px 12px; margin-bottom: 10px; box-shadow: var(--shadow-sm); }
  table.stackable td { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 8px 0; border-bottom: 1px solid var(--bezel); text-align: right; word-break: break-word; }
  table.stackable td:last-child { border-bottom: 0; }
  table.stackable td[data-label]::before { content: attr(data-label); flex: none; max-width: 45%; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; text-align: left; }
  .table-wrap { overflow-x: visible; }
}
@media (max-width: 420px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .auth-card { padding: 22px 18px; }
}

@media (max-width: 960px) {
  html, body { overflow-x: hidden; }
  .content, .card, .tab-panel, .form-grid, .field { min-width: 0; max-width: 100%; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .input, .select { max-width: 100%; min-width: 0; }
  .form-grid .field { min-width: 0; }
}
@media (max-width: 420px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }

.row-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
@media (max-width: 960px) { .row-actions { align-items: flex-end; text-align: right; } }

/* Meter Behaviour and Fatigue */
.instruction-toolbar, .button-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.instruction-search { flex: 1; min-width: 240px; }
.instruction-groups { display: flex; flex-direction: column; gap: 10px; }
.instruction-group { border: 1px solid var(--bezel); border-radius: 10px; background: var(--surface); overflow: hidden; }
.instruction-group summary { cursor: pointer; padding: 12px 14px; font-weight: 700; color: var(--text); display: flex; justify-content: space-between; }
.instruction-group summary span { color: var(--muted); font: 11px var(--mono); }
.instruction-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(160px, 260px); gap: 14px; padding: 14px; border-top: 1px solid var(--bezel); }
.instruction-row strong, .instruction-row code { display: block; }
.instruction-row code, .instruction-row small, .fatigue-field small { color: var(--muted); font-size: 11px; }
.instruction-row p { margin: 5px 0; color: var(--text-sub); font-size: 13px; }
.instruction-control { display: flex; flex-direction: column; align-items: stretch; gap: 8px; justify-content: center; }
.instruction-import { width: 100%; min-height: 130px; resize: vertical; font-family: var(--mono); }
.import-result { white-space: pre-wrap; font: 12px var(--mono); margin-top: 12px; padding: 12px; background: var(--surface-elevated); border: 1px solid var(--bezel); border-radius: 8px; }
.inline-feedback { margin: 0 0 12px; font-size: 13px; color: var(--text-sub); }
.inline-feedback.error { color: var(--coral); }
.switch { display: inline-flex; align-items: center; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch span { width: 42px; height: 24px; border-radius: 999px; background: #d4d4d8; border: 1px solid var(--bezel-strong); position: relative; }
.switch span::after { content: ""; width: 18px; height: 18px; border-radius: 50%; background: #ffffff; position: absolute; top: 2px; left: 2px; transition: transform .15s ease; }
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:disabled + span { opacity: .55; cursor: not-allowed; }
@media (max-width: 640px) { .instruction-row { grid-template-columns: 1fr; } }

.btn-sm { padding: 6px 10px; font-size: 12px; margin-top: 8px; }
.instruction-control { display: flex; flex-direction: column; align-items: flex-end; }
