:root {
  /* Design tokens: shared color palette, spacing, radius, and layout constraints. */
  --bg: #f7f9fc;
  --surface: #ffffff;
  --primary: #2d6cdf;
  --primary-hover: #1f57bb;
  --tab-bg: #e9f2ff;
  --tab-text: #184d95;
  --tab-hover: #dbeafe;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #dbe3ef;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(30, 58, 138, 0.08);
  --spacing: 1rem;
  --content-width: clamp(320px, 50vw, 900px);
}

* {
  /* Keep element dimensions predictable when padding/borders are applied. */
  box-sizing: border-box;
}

body {
  /* Global typography and page direction (English, left-to-right). */
  margin: 0;
  font-family: "Tahoma", "Arial", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  direction: ltr;
  text-align: left;
}

body.font-small {
  font-size: 14px;
}

body.font-medium {
  font-size: 16px;
}

body.font-large {
  font-size: 18px;
}

.app-header {
  /* Top branding banner with gradient background and centered headings. */
  background: linear-gradient(135deg, #2d6cdf 0%, #1550b3 100%);
  color: #fff;
  box-shadow: var(--shadow);
  padding: 0.85rem 1rem;
  text-align: center;
  width: var(--content-width);
  margin: 1rem auto 0;
  border-radius: var(--radius);
}

.app-header h1 {
  margin: 0 0 0.15rem;
  font-size: clamp(1.2rem, 4vw, 1.8rem);
}

.app-header h2 {
  margin: 0;
  font-size: clamp(0.9rem, 2.2vw, 1rem);
  font-weight: 500;
  opacity: 0.92;
}

.app-container {
  /* Main card that wraps all app screens and navigation tabs. */
  width: var(--content-width);
  margin: 1.2rem auto 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.tabs-nav {
  position: relative;
}

.tabs {
  /* Responsive tab layout: 2 columns on small screens, 5 on desktop via media query. */
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.tab-button,
button,
select,
input {
  font: inherit;
}

.tab-button,
button {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  background: var(--tab-bg);
  color: var(--tab-text);
  cursor: pointer;
  transition: 0.2s ease;
  font-weight: 600;
  min-height: 44px;
}

.tab-button:hover,
button:hover {
  border-color: #7aa8ea;
  background: var(--tab-hover);
}

.tab-button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.menu-toggle {
  /* Hidden on desktop; appears on mobile as a compact menu trigger. */
  display: none;
  align-items: center;
  justify-content: center;
  width: auto;
  min-width: 96px;
  height: 44px;
  margin-left: auto;
  margin-bottom: 0.6rem;
  border-radius: 12px;
  border: 1px solid #94b4e6;
  background: #e2eeff;
}

.screen {
  padding: 0.2rem;
}

.screen h2 {
  margin: 0 0 0.5rem;
}

.intro {
  color: var(--muted);
  font-size: 1.05rem;
}

.home-alert {
  display: none;
  margin: 0.8rem 0;
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  background: #fee2e2;
  color: #b91c1c;
  font-weight: 700;
  border: 1px solid #fecaca;
}

.home-alert.visible {
  display: block;
}

.home-panel {
  /* Reusable panel style for home dashboard sections. */
  border: 1px solid #d7e2f3;
  border-radius: 14px;
  padding: 1rem;
  margin-top: 0.8rem;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.05);
}

.stats-grid {
  /* Auto-fit card grid for counters and small statistics blocks. */
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.65rem;
}

.stats-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.stat-card {
  background: #f4f8ff;
  border: 1px solid #d5e4fb;
  border-radius: 12px;
  padding: 0.7rem;
  min-height: 90px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.2rem;
}

.stat-label {
  margin: 0;
  color: #34527d;
  font-weight: 600;
  font-size: 0.9rem;
}

.stat-value {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: #0b4fa8;
}

#next-dose-title {
  color: #0b4fa8;
}

#next-reminder {
  background: #e8f3ff;
  border: 1px solid #c7dcfb;
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
}

#home-screen .home-panel:last-of-type {
  background: #f8fbff;
}

.home-schedule-list .home-schedule-item {
  background: #ffffff;
  border: 1px solid #e5edf8;
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
}

.home-panel h3 {
  margin: 0 0 0.5rem;
}

.next-reminder {
  margin: 0;
  font-weight: 600;
}

.home-schedule-list {
  margin: 0;
  padding-left: 1rem;
  padding-right: 0;
  display: grid;
  gap: 0.35rem;
}

.home-schedule-item {
  color: var(--text);
}

#reminder-form,
.settings-list {
  /* Vertical stacked layout for form/settings controls with consistent spacing. */
  display: grid;
  gap: 0.95rem;
  margin-top: 0.7rem;
}

.form-group {
  display: grid;
  gap: 0.35rem;
}

.form-group label,
legend {
  font-weight: 600;
}

.time-options-group {
  border: 1px solid #cfe0f6;
  background: #f8fbff;
  border-radius: 10px;
  padding: 0.7rem;
}

.time-options {
  /* Grid of selectable dose-time chips. */
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.5rem;
}

.time-option {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid #bfd8f7;
  background: #edf5ff;
  border-radius: 8px;
  padding: 0.45rem 0.5rem;
}

.time-option:has(input:checked) {
  background: #dbeafe;
  border-color: #3b82f6;
  color: #0f3f83;
}

.manual-time-row {
  margin-top: 0.7rem;
  display: grid;
  gap: 0.35rem;
}

.manual-time-row label {
  font-weight: 600;
}

.form-group input,
.form-group select {
  /* Unified input appearance and touch-friendly minimum height. */
  border: 1px solid #bfd3ef;
  border-radius: 10px;
  padding: 0.65rem;
  min-height: 44px;
  background: #f8fbff;
}

.form-group input:focus,
.form-group select:focus {
  outline: 2px solid #93c5fd;
  border-color: #3b82f6;
}

.checkbox-group {
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.6rem;
}

.form-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.primary:hover {
  background: var(--primary-hover);
}

.secondary {
  background: #eaf3ff;
  border-color: #bed6f6;
  color: #16427f;
}

.table-wrap {
  /* Horizontal scroll wrapper to keep schedule/history tables usable on small screens. */
  overflow-x: auto;
  border: 1px solid #cfe0f6;
  background: #f8fbff;
  border-radius: 10px;
  margin-top: 0.8rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 0.7rem;
  text-align: left;
}

th {
  background: #dbeafe;
  color: #0f3f83;
}

tbody tr:nth-child(even) td {
  background: #f9fcff;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 1.2rem;
}

.delete-btn {
  background: #fee2e2;
  border-color: #fecaca;
  color: #991b1b;
}

.delete-btn:hover {
  border-color: #ef4444;
}

.inline-message {
  margin: 0;
  min-height: 1.5rem;
  font-size: 0.95rem;
  color: var(--muted);
}

.inline-message.success {
  color: #065f46;
}

.inline-message.error {
  color: #b91c1c;
}

.helper-note {
  margin: -0.35rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.toolbar-row {
  margin-top: 0.8rem;
  display: flex;
  justify-content: flex-start;
}

.print-btn {
  min-width: 180px;
}

#settings-screen .settings-list {
  background: #f8fbff;
  border: 1px solid #d4e2f6;
  border-radius: 14px;
  padding: 1rem;
}

.reminder-modal {
  /* Full-screen overlay that focuses user attention on due-dose actions. */
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 999;
}

.reminder-modal[hidden] {
  display: none;
}

.reminder-modal-card {
  width: min(560px, 100%);
  background: var(--surface);
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 1rem;
  text-align: center;
}

.reminder-modal-card h2 {
  margin-top: 0;
  margin-bottom: 0.8rem;
  color: #b91c1c;
  font-size: clamp(1.5rem, 4vw, 2rem);
}

.modal-reminder-name {
  font-size: clamp(1.1rem, 3.8vw, 1.4rem);
  font-weight: 700;
  margin: 0.4rem 0;
}

.modal-reminder-time {
  font-size: 1.05rem;
  margin: 0.25rem 0;
  color: var(--text);
}

.modal-reminder-note {
  margin: 0.2rem 0 1rem;
  color: var(--muted);
  font-size: 1.02rem;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
}

@media (min-width: 768px) {
  /* Desktop/tablet adjustments for wider spacing and full tab row. */
  .tabs {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .app-container {
    padding: 1.3rem;
  }
}

@media (max-width: 767px) {
  /* Mobile layout: compact header, collapsible tabs, stacked action buttons. */
  .app-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    padding: 0.7rem 0.8rem;
  }

  .app-header h1 {
    margin: 0;
    font-size: 1.1rem;
  }

  .app-header h2 {
    margin: 0;
    font-size: 0.72rem;
    white-space: nowrap;
  }

  .menu-toggle {
    display: flex;
    margin-left: auto;
    margin-right: 0;
  }

  .tabs {
    display: none;
    position: absolute;
    right: calc((100vw - 100%) / -2);
    left: auto;
    top: calc(100% - 0.3rem);
    width: min(240px, calc(100vw - 2rem));
    background: #f5f9ff;
    border: 1px solid #bcd2f4;
    border-radius: 12px;
    padding: 0.45rem;
    box-shadow: 0 10px 20px rgba(30, 58, 138, 0.16);
    z-index: 10;
    grid-template-columns: 1fr;
    gap: 0.4rem;
  }

  .tabs.open {
    display: grid;
  }

  .form-actions button,
  .modal-actions button {
    flex: 1 1 100%;
  }
}


.status-pill {
  /* Shared badge base style; color variants are defined per status below. */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 82px;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.86rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.status-pending {
  background: #fff7ed;
  color: #9a3412;
  border-color: #fed7aa;
}

.status-taken {
  background: #ecfdf5;
  color: #065f46;
  border-color: #a7f3d0;
}

.status-snoozed {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.status-missed {
  background: #fef2f2;
  color: #b91c1c;
  border-color: #fecaca;
}

.print-patient-name {
  margin: 0 0 0.75rem;
  font-weight: 700;
  color: #1f2937;
}

@media print {
  /* Print mode: show report-focused layout and hide interactive controls. */
  @page {
    size: landscape;
    margin: 10mm;
  }

  body {
    background: #fff;
  }

  .tabs-nav,
  .form-actions,
  .toolbar-row,
  .modal-actions,
  button,
  .delete-btn,
  .menu-toggle,
  .home-alert {
    display: none !important;
  }

  .app-header,
  .app-container,
  .table-wrap,
  .home-panel {
    box-shadow: none;
    border-color: #ddd;
    background: #fff;
  }

  .app-header,
  .app-container {
    width: 100%;
    max-width: none;
    margin: 0 0 0.6rem;
    padding: 0.5rem;
  }

  .table-wrap {
    overflow: visible;
  }

  .screen {
    display: none !important;
  }

  #today-screen {
    display: block !important;
  }

  #print-patient-name {
    display: block !important;
  }

  table {
    width: 100%;
    min-width: 0;
  }
}
