/* ============================================================
   MCAS & FHM study tracker — shared by the participant form
   and Charein's study dashboard. Palette follows styles.css.
   ============================================================ */
:root {
    color-scheme: light;
    --ivory: #f6f3ee;
    --ivory-deep: #eee9e0;
    --sage: #3f6b48;
    --sage-dark: #33573a;
    --sage-soft: #e6efe6;
    --charcoal: #2c2a26;
    --stone: #6d685c;
    --muted: #8a8578;
    --line: #ddd6c8;
    --white: #ffffff;
    --warn-bg: #fdf4e3;
    --warn-text: #7a5d14;
    --alert-bg: #fbe4e0;
    --alert-text: #a33d2e;
    --radius: 14px;
    --shadow: 0 2px 14px rgba(44, 42, 38, 0.07);
    /* Severity bands for the 0–10 scales */
    --s0: #e9f1e9;
    --s-mild: #f3f0d6;
    --s-mod: #f8e2c4;
    --s-sev: #f3cdc4;
    --s-worst: #e9b1a6;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: 'Jost', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 17px;
    line-height: 1.5;
    color: var(--charcoal);
    background: var(--ivory);
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: 'Fraunces', Georgia, serif; font-weight: 500; line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.08rem; }
p { margin: 0 0 12px; }
a { color: var(--sage); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Page frame ---------- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    background: rgba(246, 243, 238, 0.94);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
}
.topbar-inner {
    max-width: 680px; margin: 0 auto; padding: 10px 16px;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { font-family: 'Fraunces', Georgia, serif; font-size: 1.02rem; line-height: 1.2; }
.brand small { display: block; font-family: 'Jost', sans-serif; font-size: .74rem; color: var(--stone); letter-spacing: .02em; }
.page { max-width: 680px; margin: 0 auto; padding: 18px 16px 120px; }
.wide .page, .wide .topbar-inner { max-width: 1040px; }

.card {
    background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 18px; margin-bottom: 14px;
}
.card > h2, .card > h3 { margin-bottom: 8px; }
.lede { color: var(--stone); }
.muted { color: var(--muted); font-size: .9rem; }
.small { font-size: .88rem; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }

ul.ticks { padding-left: 0; list-style: none; margin: 0 0 12px; }
ul.ticks li { position: relative; padding-left: 26px; margin-bottom: 8px; }
ul.ticks li::before {
    content: ''; position: absolute; left: 4px; top: .55em; width: 9px; height: 9px;
    border-radius: 50%; background: var(--sage);
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 48px; padding: 10px 22px; border: none; border-radius: 99px;
    background: var(--sage); color: var(--white); font-weight: 500; letter-spacing: .01em;
    text-decoration: none; cursor: pointer; transition: background .15s, transform .1s;
}
.btn:hover { background: var(--sage-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: var(--ivory-deep); color: var(--charcoal); }
.btn.secondary:hover { background: #e4ddd0; }
.btn.ghost { background: transparent; color: var(--sage); padding-left: 8px; padding-right: 8px; }
.btn.danger { background: var(--alert-text); }
.btn.small { min-height: 38px; padding: 6px 14px; font-size: .9rem; }
.btn.block { width: 100%; }
.linkish { background: none; border: none; padding: 0; color: var(--sage); text-decoration: underline; cursor: pointer; }

/* ---------- Form controls ---------- */
label.field { display: block; margin-bottom: 14px; }
label.field > span, .q-label { display: block; font-weight: 500; margin-bottom: 6px; }
.q-hint { display: block; font-size: .86rem; color: var(--stone); font-weight: 400; margin-top: -2px; }
input[type=text], input[type=date], input[type=password], input[type=tel], textarea, select {
    width: 100%; padding: 12px 14px; font-size: 1rem; border: 1.5px solid var(--line);
    border-radius: 10px; background: var(--white);
}
input:focus, textarea:focus, select:focus, button:focus-visible {
    outline: 3px solid rgba(63, 107, 72, .35); outline-offset: 1px; border-color: var(--sage);
}
textarea { min-height: 92px; resize: vertical; }
.code-input { font-size: 1.5rem !important; letter-spacing: .35em; text-align: center; }
.with-mic { position: relative; }
.with-mic textarea, .with-mic input[type=text] { padding-right: 56px; }
.with-mic .mic { position: absolute; right: 6px; top: 6px; }
.with-mic input + .mic { top: 50%; transform: translateY(-50%); }

/* Microphone button — shown only where the browser can listen */
.mic {
    width: 44px; height: 44px; flex: none; border-radius: 50%; border: 1.5px solid var(--line);
    background: var(--white); color: var(--sage); cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
}
.mic svg { width: 20px; height: 20px; }
.mic.listening { background: var(--alert-text); border-color: var(--alert-text); color: #fff;
    animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(163, 61, 46, .45); } 50% { box-shadow: 0 0 0 8px rgba(163, 61, 46, 0); } }
.no-speech .mic { display: none; }
.speech-note { font-size: .82rem; color: var(--stone); margin-top: 6px; }
.speech-note:empty, .q-value:empty { display: none; }

/* ---------- Questions ---------- */
.q { padding: 14px 0; border-top: 1px solid var(--ivory-deep); }
.q:first-of-type { border-top: none; padding-top: 4px; }
.q-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.q-head .q-text { flex: 1; }
.q-value { font-size: .88rem; color: var(--stone); margin-top: 6px; min-height: 1.2em; }
.q-value b { color: var(--charcoal); }

/* 0–10 scale: eleven buttons in one row */
.scale { display: grid; grid-template-columns: repeat(11, 1fr); gap: 4px; }
.scale button {
    min-height: 46px; padding: 0; border: 1.5px solid transparent; border-radius: 9px;
    font-weight: 600; font-size: 1rem; cursor: pointer; color: var(--charcoal);
}
.scale button[data-band="0"] { background: var(--s0); }
.scale button[data-band="mild"] { background: var(--s-mild); }
.scale button[data-band="mod"] { background: var(--s-mod); }
.scale button[data-band="sev"] { background: var(--s-sev); }
.scale button[data-band="worst"] { background: var(--s-worst); }
.scale button[aria-checked="true"] {
    background: var(--charcoal); color: var(--white); border-color: var(--charcoal);
    transform: scale(1.06);
}
.scale-ends { display: flex; justify-content: space-between; font-size: .76rem; color: var(--muted); margin-top: 4px; }
@media (max-width: 380px) {
    .scale { gap: 2px; }
    .scale button { font-size: .9rem; border-radius: 7px; }
}

/* Chips (tick all that apply) and pills (pick one) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 14px;
    border: 1.5px solid var(--line); border-radius: 99px; background: var(--white);
    cursor: pointer; font-size: .95rem; text-align: left; line-height: 1.25;
}
.chip::before {
    content: ''; flex: none; width: 18px; height: 18px; border-radius: 5px;
    border: 1.5px solid #b9b2a3; background: var(--white);
}
.chip.radio::before { border-radius: 50%; }
.chip[aria-checked="true"] { background: var(--sage-soft); border-color: var(--sage); color: var(--sage-dark); font-weight: 500; }
.chip[aria-checked="true"]::before {
    background: var(--sage) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.5l3 3 6-7' stroke='white' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/14px no-repeat;
    border-color: var(--sage);
}
.chip.radio[aria-checked="true"]::before { background: var(--white); box-shadow: inset 0 0 0 4px var(--sage); }
.chips.yesno .chip { min-width: 96px; justify-content: flex-start; }
.sub-q { margin-top: 10px; }

/* Running total */
.total-bar {
    position: sticky; top: 58px; z-index: 5; margin: -4px 0 12px;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    background: var(--charcoal); color: var(--white); border-radius: 12px; padding: 10px 16px;
}
.total-bar .num { font-family: 'Fraunces', Georgia, serif; font-size: 1.6rem; line-height: 1; }
.total-bar .num small { font-size: .9rem; opacity: .7; }
.total-bar .lbl { font-size: .85rem; opacity: .85; }

/* ---------- Wizard ---------- */
.wiz-head { margin-bottom: 14px; }
.wiz-head .eyebrow { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--stone); }
.progress { height: 6px; background: var(--ivory-deep); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress > i { display: block; height: 100%; background: var(--sage); transition: width .25s; }
.wiz-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: rgba(246, 243, 238, 0.96); border-top: 1px solid var(--line);
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.wiz-nav-inner { max-width: 680px; margin: 0 auto; display: flex; gap: 10px; }
.wiz-nav .btn { flex: 1; }
.wiz-nav .btn.secondary { flex: 0 0 auto; }
.form-error { background: var(--alert-bg); color: var(--alert-text); padding: 10px 14px; border-radius: 10px; margin: 0 0 12px; }
.wiz-nav .form-error { max-width: 680px; margin: 0 auto 10px; font-size: .95rem; }

/* ---------- Notices ---------- */
.notice { padding: 12px 14px; border-radius: 10px; margin-bottom: 12px; font-size: .95rem; }
.notice.info { background: var(--sage-soft); color: var(--sage-dark); }
.notice.warn { background: var(--warn-bg); color: var(--warn-text); }
.notice.alert { background: var(--alert-bg); color: var(--alert-text); }
.disclaimer { font-size: .8rem; color: var(--muted); margin-top: 22px; line-height: 1.45; }

/* ---------- Participant home ---------- */
.steps-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 4px 0 16px; }
.steps-strip div {
    text-align: center; font-size: .8rem; padding: 8px 4px; border-radius: 10px;
    background: var(--ivory-deep); color: var(--stone);
}
.steps-strip div b { display: block; font-size: 1rem; color: var(--charcoal); font-weight: 600; }
.steps-strip .done { background: var(--sage); color: #e9f1e9; }
.steps-strip .done b { color: #fff; }
.steps-strip .now { background: var(--white); box-shadow: inset 0 0 0 2px var(--sage); color: var(--sage-dark); }

.daylist { list-style: none; margin: 0; padding: 0; }
.daylist li {
    display: flex; align-items: center; gap: 12px; padding: 12px 0;
    border-top: 1px solid var(--ivory-deep);
}
.daylist li:first-child { border-top: none; }
.daylist .dot {
    flex: none; width: 38px; height: 38px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; font-size: .82rem; font-weight: 600;
    background: var(--ivory-deep); color: var(--stone);
}
.daylist .done .dot { background: var(--sage); color: #fff; }
.daylist .today .dot { background: var(--white); box-shadow: inset 0 0 0 2px var(--sage); color: var(--sage-dark); }
.daylist .tx .dot { font-size: .7rem; }
.daylist .what { flex: 1; min-width: 0; }
.daylist .what b { display: block; font-weight: 500; }
.daylist .what span { font-size: .85rem; color: var(--stone); }
.tag { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .74rem; font-weight: 600;
       background: var(--sage-soft); color: var(--sage-dark); vertical-align: middle; }
.tag.grey { background: var(--ivory-deep); color: var(--stone); }
.tag.warn { background: var(--warn-bg); color: var(--warn-text); }
.tag.alert { background: var(--alert-bg); color: var(--alert-text); }

.plan { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin: 12px 0; }
.plan div { background: var(--ivory); border-radius: 8px; padding: 6px 2px; text-align: center; font-size: .72rem; color: var(--stone); }
.plan div b { display: block; font-size: .84rem; color: var(--charcoal); }
.plan .tx { background: var(--sage); color: #e9f1e9; }
.plan .tx b { color: #fff; }

/* Review list */
.review dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.review dt { color: var(--stone); font-size: .9rem; }
.review dd { margin: 0; font-weight: 500; }

/* ---------- Dashboard tables & charts ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--ivory-deep); vertical-align: top; }
table.data th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--stone); font-weight: 600; background: var(--ivory); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr.unread td { background: #f4f8f1; }
table.data td.small { min-width: 170px; }
.updates { max-height: 380px; overflow-y: auto; }
.chart-box { position: relative; height: 280px; }
.better { color: var(--sage); font-weight: 600; }
.worse { color: var(--alert-text); font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 760px) { .grid2 { grid-template-columns: 1fr; } }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.kpi { background: var(--ivory); border-radius: 10px; padding: 10px 12px; }
.kpi .v { font-family: 'Fraunces', Georgia, serif; font-size: 1.45rem; }
.kpi .l { font-size: .78rem; color: var(--stone); }
details.card > summary { cursor: pointer; font-weight: 500; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: '▸ '; color: var(--sage); }
details.card[open] > summary::before { content: '▾ '; }
.badge-count { display: inline-block; min-width: 22px; padding: 1px 7px; border-radius: 99px; background: var(--alert-text);
               color: #fff; font-size: .78rem; font-weight: 600; text-align: center; }
.invite { background: var(--ivory); border-radius: 10px; padding: 12px; white-space: pre-wrap; font-size: .92rem; }
.big-code { font-family: 'Fraunces', Georgia, serif; font-size: 2rem; letter-spacing: .2em; }

/* ---------- Admin controls on the participant page ---------- */
.admin-cell { min-width: 150px; }
.admin-cell > * + * { margin-top: 6px; }
details.mini > summary { cursor: pointer; font-size: .85rem; color: var(--sage); }
details.mini form { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
details.mini input { padding: 7px 9px; font-size: .9rem; }
.daylist .skipped .what span { color: var(--muted); }
