/* === Design Tokens === */
:root {
  --color-accent:          #1557b0;
  --color-accent-bg:       #e8f0fe;
  --color-mild:            #2e7d32;
  --color-moderate:        #b45309;
  --color-severe:          #b91c1c;
  --color-text:            #1a1a1a;
  --color-text-secondary:  #555555;
  --color-text-muted:      #767676;
  --color-border:          #d1d5db;
  --color-surface:         #f5f7fa;
  --color-white:           #ffffff;

  --radius-sm:   8px;
  --radius-md:   12px;
  --radius-pill: 24px;

  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  16px;
  --space-lg:  24px;
  --space-xl:  32px;

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --tab-bar-height: 60px;
  --header-height: 52px;
}

/* === Base font size === */
html { font-size: 18px; }

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

body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-white);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

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

input, textarea {
  font-family: inherit;
  font-size: 1rem;
}

/* === App Layout === */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* override with dvh where supported (Safari 15.4+) */
  max-width: 480px;
  margin: 0 auto;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-md);
  height: var(--header-height);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.app-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-accent);
}

.lang-toggle {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-accent);
  padding: var(--space-xs) var(--space-sm);
  border: 1.5px solid var(--color-accent);
  border-radius: var(--radius-pill);
  min-width: 44px;
  min-height: 36px;
}

.lang-toggle:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

/* === Views === */
#views {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: var(--space-md);
  -webkit-overflow-scrolling: touch;
}

.view[hidden] { display: none; }
.view.active  { display: block; }

/* === Tab Bar === */
.tab-bar {
  display: flex;
  height: var(--tab-bar-height);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--color-text-muted);
  min-height: 44px;
  transition: color 0.15s;
}

.tab.active,
.tab[aria-current="page"] {
  color: var(--color-accent);
  font-weight: 700;
}

.tab:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: -3px;
}

.tab span:first-child { display: flex; align-items: center; justify-content: center; }

/* === Severity Pills (Mild / Moderate / Severe) === */
.pill-group {
  display: flex;
  gap: var(--space-sm);
}

.pill {
  flex: 1;
  padding: 10px 0;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  background: var(--color-surface);
  min-height: 44px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.pill:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

.pill[aria-pressed="true"].pill--mild {
  background: var(--color-mild);
  color: var(--color-white);
  border-color: var(--color-mild);
}

.pill[aria-pressed="true"].pill--moderate {
  background: var(--color-moderate);
  color: var(--color-white);
  border-color: var(--color-moderate);
}

.pill[aria-pressed="true"].pill--severe {
  background: var(--color-severe);
  color: var(--color-white);
  border-color: var(--color-severe);
}

.pill[aria-pressed="true"].pill--none {
  background: var(--color-text-secondary);
  color: var(--color-white);
  border-color: var(--color-text-secondary);
}

/* === Severity Badge (history list) === */
.severity-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.severity-badge--mild     { background: #dcfce7; color: var(--color-mild); }
.severity-badge--moderate { background: #fef3c7; color: var(--color-moderate); }
.severity-badge--severe   { background: #fee2e2; color: var(--color-severe); }
.severity-badge--none     { background: var(--color-surface); color: var(--color-text-muted); }

/* Amber dot + text shown when dizziness severity has not been recorded */
.episode-needs-details {
  color: var(--color-moderate);
  font-weight: 600;
}
.episode-needs-details::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--color-moderate);
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
  margin-bottom: 1px;
}

/* === Buttons === */
.btn-primary {
  display: block;
  width: 100%;
  padding: var(--space-md);
  background: var(--color-accent);
  color: var(--color-white);
  border-radius: var(--radius-md);
  font-size: 1.1rem;
  font-weight: 700;
  min-height: 52px;
  transition: background 0.15s;
}

.btn-primary:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

.btn-primary:active { background: #0e3f7a; }

/* Circular primary action button (home screen) */
.btn-log {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: var(--color-accent);
  color: var(--color-white);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  margin: 0 auto var(--space-xl);
  box-shadow: 0 6px 16px rgba(21, 87, 176, 0.5), 0 12px 40px rgba(21, 87, 176, 0.3);
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
}


.btn-log:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 4px;
}
.btn-log:active {
  background: #0e3f7a;
  box-shadow: 0 2px 6px rgba(21, 87, 176, 0.3);
  transform: scale(0.92);
}

/* === Form Fields === */
.field {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-md);
  min-height: 44px;
}

.field-label {
  font-size: 0.9rem;
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.field-input {
  padding: var(--space-xs) var(--space-sm);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--color-text);
  background: var(--color-surface);
  text-align: right;
  width: 120px;
}

.field-input:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 1px;
}

textarea.field-input {
  width: 100%;
  height: 80px;
  resize: none;
  text-align: left;
  line-height: 1.5;
}

/* === Section Label === */
.section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-sm);
}

/* === Divider === */
.divider {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin: var(--space-md) 0;
  color: var(--color-text-muted);
  font-size: 0.8rem;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

/* Brief highlight when a new episode card is created */
@keyframes episode-highlight {
  0%, 35% { background: #bfdbfe; transform: scaleY(1.04); transform-origin: top; }
  50%     { transform: scaleY(1); }
  100%    { background: transparent; }
}

.episode-card--new {
  animation: episode-highlight 2.5s ease-out forwards;
}

/* === Episode Card (home + history list) === */
.episode-card {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  border-bottom: 1px solid var(--color-border);
  min-height: 64px;
  cursor: pointer;
  background: none;
  width: 100%;
  text-align: left;
}

.episode-card:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: -3px;
}

.episode-card-body { flex: 1; overflow: hidden; }

.episode-card-date {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text);
}

.episode-card-summary {
  display: block;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.episode-card-arrow {
  color: var(--color-border);
  font-size: 1.2rem;
  flex-shrink: 0;
}

/* === Log Modal === */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
}

.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.modal-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  background: var(--color-white);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--space-lg) + env(safe-area-inset-bottom));
}

.modal-handle {
  width: 40px;
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  margin: var(--space-sm) auto var(--space-md);
}

/* === History Chart === */
.chart-container {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-sm);
}

.chart-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text);
}

.chart-period-btns {
  display: flex;
  gap: var(--space-xs);
}

.chart-period-btn {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  color: var(--color-text-muted);
  min-height: 28px;
}

.chart-period-btn.active {
  background: var(--color-accent-bg);
  color: var(--color-accent);
}

.chart-period-btn:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

/* === Doctor Summary === */
.doctor-controls {
  position: sticky;
  top: 0;
  background: var(--color-white);
  padding: var(--space-sm) 0 var(--space-md);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-sm);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-md);
  z-index: 10;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.stat-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  text-align: center;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--color-accent);
}

.stat-label {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-bottom: var(--space-md);
}

.summary-table th {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  text-align: left;
  padding: var(--space-xs) var(--space-xs);
  border-bottom: 2px solid var(--color-border);
}

.summary-table td {
  padding: var(--space-sm) var(--space-xs);
  border-bottom: 1px solid var(--color-surface);
  vertical-align: top;
}

/* === Empty state === */
.empty-state {
  text-align: center;
  padding: var(--space-xl) var(--space-md);
  color: var(--color-text-muted);
  font-size: 0.9rem;
  line-height: 2;
}

/* === Print styles === */
@media print {
  .app-header, .tab-bar, .doctor-controls { display: none !important; }
  #views { overflow: visible; }
  .view { position: static; overflow: visible; padding: 0; }
  #view-doctor { display: block !important; }
  .summary-table td, .summary-table th { border-color: #ccc; }
  .modal { display: none !important; }
}
