/* StrataWave v2 — Clean DEEPSOIL-style UI */

:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --ink: #1a1a2e;
  --ink-70: #555;
  --ink-60: #777;
  --ink-40: #bbb;
  --ink-10: #e8e8e8;
  --accent: #D35400;
  --accent-light: #E67E22;
  --blue: #2980B9;
  --green: #27AE60;
  --red: #E74C3C;
  --border: #ddd;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', 'Consolas', monospace;
}

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

body {
  font-family: var(--font);
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

/* ── Shell Layout ───────────────────────────────────── */

.shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 1.5rem;
  background: var(--ink);
  color: white;
}

.logo {
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.header-actions { margin-left: auto; display: flex; gap: 2px; }

.header-tab {
  background: rgba(255,255,255,0.1);
  border: none;
  color: rgba(255,255,255,0.6);
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius);
  transition: all 0.15s;
}
.header-tab:hover { color: white; background: rgba(255,255,255,0.15); }
.header-tab.active { color: white; background: var(--accent); }

.tagline {
  font-size: 0.75rem;
  opacity: 0.6;
}

.main-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  flex: 1;
  overflow: hidden;
}

.main-layout-3col {
  display: grid;
  grid-template-columns: 200px 1fr;
  flex: 1;
  overflow: hidden;
}

/* ── Nav Rail (left sidebar) ────────────────────────── */

.nav-rail {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 0.5rem 0;
  display: flex;
  flex-direction: column;
}

.nav-section { padding: 0.25rem 0; }

.nav-label {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--ink-40);
  letter-spacing: 1px;
  padding: 0.5rem 0.75rem 0.25rem;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.45rem 0.75rem;
  border: none;
  background: none;
  font-family: var(--font);
  font-size: 0.78rem;
  color: var(--ink-60);
  cursor: pointer;
  text-align: left;
  transition: all 0.12s;
}

.nav-btn:hover { background: var(--bg); color: var(--ink); }
.nav-btn.active {
  background: #FFF5EB;
  color: var(--accent);
  font-weight: 600;
  border-left: 3px solid var(--accent);
}

.nav-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--ink-10);
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--ink-60);
  flex-shrink: 0;
}
.nav-btn.active .nav-num { background: var(--accent); color: white; }

.nav-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.run-text { font-family: var(--mono); font-size: 0.7rem; }
.nav-badge {
  font-size: 0.6rem;
  color: var(--ink-40);
  margin-left: auto;
}
.nav-run.active { border-left-color: var(--blue); }
.nav-run.active .nav-text { color: var(--blue); }

.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 0.5rem 0.75rem;
}

.nav-error {
  margin: 0.5rem 0.75rem;
  padding: 0.35rem 0.5rem;
  background: #FEF2F2;
  border-radius: var(--radius);
  color: var(--red);
  font-size: 0.7rem;
}

/* ── Content Area ───────────────────────────────────── */

.content-area {
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
  background: var(--bg);
}

/* ── Wizard Panel ───────────────────────────────────── */

.wizard-panel {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.wizard-steps {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--ink-10);
  border-bottom: 1px solid var(--border);
}

.wizard-step-btn {
  background: var(--surface);
  border: none;
  padding: 0.5rem 1rem;
  text-align: left;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink-60);
  cursor: pointer;
  transition: all 0.15s;
}

.wizard-step-btn:hover { background: var(--bg); color: var(--ink); }
.wizard-step-btn.active {
  background: var(--accent);
  color: white;
  font-weight: 600;
}

.wizard-body { padding: 1rem; flex: 1; }

/* ── Step Body ──────────────────────────────────────── */

.step-body { display: flex; flex-direction: column; gap: 0.75rem; }

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.field label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-60);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.field input, .field select, .field textarea {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.85rem;
  background: var(--surface);
  transition: border-color 0.15s;
}

.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
}

.row {
  display: flex;
  gap: 0.75rem;
}

.row > .field { flex: 1; }

/* ── Buttons ────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

.btn:hover { background: var(--bg); border-color: var(--ink-40); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.75rem; }
.btn-lg { padding: 0.6rem 1.2rem; font-size: 0.9rem; }

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

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink-40);
  font-size: 0.9rem;
  padding: 0.2rem;
}
.btn-icon:hover { color: var(--red); }

/* ── Tables ─────────────────────────────────────────── */

.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.tbl th {
  background: var(--bg);
  padding: 0.4rem 0.5rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--ink-60);
  border-bottom: 2px solid var(--border);
}

.tbl td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--ink-10);
}

.tbl tr.selected { background: #FFF5EB; }
.tbl tr:hover { background: var(--bg); }

.tbl input {
  width: 100%;
  padding: 0.2rem 0.3rem;
  border: 1px solid transparent;
  border-radius: 3px;
  font-size: 0.8rem;
  font-family: var(--mono);
  background: transparent;
}
.tbl input:focus {
  border-color: var(--accent);
  background: var(--surface);
  outline: none;
}

.tbl select {
  padding: 0.2rem;
  border: 1px solid transparent;
  border-radius: 3px;
  font-size: 0.8rem;
  background: transparent;
}

/* ── Profile Editor ─────────────────────────────────── */

.profile-editor {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.layer-table-container { overflow-y: auto; max-height: 300px; }

.layer-table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.layer-properties {
  border-left: 2px solid var(--accent);
  padding-left: 0.75rem;
}

.param-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.params-section summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--ink-70);
  margin-bottom: 0.5rem;
}

.auto-profile-details {
  margin-bottom: 0.5rem;
  font-size: 0.8rem;
}
.auto-profile-details summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--ink-60);
}

.calibration-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.calib-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* ── Results Panel ──────────────────────────────────── */

.results-panel {
  overflow-y: auto;
  padding: 1rem 1.5rem;
  background: var(--bg);
}

.results-viewer { max-width: 1000px; }

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.results-header h3 { font-size: 1rem; }

.results-actions { display: flex; gap: 0.5rem; }

.results-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  color: var(--ink-40);
}

.results-content { margin-top: 0.75rem; }

/* ── Tabs ───────────────────────────────────────────── */

.tab-row {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--border);
}

.tab-btn {
  background: none;
  border: none;
  padding: 0.5rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ink-60);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
}

.tab-btn:hover { color: var(--ink); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.tab-content { margin-top: 1rem; }

/* ── Metric Cards ───────────────────────────────────── */

.metric-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  min-width: 100px;
  box-shadow: var(--shadow);
}

.metric-card span {
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
  color: var(--ink-60);
  letter-spacing: 0.3px;
}

.metric-card b {
  font-size: 1rem;
  font-family: var(--mono);
  color: var(--ink);
}

/* ── Chart Cards ────────────────────────────────────── */

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow);
}

.chart-card h4 {
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.chart-card h4 small { font-weight: 400; }

.chart-card svg { display: block; }

.profile-charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

/* ── Run List ───────────────────────────────────────── */

.run-list {
  border-top: 1px solid var(--border);
  padding: 0.75rem 1rem;
}

.run-list h4 {
  font-size: 0.75rem;
  color: var(--ink-60);
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}

.run-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.78rem;
  transition: background 0.1s;
}

.run-item:hover { background: var(--bg); }
.run-item.active { background: #FFF5EB; border-left: 2px solid var(--accent); }

.run-id { font-family: var(--mono); font-size: 0.75rem; }
.run-backend { font-size: 0.7rem; }

/* ── Motion Panel ───────────────────────────────────── */

.motion-upload-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.hidden-input { display: none; }

/* ── Utility ────────────────────────────────────────── */

.muted { color: var(--ink-60); }
.error-text { color: var(--red); font-size: 0.8rem; }
.error-banner {
  background: #FEF2F2;
  border: 1px solid #FECACA;
  color: var(--red);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  margin-top: 0.5rem;
  font-size: 0.8rem;
}

/* ── Progress Bar ───────────────────────────────────── */

.nav-progress {
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.progress-bar {
  height: 4px;
  background: var(--ink-10);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.profile-editor-full {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.example-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.set-results { margin-top: 0.75rem; }
.set-results h5 { font-size: 0.8rem; margin-bottom: 0.5rem; }

/* ── Responsive ─────────────────────────────────────── */

@media (max-width: 900px) {
  .main-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .main-layout-3col {
    grid-template-columns: 1fr;
  }
  .nav-rail {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 0.25rem;
    max-height: none;
  }
  .nav-section { flex-direction: row; flex-wrap: wrap; gap: 0.15rem; }
  .nav-btn { padding: 0.2rem 0.5rem; font-size: 0.65rem; }
  .nav-num { width: 16px; height: 16px; font-size: 8px; }
  .nav-divider { display: none; }
  .nav-runs-section { display: none; }
  .nav-shortcuts { display: none; }
  .content-area { padding: 0.75rem; }
  .wizard-panel { max-height: 50vh; }
  .profile-editor { grid-template-columns: 1fr; }
  .profile-charts-grid { grid-template-columns: 1fr; }
  .calib-charts { grid-template-columns: 1fr; }
  .results-header { flex-direction: column; gap: 0.5rem; }
  .metric-row { flex-wrap: wrap; }
  .header { padding: 0.3rem 0.75rem; }
  .tagline { display: none; }
}

/* ── Dark Theme ────────────────────────────────────── */

[data-theme="dark"] {
  --bg: #1a1a2e;
  --surface: #222240;
  --ink: #e8e8f0;
  --ink-70: #b0b0c0;
  --ink-60: #9090a0;
  --ink-40: #606078;
  --ink-10: #3a3a50;
  --accent: #E67E22;
  --accent-light: #F39C12;
  --blue: #5DADE2;
  --green: #2ECC71;
  --red: #E74C3C;
  --border: #3a3a50;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

[data-theme="dark"] .header { background: #12122a; }
[data-theme="dark"] .nav-btn.active { background: #2a2a48; color: var(--accent); }
[data-theme="dark"] .nav-btn:hover { background: #2a2a48; }
[data-theme="dark"] .btn { background: var(--surface); border-color: var(--ink-40); color: var(--ink); }
[data-theme="dark"] .btn:hover { background: var(--ink-10); }
[data-theme="dark"] .btn-accent { background: var(--accent); color: white; border-color: var(--accent); }
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea {
  background: var(--surface); color: var(--ink); border-color: var(--ink-40);
}
[data-theme="dark"] .metric-card { background: var(--surface); border-color: var(--ink-10); }
[data-theme="dark"] .tbl th { background: var(--ink-10); color: var(--ink-70); }
[data-theme="dark"] .tbl td { border-color: var(--ink-10); }
[data-theme="dark"] .chart-card { background: var(--surface); }

/* Theme toggle button */
.theme-toggle {
  background: none;
  border: 1px solid rgba(255,255,255,0.2);
  color: white;
  border-radius: 4px;
  padding: 0.15rem 0.5rem;
  font-size: 0.7rem;
  cursor: pointer;
  opacity: 0.7;
}
.theme-toggle:hover { opacity: 1; }

/* Step completion badges */
.nav-num.step-ok { background: #27AE60; color: white; }
.nav-num.step-blocked { background: var(--ink-10); color: var(--ink-40); }

/* Help tooltip */
.help-tip {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--ink-10);
  color: var(--ink-60);
  font-size: 9px;
  text-align: center;
  line-height: 14px;
  cursor: help;
  position: relative;
  margin-left: 4px;
  vertical-align: middle;
}
.help-tip:hover::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: 120%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 10px;
  line-height: 1.4;
  white-space: normal;
  width: max-content;
  max-width: 240px;
  z-index: 100;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* ── Pro Plan Gating ───────────────────────────────── */

.pro-badge, .tier-badge {
  display: inline-block;
  background: linear-gradient(135deg, #D35400, #E67E22);
  color: white;
  font-size: 7px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  margin-left: 4px;
  vertical-align: middle;
  letter-spacing: 0.5px;
}

.pro-guard {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
}
.pro-guard-blurred {
  filter: blur(3px);
  opacity: 0.4;
  pointer-events: none;
  user-select: none;
}
.pro-guard-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  background: rgba(255,255,255,0.05);
}
.pro-guard-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.pro-guard-icon { font-size: 1.5rem; }
.pro-guard-label { font-size: 0.85rem; font-weight: 600; color: var(--ink); }
.pro-guard-hint { font-size: 0.7rem; color: var(--ink-60); }

.plan-toggle {
  background: none;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  padding: 0.1rem 0.5rem;
  font-size: 0.65rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.plan-toggle:hover { opacity: 0.8; }
