:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1a1a1a;
  --muted: #5a5a5a;
  --brand: #1a5fb4;
  --brand-dark: #14487f;
  --good: #217a3c;
  --good-bg: #e4f3e9;
  --warn: #b03500;
  --line: #d9d5cc;
  --radius: 14px;
}
* { box-sizing: border-box; }
html { font-size: 20px; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}
h1, h2, h3 { line-height: 1.25; }
button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 0.7rem 1.2rem;
}
input, select {
  font: inherit;
  padding: 0.65rem 0.8rem;
  border: 2px solid var(--line);
  border-radius: 10px;
  width: 100%;
  background: #fff;
}
input:focus, select:focus, button:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 1px;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-quiet { background: #eceae4; color: var(--ink); }
.btn-quiet:hover { background: #e0ddd4; }
.btn-good { background: var(--good); color: #fff; }
.btn-good:hover { background: #185c2d; }
.btn-danger { background: #fff; color: var(--warn); border: 2px solid var(--warn); }
.btn-danger:hover { background: #fdece5; }
.hidden { display: none !important; }

/* ---- Login ---- */
#login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 26rem;
  box-shadow: 0 4px 18px rgba(0,0,0,0.07);
}
.login-card h1 { margin-top: 0; text-align: center; }
.login-card label { display: block; margin: 0.9rem 0 0.3rem; font-weight: 600; }
.login-card button { width: 100%; margin-top: 1.4rem; font-size: 1.1rem; }
.login-error { color: var(--warn); font-weight: 600; margin-top: 0.9rem; text-align: center; min-height: 1.5rem; }

/* ---- App shell ---- */
header.appbar {
  background: var(--brand);
  color: #fff;
  padding: 0.7rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
header.appbar .title { font-size: 1.25rem; font-weight: 700; }
header.appbar .who { font-size: 0.9rem; opacity: 0.95; }
header.appbar button {
  background: rgba(255,255,255,0.16);
  color: #fff;
  padding: 0.45rem 0.9rem;
}
header.appbar button:hover { background: rgba(255,255,255,0.28); }

nav.tabs {
  display: flex;
  background: var(--card);
  border-bottom: 2px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
nav.tabs button {
  flex: 1;
  background: none;
  border-radius: 0;
  padding: 0.85rem 0.4rem;
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 4px solid transparent;
}
nav.tabs button.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

main { max-width: 52rem; margin: 0 auto; padding: 1.2rem 1rem 4rem; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
}
.placeholder { color: var(--muted); text-align: center; padding: 2.5rem 1rem; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}
.section-head h2 { margin: 0; }
.subtle { color: var(--muted); font-size: 0.9rem; }
.msg-error { color: var(--warn); font-weight: 600; }

/* ---- Today checklist ---- */
.dose {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.dose.taken { background: var(--good-bg); border-color: var(--good); }
.dose .dose-time {
  font-size: 1.3rem;
  font-weight: 700;
  min-width: 6.2rem;
}
.dose .dose-info { flex: 1; min-width: 12rem; }
.dose .dose-name { font-size: 1.15rem; font-weight: 700; }
.dose .dose-detail { color: var(--muted); }
.dose .taken-note { color: var(--good); font-weight: 600; }
.dose button { min-width: 10.5rem; font-size: 1.05rem; padding: 0.85rem 1rem; }
.progress { font-size: 1.05rem; font-weight: 600; }
.progress.done { color: var(--good); }

/* ---- My Meds ---- */
.med-row .med-name { font-size: 1.15rem; font-weight: 700; }
.med-row .med-detail { color: var(--muted); margin: 0.15rem 0 0.5rem; }
.med-row .med-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.med-row.inactive { opacity: 0.75; border-style: dashed; }
.badge {
  display: inline-block;
  background: #eceae4;
  border-radius: 8px;
  padding: 0.1rem 0.55rem;
  font-size: 0.85rem;
  margin-right: 0.35rem;
}
#med-form label { display: block; font-weight: 600; margin: 0.8rem 0 0.25rem; }
.time-row { display: flex; gap: 0.6rem; margin-bottom: 0.5rem; align-items: center; }
.time-row input[type="time"] { max-width: 11rem; }
.time-row input.time-label { flex: 1; }
.time-row .remove-time { padding: 0.5rem 0.8rem; }
.form-actions { display: flex; gap: 0.7rem; margin-top: 1.2rem; flex-wrap: wrap; }

/* ---- Look Up ---- */
.search-row { display: flex; gap: 0.7rem; }
.search-row input { flex: 1; font-size: 1.1rem; }
.search-row button { font-size: 1.05rem; min-width: 7rem; }
.result-title { font-size: 1.2rem; font-weight: 700; }
.result-sub { color: var(--muted); margin-bottom: 0.6rem; }
.interaction-alert {
  background: #fdf0e5;
  border: 2px solid var(--warn);
  border-radius: 10px;
  padding: 0.8rem 1rem;
  margin: 0.6rem 0;
  color: #7a2600;
  font-weight: 600;
}
details.label-section {
  border: 1px solid var(--line);
  border-radius: 10px;
  margin: 0.45rem 0;
  background: #fbfaf7;
}
details.label-section summary {
  cursor: pointer;
  font-weight: 700;
  padding: 0.7rem 0.9rem;
  list-style-position: inside;
}
details.label-section[open] summary { border-bottom: 1px solid var(--line); }
details.label-section .section-text { padding: 0.7rem 0.9rem; }
.sources-list { padding-left: 1.2rem; }
.sources-list li { margin: 0.35rem 0; }
.sources-list a { color: var(--brand); font-weight: 600; }
.disclaimer {
  background: #eef3fa;
  border: 1px solid #c4d4ea;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  color: #23406b;
  font-size: 0.92rem;
}

/* ---- News ---- */
.news-filters { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.news-filters button {
  background: #eceae4;
  color: var(--ink);
  padding: 0.45rem 0.9rem;
  font-size: 0.9rem;
  border-radius: 999px;
}
.news-filters button.active { background: var(--brand); color: #fff; }
.news-item .news-source {
  display: inline-block;
  background: #eef3fa;
  color: #23406b;
  border-radius: 8px;
  padding: 0.05rem 0.55rem;
  font-size: 0.82rem;
  font-weight: 600;
  margin-right: 0.5rem;
}
.news-item .news-date { color: var(--muted); font-size: 0.85rem; }
.news-item .news-title { display: block; font-size: 1.1rem; font-weight: 700; color: var(--brand); margin: 0.3rem 0; text-decoration: none; }
.news-item .news-title:hover { text-decoration: underline; }
.news-item .news-summary { color: var(--ink); }

/* ---- Modal dialog ---- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem; z-index: 100;
}
.modal {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.4rem 1.5rem;
  width: 100%; max-width: 30rem;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}
.modal h3 { margin: 0 0 0.6rem; }
.modal .modal-hint { color: var(--muted); font-size: 0.92rem; margin-bottom: 0.4rem; }
.modal textarea {
  font: inherit; width: 100%; min-height: 4.5rem;
  padding: 0.65rem 0.8rem; border: 2px solid var(--line);
  border-radius: 10px; resize: vertical; background: #fff;
}
.modal textarea:focus { outline: 3px solid var(--brand); outline-offset: 1px; }
.modal .modal-actions { display: flex; gap: 0.7rem; margin-top: 1.1rem; flex-wrap: wrap; }
.modal .modal-actions button { flex: 1; min-width: 9rem; font-size: 1.05rem; }

/* ---- Lookup suggestions dropdown ---- */
.search-wrap { position: relative; flex: 1; }
.suggest-box {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 50;
  max-height: 18rem; overflow-y: auto;
}
.suggest-box .dym {
  padding: 0.45rem 0.9rem; font-size: 0.85rem; font-weight: 700;
  color: var(--warn); border-bottom: 1px solid var(--line);
}
.suggest-box button {
  display: block; width: 100%; text-align: left;
  background: none; border-radius: 0;
  padding: 0.6rem 0.9rem; font-size: 1rem; color: var(--ink);
}
.suggest-box button:hover, .suggest-box button.hilite { background: #eef3fa; }

/* ---- Doctors ---- */
.doc-row .doc-name { font-size: 1.15rem; font-weight: 700; }
.doc-specialty {
  display: inline-block; background: #eef3fa; color: #23406b;
  border-radius: 8px; padding: 0.1rem 0.6rem;
  font-size: 0.85rem; font-weight: 600; margin-left: 0.5rem; vertical-align: middle;
}
.doc-row .doc-detail { color: var(--muted); margin: 0.25rem 0; }
.doc-row .doc-links { display: flex; gap: 0.6rem; flex-wrap: wrap; margin: 0.5rem 0; }
.doc-row .doc-links a {
  display: inline-block; background: #eceae4; color: var(--ink);
  text-decoration: none; font-weight: 600;
  padding: 0.5rem 0.9rem; border-radius: 10px;
}
.doc-row .doc-links a:hover { background: #e0ddd4; }
.doc-row.inactive { opacity: 0.75; border-style: dashed; }

/* ---- Color picker ---- */
.color-grid {
  display: grid;
  grid-template-columns: repeat(8, 2.2rem);
  gap: 0.45rem;
  margin: 0.3rem 0 0.2rem;
}
.color-grid button {
  width: 2.2rem; height: 2.2rem;
  padding: 0; border-radius: 50%;
  border: 3px solid transparent;
}
.color-grid button.selected {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px #fff inset;
}
.doc-color-dot {
  display: inline-block; width: 0.9rem; height: 0.9rem;
  border-radius: 50%; margin-right: 0.45rem; vertical-align: baseline;
}

/* ---- Calendar ---- */
.cal-nav { display: flex; align-items: center; gap: 0.8rem; }
.cal-nav h2 { margin: 0; min-width: 12rem; text-align: center; }
.cal-nav button { padding: 0.5rem 0.9rem; font-size: 1.1rem; }
.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 4px; margin-top: 0.8rem;
}
.cal-dow { text-align: center; font-weight: 700; color: var(--muted); font-size: 0.85rem; padding: 0.3rem 0; }
.cal-day {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 4.6rem;
  padding: 0.25rem 0.3rem;
  cursor: pointer;
  text-align: left; font: inherit;
  display: flex; flex-direction: column; gap: 2px;
  overflow: hidden;
}
.cal-day:hover { border-color: var(--brand); }
.cal-day.other-month { opacity: 0.4; }
.cal-day.today { border: 2px solid var(--brand); }
.cal-day.selected { outline: 3px solid var(--brand); outline-offset: 1px; }
.cal-day .day-num { font-weight: 700; font-size: 0.9rem; }
.appt-chip {
  color: #fff; border-radius: 6px;
  font-size: 0.72rem; font-weight: 600;
  padding: 1px 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.appt-more { font-size: 0.72rem; color: var(--muted); font-weight: 600; }

/* Day detail */
.appt-row { display: flex; align-items: flex-start; gap: 0.8rem; flex-wrap: wrap; }
.appt-color-bar { width: 0.45rem; align-self: stretch; border-radius: 4px; }
.appt-info { flex: 1; min-width: 12rem; }
.appt-info .appt-doc { font-weight: 700; font-size: 1.05rem; }
.appt-info .appt-when { color: var(--muted); }
.appt-info .appt-note { margin-top: 0.2rem; }
#appt-form label { display: block; font-weight: 600; margin: 0.7rem 0 0.25rem; }
#appt-form select { font: inherit; padding: 0.6rem 0.8rem; border: 2px solid var(--line); border-radius: 10px; width: 100%; background: #fff; }
#appt-form textarea {
  font: inherit; width: 100%; min-height: 3.5rem;
  padding: 0.6rem 0.8rem; border: 2px solid var(--line); border-radius: 10px;
  resize: vertical; background: #fff;
}
.cal-legend { display: flex; flex-wrap: wrap; gap: 0.7rem; margin-top: 0.7rem; }
.cal-legend span { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.88rem; color: var(--muted); }

/* ---- Visit history ---- */
.visit-history { margin-top: 0.7rem; border-top: 1px solid var(--line); padding-top: 0.7rem; }
.visit-history h4 { margin: 0.4rem 0 0.4rem; font-size: 0.95rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.visit-item { display: flex; gap: 0.7rem; padding: 0.4rem 0; align-items: baseline; }
.visit-item .visit-date { font-weight: 700; min-width: 10.5rem; }
.visit-item .visit-note { color: var(--muted); flex: 1; }
.visit-item.upcoming .visit-date { color: var(--brand); }

/* ---- Footer ---- */
.site-footer {
  text-align: center;
  padding: 1.2rem 1rem 1.6rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.site-footer strong { color: var(--ink); }
.site-footer .foot-sep { display: inline-block; width: 1.5rem; }
.site-footer .foot-div { color: var(--line); padding: 0 0.3rem; }

/* ---- Mobile (phones) ---- */
@media (max-width: 640px) {
  html { font-size: 17px; }

  /* 1. Tabs: scroll horizontally instead of squeezing six labels */
  nav.tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  nav.tabs button {
    flex: 1 0 auto;
    padding: 0.8rem 0.85rem;
    font-size: 0.95rem;
    white-space: nowrap;
  }

  /* 2. Color picker: fluid columns, never wider than the screen */
  .color-grid { grid-template-columns: repeat(8, 1fr); max-width: 22rem; }
  .color-grid button { width: 100%; aspect-ratio: 1; height: auto; }

  /* 3. Calendar: chips become dots; compact cells and header */
  .cal-day { min-height: 3.2rem; padding: 0.15rem 0.2rem; }
  .cal-day .day-num { font-size: 0.8rem; }
  .cal-grid { gap: 2px; }
  .appt-chip {
    font-size: 0; line-height: 0;
    width: 0.55rem; height: 0.55rem;
    border-radius: 50%; padding: 0;
    display: inline-block; margin-right: 2px;
  }
  .cal-day { flex-direction: row; flex-wrap: wrap; align-content: flex-start; column-gap: 2px; }
  .cal-day .day-num { width: 100%; }
  .appt-more { font-size: 0.65rem; }
  .cal-nav h2 { min-width: 0; font-size: 1.1rem; }
  .cal-nav { gap: 0.4rem; }

  /* 4. Med-form time rows: wrap instead of overflowing */
  .time-row { flex-wrap: wrap; }

  /* Proportion tweaks */
  header.appbar { padding: 0.55rem 0.8rem; }
  header.appbar .title { font-size: 1.1rem; }
  .dose button { min-width: 0; flex: 1 1 auto; }
  main { padding: 0.9rem 0.7rem 3rem; }
}
