/* ─── Zinapsian — Dark Theme, Mobile-First ─── */

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22252f;
  --border: #2a2d3a;
  --text: #e4e4e7;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent: #8B5CF6;
  --accent-dim: rgba(139,92,246,0.15);
  --green: #10b981;
  --green-dim: rgba(16,185,129,0.15);
  --red: #ef4444;
  --red-dim: rgba(239,68,68,0.15);
  --orange: #f59e0b;
  --orange-dim: rgba(245,158,11,0.15);
  --blue: #3b82f6;
  --blue-dim: rgba(59,130,246,0.15);
}

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

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

button, a, input, select, textarea, .btn, .tap-btn, .ritual-item {
  touch-action: manipulation;
}

/* ─── Layout ─── */

.page {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 80px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.header h1 {
  font-size: 20px;
  font-weight: 700;
}

.header .date {
  color: var(--text-secondary);
  font-size: 13px;
}

/* ─── Nav Bar (bottom) ─── */

.nav-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 8px;
  transition: color 0.15s;
}

.nav-item.active { color: var(--accent); }
.nav-item svg { width: 22px; height: 22px; }

/* ─── Section ─── */

.section {
  margin-bottom: 24px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

/* ─── Cards ─── */

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

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
}

/* ─── Stat Grid ─── */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-top: 2px;
}

/* ─── Buttons ─── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  color: #fff;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
}

.btn-full {
  width: 100%;
}

.btn-green { background: var(--green); }
.btn-red { background: var(--red); }
.btn-orange { background: var(--orange); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ─── Inputs ─── */

input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
}

textarea { resize: vertical; min-height: 60px; }

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

/* ─── Tap Buttons (activity types, durations) ─── */

.tap-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.tap-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 8px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}

.tap-btn:active { transform: scale(0.95); }
.tap-btn.selected {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
}

/* ─── Ritual Checklist ─── */

.ritual-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ritual-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  transition: all 0.15s;
}

.ritual-item:active { transform: scale(0.98); }

.ritual-item.done {
  border-color: var(--green);
  background: var(--green-dim);
}

.ritual-check {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}

.ritual-item.done .ritual-check {
  background: var(--green);
  border-color: var(--green);
}

.ritual-name {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
}

.ritual-counter {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ritual-counter button {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ritual-counter button:active { transform: scale(0.9); }

.ritual-count {
  font-size: 16px;
  font-weight: 600;
  min-width: 20px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ─── Thread List (carried items) ─── */

.thread-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 6px;
}

.thread-title {
  font-size: 13px;
  font-weight: 500;
  flex: 1;
}

.thread-age {
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 2px 8px;
  border-radius: 6px;
  white-space: nowrap;
  margin-left: 10px;
}

.age-ok { background: var(--green-dim); color: var(--green); }
.age-warn { background: var(--orange-dim); color: var(--orange); }
.age-crit { background: var(--red-dim); color: var(--red); }

.thread-category {
  font-size: 11px;
  color: var(--text-muted);
}

/* ─── Badge ─── */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
}

.badge-green { background: var(--green-dim); color: var(--green); }
.badge-red { background: var(--red-dim); color: var(--red); }
.badge-orange { background: var(--orange-dim); color: var(--orange); }
.badge-blue { background: var(--blue-dim); color: var(--blue); }
.badge-purple { background: var(--accent-dim); color: var(--accent); }

/* ─── Revenue Gate ─── */

.gate-box {
  background: var(--surface);
  border: 2px solid var(--red);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.gate-box.completed {
  border-color: var(--green);
}

.gate-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--red);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.gate-box.completed .gate-label {
  color: var(--green);
}

.gate-input {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.gate-input input {
  flex: 1;
}

.gate-saved {
  font-size: 14px;
  color: var(--green);
  font-weight: 500;
}

/* ─── Activity Log List ─── */

.activity-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 6px;
}

.activity-type {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 6px;
  white-space: nowrap;
}

.activity-desc {
  flex: 1;
  font-size: 13px;
}

.activity-dur {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.activity-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  font-size: 16px;
}

.activity-delete:active { color: var(--red); }

/* Classification colors */
.cls-signal { background: var(--green-dim); color: var(--green); }
.cls-maintenance { background: var(--blue-dim); color: var(--blue); }
.cls-noise { background: var(--red-dim); color: var(--red); }

/* ─── Lap Timer ─── */

.timer-display {
  text-align: center;
  padding: 24px 16px 16px;
  margin-bottom: 16px;
}

.timer-digits {
  font-size: 56px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
  color: var(--text-muted);
  line-height: 1;
  font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
}

.timer-display.running .timer-digits {
  color: var(--accent);
}

.timer-active-type {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 8px;
  color: var(--text-muted);
}

.timer-display.running .timer-active-type {
  color: var(--green);
}

.timer-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.timer-display.running .timer-hint {
  display: none;
}

.timer-input-row {
  display: flex;
  gap: 8px;
}

.timer-input-row input {
  flex: 1;
  font-size: 16px;
  padding: 12px 14px;
}

.timer-input-row .btn {
  padding: 12px 24px;
  font-size: 15px;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-btn {
  padding: 6px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.tag-btn:active { transform: scale(0.95); }

.tag-btn.selected {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
}

.stop-btn {
  display: none;
  width: 100%;
  padding: 14px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  background: var(--red);
  color: #fff;
  margin-bottom: 16px;
  transition: all 0.15s;
}

.stop-btn:active { transform: scale(0.97); }
.stop-btn.visible { display: block; }

/* Lap list */
.lap-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 6px;
}

.lap-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lap-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 24px;
}

.lap-type-badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 6px;
  white-space: nowrap;
}

.lap-desc {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  background: none;
  border: none;
  outline: none;
  font-family: inherit;
  padding: 0;
  min-width: 0;
}

.lap-desc:focus {
  border-bottom: 1px solid var(--accent);
}

.lap-dur {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  white-space: nowrap;
}

.lap-bottom {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.lap-cls-btn {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.lap-cls-btn.active-signal { background: var(--green-dim); color: var(--green); border-color: var(--green); }
.lap-cls-btn.active-maintenance { background: var(--blue-dim); color: var(--blue); border-color: var(--blue); }
.lap-cls-btn.active-noise { background: var(--red-dim); color: var(--red); border-color: var(--red); }

.lap-spacer { flex: 1; }

.lap-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  font-size: 14px;
}
.lap-delete:active { color: var(--red); }

.lap-time-range {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ─── Ritual Strip ─── */

.ritual-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ritual-pill {
  font-size: 11px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.15s;
}

.ritual-pill:active { transform: scale(0.95); }

.ritual-pill.done {
  opacity: 1;
  border-color: var(--green);
  color: var(--green);
  background: var(--green-dim);
}

/* ─── DBRS Sliders ─── */

.slider-group {
  margin-bottom: 14px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.slider-label {
  font-size: 13px;
  font-weight: 500;
}

.slider-value {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--surface2);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

/* ─── Grove Grid ─── */

.grove-grid {
  display: grid;
  grid-template-columns: 1fr repeat(3, 60px);
  gap: 4px;
  font-size: 12px;
}

.grove-header {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  padding: 4px;
  font-weight: 600;
}

.grove-label {
  font-size: 12px;
  font-weight: 500;
  padding: 8px 4px;
  display: flex;
  align-items: center;
}

.grove-cell {
  text-align: center;
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  transition: all 0.15s;
  border: 1px solid var(--border);
  background: var(--surface);
}

.grove-cell:active { transform: scale(0.9); }
.grove-cell[data-val="1"] { background: var(--green-dim); color: var(--green); border-color: var(--green); }
.grove-cell[data-val="0"] { background: var(--orange-dim); color: var(--orange); border-color: var(--orange); }
.grove-cell[data-val="-1"] { background: var(--red-dim); color: var(--red); border-color: var(--red); }

/* ─── DBRS Total Display ─── */

.dbrs-total {
  text-align: center;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 16px;
}

.dbrs-number {
  font-size: 48px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.dbrs-max {
  font-size: 16px;
  color: var(--text-muted);
}

.dbrs-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ─── Chart ─── */

.chart-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.chart-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

canvas {
  width: 100% !important;
  height: 200px !important;
}

/* ─── Signal/Noise Bars ─── */

.ratio-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--surface2);
  overflow: hidden;
  margin-top: 6px;
  display: flex;
}

.ratio-signal { background: var(--green); height: 100%; }
.ratio-maintenance { background: var(--blue); height: 100%; }
.ratio-noise { background: var(--red); height: 100%; }

/* ─── Loading / Empty ─── */

.loading {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
}

.empty {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ─── Toast ─── */

.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transition: all 0.3s;
  z-index: 200;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success { border-color: var(--green); color: var(--green); }
.toast.error { border-color: var(--red); color: var(--red); }

/* ─── Question Groups (Truth Check) ─── */

.question-group {
  margin-bottom: 16px;
}

.question-text {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
}

.question-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* ─── Toggle ─── */

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
}

.toggle {
  width: 44px;
  height: 24px;
  border-radius: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  position: relative;
  cursor: pointer;
  transition: all 0.2s;
}

.toggle.on {
  background: var(--green);
  border-color: var(--green);
}

.toggle-knob {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: all 0.2s;
}

.toggle.on .toggle-knob {
  left: 22px;
}

/* ─── Scorecard Table ─── */

.scorecard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.scorecard-table th {
  text-align: left;
  padding: 8px 6px;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
}

.scorecard-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

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