/* ALS Care Tracker — Mobile-first, clean, accessible */
:root {
  --bg: #f5f5f0;
  --card: #ffffff;
  --text: #2c2c2c;
  --text-light: #6b6b6b;
  --primary: #4a7c6f;
  --primary-light: #e8f2ee;
  --primary-dark: #3a6359;
  --accent: #c4785b;
  --accent-light: #fdf0ea;
  --danger: #c0392b;
  --danger-light: #fdedec;
  --border: #ddd;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --radius: 8px;
  --touch: 44px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  padding-bottom: 80px;
}

/* ---- TOP BAR ---- */
.topbar {
  background: var(--primary);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.topbar h1 { font-size: 1.1rem; font-weight: 600; }
.topbar .timer-display {
  font-size: 0.85rem;
  background: rgba(255,255,255,0.15);
  padding: 4px 10px;
  border-radius: 12px;
  font-variant-numeric: tabular-nums;
}
.topbar a.back { color: #fff; text-decoration: none; font-size: 1.2rem; margin-right: 10px; }

/* ---- NAV BAR ---- */
.navbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
}
.navbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  color: var(--text-light);
  text-decoration: none;
  font-size: 0.7rem;
  gap: 2px;
}
.navbar a.active { color: var(--primary); }
.navbar a svg { width: 22px; height: 22px; }

/* ---- CONTAINER ---- */
.container { padding: 16px; max-width: 600px; margin: 0 auto; }

/* ---- CARDS ---- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card h2 {
  font-size: 1rem;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---- FORM ELEMENTS ---- */
label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin: 12px 0 4px;
}
label:first-child { margin-top: 0; }

input[type="text"],
input[type="date"],
input[type="time"],
input[type="number"],
input[type="tel"],
input[type="email"],
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px; /* prevents iOS zoom */
  background: #fff;
  min-height: var(--touch);
  -webkit-appearance: none;
}
textarea { resize: vertical; min-height: 80px; font-family: inherit; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--touch);
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover, .btn-primary:active { background: var(--primary-dark); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #a86348; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }
.btn-block { display: flex; width: 100%; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* ---- CHECKBOX / RADIO ---- */
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 4px;
  margin: 4px 0;
}
.checkbox-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  min-height: var(--touch);
}
.checkbox-item:hover { background: var(--primary-light); }
.checkbox-item input { width: 18px; height: 18px; accent-color: var(--primary); }

/* ---- TOGGLE SWITCH ---- */
.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}
.toggle-label { font-weight: 600; font-size: 0.85rem; }
.switch {
  position: relative;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 26px;
  cursor: pointer;
  transition: 0.2s;
}
.slider::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(22px); }

/* ---- VOICE INPUT ---- */
.field-with-voice {
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
}

.field-with-voice input,
.field-with-voice textarea {
  flex: 1;
}

.voice-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--card);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
}

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

.voice-btn.listening {
  background: var(--danger-light);
  border-color: var(--danger);
  color: var(--danger);
  animation: voice-pulse 1.5s infinite;
}

@keyframes voice-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(192, 57, 43, 0.4); }
  70%  { box-shadow: 0 0 0 10px rgba(192, 57, 43, 0); }
  100% { box-shadow: 0 0 0 0 rgba(192, 57, 43, 0); }
}

.voice-interim {
  display: none;
  font-size: 0.85rem;
  color: var(--text-light);
  font-style: italic;
  padding: 4px 8px;
  background: var(--primary-light);
  border-radius: 4px;
  margin-top: 4px;
}

.field-with-voice.voice-active input,
.field-with-voice.voice-active textarea {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(74, 124, 111, 0.2);
}

/* Voice settings: per-field toggle list */
#voice-field-list .toggle {
  padding: 4px 0;
}
#voice-field-list .toggle-label {
  font-weight: 400;
  font-size: 0.8rem;
}

/* ---- TABLE ---- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.data-table th {
  background: var(--primary-light);
  padding: 8px;
  text-align: left;
  font-weight: 600;
  position: sticky;
  top: 0;
}
.data-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
}
.data-table tr:nth-child(even) { background: #fafafa; }

/* ---- STATUS BADGE ---- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-green { background: #d4edda; color: #155724; }
.badge-yellow { background: #fff3cd; color: #856404; }
.badge-red { background: #f8d7da; color: #721c24; }
.badge-gray { background: #e2e3e5; color: #383d41; }

/* ---- ALERTS ---- */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 0.85rem;
  font-weight: 500;
}
.alert-info { background: #d1ecf1; color: #0c5460; }
.alert-success { background: #d4edda; color: #155724; }
.alert-warning { background: #fff3cd; color: #856404; }
.alert-danger { background: #f8d7da; color: #721c24; }

/* ---- DASHBOARD ---- */
.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.dash-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
}
.dash-card .icon { font-size: 1.8rem; margin-bottom: 4px; }
.dash-card .label { font-size: 0.8rem; font-weight: 600; }
.dash-card .value { font-size: 1.4rem; font-weight: 700; color: var(--primary); }

/* ---- DATE SELECTOR ---- */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  padding: 8px 12px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.date-nav a {
  color: var(--primary);
  text-decoration: none;
  font-size: 1.2rem;
  padding: 4px 8px;
}
.date-nav span { font-weight: 600; font-size: 0.95rem; }

/* ---- SECTION DIVIDER ---- */
.section-header {
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 8px 12px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.9rem;
  margin: 16px 0 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ---- SYMPTOM CHECKLIST ---- */
.symptom-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.symptom-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.symptom-row .name { flex: 1; font-size: 0.85rem; }
.symptom-row select {
  min-height: var(--touch);
  padding: 4px 8px;
  font-size: 0.8rem;
  min-width: 90px;
}

/* ---- NOTIFICATION TOAST ---- */
.toast-container {
  position: fixed;
  top: 60px;
  right: 12px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  font-size: 0.85rem;
  animation: slideIn 0.3s ease;
  max-width: 280px;
}
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ---- HISTORY LIST ---- */
.history-item {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 8px;
}
.history-info { flex: 1; cursor: pointer; min-width: 0; }
.history-item .date { font-weight: 700; font-size: 0.95rem; }
.history-item .meta { font-size: 0.8rem; color: var(--text-light); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-delete {
  background: var(--danger-light);
  border: none;
  border-radius: var(--radius);
  min-width: var(--touch);
  min-height: var(--touch);
  font-size: 1.2rem;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.btn-delete:hover, .btn-delete:active { background: var(--danger); color: #fff; }

/* ---- COUNT BADGE ---- */
.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.25);
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 700;
  margin-left: 6px;
  min-width: 20px;
}

/* ---- RESPONSIVE ---- */
@media (min-width: 601px) {
  .container { padding: 20px; }
  .dash-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ---- MOBILE KEYBOARD / SCROLL IMPROVEMENTS ---- */
@supports (scroll-behavior: smooth) {
  html { scroll-behavior: smooth; }
}

/* Prevent body scroll bounce on iOS */
body { overscroll-behavior-y: contain; }

/* Ensure inputs don't get hidden behind keyboard */
input:focus, textarea:focus, select:focus { scroll-margin-bottom: 200px; }

/* Safe area for iPhone notch/home-indicator */
.navbar { padding-bottom: env(safe-area-inset-bottom, 0px); }
.container { padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }

/* ---- PRINT ---- */
@media print {
  .navbar, .topbar, .btn-group { display: none !important; }
  body { padding-bottom: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
}
