/* MediMemo Premium Style Sheet */

/* --- CSS Variable Declarations & Design System --- */
:root {
  --bg-main: #0b0f19;
  --bg-card: rgba(17, 24, 39, 0.7);
  --bg-card-hover: rgba(31, 41, 55, 0.8);
  --bg-input: #1f2937;
  --tint-rgb: 255, 255, 255;  /* overlays/borders: white on dark, slate on light */
  --border-subtle: rgba(var(--tint-rgb), 0.07);
  --border-focus: rgba(99, 102, 241, 0.5);
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-inverse: #0b0f19;
  --text-strong: #ffffff;     /* headings and key figures */
  --accent-night: #a855f7;    /* "Night" doses */

  --surface-nav: rgba(15, 23, 42, 0.85);
  --surface-nav-mobile: rgba(11, 15, 25, 0.95);
  --surface-card-solid: rgba(22, 30, 49, 0.85);
  --overlay-scrim: rgba(0, 0, 0, 0.75);
  --chart-grid: rgba(255, 255, 255, 0.05);
  --chart-text: #9ca3af;
  --chart-fill: rgba(129, 140, 248, 0.32);
  --chart-skipped: rgba(156, 163, 175, 0.55);
  color-scheme: dark;

  /* Premium Harmony Palette */
  --primary: #818cf8;         /* Indigo (WCAG AA compliant on dark) */
  --primary-hover: #6366f1;
  --primary-glow: rgba(129, 140, 248, 0.15);
  
  --success: #10b981;         /* Emerald Green for Taken */
  --success-glow: rgba(16, 185, 129, 0.15);
  
  --warning: #f59e0b;         /* Amber for Upcoming/Pending */
  --warning-glow: rgba(245, 158, 11, 0.15);
  
  --danger: #f43f5e;          /* Rose Red for Missed */
  --danger-glow: rgba(244, 63, 94, 0.15);
  
  --info: #0ea5e9;            /* Sky Blue for details */
  --info-glow: rgba(14, 165, 233, 0.15);

  --font-stack: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --shadow-premium: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
  --shadow-glow-success: 0 0 15px rgba(16, 185, 129, 0.2);
  --shadow-glow-warning: 0 0 15px rgba(245, 158, 11, 0.2);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

/* --- Light theme ---
   Follows the system unless Settings → Appearance picks one; theme-init.js
   sets data-theme on <html> before first paint. */
:root[data-theme="light"] {
  --bg-main: #f4f6fb;
  --bg-card: rgba(255, 255, 255, 0.88);
  --bg-card-hover: rgba(241, 245, 249, 0.95);
  --bg-input: #ffffff;
  --tint-rgb: 15, 23, 42;
  --border-subtle: rgba(15, 23, 42, 0.12);
  --border-focus: rgba(79, 70, 229, 0.5);
  --text-main: #1f2937;
  --text-muted: #4b5563;
  --text-strong: #0b1220;
  --accent-night: #7e22ce;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-glow: rgba(79, 70, 229, 0.12);
  --success: #047857;
  --success-glow: rgba(4, 120, 87, 0.12);
  --warning: #b45309;
  --warning-glow: rgba(180, 83, 9, 0.12);
  --danger: #e11d48;
  --danger-glow: rgba(225, 29, 72, 0.1);
  --info: #0369a1;
  --info-glow: rgba(3, 105, 161, 0.12);
  --shadow-premium: 0 10px 30px -12px rgba(15, 23, 42, 0.18);
  --shadow-glow-success: 0 0 12px rgba(4, 120, 87, 0.15);
  --shadow-glow-warning: 0 0 12px rgba(180, 83, 9, 0.15);
  --surface-nav: rgba(255, 255, 255, 0.9);
  --surface-nav-mobile: rgba(255, 255, 255, 0.96);
  --surface-card-solid: rgba(255, 255, 255, 0.94);
  --overlay-scrim: rgba(15, 23, 42, 0.45);
  --chart-grid: rgba(15, 23, 42, 0.08);
  --chart-text: #4b5563;
  --chart-fill: rgba(79, 70, 229, 0.18);
  --chart-skipped: rgba(100, 116, 139, 0.45);
  color-scheme: light;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg-main: #f4f6fb;
    --bg-card: rgba(255, 255, 255, 0.88);
    --bg-card-hover: rgba(241, 245, 249, 0.95);
    --bg-input: #ffffff;
    --tint-rgb: 15, 23, 42;
    --border-subtle: rgba(15, 23, 42, 0.12);
    --border-focus: rgba(79, 70, 229, 0.5);
    --text-main: #1f2937;
    --text-muted: #4b5563;
    --text-strong: #0b1220;
    --accent-night: #7e22ce;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-glow: rgba(79, 70, 229, 0.12);
    --success: #047857;
    --success-glow: rgba(4, 120, 87, 0.12);
    --warning: #b45309;
    --warning-glow: rgba(180, 83, 9, 0.12);
    --danger: #e11d48;
    --danger-glow: rgba(225, 29, 72, 0.1);
    --info: #0369a1;
    --info-glow: rgba(3, 105, 161, 0.12);
    --shadow-premium: 0 10px 30px -12px rgba(15, 23, 42, 0.18);
    --shadow-glow-success: 0 0 12px rgba(4, 120, 87, 0.15);
    --shadow-glow-warning: 0 0 12px rgba(180, 83, 9, 0.15);
    --surface-nav: rgba(255, 255, 255, 0.9);
    --surface-nav-mobile: rgba(255, 255, 255, 0.96);
    --surface-card-solid: rgba(255, 255, 255, 0.94);
    --overlay-scrim: rgba(15, 23, 42, 0.45);
    --chart-grid: rgba(15, 23, 42, 0.08);
    --chart-text: #4b5563;
    --chart-fill: rgba(79, 70, 229, 0.18);
    --chart-skipped: rgba(100, 116, 139, 0.45);
    color-scheme: light;
}
}

/* --- Base Styles & Reset --- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* Form controls don't inherit the page font by default (buttons were Arial, G8) */
button, input, select, textarea {
  font-family: inherit;
}

*:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

body {
  font-family: var(--font-stack);
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* Glassmorphism utility */
.glass {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-premium);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-main);
}
::-webkit-scrollbar-thumb {
  background: rgba(var(--tint-rgb), 0.1);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(var(--tint-rgb), 0.2);
}

/* --- Layout Architecture --- */
.app-container {
  display: flex;
  flex: 1;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  position: relative;
}

/* Desktop Sidebar Nav */
.sidebar {
  width: 260px;
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  border-right: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--text-strong) 0%, var(--primary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-icon {
  color: var(--primary);
  filter: drop-shadow(0 0 8px var(--primary));
}

.nav-links {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  list-style: none;
}

.nav-item {
  width: 100%;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  padding: 0.85rem 1rem;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  text-align: left;
}

.nav-btn i, .nav-btn svg {
  width: 20px;
  height: 20px;
  transition: transform 0.2s;
}

.nav-btn:hover {
  background: rgba(var(--tint-rgb), 0.04);
  color: var(--text-main);
}

.nav-btn:hover svg {
  transform: translateX(3px);
}

.nav-btn.active {
  background: var(--primary-glow);
  color: var(--primary);
  border: 1px solid rgba(99, 102, 241, 0.2);
  font-weight: 600;
}

.nav-btn.active svg {
  color: var(--primary);
  filter: drop-shadow(0 0 4px var(--primary));
}

/* Main Content Area */
.main-content {
  flex: 1;
  padding: 2.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  padding-bottom: 6rem; /* extra spacing for mobile navbar */
}

/* Header Component */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.welcome-section .greeting-title {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 0.25rem;
  background: linear-gradient(135deg, var(--text-strong) 60%, var(--text-muted) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.welcome-section p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.header-widgets {
  display: flex;
  gap: 1rem;
}

.header-widget-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
}

.streak-card {
  background: var(--warning-glow);
  border: 1px solid rgba(245, 158, 11, 0.2);
  color: var(--warning);
}

.streak-card svg {
  filter: drop-shadow(0 0 4px var(--warning));
  animation: pulse-slow 2s infinite;
}

.adherence-card {
  background: var(--success-glow);
  border: 1px solid rgba(16, 185, 129, 0.2);
  color: var(--success);
}

/* Navigation Drawer for Mobile */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 70px;
  background: var(--surface-nav);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-subtle);
  z-index: 100;
  justify-content: space-around;
  align-items: center;
  padding: 0 1rem;
}

.mobile-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 500;
  cursor: pointer;
  flex: 1;
  height: 100%;
  transition: all 0.2s ease;
}

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

.mobile-nav-btn.active {
  color: var(--primary);
}

.mobile-nav-btn.active svg {
  transform: translateY(-2px);
  filter: drop-shadow(0 0 6px var(--primary));
}

/* --- Panel Layouts & Navigation --- */
.view-panel {
  display: none;
  animation: fadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.view-panel.active {
  display: block;
}

/* --- Today's Schedule Screen (Quick Log) --- */
.tracker-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
}

/* Calendar horizontal selector */
.date-selector-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.5rem;
  margin-bottom: 0.75rem;
}

.date-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.5rem;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

@media (hover: hover) {
  .date-btn:hover {
    background: rgba(var(--tint-rgb), 0.05);
    color: var(--text-main);
  }
}

.calendar-strip {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  overflow-x: auto;
  padding: 0.25rem;
  margin-bottom: 1.5rem; /* space before the first section title (T1) */
  scrollbar-width: none;
}
.calendar-strip::-webkit-scrollbar {
  display: none;
}

.calendar-day-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1 0 44px;
  max-width: 72px;
  padding: 0.65rem 0.25rem 0.8rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

@media (hover: hover) {
  .calendar-day-btn:hover {
    background: rgba(var(--tint-rgb), 0.03);
  }
}

.calendar-day-btn.active {
  background: var(--primary-glow);
  color: var(--primary);
  border-color: rgba(99, 102, 241, 0.3);
  font-weight: 700;
}

.calendar-day-btn .day-num {
  font-size: 1.1rem;
  font-weight: 700;
  margin-top: 0.15rem;
}

.calendar-day-btn .day-lbl {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Today stays findable when another day is selected (T11) */
.calendar-day-btn.is-today::after {
  content: '';
  position: absolute;
  bottom: 0.3rem;
  left: 50%;
  width: 5px;
  height: 5px;
  margin-left: -2.5px;
  border-radius: 50%;
  background: var(--primary);
}

.current-date-display {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.25rem 0.6rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-main);
  text-align: center;
}

.today-jump-btn {
  background: var(--primary-glow);
  color: var(--primary);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 9999px;
  padding: 0.3rem 0.75rem;
  min-height: 32px;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

/* Section Header (Schedule times like "Morning", "Night") */
.schedule-section {
  margin-bottom: 2rem;
}

.schedule-section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.schedule-section-title svg {
  width: 18px;
  height: 18px;
}

/* Dose cards */
.doses-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.dose-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.dose-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--warning);
}

.dose-card.taken::before {
  background: var(--success);
}

.dose-card.missed::before {
  background: var(--danger);
}

@media (hover: hover) {
  .dose-card:hover {
    transform: translateY(-2px);
    background: var(--bg-card-hover);
  }
}

.dose-info-wrapper {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 1;
}

/* Filled medicine colour dot (was an unfilled glow, near-invisible: T4) */
.med-color-indicator {
  display: inline-block;
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dose-details {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.dose-med-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-strong);
}

.dose-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.meta-item svg {
  width: 14px;
  height: 14px;
}

/* Intake status badge */
.status-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  white-space: nowrap;
}

.status-badge.pending {
  background: var(--warning-glow);
  color: var(--warning);
}

.status-badge.taken {
  background: var(--success-glow);
  color: var(--success);
}

.status-badge.missed {
  background: var(--danger-glow);
  color: var(--danger);
}

/* Logging Button - MOBILE EXTREMELY BIG ACTION */
.log-action-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 0.85rem 1.5rem;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 48px; /* Finger friendly */
}

@media (hover: hover) {
  .log-action-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.03);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
  }
}

.log-action-btn.btn-taken-state {
  background: var(--success-glow);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.3);
  box-shadow: none;
}

.log-action-btn.btn-taken-state:hover {
  background: rgba(16, 185, 129, 0.2);
  transform: none;
}

.log-action-btn.btn-missed-state {
  background: var(--danger-glow);
  color: var(--danger);
  border: 1px solid rgba(244, 63, 94, 0.3);
  box-shadow: none;
}

.log-action-btn.btn-missed-state:hover {
  background: rgba(244, 63, 94, 0.2);
  transform: none;
}

/* Empty checklist state style */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  text-align: center;
  color: var(--text-muted);
  gap: 1rem;
}

/* Only the decorative icon, not icons inside the empty state's buttons */
.empty-state > svg {
  width: 48px;
  height: 48px;
  color: var(--text-muted);
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 1.25rem;
  color: var(--text-main);
  font-weight: 700;
}

.empty-state p {
  max-width: 320px;
  font-size: 0.9rem;
}

.empty-state p.empty-state-note {
  margin-top: 0.75rem;
  font-size: 0.8rem;
}

/* --- iOS install / storage guidance (Safari only) --- */
.ios-hint {
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  border: 1px solid rgba(14, 165, 233, 0.3);
}

.ios-hint[hidden] {
  display: none;
}

.ios-hint-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.ios-hint-header h3 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
}

.ios-hint-header h3 svg {
  width: 18px;
  height: 18px;
  color: var(--info);
}

.ios-hint-list {
  margin: 0 0 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.ios-hint-list strong {
  color: var(--text-main);
}

.ios-hint-list li[hidden],
.ios-hint .btn-secondary[hidden] {
  display: none;
}

/* Test-version note (development address only) */
.dev-address-notice {
  border-color: rgba(var(--tint-rgb), 0.18);
}

.dev-address-notice .ios-hint-header h3 svg {
  color: var(--warning);
}

.hint-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.hint-actions .btn-primary {
  width: auto;
  text-decoration: none;
}

.btn-secondary {
  background: rgba(var(--tint-rgb), 0.05);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.75rem 1.25rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}

.btn-secondary svg {
  flex-shrink: 0;
}

.btn-secondary:hover {
  background: rgba(var(--tint-rgb), 0.1);
}

.btn-secondary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Primary-coloured secondary button (page-level "add" actions) */
.btn-secondary.btn-accent {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
}

.btn-secondary.btn-accent:hover {
  background: var(--primary-hover);
}

/* --- Medicine Management Screen --- */
/* Title + optional action on one row, subtitle full width below (G6) */
.page-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-header h2 {
  grid-column: 1;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-strong);
}

.page-header-action {
  grid-column: 2;
  grid-row: 1;
}

.page-header p {
  grid-column: 1 / -1;
  margin-top: 0.2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.meds-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr));
  gap: 1.5rem;
}

.med-card {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: relative;
}

.med-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}

.med-name-dosage {
  min-width: 0;
}

.med-name-dosage h3 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-strong);
  margin-bottom: 0.35rem;
  overflow-wrap: anywhere;
}

.med-name-dosage h3 .med-color-indicator {
  width: 12px;
  height: 12px;
}

.med-dose-chip {
  display: inline-block;
  font-size: 0.9rem;
  color: var(--text-muted);
  background: rgba(var(--tint-rgb), 0.04);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
}

.med-card-actions {
  display: flex;
  flex-shrink: 0;
  gap: 0.25rem;
  margin: -0.4rem -0.5rem 0 0; /* 44px targets without pushing the layout */
}

.med-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.med-action-btn svg {
  width: 20px;
  height: 20px;
}

.med-action-btn[aria-expanded="true"] {
  background: rgba(var(--tint-rgb), 0.08);
  color: var(--text-strong);
}

.med-action-btn:hover {
  background: rgba(var(--tint-rgb), 0.05);
  color: var(--text-main);
}

.med-action-btn.btn-delete:hover {
  color: var(--danger);
  background: var(--danger-glow);
}

.med-card-details {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.detail-line {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.detail-line svg {
  width: 16px;
  height: 16px;
  color: var(--primary);
}

.med-card-times {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.med-card-label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.med-card-note {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.med-card-note svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--info);
}

/* Ended medicines: grouped after the active ones, dimmed (M4) */
.meds-group-title {
  grid-column: 1 / -1;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.med-card.is-ended {
  opacity: 0.72;
}

.time-pill {
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.2);
  color: var(--primary);
  padding: 0.2rem 0.6rem;
  border-radius: 50px;
  font-size: 0.75rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.time-pill svg {
  width: 12px;
  height: 12px;
}

/* --- Analytics Screen --- */
.analytics-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.stat-box {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

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

.stat-box-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-strong);
}

.stat-box-value.is-bad {
  color: var(--danger);
}

.stat-box-trend {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
}

/* "Overall · since Mon, Apr 20": the KPIs are lifetime totals (A1) */
.analytics-section-title {
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.analytics-period {
  font-weight: 600;
  letter-spacing: normal;
  text-transform: none;
}

.stat-box-trend.up {
  color: var(--success);
}
.stat-box-trend.down {
  color: var(--danger);
}

/* Charts Containers */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.chart-card {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chart-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}

.chart-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-strong);
}

.chart-subtitle {
  margin-top: 0.15rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.chart-wrapper {
  position: relative;
  height: 280px;
  width: 100%;
}

/* --- Modal Overlays & Forms --- */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--overlay-scrim);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
  animation: fadeIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 500px;
  /* Tall dialogs (the medicine form) scroll inside the card instead of
     running off a short screen. */
  max-height: calc(100vh - 3rem);
  max-height: calc(100dvh - 3rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2rem;
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-strong);
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.5rem;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.modal-close-btn:hover {
  background: rgba(var(--tint-rgb), 0.05);
  color: var(--text-strong);
}

/* Form Styles */
.form-group {
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem;
}

.form-row > * {
  min-width: 0;
}

label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

input, select, textarea {
  width: 100%;
  min-width: 0;
  padding: 0.75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-strong);
  font-family: var(--font-stack);
  font-size: 0.95rem;
  transition: all 0.2s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* Custom time input adding list */
.time-chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.time-chip {
  background: var(--primary-glow);
  color: var(--primary);
  border: 1px solid rgba(99, 102, 241, 0.2);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.time-chip-remove {
  background: transparent;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-weight: 700;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.time-chip-remove:hover {
  color: var(--danger);
}

.btn-primary {
  width: 100%;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 0.85rem;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  white-space: nowrap;
}

.btn-primary svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

/* Custom Dialog Modal (Time taken selection) */
.custom-log-modal {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.custom-time-selectors {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.custom-time-btn {
  width: 100%;
  padding: 1rem;
  background: rgba(var(--tint-rgb), 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.2s;
}

.custom-time-btn:hover {
  background: rgba(var(--tint-rgb), 0.06);
  border-color: rgba(var(--tint-rgb), 0.15);
}

/* The main action ("Taken Right Now") looks like an action, not like a
   pre-selected option (D3). */
.custom-time-btn.primary-action {
  background: var(--primary);
  border-color: transparent;
  color: #fff;
}

@media (hover: hover) {
  .custom-time-btn.primary-action:hover {
    background: var(--primary-hover);
  }
}

.custom-time-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.dialog-desc {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

/* What's recorded for this dose right now (D3) */
.dose-current-status {
  margin-top: -0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  background: rgba(var(--tint-rgb), 0.04);
  color: var(--text-main);
}

.dose-current-status.taken { background: var(--success-glow); color: var(--success); }
.dose-current-status.missed { background: var(--danger-glow); color: var(--danger); }
.dose-current-status.skipped { color: var(--text-muted); }

.custom-time-box {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  background: rgba(var(--tint-rgb), 0.02);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.custom-time-box label {
  font-size: 0.8rem;
}

.custom-time-row,
.time-add-row {
  display: flex;
  gap: 0.5rem;
}

.custom-time-row input,
.time-add-row input {
  flex: 1;
}

.custom-time-row input {
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
}

.custom-time-row .btn-secondary {
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  background: var(--primary);
  color: #fff;
  border-color: transparent;
}

/* Settings utility section */
.settings-section-card {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.settings-section-card > h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-strong);
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border-subtle);
}

.settings-section-card.danger-zone {
  border-color: rgba(244, 63, 94, 0.3);
}

.settings-section-card > h3.danger-title {
  color: var(--danger);
  border-bottom-color: rgba(244, 63, 94, 0.2);
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

/* No divider under the last *visible* row (a hidden row may follow it, S2) */
.settings-row:last-child,
.settings-row:not(:has(~ .settings-row:not([hidden]))) {
  border-bottom: none;
  padding-bottom: 0;
}

.settings-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}

.settings-row > button,
.settings-row > a,
.settings-row > select,
.settings-actions {
  flex-shrink: 0;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.settings-title {
  font-weight: 700;
  color: var(--text-strong);
  font-size: 1rem;
}

.settings-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* --- Dynamic Animations --- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes pulse-slow {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.8;
    transform: scale(1.05);
  }
}

/* --- Mobile Responsiveness Breakpoints --- */

@media (max-width: 900px) {
  .app-container {
    flex-direction: column;
  }
  
  .sidebar {
    display: none; /* Hide desktop sidebar */
  }
  
  .mobile-nav {
    display: flex; /* Show bottom bar navigation */
    background: var(--surface-nav-mobile); /* Deeper overlay */
    border-top: 1px solid rgba(var(--tint-rgb), 0.05);
  }
  
  .main-content {
    padding: 1.25rem 1rem 6rem 1rem;
    gap: 1.25rem;
  }
  
  /* Distraction-Free Mobile Tracker Styles */
  #panel-tracker .date-selector-bar,
  #panel-tracker #calendar-strip-container,
  .dashboard-header {
    display: none !important; /* Hide header, widgets, calendar by default on mobile */
  }
  
  /* Show headers/calendars only when mobile focus is explicitly expanded */
  body.show-mobile-details #panel-tracker .date-selector-bar,
  body.show-mobile-details #panel-tracker #calendar-strip-container,
  body.show-mobile-details .dashboard-header {
    display: flex !important;
  }
  
  .charts-grid {
    grid-template-columns: 1fr;
  }

  .calendar-strip {
    justify-content: space-between;
    gap: 0.25rem;
  }
  
  /* Large finger-friendly checklist adjustments */
  .schedule-section-title {
    font-size: 1.2rem;
    padding-bottom: 0.75rem;
    margin-bottom: 1.25rem;
  }
  
  .dose-card {
    padding: 1.5rem 1.25rem;
    border-radius: var(--radius-lg);
    background: var(--surface-card-solid); /* Slightly solid card */
  }
  
  .dose-med-name {
    font-size: 1.3rem;
  }
  
  .dose-meta {
    font-size: 0.95rem;
    gap: 1rem;
    margin-top: 0.5rem;
  }
  
  .log-action-btn {
    width: 100%;
    padding: 1rem;
    font-size: 1.1rem;
    border-radius: var(--radius-md);
  }
  
  /* "Due now" filter: top of the list, says what is shown (T8, T9) */
  .focus-toggle-container {
    display: flex;
    justify-content: center;
    margin-bottom: 1.25rem;
  }
  
  .focus-toggle-btn {
    background: rgba(var(--tint-rgb), 0.03);
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
    padding: 0.55rem 1.1rem;
    min-height: 44px;
    border-radius: 50px;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
  }

  .focus-toggle-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
  }

  .focus-toggle-btn.is-focused {
    width: 100%;
    border-radius: var(--radius-md);
    background: var(--primary-glow);
    border-color: rgba(99, 102, 241, 0.3);
    color: var(--text-main);
    text-align: left;
  }

  .focus-toggle-btn.is-focused svg {
    color: var(--primary);
  }

  .focus-toggle-text {
    flex: 1;
    min-width: 0;
  }

  .focus-toggle-text strong {
    color: var(--text-strong);
  }

  .focus-toggle-action {
    flex-shrink: 0;
    color: var(--primary);
    font-weight: 700;
  }
}

@media (max-width: 480px) {
  /* Extra compact spacing for mobile trackers */
  .dose-card {
    padding: 1.5rem 1.25rem;
    flex-direction: column;
    align-items: stretch;
    gap: 1.25rem;
  }
  
  .log-action-btn {
    width: 100%;
    justify-content: center;
  }
}

/* --- Floating Undo Snackbar/Toast --- */
.toast-container {
  position: fixed;
  bottom: 85px; /* Neatly above the mobile bottom tab bar (70px height + 15px gap) */
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 90%;
  max-width: 400px;
  pointer-events: none;
}

.toast-card {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  background: rgba(17, 24, 39, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(var(--tint-rgb), 0.08);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.6), 0 0 1px 1px rgba(255, 255, 255, 0.05);
  animation: toastSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast-card.fade-out {
  opacity: 0;
  transform: scale(0.9) translateY(10px);
}

.toast-message {
  font-size: 0.9rem;
  font-weight: 500;
  color: #fff;
  line-height: 1.4;
  flex: 1;
}

.toast-undo-btn {
  background: var(--warning-glow);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
  min-height: 44px;
  padding: 0.4rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.toast-undo-btn:hover {
  background: rgba(245, 158, 11, 0.25);
  border-color: var(--warning);
  transform: scale(1.03);
}

.toast-dismiss-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.toast-dismiss-btn:hover {
  background: rgba(var(--tint-rgb), 0.08);
  color: #fff;
}

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

/* Adjust toast container and layout parameters for desktop viewports */
@media (min-width: 901px) {
  .toast-container {
    bottom: 2rem;
    left: auto;
    right: 2rem;
    transform: none;
    max-width: 360px;
  }
  
  @keyframes toastSlideUp {
    from {
      opacity: 0;
      transform: translateY(20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

/* --- Unified Time-Slot Group Cards --- */
.slot-card {
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  margin-bottom: 1rem;
}

/* Status stripe, inset so the card's corner radius doesn't clip it (T7) */
.slot-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 1rem;
  bottom: 1rem;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: var(--warning); /* Default pending amber */
  transition: background 0.3s ease;
}

.slot-card.taken::before {
  background: var(--success); /* Green if all are taken */
}

.slot-card.missed::before {
  background: var(--danger); /* Red if all are missed */
}

@media (hover: hover) {
  .slot-card:hover {
    transform: translateY(-2px);
    background: var(--bg-card-hover);
  }
}

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

.slot-time-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-strong);
}

.slot-time-badge svg, .slot-time-badge i {
  width: 18px;
  height: 18px;
  color: var(--primary);
  filter: drop-shadow(0 0 3px var(--primary));
}

.slot-header-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.slot-status-summary {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(var(--tint-rgb), 0.04);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-slot-options {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
  border-radius: var(--radius-sm);
  background: rgba(var(--tint-rgb), 0.02);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn-slot-options:hover {
  background: rgba(var(--tint-rgb), 0.06);
  color: var(--text-strong);
}

.btn-slot-options svg, .btn-slot-options i {
  width: 16px;
  height: 16px;
}

.slot-medicines-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

/* No footer button below: don't leave an empty band (T6) */
.slot-medicines-list:last-child {
  margin-bottom: 0;
}

.slot-med-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: rgba(var(--tint-rgb), 0.01);
  border: 1px solid rgba(var(--tint-rgb), 0.03);
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
}

.slot-med-line:hover {
  background: rgba(var(--tint-rgb), 0.02);
  border-color: rgba(var(--tint-rgb), 0.06);
}

.slot-med-info-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0; /* let a long note ellipsize instead of widening the row */
}

.slot-med-details {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex: 1;
  min-width: 0;
}

.slot-med-name {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-strong);
  overflow-wrap: anywhere;
}

/* Wraps instead of pushing a note past the card edge (T2, T3) */
.slot-med-dose-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.5rem;
}

.slot-med-dose-meta span,
.slot-med-dose {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.slot-med-dose {
  white-space: nowrap;
}

.slot-med-dose-meta .dose-note {
  flex-basis: 100%;
  display: block;
}

.slot-med-dose-meta svg, .slot-med-dose-meta i {
  width: 12px;
  height: 12px;
}

.slot-med-right-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* --- Premium Custom Checkboxes --- */
.custom-checkbox {
  flex-shrink: 0;
  display: inline-block;
  position: relative;
  width: 22px;
  height: 22px;
  cursor: pointer;
  user-select: none;
}

.custom-checkbox input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

.checkmark {
  position: absolute;
  top: 0;
  left: 0;
  height: 22px;
  width: 22px;
  background-color: rgba(var(--tint-rgb), 0.03);
  border: 1.5px solid var(--border-subtle);
  border-radius: 6px;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.custom-checkbox:hover input ~ .checkmark {
  background-color: rgba(var(--tint-rgb), 0.08);
  border-color: rgba(var(--tint-rgb), 0.15);
}

.custom-checkbox input:checked ~ .checkmark {
  background-color: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
}

.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}

.custom-checkbox input:checked ~ .checkmark:after {
  display: block;
}

.custom-checkbox .checkmark:after {
  left: 7px;
  top: 3px;
  width: 5px;
  height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* Custom Checkbox Status Icons for Completed Intake Rows */
/* Logged doses get a round status mark; only pending ones get the square
   checkbox, so a logged dose no longer looks like a box to untick (T5). */
.slot-med-status-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.slot-med-status-icon.taken {
  background: var(--success-glow);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.slot-med-status-icon.taken svg, .slot-med-status-icon.taken i {
  width: 14px;
  height: 14px;
}

.slot-med-status-icon.missed {
  background: var(--danger-glow);
  color: var(--danger);
  border: 1px solid rgba(244, 63, 94, 0.2);
}

.slot-med-status-icon.missed svg, .slot-med-status-icon.missed i {
  width: 14px;
  height: 14px;
}

/* --- Group Slot Footer Logging Button --- */
.slot-footer {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.btn-group-log {
  width: 100%;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 0.85rem 1.5rem;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  min-height: 48px; /* Finger-friendly touch height */
}

@media (hover: hover) {
  .btn-group-log:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: scale(1.015);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
  }
}

.btn-group-log:disabled {
  background: rgba(var(--tint-rgb), 0.03);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

/* Finger-friendly tap scaling adjustments inside lines */
@media (max-width: 900px) {
  .slot-card {
    padding: 1.5rem 1.25rem;
    border-radius: var(--radius-lg);
    background: var(--surface-card-solid); /* Slightly solid card */
  }
  
  .slot-med-line {
    padding: 0.85rem 0.75rem 0.85rem 0.9rem;
    border-radius: var(--radius-lg);
  }

  .slot-med-info-group {
    gap: 0.65rem;
  }
  
  .slot-med-name {
    font-size: 1.15rem;
  }
  
  .slot-med-dose-meta {
    font-size: 0.9rem;
    margin-top: 0.15rem;
  }
  
  .btn-group-log {
    padding: 1rem;
    font-size: 1.05rem;
  }
}

/* --- Skipped State Visual Styling --- */
.slot-card.skipped::before {
  background: var(--text-muted); /* Grey border indicator if whole slot is skipped */
}

.slot-med-line.skipped {
  opacity: 0.6;
  background: rgba(var(--tint-rgb), 0.01);
  border-color: rgba(var(--tint-rgb), 0.03);
}

.slot-med-line.skipped:hover {
  background: rgba(var(--tint-rgb), 0.015);
}

.status-badge.skipped {
  background: rgba(var(--tint-rgb), 0.05);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

.slot-med-status-icon.skipped {
  background: rgba(var(--tint-rgb), 0.03);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

.slot-med-status-icon.skipped svg, .slot-med-status-icon.skipped i {
  width: 13px;
  height: 13px;
  opacity: 0.8;
}

/* --- Skip Reason Modal & Predefined Chips --- */
.reason-chips-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
  margin-bottom: 0.75rem;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.reason-chip-btn {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: rgba(var(--tint-rgb), 0.02);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-family: var(--font-stack);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.reason-chip-btn:hover {
  background: rgba(var(--tint-rgb), 0.05);
  border-color: rgba(var(--tint-rgb), 0.15);
  color: var(--text-strong);
}

.reason-chip-btn.selected {
  background: var(--warning-glow);
  border-color: var(--warning);
  color: var(--warning);
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.15);
}

/* Scrollbar for chips grid if needed */
.reason-chips-grid::-webkit-scrollbar {
  width: 4px;
}
.reason-chips-grid::-webkit-scrollbar-thumb {
  background: rgba(var(--tint-rgb), 0.05);
}

@media (max-width: 480px) {
  /* The dialog scrolls; a nested 180px scroller hid the 5th reason (D2). */
  .reason-chips-grid {
    max-height: none;
    overflow: visible;
  }
}

/* --- SW Update Banner --- */
.sw-update-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: rgba(99, 102, 241, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: var(--font-stack);
  animation: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.sw-update-banner button {
  background: rgba(var(--tint-rgb), 0.2);
  color: #fff;
  border: 1px solid rgba(var(--tint-rgb), 0.3);
  border-radius: var(--radius-sm);
  padding: 0.4rem 1rem;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
  font-family: var(--font-stack);
  white-space: nowrap;
}

.sw-update-banner button:hover {
  background: rgba(var(--tint-rgb), 0.35);
}

/* Read-only mode banner (H3): data couldn't be loaded, saving is disabled */
.sw-update-banner.readonly-banner {
  background: rgba(190, 18, 60, 0.95);
  flex-wrap: wrap;
  text-align: center;
}

.sw-update-banner.readonly-banner[hidden] {
  display: none;
}

/* Error variant of the status toast (failed saves) */
.toast-card.toast-error {
  border-color: rgba(244, 63, 94, 0.5);
}

@keyframes slideDown {
  from { transform: translateY(-100%); }
  to { transform: translateY(0); }
}


/* --- Accessibility: respect reduced-motion preference --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* The hidden attribute must win over class display rules (e.g. .empty-state's flex) */
[hidden] {
  display: none !important;
}

/* --- Inline form field errors --- */
.field-error {
  color: var(--danger);
  font-size: 0.82rem;
  font-weight: 600;
  margin-top: 0.4rem;
}

/* Informational note under a form field (e.g. past start date, M3) */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Frequency controls in the medicine form --- */
.weekday-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.6rem;
  border: none;
  padding: 0;
}

.weekday-picker[hidden],
.interval-picker[hidden],
.effective-date-row[hidden],
#group-med-times[hidden] {
  display: none;
}

.weekday-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 36px;
  padding: 0 0.6rem;
  border-radius: 9999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.weekday-chip input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}

.weekday-chip:has(input:checked) {
  background: var(--primary-glow);
  border-color: var(--primary);
  color: var(--text-main);
}

.weekday-chip:has(input:focus-visible) {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.interval-picker {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.interval-picker label {
  margin: 0;
}

.interval-picker input {
  width: 5rem;
}

.effective-date-row {
  margin-top: 0.85rem;
  padding: 0.75rem;
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-md);
}

.effective-date-row label {
  font-size: 0.85rem;
}

.field-hint {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 0.4rem;
  line-height: 1.4;
}

#form-medicine input[aria-invalid="true"] {
  border-color: var(--danger);
}

/* --- Notes on doses (schema v3) --- */
.dose-note {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  max-width: 100%;
  font-size: 0.75rem;
  color: var(--info);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dose-note svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

.history-note {
  display: flex;
  align-items: flex-start;
  gap: 0.25rem;
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--info);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.history-note svg {
  width: 12px;
  height: 12px;
  margin-top: 2px;
  flex-shrink: 0;
}

/* A time that starts or stops on a later day (A+) */
.time-pill-note {
  font-weight: 500;
  color: var(--text-muted);
}

/* --- As-needed (PRN) medicines --- */
.prn-entry-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.5rem;
  padding-left: 0.25rem;
}

.prn-entry {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--text-main);
}

.prn-entry-time {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-weight: 600;
}

.prn-entry-time svg {
  width: 14px;
  height: 14px;
  color: var(--success);
}

.prn-entry-actions {
  margin-left: auto;
  display: inline-flex;
  gap: 0.25rem;
}

.prn-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  min-height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.prn-icon-btn:hover {
  color: var(--text-main);
  background: var(--bg-card-hover);
}

.prn-icon-btn svg {
  width: 16px;
  height: 16px;
}

.prn-footer {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.prn-footer .prn-time-input {
  width: auto;
  flex: 0 0 auto;
  padding: 0.5rem;
  font-size: 0.9rem;
}

.prn-footer .btn-group-log {
  flex: 1;
}

.prn-usage-card {
  padding: 1.25rem 1.5rem;
  margin-bottom: 2rem;
}

.prn-usage-card h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.prn-usage-card[hidden] {
  display: none;
}

#prn-usage-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#prn-usage-list li {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  font-size: 0.9rem;
}

.prn-usage-name {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
}

.prn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.prn-usage-counts {
  color: var(--text-muted);
}

/* --- Tapering (linked phases) --- */
.taper-phases-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.taper-phase-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.taper-phase-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 7rem auto;
  align-items: center;
  gap: 0.5rem;
}

/* "7 days", not a bare "7" (D6) */
.taper-days-wrap {
  position: relative;
  display: block;
}

.taper-phase-row .taper-days {
  padding-right: 3rem;
}

.taper-days-unit {
  position: absolute;
  right: 0.7rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.8rem;
  color: var(--text-muted);
  pointer-events: none;
}

.taper-phase-num {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 1.5rem;
}

.taper-phase-row input {
  padding: 0.55rem 0.7rem;
  font-size: 0.9rem;
}

.taper-continue {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0.75rem 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
}

.taper-continue input {
  width: auto;
  margin-top: 0.15rem;
}

.taper-timeline {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.25rem 0 0.75rem;
}

.taper-timeline li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.taper-timeline li.current {
  color: var(--text-main);
  font-weight: 600;
}

.taper-timeline li.done {
  opacity: 0.6;
}

.taper-timeline .taper-phase-dates {
  flex: 1;
}

.taper-timeline .med-action-btn {
  min-width: 32px;
  min-height: 32px;
}

.taper-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--info);
}

/* --- Doctor report (print only) --- */
#print-report {
  display: none;
}

@media print {
  @page {
    margin: 16mm;
  }

  body > *:not(#print-report) {
    display: none !important;
  }

  html,
  body {
    background: #fff !important;
    color: #111 !important;
  }

  #print-report {
    display: block;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 10.5pt;
    line-height: 1.4;
    color: #111;
  }

  #print-report h1 {
    font-size: 17pt;
    margin: 0 0 2pt;
  }

  #print-report h2 {
    font-size: 12pt;
    margin: 14pt 0 5pt;
    break-after: avoid;
  }

  #print-report .report-meta {
    color: #444;
    margin-bottom: 8pt;
  }

  #print-report table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 6pt;
  }

  #print-report th,
  #print-report td {
    text-align: left;
    padding: 3pt 5pt;
    border-bottom: 0.5pt solid #bbb;
    vertical-align: top;
  }

  #print-report th {
    font-weight: 700;
    border-bottom: 1pt solid #333;
  }

  #print-report tr {
    break-inside: avoid;
  }

  #print-report .num {
    text-align: right;
    white-space: nowrap;
  }

  #print-report .report-footer {
    margin-top: 14pt;
    color: #555;
    font-size: 8.5pt;
  }
}

/* --- Settings controls --- */
.settings-select {
  width: auto;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
}

.settings-desc-status:empty {
  display: none;
}

.pwa-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.85rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--success-glow);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.pwa-badge svg {
  width: 14px;
  height: 14px;
}

/* --- Phone layout (UX audit 2026-10-03, batch 1) --- */
@media (max-width: 900px) {
  /* The greeting and streak/today pills belong to the tracker only (G2). */
  body:not([data-view="tracker"]) .dashboard-header {
    display: none !important;
  }

  /* Greeting on top, pills below; nothing runs off the right edge (G1). */
  body.show-mobile-details .dashboard-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .welcome-section .greeting-title {
    font-size: 1.6rem;
  }

  .header-widgets {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .header-widget-card {
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    white-space: nowrap;
  }

  .header-widget-card svg {
    width: 16px;
    height: 16px;
  }

  .page-header-action {
    padding: 0.6rem 0.9rem;
  }
}

@media (max-width: 600px) {
  /* Text first, then its controls: no squeezed one-word columns (S1). */
  .settings-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .settings-row > button,
  .settings-row > a,
  .settings-row > select,
  .settings-row > .badge {
    align-self: flex-start;
  }

  .settings-section-card {
    padding: 1.25rem;
  }
}

@media (max-width: 420px) {
  /* Paired fields (dates, dose + colour) stack on narrow phones (D1). */
  .form-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }
}

/* --- As-needed cards (T12): medicine in the header, neutral stripe --- */
.slot-card.prn-card::before {
  background: var(--info);
}

.prn-header {
  flex-wrap: wrap;
  min-width: 0;
  gap: 0.5rem;
}

.prn-header .slot-med-name {
  font-size: 1.1rem;
}

.prn-header .slot-med-dose {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

.prn-header .slot-med-dose svg {
  width: 12px;
  height: 12px;
  color: var(--text-muted);
  filter: none;
}

.prn-card .prn-entry-list {
  margin-top: 0;
}

/* --- Action menu (Medicines "More" ⋮, M1) --- */
.action-menu {
  position: fixed;
  z-index: 900;
  min-width: 230px;
  max-width: calc(100vw - 16px);
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  background: var(--surface-card-solid);
  border-radius: var(--radius-md);
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, 0.55);
  animation: fadeIn 0.12s ease-out;
}

.action-menu-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 48px;
  padding: 0.55rem 0.75rem;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 0.95rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.action-menu-item:hover,
.action-menu-item:focus-visible {
  background: rgba(var(--tint-rgb), 0.06);
  outline: none;
}

.action-menu-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.action-menu-item.danger,
.action-menu-item.danger svg {
  color: var(--danger);
}

.action-menu-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.action-menu-hint {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}

/* --- History table (A8): a table on wide screens, cards on phones --- */
.history-card {
  padding: 1.5rem;
}

.history-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-strong);
}

.history-table {
  width: 100%;
  margin-top: 1rem;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.history-table th {
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-weight: 600;
}

.history-table td {
  padding: 0.75rem 0.5rem;
  vertical-align: top;
}

.history-table tbody tr {
  border-bottom: 1px solid var(--border-subtle);
}

.history-table .h-date { font-weight: 500; white-space: nowrap; }
.history-table .h-sched,
.history-table .h-dose { color: var(--text-muted); white-space: nowrap; }
.history-table .h-logged { color: var(--text-strong); white-space: nowrap; }
.history-table .h-none { color: var(--text-muted); }

.history-table .h-sched svg {
  width: 14px;
  height: 14px;
  margin-right: 0.25rem;
  vertical-align: -2px;
}

.h-med-name {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 700;
  color: var(--text-strong);
}

.history-reason {
  display: block;
  margin-top: 2px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.history-empty td {
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
}

@media (max-width: 900px) {
  /* KPIs: 2 × 2 instead of four full-width cards (A2) */
  .analytics-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
  }

  .stat-box {
    padding: 1rem;
    gap: 0.3rem;
  }

  .stat-box-value {
    font-size: 1.6rem;
  }

  .chart-card {
    padding: 1.25rem 1rem;
  }

  .chart-wrapper-trend {
    height: 220px;
  }

  .history-card {
    padding: 1.25rem 1rem;
  }
}

@media (max-width: 600px) {
  .history-table,
  .history-table tbody {
    display: block;
  }

  .history-table thead {
    display: none;
  }

  /* Each entry: name + status, then date · time · dose · logged */
  .history-table tbody tr {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    column-gap: 0.4rem;
    padding: 0.8rem 0;
  }

  .history-table td {
    display: block;
    padding: 0;
    font-size: 0.8rem;
  }

  /* Name + badge fill the first line, so date · time · dose wrap below */
  .history-table .h-med {
    order: 1;
    flex: 1 0 calc(100% - 7rem);
    min-width: 0;
    font-size: 0.95rem;
  }

  .history-table .h-status {
    order: 2;
    max-width: 6.5rem;
    margin-left: auto;
  }
  .history-table .h-date { order: 3; margin-top: 0.3rem; font-weight: 600; color: var(--text-main); }
  .history-table .h-sched { order: 4; margin-top: 0.3rem; }
  .history-table .h-dose { order: 5; margin-top: 0.3rem; }
  .history-table .h-logged { order: 6; margin-top: 0.3rem; color: var(--text-muted); }

  .history-table .h-sched::before,
  .history-table .h-dose::before { content: '· '; }
  .history-table .h-logged::before { content: '· logged '; }
  .history-table .h-logged:has(.h-none) { display: none; }
  .history-table .h-sched svg { display: none; }

  .history-table tr.history-empty {
    display: block;
  }

  .history-empty td {
    padding: 1.5rem 0;
    font-size: 0.9rem;
  }
}

/* --- Colour swatches in the medicine form (D5) --- */
fieldset.form-group {
  border: none;
  padding: 0;
  min-width: 0;
}

fieldset.form-group legend {
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.color-swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.color-swatch {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  cursor: pointer;
}

.color-swatch input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.color-swatch .swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: 0 0 0 2px var(--bg-card), 0 0 0 2px transparent;
  transition: box-shadow 0.15s ease;
}

.color-swatch input:checked + .swatch {
  box-shadow: 0 0 0 3px var(--bg-input), 0 0 0 5px var(--swatch);
}

.color-swatch input:focus-visible + .swatch {
  outline: 2px solid var(--primary);
  outline-offset: 6px;
}

/* --- Dialogs become bottom sheets on phones (D7) --- */
@media (max-width: 600px) {
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal-card,
  .modal-overlay .modal-card {
    max-width: none !important;
    max-height: 92vh;
    max-height: 92dvh;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    padding: 1.25rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom)) !important;
  }

  /* Grab handle */
  .modal-card::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    margin: -0.35rem auto 0.9rem;
    border-radius: 2px;
    background: rgba(var(--tint-rgb), 0.18);
  }

  .modal-header {
    margin-bottom: 1rem !important;
  }
}

/* --- History: not-logged doses, Missed filter, tap to open (batch 7) --- */
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
}

.history-filter {
  display: inline-flex;
  padding: 3px;
  border-radius: 9999px;
  background: rgba(var(--tint-rgb), 0.05);
  border: 1px solid var(--border-subtle);
}

.history-filter-btn {
  min-height: 36px;
  padding: 0.35rem 0.95rem;
  border: none;
  border-radius: 9999px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.history-filter-btn[aria-pressed="true"] {
  background: var(--surface-card-solid);
  color: var(--text-strong);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

/* "Not logged": a derived miss, drawn as an outline so it differs from
   a dose the user marked missed */
.status-badge.not-logged {
  background: transparent;
  border: 1px dashed var(--danger);
}

/* The medicine name is a button; its ::after stretches over the whole row
   so the entire row (or card on phones) is the tap target. */
.history-table tr.is-openable {
  position: relative;
}

button.history-open {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
  line-height: inherit;
  text-align: left;
  cursor: pointer;
}

button.history-open::after {
  content: '';
  position: absolute;
  inset: 0;
}

button.history-open:focus-visible {
  outline: none;
}

.history-table tr.is-openable:has(.history-open:focus-visible) {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

@media (hover: hover) {
  .history-table tr.is-openable:hover {
    background: rgba(var(--tint-rgb), 0.03);
  }
}
