/* === Design Tokens === */
:root {
  --color-accent:          #0f766e;
  --color-accent-dark:     #0d5c56;
  --color-accent-rgb:      15, 118, 110; /* keep in sync with --color-accent; used for rgba() shadows */
  --color-accent-bg:       #ccfbf1;
  --color-mild:            #2e7d32;
  --color-moderate:        #b45309;
  --color-severe:          #b91c1c;
  --color-mild-bg:         #dcfce7;
  --color-moderate-bg:     #fef3c7;
  --color-severe-bg:       #fee2e2;
  --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;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* upward shadow — strip sits above scrolling content */
}

.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;
  /* expand total height by safe-area-inset-bottom so the icon content area
     stays at --tab-bar-height in PWA mode (otherwise padding eats into it) */
  height: calc(var(--tab-bar-height) + env(safe-area-inset-bottom));
  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.8rem;
  font-weight: 500;
  color: var(--color-text-muted);
  min-height: 44px;
  transition: color 0.15s;
  text-decoration: none; /* <a> elements have underline by default */
}

.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; }

/* === Loudness 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);
}

/* === Loudness Badge (history list) === */
.loudness-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.8rem;
  font-weight: 700;
  flex-shrink: 0;
}

.loudness-badge--mild     { background: var(--color-mild-bg); color: var(--color-mild); }
.loudness-badge--moderate { background: var(--color-moderate-bg); color: var(--color-moderate); }
.loudness-badge--severe   { background: var(--color-severe-bg); color: var(--color-severe); }
.loudness-badge--unset     { background: var(--color-surface); color: var(--color-text-muted); }

/* Amber dot + text shown when loudness has not been recorded */
.entry-needs-details {
  color: var(--color-moderate);
  font-weight: 600;
}
.entry-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: var(--color-accent-dark); }

/* 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(var(--color-accent-rgb), 0.5), 0 12px 40px rgba(var(--color-accent-rgb), 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: var(--color-accent-dark);
  box-shadow: 0 2px 6px rgba(var(--color-accent-rgb), 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: 1rem;
  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: 1rem;
  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.8rem;
  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);
}

/* === Entry Card (home + history list) === */
.entry-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;
}

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

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

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

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

.entry-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);
}

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

/* === Pressure Strip === */
.pressure-strip {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 0 var(--space-md);
  height: var(--tab-bar-height);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -4px 8px rgba(0, 0, 0, 0.1); /* upward shadow — strip sits above scrolling content */
  flex-shrink: 0;
  background: var(--color-white);
}

.pressure-strip[hidden] { display: none; }

.pressure-strip-chart {
  flex: 1;
  align-self: stretch; /* fill full strip height so dividers can span it */
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  position: relative;
}

.pressure-day-divider {
  position: absolute;
  top: 6px;    /* equal gap from strip top/bottom border */
  bottom: 6px;
  width: 1px;
  background: var(--color-border);
  pointer-events: none;
}

@keyframes pressure-pulse {
  0%, 100% { opacity: 0.25; }
  50%       { opacity: 0.7; }
}

.pressure-placeholder {
  height: 28px;
  display: flex;
  align-items: center;
}

.pressure-placeholder-line {
  width: 100%;
  height: 2px;
  background: var(--color-border);
  border-radius: 1px;
  animation: pressure-pulse 1.5s ease-in-out infinite;
}

.pressure-strip-days {
  display: flex;
}

.pressure-strip-day {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  text-align: center;
  flex: 1;
}

.pressure-strip-value {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  white-space: nowrap;
  min-width: 58px;
}

.pressure-sparkline {
  display: block;
  width: 100%;   /* fill chart width in column flex context */
  height: 32px;
  flex-shrink: 0; /* don't grow; explicit height takes effect */
  overflow: visible;
  position: relative; /* participate in stacking order so it paints above the absolute-positioned day dividers */
}

/* === See More Link (home page) === */
.see-more-link {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: var(--space-sm);
  padding: var(--space-sm);
  min-height: 44px; /* touch target */
  font-size: 0.85rem;
  color: var(--color-text-muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
}

.see-more-link:hover {
  color: var(--color-text-secondary);
  text-decoration: underline;
}

.see-more-link:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
  color: var(--color-text-secondary);
}

/* Active state for pills that have no colour modifier (period / character / pitch / location / pulsatile).
   The more specific .pill[aria-pressed="true"].pill--mild|moderate|severe rules still win for loudness pills. */
.pill[aria-pressed="true"] { background: var(--color-accent); color: var(--color-white); border-color: var(--color-accent); }

.btn-danger {
  display: block; width: 100%; margin-top: 16px; padding: 12px;
  color: var(--color-severe); font-weight: 600; background: none;
  border: 1.5px solid var(--color-severe); border-radius: var(--radius-md);
}

.bar-chart { width: 100%; height: 140px; margin: 8px 0 20px; display: block; }

@media print {
  .tab-bar, .app-header, .pressure-strip, #doctor-print, .pill-group { display: none !important; }
  #view-doctor { display: block !important; }
}

.doctor-summary { margin: 16px 0; line-height: 1.6; }
.doctor-summary p { margin: 6px 0; }

/* "Different from usual?" collapse. Layout lives here (not inline) so the `hidden`
   attribute actually hides it — an inline display: declaration would override [hidden]. */
.optional-section { display: flex; flex-direction: column; padding-top: 12px; }
.optional-section[hidden] { display: none; }
