/* ---------- Auth pages ---------- */

.auth-page {
  display: grid;
  place-items: center;
  padding: 32px 16px;
}

.auth-page::before {
  content: "";
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--stripe);
  background: linear-gradient(90deg, var(--primary) 0%, var(--primary-hover) 60%, var(--primary) 100%);
  z-index: 6;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  padding: 28px 24px 24px;
}

.auth-header { margin-bottom: 6px; }
.auth-header h1 { margin-bottom: 0; }
.auth-header p { margin-top: 0; }

.auth-intro {
  margin: 14px 0 4px;
  padding: 14px 16px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.auth-intro p { margin: 0 0 8px; line-height: 1.45; }
.auth-intro p:last-child { margin-bottom: 0; }

.auth-disclaimer {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.auth-disclaimer p { margin: 0 0 6px; }
.auth-disclaimer p:last-child { margin-bottom: 0; }

.seg {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin: 22px 0 18px;
}

.seg-btn {
  flex: 1;
  background: transparent;
  color: var(--text-muted);
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 9px;
  min-height: 38px;
}

.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.auth-form button.primary { width: 100%; margin-top: 6px; }

.callout {
  background: var(--primary-soft);
  border-left: 3px solid var(--primary);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  color: var(--text);
}

.msg {
  margin-top: 14px;
  min-height: 1.4em;
  font-size: 0.92rem;
  font-weight: 500;
}

.msg.error { color: var(--red); }
.msg.ok { color: var(--green); }

/* ---------- App shell ---------- */

.app-page {
  padding-bottom: 96px;
}

.app-page::before, .brand-stripe {
  content: "";
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--stripe);
  background: linear-gradient(90deg, var(--primary) 0%, var(--primary-hover) 60%, var(--primary) 100%);
  z-index: 7;
}

.app-header {
  position: sticky;
  top: var(--stripe);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  z-index: 5;
  gap: 14px;
}

.app-header h1 {
  font-size: 1.1rem;
  margin: 0;
  letter-spacing: -0.01em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 8px;
}

.app-main {
  padding: 18px 16px;
  display: grid;
  gap: 14px;
  max-width: 640px;
  margin: 0 auto;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 18px;
}

.card h2 {
  display: flex;
  align-items: center;
  gap: 8px;
}
.card h2::before {
  content: "";
  width: 4px;
  height: 14px;
  border-radius: 2px;
  background: var(--primary);
  display: inline-block;
}

/* ---------- Hero — instrument readout ---------- */

.hero {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 22px 20px;
  background: var(--surface-3);
  color: var(--text-on-dark);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: "ALERTNESS";
  position: absolute;
  top: 12px;
  left: 20px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: rgba(245, 239, 231, 0.55);
}

.hero::after {
  content: "";
  position: absolute;
  right: -40px;
  top: -40px;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(200, 32, 31, 0.20) 0%, transparent 70%);
  pointer-events: none;
}

.hero[data-color="green"]::after {
  background: radial-gradient(circle, rgba(31, 125, 74, 0.22) 0%, transparent 70%);
}
.hero[data-color="yellow"]::after {
  background: radial-gradient(circle, rgba(176, 115, 0, 0.22) 0%, transparent 70%);
}

.hero-circle {
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background: rgba(245, 239, 231, 0.05);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  border: 2px solid rgba(245, 239, 231, 0.10);
  position: relative;
  margin-top: 14px;
}

.hero[data-color="green"]  .hero-circle { border-color: var(--green); }
.hero[data-color="yellow"] .hero-circle { border-color: var(--yellow); }
.hero[data-color="red"]    .hero-circle { border-color: var(--red); }

.hero-num {
  font-size: 2.8rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.hero-denom {
  font-size: 0.78rem;
  color: rgba(245, 239, 231, 0.55);
  text-align: center;
  margin-top: 2px;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.hero-side { flex: 1; margin-top: 14px; }

.hero-tag {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.95rem;
}

.hero[data-color="green"]  .hero-tag { color: #6fe39a; }
.hero[data-color="yellow"] .hero-tag { color: #e6b35a; }
.hero[data-color="red"]    .hero-tag { color: #ef7878; }

.hero-kss {
  margin-top: 4px;
  color: rgba(245, 239, 231, 0.55) !important;
  font-size: 0.82rem;
}

/* ---------- Chart ---------- */

.chart-wrap {
  position: relative;
  height: 220px;
  margin: 6px 0;
}

#chart { width: 100% !important; height: 100% !important; }

/* ---------- Recommendations / lists ---------- */

.recs { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.recs li {
  background: var(--surface-2);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  border-left: 3px solid var(--primary);
}

.warnings ul { padding-left: 20px; margin: 4px 0; }
.warnings li { color: var(--text-muted); font-size: 0.9rem; }

/* ---------- Quick-log buttons ---------- */

.quick-log {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.ql {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-weight: 600;
  font-size: 0.92rem;
  padding: 16px 12px;
  border-radius: var(--radius);
  text-align: center;
  transition: all 0.12s ease;
}

.ql:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--surface);
}

/* ---------- Bottom tab bar ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom)) 4px;
  z-index: 10;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.04);
}

.tabbar .tab {
  background: transparent;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  min-height: 44px;
  padding: 6px 4px;
  display: grid;
  place-items: center;
  text-align: center;
  text-decoration: none;
  position: relative;
  letter-spacing: 0.02em;
}

.tabbar .tab.active {
  color: var(--primary);
  font-weight: 700;
}

.tabbar .tab.active::before {
  content: "";
  position: absolute;
  top: -7px;
  left: 18%;
  right: 18%;
  height: 3px;
  background: var(--primary);
  border-radius: 0 0 3px 3px;
}

/* ---------- Dialog ---------- */

dialog.dlg {
  border: none;
  border-radius: var(--radius);
  padding: 22px;
  background: var(--surface);
  color: var(--text);
  max-width: 460px;
  width: calc(100% - 32px);
  box-shadow: var(--shadow-md);
  border-top: 4px solid var(--primary);
}

dialog.dlg::backdrop {
  background: rgba(28, 26, 24, 0.55);
  backdrop-filter: blur(2px);
}

dialog.dlg h3 { margin-bottom: 12px; }

.dlg-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ---------- Routine picker ---------- */

.routine-grid {
  display: grid;
  gap: 8px;
  margin: 10px 0;
}
.routine-btn {
  width: 100%;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: all 0.12s ease;
}
.routine-btn:not(:disabled):hover {
  border-color: var(--primary);
  background: var(--surface);
  color: var(--primary);
}
.routine-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.routine-btn .routine-name {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.01em;
}
.routine-btn .routine-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
}
.routine-btn .routine-count {
  background: var(--primary);
  color: var(--primary-text);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  min-width: 24px;
  text-align: center;
}
.routine-btn:disabled .routine-count {
  background: var(--border);
  color: var(--text-muted);
}
.dlg-sep {
  margin: 14px 0 10px;
  border: none;
  border-top: 1px solid var(--border);
}
.wide-btn { width: 100%; }

/* ---------- Quality slider field ---------- */

.quality-field {
  margin: 12px 0;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.quality-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.quality-label {
  margin: 0;
  font-weight: 700;
  font-size: 0.92rem;
}
.quality-readout {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.quality-num {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
  margin-right: 2px;
}
.quality-num.tier-good { color: var(--green); }
.quality-num.tier-okay { color: var(--yellow); }
.quality-num.tier-bad { color: var(--red); }
.quality-scenario {
  margin: 8px 0 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
  min-height: 2.4em;
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--red) 0%, var(--yellow) 50%, var(--green) 100%);
  outline: none;
  padding: 0;
  margin: 4px 0;
  border: none;
  min-height: 6px;
}
input[type="range"]:focus {
  box-shadow: 0 0 0 3px rgba(200, 32, 31, 0.18);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--primary);
  box-shadow: var(--shadow);
  cursor: grab;
}
input[type="range"]::-webkit-slider-thumb:active { cursor: grabbing; }
input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--primary);
  cursor: grab;
}
