/* ==========================================================================
   CaraHealth Main Application Stylesheet
   Designed for Clarity, Elegance, and Comfort
   ========================================================================== */

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

html {
  font-size: var(--font-base);
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-family-body);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: var(--leading-normal);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* Accessibility Focus States */
:focus-visible {
  outline: 3px solid var(--border-focus);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

/* Skip link for keyboard accessibility */
.skip-link {
  position: absolute;
  top: -60px;
  left: 16px;
  background: var(--brand-primary);
  color: #fff;
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-sm);
  z-index: 9999;
  font-weight: 600;
  transition: top var(--transition-fast);
  text-decoration: none;
}
.skip-link:focus {
  top: 16px;
}

/* App Container */
.app-container {
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 var(--space-md) var(--space-3xl);
  width: 100%;
}

/* ==========================================================================
   Header & Accessibility Toolbar
   ========================================================================== */
.site-header {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: var(--space-lg) var(--space-md);
  margin-bottom: var(--space-xl);
  box-shadow: var(--shadow-sm);
  transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

.header-inner {
  max-width: 1140px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-lg);
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  text-decoration: none;
}

.brand-icon {
  width: 52px;
  height: 52px;
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.brand-icon svg {
  width: 30px;
  height: 30px;
  fill: #ffffff;
  stroke: none;
  /* Subtle pulse animation for warmth */
  animation: heartbeat 2.8s ease-in-out infinite;
}

@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  14%       { transform: scale(1.12); }
  28%       { transform: scale(1); }
  42%       { transform: scale(1.08); }
  56%       { transform: scale(1); }
}

.brand-text h1 {
  font-family: var(--font-family-display);
  font-size: var(--font-2xl);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: var(--leading-tight);
}

.brand-text p {
  font-size: var(--font-sm);
  color: var(--text-secondary);
  font-weight: 500;
}

/* Accessibility Control Bar */
.accessibility-bar {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  align-items: center;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
}

.control-group-label {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0 var(--space-xs);
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-ctrl {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-family-body);
  font-size: var(--font-md);
  font-weight: 600;
  min-height: 40px;
  min-width: 42px;
  padding: 0 var(--space-sm);
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.btn-ctrl:hover {
  background-color: var(--bg-surface);
  color: var(--text-primary);
}

.btn-ctrl.is-active {
  background-color: var(--brand-primary);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

.btn-icon-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 0 var(--space-md);
  min-height: 44px;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  color: var(--text-primary);
  font-size: var(--font-md);
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
}

.btn-icon-label:hover {
  background-color: var(--bg-accent-soft);
  border-color: var(--brand-primary);
}

.btn-icon-label svg {
  width: 20px;
  height: 20px;
}

/* ==========================================================================
   Auth Zone — Sign In / User Chip
   ========================================================================== */
.auth-zone {
  display: flex;
  align-items: center;
}

/* Sign-In Button */
.btn-sign-in {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 0 var(--space-md);
  min-height: 44px;
  background-color: var(--bg-surface);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  color: var(--text-primary);
  font-family: var(--font-family-body);
  font-size: var(--font-md);
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
  white-space: nowrap;
}

.btn-sign-in:hover {
  border-color: var(--brand-primary);
  background-color: var(--bg-accent-soft);
  box-shadow: 0 2px 8px rgba(var(--brand-primary-rgb, 224, 102, 102), 0.15);
}

/* User Chip (signed-in state) */
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 4px 8px 4px 4px;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  transition: var(--transition-fast);
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid var(--brand-primary);
}

.user-name {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-primary);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-sign-out {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: 50%;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
  flex-shrink: 0;
  margin-left: 2px;
}

.btn-sign-out:hover {
  background-color: var(--bg-surface);
  border-color: var(--brand-primary);
  color: var(--brand-primary);
}

/* Data sync indicator in toast */
.toast-sync {
  background-color: var(--brand-primary);
  color: #fff;
}

/* ==========================================================================
   Main Navigation Tabs
   ========================================================================== */
.main-nav {
  display: flex;
  gap: var(--space-xs);
  border-bottom: 2px solid var(--border-subtle);
  margin-bottom: var(--space-xl);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.main-nav::-webkit-scrollbar {
  display: none;
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-md) var(--space-lg);
  font-family: var(--font-family-body);
  font-size: var(--font-lg);
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-bottom: 4px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  min-height: var(--min-touch-size);
  transition: var(--transition-fast);
}

.nav-tab:hover {
  color: var(--brand-primary);
  background-color: var(--bg-subtle);
  border-top-left-radius: var(--radius-md);
  border-top-right-radius: var(--radius-md);
}

.nav-tab.is-active {
  color: var(--brand-primary);
  border-bottom-color: var(--brand-primary);
}

.nav-tab svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
}

.tab-label-full {
  display: inline;
}

.tab-label-mobile {
  display: none;
}

/* Tab Panels */
.tab-panel {
  display: none;
  animation: fadeIn 0.3s ease;
}

.tab-panel.is-active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Cards & Layout Components
   ========================================================================== */
.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-xl);
  transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

.card-title-group {
  margin-bottom: var(--space-lg);
}

.card-title {
  font-family: var(--font-family-display);
  font-size: var(--font-xl);
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.card-subtitle {
  font-size: var(--font-md);
  color: var(--text-secondary);
  margin-top: var(--space-2xs);
}

/* ==========================================================================
   Form: Easy Big-Number Data Entry
   ========================================================================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-lg);
}

.input-card {
  background-color: var(--bg-subtle);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.input-card:focus-within {
  border-color: var(--border-focus);
  background-color: var(--bg-surface);
  box-shadow: var(--shadow-focus);
}

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

.input-card label {
  font-size: var(--font-lg);
  font-weight: 700;
  color: var(--text-primary);
  display: block;
}

.input-hint {
  font-size: var(--font-sm);
  color: var(--text-muted);
  font-weight: 500;
}

.number-input-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-sm);
}

.big-number-input {
  width: 100%;
  font-family: var(--font-family-display);
  font-size: var(--font-3xl);
  font-weight: 700;
  color: var(--text-primary);
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--border-medium);
  padding: var(--space-xs) 0;
  min-height: 54px;
}

.big-number-input:focus {
  outline: none;
  border-bottom-color: var(--brand-primary);
}

.big-number-input::placeholder {
  color: var(--text-muted);
  opacity: 0.5;
}

.input-unit {
  font-size: var(--font-lg);
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.healthy-target-note {
  font-size: var(--font-sm);
  color: var(--status-normal-text);
  margin-top: var(--space-xs);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Toggle Option Chips (AM/PM, Arm, etc.) */
.selector-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  margin-top: var(--space-md);
}

.selector-label {
  font-size: var(--font-md);
  font-weight: 600;
  color: var(--text-secondary);
}

.pill-radios {
  display: flex;
  gap: var(--space-xs);
  flex-wrap: wrap;
}

.pill-option {
  position: relative;
}

.pill-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.pill-option label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-lg);
  min-height: var(--min-touch-size);
  background-color: var(--bg-subtle);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  font-size: var(--font-md);
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition-fast);
}

.pill-option input[type="radio"]:checked + label {
  background-color: var(--brand-primary);
  border-color: var(--brand-primary);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

.pill-option input[type="radio"]:focus-visible + label {
  outline: 3px solid var(--border-focus);
  outline-offset: 3px;
}

/* Symptom and Context Checkbox Chips */
.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-top: var(--space-xs);
}

.tag-chip {
  position: relative;
}

.tag-chip input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.tag-chip label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: var(--space-xs) var(--space-md);
  min-height: 44px;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  font-size: var(--font-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
}

.tag-chip input[type="checkbox"]:checked + label {
  background-color: var(--brand-secondary-soft);
  border-color: var(--brand-secondary);
  color: var(--brand-secondary);
  font-weight: 600;
}

.tag-chip input[type="checkbox"]:focus-visible + label {
  outline: 3px solid var(--border-focus);
}

/* Live Blood Pressure Feedback Box */
.bp-feedback-box {
  background-color: var(--bg-surface-elevated);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-top: var(--space-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-md);
  transition: var(--transition-normal);
}

.feedback-status {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: var(--space-xs) var(--space-lg);
  border-radius: var(--radius-pill);
  font-size: var(--font-lg);
  font-weight: 700;
  border: 2px solid currentColor;
}

.status-badge-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: currentColor;
}

.status-badge.normal {
  color: var(--status-normal-text);
  background-color: var(--status-normal-bg);
  border-color: var(--status-normal-border);
}
.status-badge.elevated {
  color: var(--status-elevated-text);
  background-color: var(--status-elevated-bg);
  border-color: var(--status-elevated-border);
}
.status-badge.stage1 {
  color: var(--status-stage1-text);
  background-color: var(--status-stage1-bg);
  border-color: var(--status-stage1-border);
}
.status-badge.stage2 {
  color: var(--status-stage2-text);
  background-color: var(--status-stage2-bg);
  border-color: var(--status-stage2-border);
}
.status-badge.crisis {
  color: var(--status-crisis-text);
  background-color: var(--status-crisis-bg);
  border-color: var(--status-crisis-border);
}

.feedback-description {
  font-size: var(--font-md);
  color: var(--text-secondary);
  max-width: 500px;
}

/* Action Buttons */
.btn-submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  background-color: var(--brand-primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-pill);
  padding: var(--space-md) var(--space-2xl);
  font-family: var(--font-family-body);
  font-size: var(--font-xl);
  font-weight: 700;
  cursor: pointer;
  min-height: 60px;
  width: 100%;
  box-shadow: var(--shadow-md);
  transition: var(--transition-fast);
  margin-top: var(--space-lg);
}

.btn-submit:hover {
  background-color: var(--brand-primary-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn-submit:active {
  transform: translateY(0);
}

.btn-voice {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-lg);
  border: 2px solid var(--border-medium);
  border-radius: var(--radius-pill);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-size: var(--font-md);
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
  transition: var(--transition-fast);
}

.btn-voice:hover {
  background-color: var(--bg-subtle);
  border-color: var(--brand-primary);
}

.btn-voice svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

/* ==========================================================================
   Dashboard Metrics Grid & Daily Care
   ========================================================================== */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.metric-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 6px;
  height: 100%;
  background-color: var(--brand-primary);
}

.metric-card.morning::before {
  background-color: #f59e0b; /* morning sunrise amber */
}
.metric-card.evening::before {
  background-color: #6366f1; /* evening twilight indigo */
}
.metric-card.weight::before {
  background-color: #10b981; /* weight emerald */
}
.metric-card.pulse::before {
  background-color: #ec4899; /* heart pulse pink */
}

.metric-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-secondary);
  font-size: var(--font-md);
  font-weight: 600;
  margin-bottom: var(--space-xs);
}

.metric-value {
  font-family: var(--font-family-display);
  font-size: var(--font-2xl);
  font-weight: 700;
  color: var(--text-primary);
  line-height: var(--leading-tight);
}

.metric-sub {
  font-size: var(--font-sm);
  color: var(--text-muted);
  margin-top: var(--space-2xs);
}

/* Daily Care Routine Checklist */
.daily-care-card {
  background: linear-gradient(135deg, var(--bg-accent-soft), var(--bg-surface));
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  margin-bottom: var(--space-xl);
}

.checklist-items {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-md);
  margin-top: var(--space-md);
}

.care-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  cursor: pointer;
  transition: var(--transition-fast);
}

.care-item:hover {
  border-color: var(--brand-primary);
  box-shadow: var(--shadow-sm);
}

.care-item input[type="checkbox"] {
  width: 26px;
  height: 26px;
  accent-color: var(--brand-primary);
  cursor: pointer;
  flex-shrink: 0;
}

.care-item-text {
  display: flex;
  flex-direction: column;
}

.care-item-title {
  font-size: var(--font-md);
  font-weight: 700;
  color: var(--text-primary);
}

.care-item-desc {
  font-size: var(--font-sm);
  color: var(--text-muted);
}

/* Tip of the Day Box */
.tip-box {
  background-color: var(--bg-surface);
  border-left: 5px solid var(--brand-secondary);
  border-radius: var(--radius-sm);
  padding: var(--space-md) var(--space-lg);
  margin-top: var(--space-lg);
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
}

.tip-box svg {
  width: 28px;
  height: 28px;
  stroke: var(--brand-secondary);
  flex-shrink: 0;
  margin-top: 2px;
}

.tip-box-content h4 {
  font-size: var(--font-md);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.tip-box-content p {
  font-size: var(--font-sm);
  color: var(--text-secondary);
}

/* ==========================================================================
   Interactive SVG Charts
   ========================================================================== */
.chart-card {
  position: relative;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  margin-bottom: var(--space-xl);
}

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

.chart-range-filters {
  display: flex;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
}

.btn-range {
  background: transparent;
  border: none;
  padding: var(--space-xs) var(--space-md);
  min-height: 40px;
  border-radius: var(--radius-pill);
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
}

.btn-range.is-active {
  background-color: var(--brand-primary);
  color: #ffffff;
}

.chart-legend {
  display: flex;
  gap: var(--space-lg);
  flex-wrap: wrap;
  margin-bottom: var(--space-md);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-secondary);
}

.legend-color-line {
  width: 24px;
  height: 4px;
  border-radius: 2px;
}

.legend-color-box {
  width: 14px;
  height: 14px;
  border-radius: 3px;
}

.svg-chart-container {
  width: 100%;
  height: 320px;
  position: relative;
}

.svg-chart-container svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Tooltip */
.chart-tooltip {
  position: absolute;
  background-color: var(--text-primary);
  color: var(--text-inverse);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  font-size: var(--font-sm);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 10;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
}

/* ==========================================================================
   History Table & Data Controls
   ========================================================================== */
.history-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}

.history-filter-tabs {
  display: flex;
  gap: var(--space-xs);
}

.btn-filter {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  padding: var(--space-xs) var(--space-md);
  min-height: 42px;
  border-radius: var(--radius-pill);
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.btn-filter.is-active {
  background-color: var(--brand-primary);
  color: #fff;
  border-color: var(--brand-primary);
}

.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background-color: var(--bg-surface);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.data-table th {
  background-color: var(--bg-subtle);
  padding: var(--space-md);
  font-size: var(--font-md);
  font-weight: 700;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border-subtle);
  white-space: nowrap;
}

.data-table td {
  padding: var(--space-md);
  font-size: var(--font-md);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tr:hover td {
  background-color: var(--bg-subtle);
}

.time-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--font-sm);
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
}

.time-badge.am {
  background-color: #fef3c7;
  color: #92400e;
}

.time-badge.pm {
  background-color: #e0e7ff;
  color: #3730a3;
}

.btn-action-delete {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--status-stage2-text);
  border-radius: var(--radius-pill);
  padding: var(--space-xs) var(--space-sm);
  cursor: pointer;
  font-size: var(--font-sm);
  font-weight: 600;
  transition: var(--transition-fast);
}

.btn-action-delete:hover {
  background-color: var(--status-stage2-bg);
  border-color: var(--status-stage2-border);
}

/* Data Backup Bar */
.data-backup-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-md);
  padding: var(--space-lg);
  background-color: var(--bg-subtle);
  border-radius: var(--radius-md);
  margin-top: var(--space-lg);
}

.backup-actions {
  display: flex;
  gap: var(--space-xs);
  flex-wrap: wrap;
}

.btn-secondary {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-pill);
  padding: var(--space-xs) var(--space-lg);
  min-height: 44px;
  font-size: var(--font-md);
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  transition: var(--transition-fast);
}

.btn-secondary:hover {
  background-color: var(--bg-subtle);
  border-color: var(--brand-primary);
}

/* ==========================================================================
   Doctor's Visit Report Section
   ========================================================================== */
.report-card {
  background-color: var(--bg-surface);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-2xl);
  box-shadow: var(--shadow-md);
  margin-bottom: var(--space-xl);
}

.report-header-banner {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: var(--space-lg);
  border-bottom: 2px solid var(--border-subtle);
  padding-bottom: var(--space-lg);
  margin-bottom: var(--space-xl);
}

.report-title-area h2 {
  font-family: var(--font-family-display);
  font-size: var(--font-2xl);
  color: var(--text-primary);
}

.report-patient-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
  background-color: var(--bg-subtle);
  padding: var(--space-md);
  border-radius: var(--radius-md);
}

.meta-field label {
  font-size: var(--font-sm);
  font-weight: 700;
  color: var(--text-secondary);
  display: block;
}

.meta-field span {
  font-size: var(--font-md);
  font-weight: 600;
  color: var(--text-primary);
}

.meta-field input {
  font-size: var(--font-md);
  font-family: var(--font-family-body);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  width: 100%;
}

.report-summary-box {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.summary-tile {
  background-color: var(--bg-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  border-left: 4px solid var(--brand-primary);
}

.summary-tile h4 {
  font-size: var(--font-sm);
  color: var(--text-secondary);
  font-weight: 700;
}

.summary-tile .big-val {
  font-size: var(--font-2xl);
  font-family: var(--font-family-display);
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 2px;
}

.summary-tile .sub-val {
  font-size: var(--font-sm);
  color: var(--text-muted);
}

.doctor-notes-area {
  margin-top: var(--space-xl);
  border-top: 1px dashed var(--border-medium);
  padding-top: var(--space-lg);
}

.doctor-notes-area label {
  font-size: var(--font-lg);
  font-weight: 700;
  color: var(--text-primary);
  display: block;
  margin-bottom: var(--space-xs);
}

.doctor-notes-area textarea {
  width: 100%;
  min-height: 100px;
  font-family: var(--font-family-body);
  font-size: var(--font-md);
  padding: var(--space-md);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  resize: vertical;
}

/* Print Trigger Button */
.btn-print {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  background-color: var(--brand-accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-pill);
  padding: var(--space-md) var(--space-xl);
  font-size: var(--font-lg);
  font-weight: 700;
  cursor: pointer;
  min-height: 52px;
  box-shadow: var(--shadow-md);
  transition: var(--transition-fast);
}

.btn-print:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

/* ==========================================================================
   Modal Dialogs (Guide & Import)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--space-md);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.modal-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

.modal-dialog {
  background-color: var(--bg-surface);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-subtle);
  transform: scale(0.95);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-backdrop.is-open .modal-dialog {
  transform: scale(1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-xl);
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h3 {
  font-family: var(--font-family-display);
  font-size: var(--font-xl);
  font-weight: 700;
  color: var(--text-primary);
}

.btn-close-modal {
  background: transparent;
  border: none;
  font-size: var(--font-2xl);
  color: var(--text-secondary);
  cursor: pointer;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-close-modal:hover {
  background-color: var(--bg-subtle);
  color: var(--text-primary);
}

.modal-body {
  padding: var(--space-xl);
}

/* Guide Step Cards */
.guide-step {
  display: flex;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
  align-items: flex-start;
}

.step-num {
  width: 42px;
  height: 42px;
  background-color: var(--brand-primary);
  color: #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--font-lg);
  flex-shrink: 0;
}

.step-content h4 {
  font-size: var(--font-lg);
  color: var(--text-primary);
  margin-bottom: 4px;
}

.step-content p {
  font-size: var(--font-md);
  color: var(--text-secondary);
}

/* Notification Toast */
.toast-notice {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background-color: var(--text-primary);
  color: var(--text-inverse);
  padding: var(--space-md) var(--space-xl);
  border-radius: var(--radius-pill);
  font-size: var(--font-md);
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  transform: translateY(100px);
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.toast-notice.show {
  transform: translateY(0);
  opacity: 1;
}

/* Footer */
.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--border-subtle);
  padding: var(--space-xl) var(--space-md);
  text-align: center;
  color: var(--text-secondary);
  font-size: var(--font-sm);
}

.site-footer p {
  margin-bottom: var(--space-xs);
}

/* ==========================================================================
   Comprehensive Mobile Optimizations (Smartphones & Tablets)
   Tailored for Comfort, Thumb Navigation, and Clear Legibility
   ========================================================================== */
@media (max-width: 640px) {
  :root {
    --space-xl: 20px;
    --space-2xl: 28px;
    --space-3xl: 36px;
  }

  body {
    padding-bottom: calc(76px + env(safe-area-inset-bottom, 12px));
  }

  .app-container {
    padding: 0 var(--space-sm) var(--space-xl);
  }

  /* Compact Accessible Header */
  .site-header {
    padding: var(--space-sm) var(--space-sm);
    margin-bottom: var(--space-md);
  }

  .header-inner {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-sm);
  }

  .brand-wrapper {
    gap: var(--space-sm);
  }

  .brand-icon {
    width: 44px;
    height: 44px;
  }

  .brand-icon svg {
    width: 24px;
    height: 24px;
  }

  .brand-text h1 {
    font-size: var(--font-xl);
  }

  .brand-text p {
    font-size: var(--font-xs);
  }

  /* Accessibility Bar on Mobile */
  .accessibility-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-xs);
    flex-wrap: nowrap;
  }

  .control-group {
    padding: 2px;
  }

  .control-group-label {
    display: none;
  }

  .btn-ctrl {
    min-height: 38px;
    min-width: 38px;
    padding: 0 6px;
    font-size: var(--font-sm);
  }

  .btn-icon-label {
    padding: 0 var(--space-sm);
    min-height: 38px;
    font-size: var(--font-sm);
    white-space: nowrap;
  }

  .btn-icon-label svg {
    width: 18px;
    height: 18px;
  }

  /* Thumb-Friendly Sticky Bottom Navigation Bar */
  .main-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background-color: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
    border-bottom: none;
    margin-bottom: 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 8px));
    display: flex;
    justify-content: space-around;
    gap: 2px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }

  .tab-label-full {
    display: none;
  }

  .tab-label-mobile {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: -0.01em;
  }

  .nav-tab {
    flex: 1 1 0;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 3px;
    padding: 6px 2px;
    min-height: 52px;
    border-radius: var(--radius-sm);
    border-bottom: none;
    white-space: nowrap;
    transition: var(--transition-fast);
  }

  .nav-tab svg {
    width: 22px;
    height: 22px;
  }

  .nav-tab.is-active {
    background-color: var(--bg-accent-soft);
    color: var(--brand-primary);
    border-bottom: none;
    border-radius: var(--radius-md);
  }

  /* Mobile Form & Input Cards */
  .card {
    padding: var(--space-md);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-md);
  }

  .card-title {
    font-size: var(--font-lg);
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: var(--space-md);
  }

  .input-card {
    padding: var(--space-sm) var(--space-md);
  }

  .big-number-input {
    font-size: calc(var(--font-2xl) * 1.1);
    min-height: 48px;
  }

  /* Two-column equal thumb buttons for AM/PM and Arm selection */
  .pill-radios {
    display: flex;
    gap: var(--space-xs);
    width: 100%;
  }

  .pill-option {
    flex: 1 1 0;
  }

  .pill-option label {
    width: 100%;
    justify-content: center;
    padding: var(--space-sm) var(--space-xs);
    font-size: var(--font-md);
    min-height: 48px;
    text-align: center;
  }

  /* Easy-to-tap symptom chips */
  .tag-chips {
    gap: 8px;
  }

  .tag-chip label {
    padding: 8px 14px;
    min-height: 44px;
    font-size: var(--font-sm);
  }

  /* Live BP Feedback Box on Mobile */
  .bp-feedback-box {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-md);
    padding: var(--space-md);
  }

  .feedback-status {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-xs);
  }

  .status-badge {
    width: 100%;
    justify-content: center;
    font-size: var(--font-md);
    padding: var(--space-xs) var(--space-md);
  }

  .feedback-description {
    font-size: var(--font-sm);
  }

  .btn-voice {
    width: 100%;
    justify-content: center;
    min-height: 48px;
  }

  .btn-submit {
    min-height: 56px;
    font-size: var(--font-lg);
    padding: var(--space-md);
    margin-top: var(--space-md);
  }

  /* Dashboard Metrics Grid on Mobile: 2x2 Clean Layout */
  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
  }

  .metric-card {
    padding: var(--space-md) var(--space-sm);
  }

  .metric-header {
    font-size: var(--font-xs);
  }

  .metric-value {
    font-size: var(--font-xl);
  }

  .metric-sub {
    font-size: 0.75rem;
  }

  /* Daily Care on Mobile */
  .daily-care-card {
    padding: var(--space-md);
    margin-bottom: var(--space-md);
  }

  .checklist-items {
    grid-template-columns: 1fr;
    gap: var(--space-xs);
  }

  .care-item {
    padding: var(--space-sm) var(--space-md);
    min-height: 54px;
  }

  .care-item input[type="checkbox"] {
    width: 28px;
    height: 28px;
  }

  /* Mobile SVG Charts */
  .chart-card {
    padding: var(--space-md);
    margin-bottom: var(--space-md);
  }

  .chart-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
  }

  .chart-range-filters {
    width: 100%;
  }

  .btn-range {
    flex: 1 1 0;
    text-align: center;
    padding: var(--space-2xs) var(--space-xs);
    min-height: 38px;
    font-size: 0.8rem;
  }

  .chart-legend {
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
  }

  .legend-item {
    font-size: 0.8rem;
  }

  .svg-chart-container {
    height: 250px;
  }

  /* Mobile History: Transform Table Rows into Touch-Friendly Cards */
  .history-controls {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-sm);
  }

  .history-filter-tabs {
    width: 100%;
    display: flex;
  }

  .btn-filter {
    flex: 1 1 0;
    text-align: center;
    padding: var(--space-xs) var(--space-2xs);
    font-size: var(--font-xs);
    min-height: 40px;
  }

  .table-wrapper {
    border: none;
    background: transparent;
    overflow: visible;
  }

  .data-table, 
  .data-table thead, 
  .data-table tbody, 
  .data-table tr, 
  .data-table td {
    display: block;
    width: 100%;
  }

  .data-table thead {
    display: none;
  }

  .data-table tr {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-md);
    box-shadow: var(--shadow-sm);
  }

  .data-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px dashed var(--border-subtle);
    text-align: right;
  }

  .data-table td::before {
    content: attr(data-label);
    font-size: var(--font-xs);
    font-weight: 700;
    color: var(--text-secondary);
    text-align: left;
    padding-right: 12px;
  }

  .data-table td[data-label="Action"] {
    border-bottom: none;
    padding-top: 10px;
    justify-content: flex-end;
  }

  .data-table td[data-label="Action"]::before {
    display: none;
  }

  .btn-action-delete {
    min-height: 38px;
    padding: var(--space-xs) var(--space-md);
    font-size: var(--font-sm);
  }

  /* Data Backup Bar Mobile */
  .data-backup-bar {
    padding: var(--space-md);
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-md);
  }

  .backup-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-xs);
  }

  .backup-actions .btn-secondary {
    justify-content: center;
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-sm);
  }

  /* Doctor's Visit Report Mobile */
  .report-card {
    padding: var(--space-md);
  }

  .report-header-banner {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-md);
  }

  .btn-print {
    width: 100%;
    justify-content: center;
  }

  .report-summary-box {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-sm);
  }

  .summary-tile .big-val {
    font-size: var(--font-xl);
  }

  /* Modal on Mobile */
  .modal-dialog {
    max-height: 85vh;
    border-radius: var(--radius-lg);
  }

  .modal-header {
    padding: var(--space-md);
  }

  .modal-body {
    padding: var(--space-md);
  }

  .guide-step {
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
  }

  .step-num {
    width: 34px;
    height: 34px;
    font-size: var(--font-md);
  }

  /* Toast position above bottom navigation */
  .toast-notice {
    bottom: 84px;
    left: 16px;
    right: 16px;
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-sm);
    justify-content: center;
  }
}

/* Extra small mobile adjustments (<= 380px) */
@media (max-width: 380px) {
  .metrics-grid {
    grid-template-columns: 1fr;
  }
  .report-summary-box {
    grid-template-columns: 1fr;
  }
  .backup-actions {
    grid-template-columns: 1fr;
  }
}
