/* ═════════════════════════════════════════════════════════════════
   RampCORE — Design System
   Dark theme matching BRHub product family
   ═════════════════════════════════════════════════════════════════ */

:root {
  /* Surfaces */
  --bg-base:        #0a0f1a;
  --bg-raised:      #0f1626;
  --bg-elevated:    #131c2e;
  --bg-hover:       #182238;

  /* Text */
  --text-primary:   #e8eef9;
  --text-secondary: #a3b1c8;
  --text-muted:     #6c7a96;
  --text-disabled:  #44516a;

  /* Borders */
  --border-subtle:  rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.10);
  --border-strong:  rgba(255, 255, 255, 0.18);

  /* Brand accents */
  --accent-blue:    #3b82f6;
  --accent-cyan:    #22d3ee;
  --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #22d3ee 100%);

  /* Semantic */
  --color-success: #22c55e;
  --color-warning: #eab308;
  --color-danger:  #ef4444;
  --color-info:    #3b82f6;

  /* Grades */
  --grade-a: #22c55e;
  --grade-b: #84cc16;
  --grade-c: #eab308;
  --grade-d: #f97316;
  --grade-f: #ef4444;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', Consolas, monospace;

  /* Spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;

  /* Radii */
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 36px rgba(0,0,0,0.5);

  /* Layout */
  --header-h: 60px;
  --sidebar-w: 280px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse 800px 400px at 20% -10%, rgba(59,130,246,0.08), transparent 60%),
    radial-gradient(ellipse 600px 300px at 80% 110%, rgba(34,211,238,0.06), transparent 60%),
    var(--bg-base);
}

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--text-primary);
}

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

/* ═══ Logo ═══ */
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--accent-gradient);
  color: #fff;
  border-radius: var(--r-md);
  font-weight: 800;
  font-size: 16px;
}
.logo-text { color: var(--text-primary); }
.logo-sm { font-size: 16px; }
.logo-sm .logo-mark { width: 28px; height: 28px; font-size: 14px; }

/* ═══ Buttons ═══ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--r-md);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  transition: background 120ms, border-color 120ms, transform 80ms, color 120ms;
  border: 1px solid transparent;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn:active:not(:disabled) { transform: translateY(1px); }

.btn-primary {
  background: var(--accent-gradient);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(59,130,246,0.25);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.10); }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-default);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; }

/* ═══ Forms ═══ */
.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--sp-4);
}
.form-row label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}
.form-row label .hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 12px;
}
.form-row label .req { color: var(--accent-cyan); }

.form-row input,
.form-row select,
.form-row textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-base);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  outline: none;
  transition: border-color 120ms, background 120ms;
}
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  border-color: var(--accent-blue);
  background: var(--bg-raised);
}
.form-row input::placeholder { color: var(--text-disabled); }

.form-row select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%236c7a96' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  cursor: pointer;
  margin-top: 24px;
}
.checkbox-label input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }

.form-grid { display: grid; gap: var(--sp-4); }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }

.form-error {
  padding: 10px 14px;
  background: rgba(239, 68, 68, 0.10);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: var(--r-md);
  color: #fca5a5;
  font-size: 13px;
  margin-bottom: var(--sp-3);
}

/* ═══ Auth Modal ═══ */
.auth-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 15, 26, 0.85);
  backdrop-filter: blur(8px);
  z-index: 100;
  padding: var(--sp-4);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-xl);
  padding: var(--sp-8);
  box-shadow: var(--shadow-lg);
}
.auth-header {
  text-align: center;
  margin-bottom: var(--sp-6);
}
.auth-header .logo { justify-content: center; margin-bottom: var(--sp-2); }
.auth-tagline {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
}
.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-base);
  padding: 4px;
  border-radius: var(--r-md);
  margin-bottom: var(--sp-6);
  border: 1px solid var(--border-subtle);
}
.auth-tab {
  flex: 1;
  padding: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--r-sm);
  transition: background 120ms, color 120ms;
}
.auth-tab.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.auth-form { display: none; }
.auth-form.active { display: block; }

/* ═══ App Shell ═══ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 var(--sp-6);
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.user-pill {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 6px 10px;
  background: var(--bg-elevated);
  border-radius: var(--r-md);
  border: 1px solid var(--border-subtle);
}

.app-body {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100vh - var(--header-h));
}

/* ═══ Sidebar ═══ */
.sidebar {
  background: var(--bg-raised);
  border-right: 1px solid var(--border-subtle);
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}
.sidebar-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  min-height: 0;
}
.sidebar-heading {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0 var(--sp-2);
  margin: var(--sp-2) 0 0;
}
.campaign-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  margin-top: var(--sp-2);
}
.campaign-item {
  display: block;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  text-align: left;
  width: 100%;
  cursor: pointer;
  transition: background 120ms, color 120ms, border-color 120ms;
}
.campaign-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.campaign-item.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-default);
}
.campaign-item-name {
  font-weight: 500;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.campaign-item-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.campaign-empty {
  font-size: 12px;
  color: var(--text-muted);
  padding: var(--sp-3);
  text-align: center;
}

/* ═══ Main ═══ */
.app-main {
  padding: var(--sp-6);
  overflow-y: auto;
}
.panel {
  background: var(--bg-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-xl);
  padding: var(--sp-6);
  margin-bottom: var(--sp-6);
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-6);
  gap: var(--sp-3);
  flex-wrap: wrap;
}
.panel-title {
  font-size: 18px;
  font-weight: 600;
}
.panel-actions {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
}

.section-heading {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: var(--sp-3);
}
.section-heading .hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-disabled);
  margin-left: 4px;
}

.form-section {
  padding: var(--sp-4);
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  margin-bottom: var(--sp-4);
}
.form-section:last-child { margin-bottom: 0; }
.form-section .form-row { margin-bottom: 0; }

.meta-pill {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  background: var(--bg-base);
  padding: 4px 8px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-subtle);
}

/* ═══ Variant Cards ═══ */
.variant-cards {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--sp-3);
  margin-bottom: var(--sp-6);
}
.variant-card {
  position: relative;
  background: var(--bg-base);
  border: 1px solid var(--border-default);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  cursor: pointer;
  transition: border-color 120ms, transform 120ms, background 120ms;
}
.variant-card:hover {
  border-color: var(--border-strong);
  background: var(--bg-elevated);
}
.variant-card.selected {
  border-color: var(--accent-blue);
  background: var(--bg-elevated);
  box-shadow: 0 0 0 1px var(--accent-blue), 0 4px 12px rgba(59,130,246,0.15);
}
.variant-strategy {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--text-muted);
  margin-bottom: var(--sp-3);
}
.variant-grade {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: var(--sp-2);
}
.variant-grade-letter {
  font-size: 32px;
  font-weight: 800;
  font-family: var(--font-mono);
  line-height: 1;
}
.variant-dsi {
  font-size: 13px;
  color: var(--text-secondary);
}
.variant-dsi strong { font-family: var(--font-mono); color: var(--text-primary); }

.variant-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border-subtle);
}
.variant-stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.variant-stat-value {
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.variant-flags {
  position: absolute;
  top: var(--sp-3);
  right: var(--sp-3);
  display: flex;
  gap: 4px;
}
.flag-pill {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 7px;
  border-radius: 4px;
  border: 1px solid;
}
.flag-pill.current {
  color: var(--color-success);
  background: rgba(34,197,94,0.10);
  border-color: rgba(34,197,94,0.35);
}
.flag-pill.baseline {
  color: var(--accent-cyan);
  background: rgba(34,211,238,0.10);
  border-color: rgba(34,211,238,0.35);
}

/* Grade colors */
.grade-A, .grade-A\+ { color: var(--grade-a); }
.grade-B, .grade-B\+ { color: var(--grade-b); }
.grade-C, .grade-C\+ { color: var(--grade-c); }
.grade-D { color: var(--grade-d); }
.grade-F { color: var(--grade-f); }

/* ═══ Chart ═══ */
.chart-wrap {
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  margin-bottom: var(--sp-6);
}
.chart-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-3);
}
.chart-toolbar .section-heading { margin-bottom: 0; }
.chart-modes {
  display: flex;
  gap: 4px;
  background: var(--bg-elevated);
  padding: 3px;
  border-radius: var(--r-md);
}
.chart-mode {
  font-size: 12px;
  padding: 5px 10px;
  color: var(--text-muted);
  border-radius: var(--r-sm);
}
.chart-mode.active {
  background: var(--bg-base);
  color: var(--text-primary);
}
#rampChart {
  max-height: 360px;
}

/* ═══ Schedule Table ═══ */
.schedule-detail {
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
}
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-3);
  gap: var(--sp-3);
  flex-wrap: wrap;
}
.detail-actions { display: flex; gap: var(--sp-2); }

.table-wrap {
  overflow-x: auto;
  max-height: 480px;
  overflow-y: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
}
.schedule-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.schedule-table thead {
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  z-index: 1;
}
.schedule-table th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
}
.schedule-table th.num,
.schedule-table td.num {
  text-align: right;
  font-family: var(--font-mono);
}
.schedule-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}
.schedule-table tbody tr:last-child td { border-bottom: none; }
.schedule-table tbody tr:hover { background: var(--bg-elevated); }

.phase-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.phase-tag::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.phase-warmup { color: #93c5fd; background: rgba(59,130,246,0.10); }
.phase-warmup::before { background: var(--accent-blue); }
.phase-ramp   { color: #fde68a; background: rgba(234,179,8,0.10); }
.phase-ramp::before { background: var(--color-warning); }
.phase-cruise { color: #86efac; background: rgba(34,197,94,0.10); }
.phase-cruise::before { background: var(--color-success); }

/* ═══ Toast ═══ */
.toast {
  position: fixed;
  bottom: var(--sp-6);
  right: var(--sp-6);
  padding: 12px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  font-size: 13px;
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
  z-index: 200;
  max-width: 360px;
}
.toast.success { border-left: 3px solid var(--color-success); }
.toast.error   { border-left: 3px solid var(--color-danger); }
.toast.info    { border-left: 3px solid var(--accent-blue); }

/* ═══ Loading ═══ */
.loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: var(--sp-3);
  background: rgba(10, 15, 26, 0.65);
  backdrop-filter: blur(2px);
  z-index: 150;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-default);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ═══ Responsive ═══ */
@media (max-width: 900px) {
  .app-body { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
  .variant-cards { grid-template-columns: 1fr; }
  .panel-header, .detail-header { flex-direction: column; align-items: flex-start; }
}

/* Force-honor the hidden HTML attribute over any class-level display rules */
[hidden] { display: none !important; }
