/* Mobile-first: base rules target a phone; @media (min-width) widens up.
   Logical properties (margin-inline-*, border-inline-*, text-align: start)
   throughout, so the layout mirrors correctly for Hebrew without a parallel
   set of [dir="rtl"] overrides — the same approach documented for the
   sibling questionnaire app. */

:root {
  --bg: #fafaf8;
  --surface: #ffffff;
  --text: #1c1c1a;
  --muted: #6b6b64;
  --border: #e4e2dc;
  --accent: #2f6f5e;
  --accent-contrast: #ffffff;
  --warn-bg: #fff4e6;
  --warn-border: #e8a33d;
  --warn-text: #7a4a09;
  --soft-text: #9a9990;
  --radius: 0.6rem;
  --gap: 1rem;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Noto Sans Hebrew", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --surface: #1f2023;
    --text: #eceae4;
    --muted: #9a9990;
    --border: #34353a;
    --accent: #6fcbb0;
    --accent-contrast: #0f1512;
    --warn-bg: #332405;
    --warn-border: #b97e1f;
    --warn-text: #f0c37a;
    --soft-text: #77766f;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------------------------------------------------------------- header */

.topbar {
  padding: 0.9rem var(--gap) 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  max-width: 640px;
  margin: 0 auto;
}

.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
}

.subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.lang-toggle {
  flex-shrink: 0;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.4rem 0.75rem;
  min-height: 40px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

.lang-toggle:hover { border-color: var(--accent); color: var(--accent); }
.lang-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ----------------------------------------------------------------- main */

main#screen {
  flex: 1;
  padding: var(--gap);
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

.loading { color: var(--muted); }

/* htmx swap transition: a quick fade rather than a hard cut, in both
   directions of navigation. */
.htmx-swapping { opacity: 0; transition: opacity 120ms ease-out; }
.htmx-settling { opacity: 0; }
#screen, #tabpanel { transition: opacity 160ms ease-in; }

/* ------------------------------------------------------------ client list */

.client-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.client-card {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  text-align: start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  font: inherit;
  color: inherit;
  cursor: pointer;
  min-height: 44px;
  transition: border-color 120ms ease, transform 80ms ease;
}

.client-card:hover { border-color: var(--accent); }
.client-card:active { transform: scale(0.99); }
.client-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.avatar {
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
}

.avatar-lg {
  width: 3.2rem;
  height: 3.2rem;
  font-size: 1.15rem;
}

.client-card-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.3rem;
  min-width: 0;
}

.client-card .name {
  font-weight: 600;
  font-size: 1.02rem;
}

.client-card .meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-contrast);
}

.badge.warn {
  background: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid var(--warn-border);
}

/* ---------------------------------------------------------- client detail */

.back-link {
  display: inline-block;
  margin-bottom: 0.75rem;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
  min-height: 44px;
  line-height: 44px;
}

.back-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.client-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.client-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.tabs {
  display: flex;
  gap: 0.4rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.tab-btn {
  flex: 1;
  padding: 0.65rem 0.5rem;
  border: none;
  background: none;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  min-height: 44px;
  transition: color 120ms ease, border-color 120ms ease;
}

.tab-btn[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ------------------------------------------------------------- answers */

.lang-note {
  font-size: 0.78rem;
  color: var(--muted);
  font-style: italic;
  margin: 0 0 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px dashed var(--border);
}

.section-block { margin-bottom: 1.5rem; }

.section-block > h3 {
  font-size: 1rem;
  margin: 0 0 0.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}

.panel-block > h4 {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0.9rem 0 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

dl.qa { margin: 0; }

dl.qa > div {
  padding: 0.5rem 0;
  border-bottom: 1px dashed var(--border);
}

dl.qa dt {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 0.15rem;
}

dl.qa dd {
  margin: 0;
  font-size: 0.98rem;
}

dl.qa ul {
  margin: 0.2rem 0 0;
  padding-inline-start: 1.1rem;
}

/* ---------------------------------------------------------------- diet */

.diet-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.diet-content.is-referral {
  background: var(--warn-bg);
  border-color: var(--warn-border);
}

.diet-header { margin-bottom: 1rem; }

.diet-content h1 {
  font-size: 1.25rem;
  margin: 0 0 0.25rem;
}

.diet-meta {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0;
}

.diet-content h2 {
  font-size: 1.02rem;
  margin: 1.4rem 0 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.diet-content h2:first-of-type { padding-top: 0; border-top: none; }

.diet-content p { margin: 0.4rem 0; }
.diet-content ol, .diet-content ul { padding-inline-start: 1.3rem; }
.diet-content li { margin: 0.3rem 0; }
.diet-content .rule-soft { color: var(--muted); }

.disclaimer {
  font-size: 0.85rem;
  color: var(--muted);
}

.table-wrap { overflow-x: auto; margin: 0.5rem 0 1rem; }

.diet-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.diet-content th, .diet-content td {
  border: 1px solid var(--border);
  padding: 0.35rem 0.5rem;
  text-align: start;
  white-space: nowrap;
}

.slot-block {
  margin: 1.1rem 0;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
}

.slot-block h3 {
  font-size: 0.98rem;
  margin: 0 0 0.3rem;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  border: none;
  padding: 0;
}

.slot-time {
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--muted);
}

.portion-line {
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 600;
  margin: 0 0 0.5rem;
}

.options {
  padding-inline-start: 1.5rem;
  margin: 0;
}

.options li { font-size: 0.92rem; }

/* Widen up from a phone once there's room to spare. */
@media (min-width: 640px) {
  main#screen { padding: 1.5rem var(--gap) 2.5rem; }
  .topbar { padding: 1.1rem var(--gap) 1rem; }
}

.footer {
  padding: 1rem var(--gap) 1.5rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
  .htmx-swapping, .htmx-settling, #screen, #tabpanel,
  .client-card, .tab-btn, .lang-toggle {
    transition: none !important;
  }
}
