/*
 * Obstetric Decision Tools — Shared Design System
 * All tools reference this file for tokens, typography and common components.
 */

/* ─── Design Tokens ─────────────────────────────────────────────────────── */
:root {
  /* Surfaces */
  --ot-bg: #f8fafc;
  --ot-surface: #ffffff;
  --ot-surface-2: #f1f5f9;
  --ot-surface-3: #e2e8f0;

  /* Borders */
  --ot-border: #e2e8f0;
  --ot-border-strong: #cbd5e1;

  /* Text */
  --ot-text: #0f172a;
  --ot-text-muted: #64748b;
  --ot-text-soft: #94a3b8;

  /* Brand */
  --ot-primary: #0f172a;
  --ot-primary-fg: #ffffff;
  --ot-accent: #2563eb;
  --ot-accent-soft: #eff6ff;

  /* Semantic */
  --ot-success: #16a34a;
  --ot-success-soft: #f0fdf4;
  --ot-success-border: #bbf7d0;
  --ot-warning: #d97706;
  --ot-warning-soft: #fffbeb;
  --ot-warning-border: #fde68a;
  --ot-danger: #dc2626;
  --ot-danger-soft: #fef2f2;
  --ot-danger-border: #fecaca;

  /* Layout */
  --ot-max-w: 520px;
  --ot-radius-sm: 8px;
  --ot-radius: 12px;
  --ot-radius-lg: 16px;
  --ot-radius-xl: 20px;

  /* Shadows */
  --ot-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --ot-shadow:
    0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);

  /* Typography */
  --ot-font:
    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui,
    sans-serif;
}

/* ─── Reset ─────────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  margin: 0;
  padding: 0;
}
button,
input,
select,
textarea {
  font-family: inherit;
}

/* ─── Base ───────────────────────────────────────────────────────────────── */
body {
  font-family: var(--ot-font);
  font-size: 15px;
  line-height: 1.5;
  background: var(--ot-bg);
  color: var(--ot-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ─── App shell ──────────────────────────────────────────────────────────── */
.ot-app {
  max-width: var(--ot-max-w);
  margin: 0 auto;
  background: var(--ot-surface);
  min-height: 100vh;
  position: relative;
}

@media (min-width: 552px) {
  body {
    padding: 24px 16px;
  }
  .ot-app {
    border-radius: var(--ot-radius-xl);
    min-height: calc(100vh - 48px);
    overflow: hidden;
    box-shadow:
      0 0 0 1px var(--ot-border),
      0 8px 24px rgba(15, 23, 42, 0.06);
  }
}

/* ─── Topbar ─────────────────────────────────────────────────────────────── */
.ot-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--ot-border);
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Back / home button */
.ot-back-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  background: var(--ot-surface-2);
  border: none;
  border-radius: 50%;
  color: var(--ot-text-muted);
  text-decoration: none;
  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.1s;
  -webkit-appearance: none;
  appearance: none;
}
.ot-back-btn:active {
  background: var(--ot-surface-3);
  transform: scale(0.93);
}
.ot-back-btn svg {
  width: 18px;
  height: 18px;
  pointer-events: none;
}

.ot-topbar-info {
  flex: 1;
  min-width: 0;
}

.ot-topbar-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--ot-text);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ot-topbar-sub {
  font-size: 12px;
  color: var(--ot-text-muted);
  margin-top: 1px;
}

/* Generic action button in topbar (e.g. reset) */
.ot-topbar-action {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid var(--ot-border);
  background: var(--ot-surface);
  color: var(--ot-text-muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.ot-topbar-action:active {
  transform: scale(0.93);
  background: var(--ot-surface-2);
}
.ot-topbar-action svg {
  width: 16px;
  height: 16px;
}

/* ─── Progress bar ───────────────────────────────────────────────────────── */
.ot-progress {
  padding: 12px 20px 0;
}

.ot-progress-bar {
  height: 3px;
  background: var(--ot-surface-3);
  border-radius: 999px;
  overflow: hidden;
}

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

.ot-progress-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 12px;
  color: var(--ot-text-muted);
}

/* ─── Main content area ──────────────────────────────────────────────────── */
.ot-main {
  padding: 8px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ─── Sections (stepwise tools) ──────────────────────────────────────────── */
.ot-section {
  margin-top: 20px;
}
.ot-section:first-child {
  margin-top: 0;
}

.ot-section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.ot-section-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ot-primary);
  color: var(--ot-primary-fg);
  font-size: 11px;
  font-weight: 600;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.ot-section-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

.ot-section-desc {
  font-size: 13px;
  color: var(--ot-text-muted);
  margin: -4px 0 14px 32px;
}

/* ─── Field card ─────────────────────────────────────────────────────────── */
.ot-field {
  background: var(--ot-surface);
  border: 1px solid var(--ot-border);
  border-radius: var(--ot-radius);
  padding: 14px 16px;
  box-shadow: var(--ot-shadow-sm);
  transition: border-color 0.2s;
  margin-bottom: 10px;
}
.ot-field:last-child {
  margin-bottom: 0;
}
.ot-field.answered {
  border-color: var(--ot-border-strong);
}

.ot-field-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.ot-field-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--ot-text);
  letter-spacing: -0.005em;
}

.ot-field-unit {
  font-size: 12px;
  color: var(--ot-text-soft);
  font-weight: 400;
}

.ot-field-hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--ot-text-muted);
}

.ot-field-status {
  font-size: 11px;
  color: var(--ot-success);
  font-weight: 500;
  display: none;
  align-items: center;
  gap: 3px;
}
.ot-field.answered .ot-field-status {
  display: inline-flex;
}
.ot-field-status svg {
  width: 12px;
  height: 12px;
}

/* ─── Segmented control ──────────────────────────────────────────────────── */
.ot-seg {
  display: flex;
  background: var(--ot-surface-2);
  padding: 3px;
  border-radius: calc(var(--ot-radius-sm) + 2px);
  gap: 2px;
}

.ot-seg-btn {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--ot-text-muted);
  font-family: inherit;
  font-size: 14px;
  font-weight: 400;
  padding: 8px 6px;
  border-radius: var(--ot-radius-sm);
  cursor: pointer;
  min-height: 36px;
  line-height: 1.2;
  touch-action: manipulation;
  user-select: none;
  transition: all 0.15s;
  text-align: center;
}
.ot-seg-btn:active {
  transform: scale(0.96);
}
.ot-seg-btn.active {
  background: var(--ot-surface);
  color: var(--ot-text);
  font-weight: 500;
  box-shadow:
    0 1px 3px rgba(15, 23, 42, 0.08),
    0 0 0 0.5px rgba(15, 23, 42, 0.04);
}
.ot-seg-btn:focus-visible {
  outline: 2px solid var(--ot-accent);
  outline-offset: 2px;
}

/* ─── Choice buttons ─────────────────────────────────────────────────────── */
.ot-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ot-choices-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.ot-choices-row.cols-2 {
  grid-template-columns: 1fr 1fr;
}

.ot-choice {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  background: var(--ot-surface);
  border: 1.5px solid var(--ot-border);
  border-radius: var(--ot-radius);
  padding: 13px 14px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ot-text);
  text-align: left;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 50px;
  touch-action: manipulation;
  user-select: none;
}
.ot-choice:active {
  transform: scale(0.98);
  background: var(--ot-surface-2);
}
.ot-choice.selected {
  border-color: var(--ot-primary);
  background: var(--ot-surface-2);
}

.ot-choices-row .ot-choice {
  flex-direction: column;
  text-align: center;
  padding: 11px 8px;
  gap: 2px;
  min-height: 52px;
  justify-content: center;
}
.ot-choices-row .ot-choice.selected {
  background: var(--ot-primary);
  color: var(--ot-primary-fg);
  border-color: var(--ot-primary);
}

.ot-choice-radio {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--ot-border-strong);
  flex-shrink: 0;
  display: grid;
  place-items: center;
  transition: all 0.15s;
}
.ot-choice.selected .ot-choice-radio {
  border-color: var(--ot-primary);
  background: var(--ot-primary);
}
.ot-choice.selected .ot-choice-radio::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: white;
}
.ot-choices-row .ot-choice .ot-choice-radio {
  display: none;
}

.ot-choice-text {
  flex: 1;
  min-width: 0;
}
.ot-choice-main {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
}
.ot-choice-sub {
  display: block;
  font-size: 12px;
  color: var(--ot-text-muted);
  font-weight: 400;
  margin-top: 2px;
}
.ot-choices-row .ot-choice.selected .ot-choice-sub {
  color: rgba(255, 255, 255, 0.7);
}
.ot-choice:focus-visible {
  outline: 2px solid var(--ot-accent);
  outline-offset: 2px;
}

/* ─── Info note ──────────────────────────────────────────────────────────── */
.ot-info-note {
  background: var(--ot-accent-soft);
  border: 1px solid #dbeafe;
  border-radius: var(--ot-radius-sm);
  padding: 10px 12px;
  margin-top: 10px;
  font-size: 12px;
  color: #1e40af;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  line-height: 1.4;
}
.ot-info-note svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ─── Info banner (prominent) ────────────────────────────────────────────── */
.ot-info-banner {
  background: var(--ot-surface);
  border: 1px solid var(--ot-border);
  border-radius: var(--ot-radius);
  padding: 14px 16px;
  display: flex;
  gap: 12px;
  align-items: center;
  box-shadow: var(--ot-shadow-sm);
}
.ot-info-banner-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--ot-accent-soft);
  color: var(--ot-accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ot-info-banner-icon svg {
  width: 18px;
  height: 18px;
}
.ot-info-banner-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 2px;
}
.ot-info-banner-sub {
  font-size: 13px;
  color: var(--ot-text-muted);
  margin: 0;
}

/* ─── Result — banner style (stepwise tools) ─────────────────────────────── */
.ot-result {
  border-radius: var(--ot-radius-lg);
  overflow: hidden;
  border: 1.5px solid var(--ot-border);
  background: var(--ot-surface);
  animation: ot-fade-up 0.25s ease both;
}
.ot-result.empty {
  padding: 28px 20px;
  text-align: center;
  color: var(--ot-text-muted);
  background: var(--ot-surface-2);
  border-style: dashed;
}
.ot-result.empty svg {
  width: 36px;
  height: 36px;
  margin-bottom: 10px;
  opacity: 0.45;
}
.ot-result.empty p {
  margin: 0;
  font-size: 14px;
}
.ot-result.empty p strong {
  display: block;
  color: var(--ot-text);
  margin-bottom: 4px;
}

.ot-result-banner {
  padding: 18px 20px;
  color: white;
  background: var(--ot-primary);
}
.ot-result-banner.success {
  background: var(--ot-success);
}
.ot-result-banner.warning {
  background: var(--ot-warning);
}
.ot-result-banner.danger {
  background: var(--ot-danger);
}
.ot-result-banner.info {
  background: var(--ot-accent);
}
.ot-result-banner.intermediate {
  background: #475569;
}

.ot-result-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: grid;
  place-items: center;
  margin-bottom: 12px;
}
.ot-result-icon svg {
  width: 22px;
  height: 22px;
}

.ot-result-eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
  opacity: 0.8;
  margin-bottom: 3px;
}

.ot-result-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.2;
}

.ot-result-body {
  padding: 18px 20px;
}

.ot-result-section + .ot-result-section {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--ot-border);
}

.ot-result-section h4 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ot-text-muted);
  margin: 0 0 12px;
}

.ot-result-desc {
  font-size: 14px;
  color: var(--ot-text);
  margin: 0;
  line-height: 1.5;
}

/* ─── Result — flat style (simple lookup tools) ──────────────────────────── */
.ot-result-flat {
  background: var(--ot-surface);
  border: 1px solid var(--ot-border);
  border-radius: var(--ot-radius);
  padding: 16px;
  box-shadow: var(--ot-shadow-sm);
  transition:
    background 0.25s,
    border-color 0.25s;
  animation: ot-fade-up 0.25s ease both;
}
.ot-result-flat.success {
  background: var(--ot-success-soft);
  border-color: var(--ot-success-border);
}
.ot-result-flat.warning {
  background: var(--ot-warning-soft);
  border-color: var(--ot-warning-border);
}
.ot-result-flat.danger {
  background: var(--ot-danger-soft);
  border-color: var(--ot-danger-border);
}

.ot-result-flat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.ot-result-flat-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: var(--ot-surface-3);
  color: var(--ot-text-muted);
}
.ot-result-flat.success .ot-result-flat-icon {
  background: var(--ot-success);
  color: white;
}
.ot-result-flat.warning .ot-result-flat-icon {
  background: var(--ot-warning);
  color: white;
}
.ot-result-flat.danger .ot-result-flat-icon {
  background: var(--ot-danger);
  color: white;
}
.ot-result-flat-icon svg {
  width: 18px;
  height: 18px;
}

.ot-result-flat-tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ot-text-muted);
}
.ot-result-flat.success .ot-result-flat-tag {
  color: var(--ot-success);
}
.ot-result-flat.warning .ot-result-flat-tag {
  color: var(--ot-warning);
}
.ot-result-flat.danger .ot-result-flat-tag {
  color: var(--ot-danger);
}

.ot-result-flat-text {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--ot-text);
  margin: 0 0 10px;
}

.ot-result-flat-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ot-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--ot-text-muted);
  border: 1px solid var(--ot-border-strong);
}
.ot-result-flat.success .ot-chip {
  color: var(--ot-success);
  border-color: rgba(22, 163, 74, 0.25);
}
.ot-result-flat.warning .ot-chip {
  color: var(--ot-warning);
  border-color: rgba(217, 119, 6, 0.25);
}
.ot-result-flat.danger .ot-chip {
  color: var(--ot-danger);
  border-color: rgba(220, 38, 38, 0.25);
}

/* ─── Treatment list ─────────────────────────────────────────────────────── */
.ot-treat-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ot-treat-item {
  padding: 12px 14px;
  background: var(--ot-surface-2);
  border: 1px solid var(--ot-border);
  border-radius: var(--ot-radius-sm);
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.ot-treat-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ot-primary);
  color: var(--ot-primary-fg);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  margin-top: 1px;
}

.ot-treat-text {
  flex: 1;
  min-width: 0;
}
.ot-treat-name {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
  line-height: 1.3;
}
.ot-treat-detail {
  font-size: 12px;
  color: var(--ot-text-muted);
  margin: 3px 0 0;
  line-height: 1.4;
}

/* ─── Reset button ───────────────────────────────────────────────────────── */
.ot-btn-reset {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  padding: 14px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--ot-text-muted);
  background: var(--ot-surface);
  border: 1px solid var(--ot-border);
  border-radius: var(--ot-radius-sm);
  cursor: pointer;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.15s;
  touch-action: manipulation;
}
.ot-btn-reset:active {
  background: var(--ot-surface-2);
  transform: scale(0.99);
}
.ot-btn-reset svg {
  width: 16px;
  height: 16px;
}

/* ─── About section ──────────────────────────────────────────────────────── */
.ot-about {
  border: 1px solid var(--ot-border);
  border-radius: var(--ot-radius);
  background: var(--ot-surface);
  margin: 16px 0 0;
  overflow: hidden;
}

.ot-about summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
  list-style: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--ot-text-muted);
  transition: background 0.15s;
}
.ot-about summary::-webkit-details-marker { display: none; }
.ot-about summary:active { background: var(--ot-surface-2); }

.ot-about-chevron {
  margin-left: auto;
  flex-shrink: 0;
  color: var(--ot-text-soft);
  transition: transform 0.2s;
}
.ot-about[open] .ot-about-chevron {
  transform: rotate(180deg);
}
.ot-about-chevron svg { width: 16px; height: 16px; display: block; }

.ot-about-body {
  padding: 0 16px 18px;
  border-top: 1px solid var(--ot-border);
}

.ot-about-section {
  margin-top: 16px;
}
.ot-about-section:first-child { margin-top: 14px; }

.ot-about-section h3 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ot-text-soft);
  margin: 0 0 6px;
}

.ot-about-section p,
.ot-about-section li {
  font-size: 13px;
  color: var(--ot-text-muted);
  line-height: 1.55;
  margin: 0 0 4px;
}
.ot-about-section ul {
  margin: 0;
  padding-left: 16px;
}
.ot-about-section li { margin: 0 0 3px; }

.ot-about-cite {
  font-size: 12px;
  color: var(--ot-text-soft);
  line-height: 1.5;
  padding: 8px 10px;
  background: var(--ot-surface-2);
  border-radius: var(--ot-radius-sm);
  margin-top: 6px;
}
.ot-about-cite + .ot-about-cite { margin-top: 4px; }

/* ─── Disclaimer ─────────────────────────────────────────────────────────── */
.ot-disclaimer {
  margin: 0 16px 20px;
  padding: 12px 14px;
  background: var(--ot-surface-2);
  border: 1px solid var(--ot-border);
  border-radius: var(--ot-radius-sm);
  font-size: 12px;
  color: var(--ot-text-muted);
  line-height: 1.5;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.ot-disclaimer svg {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  margin-top: 1px;
}

/* ─── Footer ─────────────────────────────────────────────────────────────── */
.ot-footer {
  padding: 18px 20px;
  border-top: 1px solid var(--ot-border);
  font-size: 11px;
  color: var(--ot-text-soft);
  line-height: 1.5;
  text-align: center;
}
.ot-footer p {
  margin: 0 0 3px;
}

/* ─── Animations ─────────────────────────────────────────────────────────── */
@keyframes ot-fade-up {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ─── Utility ────────────────────────────────────────────────────────────── */
.hidden {
  display: none !important;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
