/* =========================================================================
   EczemaClues — styles (v2, "Apricot & Clay" warm health-tech theme)
   Mobile-first. No external fonts (system stack) so nothing phones home.
   Design language: soft sage/emerald, warm neutrals, layered soft shadows,
   generous radii, frosted sticky chrome, gentle motion.
   ========================================================================= */

:root {
  /* Neutrals — warm-cool off-white, deep green-charcoal text */
  /* Neutrals — warm cream & clay ("Apricot & Clay") */
  --bg: #fbf4ec;
  --surface: #fffdfb;
  --surface-2: #f4e9de;
  --surface-3: #ecdfd1;
  --text: #3a2c24;
  --text-soft: #7a6557;
  --border: #eeddce;
  --border-strong: #dcc8b6;

  /* Brand — apricot / terracotta with a warm tint + sage accent */
  --primary: #d9744a;
  --primary-dark: #a8501f;     /* darker terracotta for link/chip text */
  --primary-hi: #e89468;       /* gradient top for buttons */
  --primary-soft: #f9e6d8;
  --primary-softer: #fef4ec;
  --accent: #5e9b7e;           /* sage green — quiet complement */
  --danger: #bf3b2c;
  --warning: #b5791a;

  /* Layered, soft (warm-tinted) shadows */
  --shadow-sm: 0 1px 2px rgba(74,43,25,.06);
  --shadow: 0 1px 2px rgba(74,43,25,.06), 0 10px 24px -12px rgba(74,43,25,.18);
  --shadow-lg: 0 8px 24px -6px rgba(74,43,25,.16), 0 24px 60px -12px rgba(74,43,25,.30);
  --ring: 0 0 0 3px var(--primary-soft);

  /* Frosted chrome */
  --chrome: rgba(255,251,246,.72);

  /* Severity scale */
  --sev-0: #5fb597;
  --sev-mild: #9ccb5a;
  --sev-mod: #e6b04a;
  --sev-sev: #e07a4e;
  --sev-max: #c9483a;

  --radius-lg: 22px;
  --radius: 16px;
  --radius-sm: 11px;
  --maxw: 720px;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Warm "clay night" dark mode */
    --bg: #17110c;
    --surface: #211a13;
    --surface-2: #2b211a;
    --surface-3: #362a20;
    --text: #f2e7dd;
    --text-soft: #b7a392;
    --border: #352a20;
    --border-strong: #46372a;

    --primary: #e68a5b;
    --primary-dark: #f0a176;    /* lighter apricot reads on dark tints */
    --primary-hi: #f09a6a;
    --primary-soft: #3a241a;
    --primary-softer: #29190f;
    --accent: #6fae8b;
    --danger: #e0574a;
    --warning: #d59a45;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 28px -14px rgba(0,0,0,.6);
    --shadow-lg: 0 10px 30px -6px rgba(0,0,0,.6), 0 30px 70px -16px rgba(0,0,0,.7);
    --ring: 0 0 0 3px rgba(230,138,91,.28);
    --chrome: rgba(24,18,13,.72);
  }
}

* { box-sizing: border-box; }

/* The hidden attribute must always win, even over class rules that set a
   display value (.modal-host, .tabbar). */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(1200px 600px at 100% -10%, var(--primary-softer), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  padding-bottom: 92px; /* room for tabbar on mobile */
}

h1, h2, h3 { line-height: 1.22; letter-spacing: -0.015em; }
h1 { font-size: 1.55rem; margin: 0 0 .5rem; font-weight: 750; }
h2 { font-size: 1.2rem; margin: 0 0 .75rem; font-weight: 700; }
h3 { font-size: 1rem; margin: 0 0 .4rem; font-weight: 650; }
p { margin: 0 0 .75rem; }

.visually-hidden, .skip-link {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link:focus {
  position: fixed; top: 8px; left: 8px; width: auto; height: auto;
  background: var(--primary); color: #fff; padding: 8px 12px; border-radius: 8px; z-index: 1000;
}

/* ---------- Header (frosted, sticky) ---------- */
.app-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--chrome);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.app-header__inner {
  max-width: var(--maxw); margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 11px 16px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 750; letter-spacing: -0.02em; }
.brand__mark {
  font-size: 1.15rem; width: 34px; height: 34px; display: grid; place-items: center;
  background: linear-gradient(160deg, var(--primary-soft), var(--surface-2));
  border: 1px solid var(--border); border-radius: 11px;
}
.brand__name { font-size: 1.06rem; }
.child-switcher { display: flex; align-items: center; gap: 6px; }
.child-switcher__select {
  font-size: .95rem; font-weight: 600; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  max-width: 42vw; box-shadow: var(--shadow-sm); cursor: pointer;
}

/* ---------- Main / views ---------- */
.app-main { max-width: var(--maxw); margin: 0 auto; padding: 18px 16px; }
.view { animation: fade .22s cubic-bezier(.2,.7,.2,1); }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow);
  margin-bottom: 16px;
}

/* ---------- Welcome / hero ---------- */
.welcome { position: relative; overflow: hidden; }
.welcome::before {
  content: ""; position: absolute; inset: -40% -30% auto auto; width: 340px; height: 340px;
  background: radial-gradient(circle at 30% 30%, var(--primary-soft), transparent 70%);
  pointer-events: none;
}
.welcome h1 { font-size: 1.9rem; }
.welcome__lead { font-size: 1.06rem; color: var(--text-soft); max-width: 52ch; }
.welcome__points { list-style: none; padding: 0; margin: 18px 0; display: grid; gap: 8px; }
.welcome__points li {
  background: var(--surface-2); padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); font-weight: 500;
}
.welcome__actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }

/* ---------- Buttons ---------- */
.btn {
  /* display + text-decoration matter for <a class="btn"> — inline anchors let
     vertical padding overlap surrounding text */
  display: inline-block; text-align: center; text-decoration: none;
  font: inherit; font-weight: 640; cursor: pointer; letter-spacing: -.01em;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: 11px 17px; border-radius: var(--radius-sm); box-shadow: var(--shadow-sm);
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.99); box-shadow: var(--shadow-sm); }

.btn--primary {
  background: linear-gradient(180deg, var(--primary-hi), var(--primary));
  border-color: var(--primary-dark); color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,.25) inset, 0 6px 16px -6px var(--primary);
}
.btn--primary:hover { filter: brightness(1.03); box-shadow: 0 1px 0 rgba(255,255,255,.3) inset, 0 10px 22px -6px var(--primary); }
.btn--ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--primary-dark); }
.btn--ghost:hover { background: var(--primary-soft); box-shadow: none; }
.btn--lg { padding: 14px 22px; font-size: 1.03rem; border-radius: var(--radius); }
.btn--icon {
  width: 42px; height: 42px; padding: 0; font-size: 1.3rem; line-height: 1; border-radius: 12px;
  display: inline-grid; place-items: center;
}
.btn--danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); background: transparent; box-shadow: none; }
.btn--danger:hover { background: color-mix(in srgb, var(--danger) 8%, transparent); }
.btn--block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.linkbtn {
  background: none; border: none; color: var(--primary-dark); font: inherit; cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px; padding: 0;
}

/* ---------- Tabbar (frosted bottom nav on mobile) ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  display: flex; gap: 2px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--chrome);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--border);
}
.tabbar__btn {
  flex: 1; background: none; border: none; cursor: pointer; color: var(--text-soft);
  padding: 8px 4px; font-size: .72rem; font-weight: 640; border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  transition: background .15s ease, color .15s ease;
}
.tabbar__icon { font-size: 1.25rem; transition: transform .15s ease; }
.tabbar__btn:hover { color: var(--text); }
.tabbar__btn.is-active { color: var(--primary-dark); background: var(--primary-soft); }
.tabbar__btn.is-active .tabbar__icon { transform: translateY(-1px) scale(1.06); }

/* ---------- Forms ---------- */
.field { margin-bottom: 22px; }
.field__label { display: block; font-weight: 640; margin-bottom: 9px; letter-spacing: -.01em; }
.field__hint { color: var(--text-soft); font-size: .85rem; font-weight: 450; }
input[type="text"], input[type="email"], input[type="tel"], input[type="number"],
input[type="date"], textarea, select {
  width: 100%; font: inherit; color: var(--text);
  padding: 12px 13px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
input::placeholder, textarea::placeholder { color: var(--text-soft); opacity: .8; }
textarea { resize: vertical; min-height: 68px; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--primary); background: var(--surface); box-shadow: var(--ring);
}
.btn:focus-visible, .chip:focus-visible, .tabbar__btn:focus-visible, .linkbtn:focus-visible {
  outline: none; box-shadow: var(--ring);
}

/* Severity */
.sev { display: flex; flex-direction: column; gap: 14px; }
.sev__row { display: flex; align-items: center; gap: 14px; }
.sev__value {
  font-size: 1.5rem; font-weight: 800; min-width: 58px; height: 52px; text-align: center;
  border-radius: 14px; padding: 0 10px; color: #fff; display: grid; place-items: center;
  box-shadow: 0 6px 16px -8px rgba(0,0,0,.5), 0 1px 0 rgba(255,255,255,.25) inset;
}
.sev__label { font-weight: 680; font-size: 1.05rem; }
input[type="range"] {
  -webkit-appearance: none; appearance: none; height: 10px; border-radius: 99px;
  background: linear-gradient(90deg, var(--sev-0), var(--sev-mild), var(--sev-mod), var(--sev-sev), var(--sev-max));
  box-shadow: inset 0 1px 2px rgba(0,0,0,.15);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 30px; height: 30px; border-radius: 50%; background: #fff;
  border: 4px solid var(--primary); cursor: pointer; box-shadow: var(--shadow); margin-top: 0;
}
input[type="range"]::-moz-range-thumb {
  width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 4px solid var(--primary);
  cursor: pointer; box-shadow: var(--shadow);
}

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  /* weight stays constant across states so toggling never reflows the layout */
  font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer; user-select: none;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 999px; box-shadow: var(--shadow-sm);
  transition: background .12s, border-color .12s, color .12s, transform .08s;
}
.chip:hover { border-color: var(--primary); transform: translateY(-1px); }
.chip:active { transform: translateY(0) scale(.97); }
.chip.is-on {
  background: var(--primary-soft); border-color: var(--primary);
  color: var(--primary-dark); box-shadow: inset 0 0 0 1px var(--primary);
}
.chip--add { border-style: dashed; color: var(--text-soft); box-shadow: none; }

.tag-input-row { display: flex; gap: 8px; margin-top: 11px; }
.tag-input-row input { flex: 1; }

.subgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.subgrid label { font-weight: 600; font-size: .9rem; display: grid; gap: 6px; }
@media (max-width: 420px) { .subgrid { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }

/* ---------- History ---------- */
.history-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.entry {
  display: flex; gap: 13px; align-items: stretch;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px; box-shadow: var(--shadow-sm);
  cursor: pointer; text-align: left; width: 100%; font: inherit; color: inherit;
  transition: box-shadow .15s ease, transform .08s ease, border-color .15s ease;
}
.entry:hover { box-shadow: var(--shadow); transform: translateY(-1px); border-color: var(--border-strong); }
.entry__sev {
  flex: 0 0 48px; border-radius: 12px; color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 800; box-shadow: 0 1px 0 rgba(255,255,255,.2) inset;
}
.entry__sev small { font-weight: 650; font-size: .58rem; opacity: .92; }
.entry__body { flex: 1; min-width: 0; }
.entry__date { font-weight: 700; letter-spacing: -.01em; }
.entry__meta { color: var(--text-soft); font-size: .85rem; }
.entry__tags { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 5px; }
.minitag { font-size: .72rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 7px; padding: 2px 8px; color: var(--text-soft); }

.empty-note { color: var(--text-soft); text-align: center; padding: 30px 14px; }

/* Timeline */
.timeline { display: flex; align-items: flex-end; gap: 3px; height: 74px; padding: 10px 0; }
.timeline__bar { flex: 1; min-width: 3px; border-radius: 4px 4px 2px 2px; background: var(--sev-0); opacity: .9; transition: opacity .15s; }
.timeline__bar:hover { opacity: 1; }
.timeline__bar[data-empty="1"] { background: var(--border-strong); opacity: .5; height: 5px !important; }

/* ---------- Insights ---------- */
.insight {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 12px; box-shadow: var(--shadow-sm);
}
.insight--strong { border-left-color: var(--sev-sev); background: linear-gradient(180deg, color-mix(in srgb, var(--sev-sev) 5%, var(--surface)), var(--surface)); }
.insight__headline { font-weight: 720; font-size: 1.06rem; margin-bottom: 5px; letter-spacing: -.01em; }
.insight__detail { color: var(--text-soft); font-size: .93rem; }
.insight__stats { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 9px 13px; }
.stat__num { font-weight: 800; font-size: 1.15rem; letter-spacing: -.02em; }
.stat__lab { font-size: .68rem; color: var(--text-soft); text-transform: uppercase; letter-spacing: .05em; font-weight: 650; }
.confidence { display: inline-block; font-size: .72rem; font-weight: 720; padding: 3px 11px; border-radius: 999px; }
.confidence--low { background: var(--surface-3); color: var(--text-soft); }
.confidence--med { background: color-mix(in srgb, var(--warning) 16%, var(--surface)); color: var(--warning); }
.confidence--high { background: var(--primary-soft); color: var(--primary-dark); }

.progress-banner { background: linear-gradient(180deg, var(--primary-soft), var(--surface)); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; margin-bottom: 16px; }
.progress-bar { height: 9px; background: var(--surface-3); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress-bar__fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-hi)); border-radius: 99px; transition: width .4s ease; }

/* ---------- Photos ---------- */
.photo-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.photo-grid:empty { display: none; }
.photo-thumb {
  width: 74px; height: 74px; object-fit: cover; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--border-strong); box-shadow: var(--shadow-sm);
  transition: transform .08s ease, box-shadow .15s ease;
}
.photo-thumb:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.viewer-img { max-width: 100%; max-height: 62vh; display: block; margin: 0 auto; border-radius: 12px; }
.report-photos { display: flex; flex-wrap: wrap; gap: 10px; }
.report-photos figure { margin: 0; width: 150px; }
.report-photos img { width: 100%; border-radius: 8px; border: 1px solid var(--border); }
.report-photos figcaption { font-size: .72rem; color: var(--text-soft); text-align: center; margin-top: 3px; }
.synccode {
  display: block; word-break: break-all; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px; font-size: .85rem; user-select: all;
}

/* ---------- Modal ---------- */
.modal-host {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: rgba(10,20,16,.42); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  padding: 16px; animation: fade .16s ease;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 22px; max-width: 440px; width: 100%; box-shadow: var(--shadow-lg);
  max-height: 90vh; overflow: auto; animation: pop .2s cubic-bezier(.2,.8,.2,1);
}
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
.modal h2 { margin-top: 0; }
.modal__actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 104px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 20px; border-radius: 999px;
  font-weight: 640; z-index: 200; box-shadow: var(--shadow-lg); max-width: 90vw;
  animation: pop .2s cubic-bezier(.2,.8,.2,1);
}

/* ---------- Footer ---------- */
.app-footer { max-width: var(--maxw); margin: 28px auto 0; padding: 16px; color: var(--text-soft); font-size: .85rem; text-align: center; }
.app-footer a { color: var(--primary-dark); }
.app-footer__disclaimer { font-size: .78rem; opacity: .85; }

/* ---------- Report (export) ---------- */
.report__head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.report-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.report-table th, .report-table td { border: 1px solid var(--border); padding: 7px 9px; text-align: left; vertical-align: top; }
.report-table th { background: var(--surface-2); font-weight: 650; }
.report-section { margin-bottom: 22px; }

/* ---------- Desktop ---------- */
@media (min-width: 760px) {
  body { padding-bottom: 0; }
  .app-main { padding: 24px 16px; }
  .tabbar {
    position: static; border-top: none; padding: 6px;
    max-width: var(--maxw); margin: 18px auto 0; border-radius: var(--radius-lg);
    box-shadow: var(--shadow); background: var(--surface); border: 1px solid var(--border);
    backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .tabbar__btn { flex-direction: row; gap: 8px; font-size: .95rem; padding: 12px 14px; }
  .toast { bottom: 28px; }
}

/* =========================================================================
   PRINT — clean dermatologist report
   ========================================================================= */
@media print {
  :root { --bg: #fff; --surface: #fff; --surface-2: #fff; --surface-3: #fff; --text: #000; --text-soft: #333; --border: #999; --border-strong: #999; --shadow: none; --shadow-sm: none; --shadow-lg: none; }
  body { padding: 0; background: #fff; }
  .app-header, .tabbar, .app-footer, .modal-host, .toast,
  .no-print, #view-log, #view-history, #view-insights { display: none !important; }
  .app-main { max-width: none; padding: 0; }
  #view-export { display: block !important; }
  .card { box-shadow: none; border: none; padding: 0; }
  .report-table { font-size: 10pt; }
  .report-table th, .report-table td { border: 1px solid #999; }
  .insight { break-inside: avoid; border: 1px solid #999; }
  .report-section { break-inside: avoid; }
  .report-photos figure { break-inside: avoid; }
  .report-photos img { border: 1px solid #999; }
  h1 { font-size: 18pt; }
  a { color: #000; text-decoration: none; }
}
