/* ============================================================
   OptiCore — Design System
   Dark industrial theme. Monospace accent. Sharp precision.
   ============================================================ */

/* ── Fonts ──────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400;0,500;1,400&family=Syne:wght@400;600;700;800&family=Inter:wght@300;400;500;600&display=swap');

/* ── CSS Variables ──────────────────────────────────────────── */
:root {
  /* Palette */
  --bg-base:       #0F0F0E;
  --bg-surface:    #171715;
  --bg-elevated:   #1E1E1B;
  --bg-hover:      #252522;
  --bg-active:     #2C2C28;

  --border:        #2A2A27;
  --border-light:  #323230;
  --border-focus:  #5E58D4;

  --text-primary:  #EEECEA;
  --text-secondary:#9E9C96;
  --text-muted:    #5E5C58;
  --text-inverse:  #0F0F0E;

  /* Brand */
  --purple:        #6B64E8;
  --purple-light:  #8B85F0;
  --purple-dim:    rgba(107,100,232,0.15);
  --purple-border: rgba(107,100,232,0.35);

  /* Module colours */
  --teal:          #2AB87A;
  --teal-dim:      rgba(42,184,122,0.12);
  --teal-border:   rgba(42,184,122,0.30);

  --amber:         #E8A030;
  --amber-dim:     rgba(232,160,48,0.12);
  --amber-border:  rgba(232,160,48,0.30);

  --blue:          #4A9FE0;
  --blue-dim:      rgba(74,159,224,0.12);
  --blue-border:   rgba(74,159,224,0.30);

  --coral:         #E05A40;
  --coral-dim:     rgba(224,90,64,0.12);
  --coral-border:  rgba(224,90,64,0.30);

  /* Semantic */
  --success:       #2AB87A;
  --warning:       #E8A030;
  --error:         #E05A40;
  --info:          #4A9FE0;

  /* Typography */
  --font-display:  'Syne', sans-serif;
  --font-body:     'Inter', sans-serif;
  --font-mono:     'DM Mono', monospace;

  /* Spacing (8pt grid) */
  --s1: 4px;  --s2: 8px;  --s3: 12px;  --s4: 16px;
  --s5: 20px; --s6: 24px; --s7: 32px;  --s8: 40px;
  --s9: 48px; --s10: 64px;--s11: 80px; --s12: 96px;

  /* Radii */
  --r1: 4px; --r2: 6px; --r3: 10px; --r4: 16px; --r5: 24px;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg:  0 8px 32px rgba(0,0,0,0.6);
  --shadow-glow: 0 0 24px rgba(107,100,232,0.25);

  /* Transitions */
  --t1: 120ms ease;
  --t2: 200ms ease;
  --t3: 320ms cubic-bezier(.23,1,.32,1);
}

/* ── Light theme ─────────────────────────────────────────────── */
[data-theme="light"] {
  --bg-base:       #F5F5F3;
  --bg-surface:    #FAFAF8;
  --bg-elevated:   #FFFFFF;
  --bg-hover:      #EEEEEB;
  --bg-active:     #E5E5E2;

  --border:        #DDDDD8;
  --border-light:  #CACAC5;
  --border-focus:  #6B64E8;

  --text-primary:  #1A1A18;
  --text-secondary:#4A4A46;
  --text-muted:    #8A8A85;
  --text-inverse:  #FAFAF8;

  --purple:        #5550CC;
  --purple-light:  #6B64E8;
  --purple-dim:    rgba(85,80,204,0.10);
  --purple-border: rgba(85,80,204,0.30);

  --teal:          #1A9960;
  --teal-dim:      rgba(26,153,96,0.10);
  --teal-border:   rgba(26,153,96,0.28);

  --amber:         #C47A0A;
  --amber-dim:     rgba(196,122,10,0.10);
  --amber-border:  rgba(196,122,10,0.28);

  --blue:          #2878B8;
  --blue-dim:      rgba(40,120,184,0.10);
  --blue-border:   rgba(40,120,184,0.28);

  --coral:         #C03820;
  --coral-dim:     rgba(192,56,32,0.10);
  --coral-border:  rgba(192,56,32,0.28);
}


/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; scroll-behavior: smooth; }

body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-surface); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── App layout ─────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-rows: 56px 1fr;
  grid-template-columns: 220px 1fr;
  grid-template-areas: "nav-top nav-top" "sidebar main";
  min-height: 100vh;
}

/* ── Top nav ────────────────────────────────────────────────── */
#nav-top {
  grid-area: nav-top;
  display: flex;
  align-items: center;
  padding: 0 var(--s6);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  gap: var(--s4);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: var(--s3);
  text-decoration: none;
}

.nav-logo-mark {
  width: 28px;
  height: 28px;
  background: var(--purple);
  border-radius: var(--r2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: white;
  letter-spacing: -1px;
}

.nav-logo-text {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.nav-logo-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: var(--s1);
}

.nav-spacer { flex: 1; }

.nav-actions {
  display: flex;
  align-items: center;
  gap: var(--s3);
}

.nav-btn {
  height: 32px;
  padding: 0 var(--s4);
  border-radius: var(--r2);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
  transition: var(--t1);
  display: flex;
  align-items: center;
  gap: var(--s2);
}

.nav-btn:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-light); }

.nav-btn-primary {
  background: var(--purple);
  border-color: var(--purple);
  color: white;
}
.nav-btn-primary:hover { background: var(--purple-light); border-color: var(--purple-light); }

/* User avatar */
.nav-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--purple-dim);
  border: 1px solid var(--purple-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--purple-light);
  cursor: pointer;
  transition: var(--t1);
}
.nav-avatar:hover { background: var(--purple-border); }

/* ── Sidebar ────────────────────────────────────────────────── */
#sidebar {
  grid-area: sidebar;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  padding: var(--s6) 0;
  overflow-y: auto;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
}

.sidebar-section {
  padding: 0 var(--s4);
  margin-bottom: var(--s5);
}

.sidebar-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0 var(--s3);
  margin-bottom: var(--s2);
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s3);
  border-radius: var(--r2);
  cursor: pointer;
  transition: var(--t1);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 400;
  margin-bottom: 1px;
}

.sidebar-nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-nav-item.active {
  background: var(--purple-dim);
  color: var(--purple-light);
  border: 1px solid var(--purple-border);
}

.sidebar-nav-item .nav-icon {
  width: 18px;
  height: 18px;
  opacity: 0.7;
  flex-shrink: 0;
}

.sidebar-nav-item.active .nav-icon { opacity: 1; }

/* Module items in sidebar */
.module-nav-item {
  padding: var(--s1) var(--s3);
  margin-bottom: 1px;
}

.module-nav-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  margin: 0 3px;
}

/* ── Main content ────────────────────────────────────────────── */
#main {
  grid-area: main;
  overflow-y: auto;
  min-height: calc(100vh - 56px);
}

/* ── Home / module selector ──────────────────────────────────── */
.home-view {
  padding: var(--s8) var(--s8);
  max-width: 1100px;
}

.home-hero {
  margin-bottom: var(--s8);
}

.home-title {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: var(--s3);
  letter-spacing: -1px;
}

.home-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  max-width: 600px;
  line-height: 1.7;
}

/* Copilot intake bar */
.intake-bar {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--r3);
  padding: var(--s5);
  margin-bottom: var(--s8);
  transition: var(--t2);
}

.intake-bar:focus-within {
  border-color: var(--purple);
  box-shadow: var(--shadow-glow);
}

.intake-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: var(--s3);
  letter-spacing: 0.05em;
}

.intake-row {
  display: flex;
  gap: var(--s3);
  align-items: flex-end;
}

.intake-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  resize: none;
  min-height: 48px;
}

.intake-input::placeholder { color: var(--text-muted); }

.intake-send {
  width: 40px;
  height: 40px;
  background: var(--purple);
  border: none;
  border-radius: var(--r2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--t1);
  flex-shrink: 0;
}
.intake-send:hover { background: var(--purple-light); }
.intake-send svg { width: 16px; height: 16px; stroke: white; }

/* Module grid */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: var(--s4);
}

.module-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r3);
  padding: var(--s5);
  cursor: pointer;
  transition: var(--t2);
  position: relative;
  overflow: hidden;
}

.module-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 3px;
  height: 100%;
  background: var(--module-color, var(--purple));
  opacity: 0;
  transition: var(--t2);
}

.module-card:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.module-card:hover::before { opacity: 1; }

.module-card-code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--module-color, var(--purple));
  margin-bottom: var(--s2);
  font-weight: 500;
}

.module-card-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--s2);
  line-height: 1.3;
}

.module-card-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.module-card-example {
  margin-top: var(--s3);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  border-top: 1px solid var(--border);
  padding-top: var(--s3);
  line-height: 1.5;
}

/* ── Module view ─────────────────────────────────────────────── */
.module-view {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 56px);
}

.module-header-bar {
  grid-area: module-header;
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: var(--s4) var(--s6);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

.module-header-code {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--module-color, var(--purple));
  font-weight: 500;
  padding: var(--s1) var(--s3);
  background: var(--module-dim, var(--purple-dim));
  border-radius: var(--r1);
  border: 1px solid var(--module-border, var(--purple-border));
}

.module-header-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.module-header-sub {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
}

/* Input panel — full-width, sits above results */
.module-input-panel {
  border-bottom: 2px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
}

/* Input sections in horizontal scroll for wide tables */
.input-sections-scroll {
  overflow-x: auto;
}

.input-section {
  padding: var(--s4) var(--s6);
  border-bottom: 1px solid var(--border);
}

/* Input sections laid out horizontally when space allows */
.input-sections-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
}

.input-sections-row .input-section {
  flex: 1 1 320px;
  border-right: 1px solid var(--border);
  border-bottom: none;
}

.input-sections-row .input-section:last-child {
  border-right: none;
}

.input-section-title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: var(--s4);
}

/* Form elements */
.form-group {
  margin-bottom: var(--s4);
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--s2);
}

.form-label .required { color: var(--coral); margin-left: 2px; }

.form-label .hint {
  font-weight: 400;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border-light);
  border-radius: var(--r2);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 13px;
  padding: var(--s2) var(--s3);
  transition: var(--t1);
  outline: none;
  appearance: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--border-focus);
  background: var(--bg-elevated);
  box-shadow: 0 0 0 2px var(--purple-dim);
}

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%235E5C58'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  cursor: pointer;
}

.form-textarea { min-height: 80px; resize: vertical; line-height: 1.5; }

/* Fuzzy selector (pill group) */
.fuzzy-group {
  display: flex;
  gap: var(--s2);
  flex-wrap: wrap;
}

.fuzzy-pill {
  padding: var(--s1) var(--s3);
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: var(--t1);
}

.fuzzy-pill:hover { border-color: var(--border-light); color: var(--text-primary); }

.fuzzy-pill.selected {
  background: var(--module-dim, var(--purple-dim));
  border-color: var(--module-color, var(--purple));
  color: var(--module-color, var(--purple));
}

/* Slider */
.form-slider-group {
  display: flex;
  align-items: center;
  gap: var(--s3);
}

.form-slider {
  flex: 1;
  -webkit-appearance: none;
  height: 3px;
  border-radius: 2px;
  background: var(--border-light);
  outline: none;
}

.form-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--purple);
  cursor: pointer;
  transition: var(--t1);
}

.form-slider::-webkit-slider-thumb:hover { background: var(--purple-light); transform: scale(1.2); }

.slider-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 36px;
  text-align: right;
}

/* Data table (task list / stop list) */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  min-width: 400px;
}

.data-table th {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  text-align: left;
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--bg-surface);
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table td {
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: middle;
}

.data-table tr:hover td {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.data-table .cell-mono {
  font-family: var(--font-mono);
  font-size: 11px;
}

.data-table .cell-action {
  padding: var(--s1) var(--s2);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--r1);
  transition: var(--t1);
  font-size: 11px;
}

.data-table .cell-action:hover { color: var(--coral); background: var(--coral-dim); }

/* Data table wrapper always scrolls horizontally */
.data-table-wrap {
  overflow-x: auto;
  margin: var(--s3) 0;
  border: 1px solid var(--border);
  border-radius: var(--r2);
}

/* Add row button */
.add-row-btn {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s3);
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--r2);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: var(--t1);
  width: 100%;
  margin-top: var(--s2);
}

.add-row-btn:hover {
  border-color: var(--purple-border);
  color: var(--purple-light);
  background: var(--purple-dim);
}

/* File upload zone */
/* .smart-upload-zone has same base styles + flex layout */
.upload-zone,
.smart-upload-zone {
  border: 1px dashed var(--border-light);
  border-radius: var(--r3);
  padding: var(--s6) var(--s5);
  text-align: center;
  cursor: pointer;
  transition: var(--t2);
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
}

.upload-zone:hover,
.upload-zone.drag-over,
.smart-upload-zone:hover,
.smart-upload-zone.drag-over {
  border-color: var(--purple-border);
  background: var(--purple-dim);
}

.upload-icon {
  width: 32px;
  height: 32px;
  margin: 0 auto var(--s3);
  opacity: 0.4;
}

.upload-text { font-size: 13px; color: var(--text-secondary); }
.upload-hint { font-size: 11px; color: var(--text-muted); margin-top: var(--s2); font-family: var(--font-mono); }

/* Solve button */
.solve-bar {
  padding: var(--s4) var(--s6);
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--s3);
  align-items: center;
  background: var(--bg-surface);
  position: sticky;
  bottom: 0;
  z-index: 10;
}



.solve-btn {
  flex: 1;
  height: 44px;
  background: var(--purple);
  border: none;
  border-radius: var(--r2);
  color: white;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--t2);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  letter-spacing: -0.3px;
  max-width: 280px;
}

.solve-btn:hover { background: var(--purple-light); box-shadow: var(--shadow-glow); }
.solve-btn:disabled { background: var(--bg-active); color: var(--text-muted); cursor: not-allowed; }

.solve-btn-icon { width: 18px; height: 18px; }

/* Loading spinner */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ── Output panel — fills remaining vertical space ──────────── */
.module-output-panel {
  flex: 1;
  overflow-y: auto;
  padding: var(--s6) var(--s8);
  max-width: 1200px;
  width: 100%;
  align-self: center;
}

/* Empty state */
.output-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 400px;
  gap: var(--s4);
  color: var(--text-muted);
  text-align: center;
}

.output-empty-icon {
  width: 48px;
  height: 48px;
  opacity: 0.2;
}

.output-empty-text { font-size: 14px; }
.output-empty-hint { font-size: 12px; font-family: var(--font-mono); }

/* Result sections */
.result-block {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r3);
  margin-bottom: var(--s5);
  overflow: hidden;
}

.result-block-header {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
}

.result-block-icon {
  width: 20px;
  height: 20px;
  border-radius: var(--r1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 700;
  flex-shrink: 0;
}

.result-block-title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-secondary);
}

.result-block-body {
  padding: var(--s5);
}

/* Answer block */
.answer-block {
  border-color: var(--teal-border);
  background: var(--bg-elevated);
}

.answer-block .result-block-header { border-color: var(--teal-border); background: var(--teal-dim); }
.answer-block .result-block-icon { background: var(--teal-dim); color: var(--teal); }
.answer-block .result-block-title { color: var(--teal); }

.answer-headline {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: var(--s3);
}

.answer-kpi-row {
  display: flex;
  gap: var(--s5);
  margin-bottom: var(--s4);
}

.answer-kpi {
  flex: 1;
}

.answer-kpi-value {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 500;
  color: var(--teal);
  line-height: 1.2;
}

.answer-kpi-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Reasoning block */
.reasoning-constraint {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  padding: var(--s3);
  border-radius: var(--r2);
  margin-bottom: var(--s2);
  background: var(--bg-hover);
}

.constraint-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--amber);
  margin-top: 6px;
  flex-shrink: 0;
}

.constraint-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.constraint-binding {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--amber);
  margin-top: var(--s1);
}

/* Sensitivity panel */
.sensitivity-row {
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: var(--s3) 0;
  border-bottom: 1px solid var(--border);
}

.sensitivity-label {
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 160px;
  flex-shrink: 0;
}

.sensitivity-slider-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--s3);
}

.sensitivity-delta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--blue);
  min-width: 70px;
  text-align: right;
}

/* AI narration */
.narration-text {
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--text-secondary);
}

.narration-highlight {
  color: var(--text-primary);
  font-weight: 500;
}

.narration-stat {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-hover);
  padding: 1px 5px;
  border-radius: var(--r1);
  color: var(--purple-light);
}

/* What-if input */
.whatif-bar {
  display: flex;
  gap: var(--s3);
  margin-top: var(--s4);
  padding-top: var(--s4);
  border-top: 1px solid var(--border);
}

.whatif-input {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  color: var(--text-primary);
  font-size: 13px;
  padding: var(--s2) var(--s3);
  outline: none;
  font-family: var(--font-body);
}

.whatif-input:focus { border-color: var(--border-focus); }
.whatif-input::placeholder { color: var(--text-muted); }

.whatif-btn {
  height: 36px;
  padding: 0 var(--s4);
  background: var(--bg-active);
  border: 1px solid var(--border-light);
  border-radius: var(--r2);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: var(--t1);
  white-space: nowrap;
}
.whatif-btn:hover { background: var(--purple-dim); color: var(--purple-light); border-color: var(--purple-border); }

/* Assignment / result table */
.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.result-table th {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  text-align: left;
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--border);
}

.result-table td {
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: top;
  line-height: 1.5;
}

.result-table tr:last-child td { border-bottom: none; }

.result-table .td-name {
  font-weight: 500;
  color: var(--text-primary);
}

.result-table .td-mono {
  font-family: var(--font-mono);
  font-size: 11px;
}

/* Progress / utilisation bar */
.utilisation-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}

.utilisation-fill {
  height: 100%;
  border-radius: 2px;
  transition: width var(--t3);
}

.utilisation-fill.low    { background: var(--teal); }
.utilisation-fill.medium { background: var(--amber); }
.utilisation-fill.high   { background: var(--coral); }

/* Tags / badges */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 500;
  white-space: nowrap;
}

.tag-teal   { background: var(--teal-dim);   color: var(--teal);   border: 1px solid var(--teal-border); }
.tag-amber  { background: var(--amber-dim);  color: var(--amber);  border: 1px solid var(--amber-border); }
.tag-blue   { background: var(--blue-dim);   color: var(--blue);   border: 1px solid var(--blue-border); }
.tag-coral  { background: var(--coral-dim);  color: var(--coral);  border: 1px solid var(--coral-border); }
.tag-purple { background: var(--purple-dim); color: var(--purple-light); border: 1px solid var(--purple-border); }

/* Chart container */
.chart-wrap {
  position: relative;
  height: 220px;
  margin: var(--s4) 0;
}

/* Export bar */
.export-bar {
  display: flex;
  gap: var(--s3);
  margin-top: var(--s5);
  padding-top: var(--s5);
  border-top: 1px solid var(--border);
}

.export-btn {
  height: 36px;
  padding: 0 var(--s4);
  border-radius: var(--r2);
  border: 1px solid var(--border-light);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: var(--t1);
  display: flex;
  align-items: center;
  gap: var(--s2);
}

.export-btn:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-light); }

.export-btn-primary {
  background: var(--purple-dim);
  border-color: var(--purple-border);
  color: var(--purple-light);
}

.export-btn-primary:hover { background: var(--purple); color: white; border-color: var(--purple); }

/* ── Auth helpers ────────────────────────────────────────────── */
.auth-error {
  display: none;
  color: var(--coral);
  font-size: 12px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: var(--coral-dim);
  border-radius: var(--r2);
  border: 1px solid var(--coral-border);
}
.auth-success {
  color: var(--teal);
  font-size: 12px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: var(--teal-dim);
  border-radius: var(--r2);
  border: 1px solid var(--teal-border);
}

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s5);
  backdrop-filter: blur(4px);
  animation: fadeIn var(--t2);
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--r4);
  padding: var(--s7);
  max-width: 540px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp var(--t3);
}

@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--s4);
}

.modal-close {
  position: absolute;
  top: var(--s4);
  right: var(--s4);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: var(--s2);
  border-radius: var(--r1);
  transition: var(--t1);
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ── Toast notifications ─────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: var(--s6);
  right: var(--s6);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s5);
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--r3);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  color: var(--text-primary);
  max-width: 340px;
  animation: toastIn var(--t3);
}

@keyframes toastIn {
  from { transform: translateX(40px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

.toast-icon { width: 16px; height: 16px; flex-shrink: 0; }
.toast-success { border-left: 3px solid var(--teal); }
.toast-error   { border-left: 3px solid var(--coral); }
.toast-info    { border-left: 3px solid var(--blue); }

/* ── CSV Mapping preview ─────────────────────────────────────── */
.mapping-preview {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin: var(--s3) 0;
}

.mapping-preview th {
  background: var(--bg-active);
  padding: var(--s2) var(--s3);
  text-align: left;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.mapping-preview th.mapped { color: var(--teal); }
.mapping-preview th.missing-required { color: var(--coral); }
.mapping-preview th.missing-optional { color: var(--amber); }

.mapping-preview td {
  padding: var(--s1) var(--s3);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Login page ──────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-base);
  position: relative;
  overflow: hidden;
}

.login-page::before {
  content: '';
  position: absolute;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, var(--purple-dim) 0%, transparent 70%);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.login-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--r4);
  padding: var(--s9) var(--s8);
  width: 380px;
  position: relative;
  z-index: 1;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin-bottom: var(--s7);
}

.login-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--s2);
}

.login-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: var(--s6);
}

.login-btn {
  width: 100%;
  height: 44px;
  background: var(--purple);
  border: none;
  border-radius: var(--r2);
  color: white;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--t2);
  margin-top: var(--s5);
}

.login-btn:hover { background: var(--purple-light); box-shadow: var(--shadow-glow); }
.login-footer { text-align: center; margin-top: var(--s5); font-size: 12px; color: var(--text-muted); }
.login-footer a { color: var(--purple-light); text-decoration: none; }

/* ── Sessions list ───────────────────────────────────────────── */
.sessions-view { padding: var(--s8); max-width: 900px; }

.sessions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s6);
}

.sessions-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

.session-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r3);
  padding: var(--s4) var(--s5);
  margin-bottom: var(--s3);
  display: flex;
  align-items: center;
  gap: var(--s4);
  cursor: pointer;
  transition: var(--t2);
}

.session-item:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
}

.session-module-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  padding: var(--s1) var(--s3);
  border-radius: var(--r1);
  min-width: 32px;
  text-align: center;
}

.session-info { flex: 1; }

.session-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.session-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.session-actions { display: flex; gap: var(--s2); }

/* ── Hamburger (hidden on desktop) ──────────────────────────── */
.nav-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  padding: 6px;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: var(--r2);
  flex-shrink: 0;
  margin-right: var(--s1);
  -webkit-tap-highlight-color: transparent;
}
.nav-hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text-secondary);
  border-radius: 2px;
  transition: var(--t2);
  transform-origin: center;
}
.nav-hamburger[aria-expanded="true"] span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.nav-hamburger[aria-expanded="true"] span:nth-child(2) {
  opacity: 0;
  transform: scaleX(0);
}
.nav-hamburger[aria-expanded="true"] span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ── Sidebar overlay (mobile) ────────────────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 199;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
#sidebar-overlay.sidebar-overlay-visible {
  display: block;
  animation: fadeIn var(--t2);
}

/* ── Responsive: Tablet (max 900px) ─────────────────────────── */
@media (max-width: 900px) {

  /* Layout: collapse to single column */
  #app {
    grid-template-columns: 1fr;
    grid-template-areas: "nav-top" "main";
    grid-template-rows: 56px 1fr;
  }

  /* Show hamburger, hide label-text buttons */
  .nav-hamburger { display: flex; }
  .nav-sessions-label,
  #nav-sessions-btn .btn-label { display: none; }

  /* Nav: tighter padding, bigger touch targets */
  #nav-top {
    padding: 0 var(--s4);
    gap: var(--s2);
  }

  /* Keep logo but hide tag */
  .nav-logo-tag { display: none; }

  /* Nav buttons — icon-only on tablet */
  .nav-btn {
    padding: 7px;
    min-width: 36px;
    height: 36px;
    font-size: 0;     /* hide text labels */
    gap: 0;
  }
  .nav-btn svg { width: 16px; height: 16px; }

  /* Keep Sessions label readable — show it again at 900 */
  #nav-sessions-btn {
    font-size: 12px;
    padding: 6px 10px;
    gap: var(--s2);
  }

  .nav-btn-primary {
    font-size: 12px;
    padding: 6px 12px;
    gap: 0;
  }
  .nav-btn-primary::after { content: '+ New'; font-size: 12px; }

  /* Sidebar: hidden off-screen, slides in */
  #sidebar {
    position: fixed;
    left: 0;
    top: 56px;
    bottom: 0;
    width: 260px;
    transform: translateX(-100%);
    transition: transform var(--t3);
    z-index: 200;
    height: calc(100vh - 56px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: var(--shadow-lg);
  }

  #sidebar.sidebar-open {
    transform: translateX(0);
  }

  /* Main: full width */
  #main { grid-area: main; }

  /* Home: comfortable mobile padding */
  .home-view {
    padding: var(--s5) var(--s4);
    max-width: 100%;
  }
  .home-title { font-size: 24px; letter-spacing: -0.5px; }
  .home-subtitle { font-size: 14px; }

  /* Module grid: 2 cols on tablet */
  .module-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--s3);
  }

  /* Intake bar */
  .intake-bar { padding: var(--s4); margin-bottom: var(--s6); }
  .intake-input { font-size: 14px; min-height: 40px; }

  /* Module header */
  .module-header-bar {
    padding: var(--s3) var(--s4);
    flex-wrap: wrap;
    gap: var(--s2);
  }

  /* Input sections */
  .input-section { padding: var(--s3) var(--s4); }
  .input-section-title { font-size: 12px; }

  /* Solve bar: full width */
  .solve-bar { padding: var(--s3) var(--s4); flex-wrap: wrap; gap: var(--s2); }
  .solve-btn { max-width: 100%; height: 44px; font-size: 14px; }

  /* Export bar */
  .export-bar { padding: var(--s3) var(--s4); flex-wrap: wrap; gap: var(--s2); }

  /* Output panel */
  .module-output-panel { padding: var(--s4); }

  /* Tables: horizontal scroll */
  .data-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .data-table { min-width: 500px; }
  .data-table th, .data-table td { padding: 8px 10px; font-size: 12px; }

  /* Form inputs: larger touch targets */
  .form-input, .form-select, .form-textarea {
    font-size: 16px !important; /* prevent iOS zoom */
    padding: 10px var(--s3);
    min-height: 44px;
  }
  .form-select { min-height: 44px; }

  /* Fuzzy pills: bigger tap targets */
  .fuzzy-pill {
    padding: 8px var(--s3);
    font-size: 12px;
    min-height: 36px;
  }

  /* Sessions view */
  .sessions-view { padding: var(--s5) var(--s4); }
  .session-card { padding: var(--s4); }

  /* Modal */
  .modal-overlay { padding: var(--s4); align-items: flex-end; }
  .modal {
    max-width: 100%;
    border-radius: var(--r4) var(--r4) 0 0;
    max-height: 90vh;
  }

  /* Settings panel */
  .settings-overlay .modal { border-radius: var(--r4); }

  /* Auth modal: slide up from bottom */
  .auth-modal {
    border-radius: var(--r4) var(--r4) 0 0;
    max-height: 90vh;
  }

  /* Toast position */
  #toast-container { bottom: var(--s4); right: var(--s4); left: var(--s4); }
  .toast { max-width: 100%; }

  /* Narration section */
  .narration-section { padding: var(--s4); }
}

/* ── Responsive: Phone (max 480px) ──────────────────────────── */
@media (max-width: 480px) {

  /* Nav: minimal */
  #nav-top { padding: 0 var(--s3); gap: var(--s1); height: 52px; }
  #app { grid-template-rows: 52px 1fr; }
  #sidebar { top: 52px; height: calc(100vh - 52px); width: 80vw; max-width: 300px; }

  /* Logo: hide text, keep mark */
  .nav-logo-text { display: none; }
  .nav-logo-mark { width: 26px; height: 26px; font-size: 11px; }

  /* Hide sessions button text, show only icon */
  #nav-sessions-btn { display: none; }

  /* + New → icon only */
  .nav-btn-primary { padding: 7px; gap: 0; }
  .nav-btn-primary::after { content: '+'; font-size: 16px; font-weight: 700; }

  /* Avatar smaller */
  .nav-avatar { width: 30px; height: 30px; font-size: 12px; }

  /* Home: single column module grid */
  .home-view { padding: var(--s4) var(--s3); }
  .home-title { font-size: 21px; }
  .module-grid { grid-template-columns: 1fr; gap: var(--s3); }
  .module-card { padding: var(--s4); }

  /* Module header: compact */
  .module-header-bar { padding: var(--s2) var(--s3); gap: var(--s2); }
  .module-header-title { font-size: 14px; }
  .module-header-code { font-size: 10px; padding: 2px 6px; }
  .module-header-sub { display: none; }

  /* Input sections */
  .input-section { padding: var(--s3); }

  /* Tables on tiny screen */
  .data-table th, .data-table td { padding: 6px 8px; font-size: 11px; }
  .data-table { min-width: 420px; }

  /* Solve bar: stacked */
  .solve-bar {
    flex-direction: column;
    gap: var(--s2);
    padding: var(--s3);
  }
  .solve-btn { width: 100%; height: 48px; font-size: 15px; border-radius: var(--r3); }

  /* Output panel */
  .module-output-panel { padding: var(--s3); }

  /* Modals: full-screen */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    width: 100%;
    border-radius: var(--r4) var(--r4) 0 0;
    max-height: 95vh;
    margin: 0;
  }

  /* Narration */
  .narration-section { padding: var(--s3); }
  .narration-text { font-size: 13px; line-height: 1.65; }

  /* Toast: full width at bottom */
  #toast-container { bottom: 0; right: 0; left: 0; padding: var(--s3); }
  .toast { border-radius: var(--r3) var(--r3) 0 0; }
}

/* ── Safe area insets (notch / home indicator) ───────────────── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .solve-bar { padding-bottom: max(var(--s3), env(safe-area-inset-bottom)); }
  #nav-top   { padding-left: max(var(--s4), env(safe-area-inset-left));
               padding-right: max(var(--s4), env(safe-area-inset-right)); }
  .modal     { padding-bottom: max(var(--s7), env(safe-area-inset-bottom)); }
}

/* ── Touch interaction improvements ─────────────────────────── */
@media (hover: none) and (pointer: coarse) {
  /* Remove hover states on touch devices — no sticky hover */
  .module-card:hover { transform: none; box-shadow: none; background: var(--bg-surface); }
  .sidebar-nav-item:hover { background: transparent; color: var(--text-secondary); }
  .nav-btn:hover { background: transparent; border-color: var(--border); color: var(--text-secondary); }

  /* Larger minimum tap targets */
  .sidebar-nav-item { min-height: 44px; }
  .nav-btn { min-height: 36px; }
  .solve-btn { min-height: 48px; }
  .fuzzy-pill { min-height: 40px; min-width: 44px; }
  .data-table .cell-action { min-width: 32px; min-height: 32px; }

  /* Show active state instead of hover */
  .nav-btn:active { background: var(--bg-hover); }
  .sidebar-nav-item:active { background: var(--bg-hover); }
  .module-card:active { background: var(--bg-hover); }
}

/* ── Light theme responsive ──────────────────────────────────── */
[data-theme="light"] #sidebar-overlay { background: rgba(0,0,0,0.35); }

/* ── Print ───────────────────────────────────────────────────── */
@media print {
  #sidebar, #nav-top, .solve-bar, .whatif-bar, .export-bar { display: none; }
  #main { padding: 0; }
  .module-view { grid-template-columns: 1fr; }
  .module-input-panel { display: none; }
  body { background: white; color: black; }
}
