/* Steady – calm, warm, high-contrast UI. Works offline (system fonts only). */
:root {
    --sand: #F4F1EA;
    --paper: #FFFDF8;
    --ink: #1F2A2C;
    --muted: #5F6B6D;
    --line: #E2DCCF;
    --teal: #2F5D62;
    --teal-2: #5E8B7E;
    --coral: #E9724C;
    --red: #C5283D;
    --gold: #F3A712;
    --anxiety: #E9724C;
    --stress: #8D5A97;
    --mood: #3FA796;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(31, 42, 44, .06), 0 4px 14px rgba(31, 42, 44, .06);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --sand: #141A1B;
        --paper: #1C2426;
        --ink: #ECE8DF;
        --muted: #A2ACAD;
        --line: #2D3739;
        --teal: #7FB3AA;
        --teal-2: #5E8B7E;
        --shadow: none;
    }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    background: var(--sand);
    color: var(--ink);
    font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-text-size-adjust: 100%;
}

h1 { font-size: 1.6rem; margin: .4rem 0 .8rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: .2rem 0 .6rem; }
h3 { font-size: 1rem; margin: 0 0 .4rem; }
a { color: var(--teal); }
small, .small { font-size: .85rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.right { display: block; text-align: right; }
.grow { flex: 1; min-width: 0; }
.error { color: var(--red); }
.ok { color: var(--mood); }
.notice { background: color-mix(in srgb, var(--teal) 12%, transparent); padding: .6rem .8rem; border-radius: 10px; }
.boot { padding: 3rem; text-align: center; color: var(--muted); }

/* ---------- shell ---------- */
.shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; gap: .6rem;
    padding: calc(var(--safe-top) + .55rem) 1rem .55rem;
    background: var(--teal); color: #fff;
}
.topbar .brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.15rem; flex: 1; }
.sync-pill { font-size: .75rem; padding: .15rem .55rem; border-radius: 99px; background: rgba(255,255,255,.18); }
.sync-pill.offline { background: rgba(243,167,18,.35); }
.sync-pill.error { background: rgba(197,40,61,.55); }
.sos {
    border: 0; border-radius: 99px; padding: .4rem .9rem;
    background: var(--red); color: #fff; font-weight: 800; letter-spacing: .05em;
    box-shadow: 0 0 0 3px rgba(255,255,255,.25);
}

.content { flex: 1; width: 100%; max-width: 720px; margin: 0 auto; padding: 1rem 1rem calc(5.5rem + var(--safe-bottom)); }

.tabbar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
    display: grid; grid-template-columns: repeat(5, 1fr);
    background: var(--paper); border-top: 1px solid var(--line);
    padding-bottom: var(--safe-bottom);
}
.tabbar a {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: .45rem 0 .5rem; font-size: .72rem; color: var(--muted); text-decoration: none;
}
.tabbar a .ico { font-size: 1.25rem; line-height: 1.2; }
.tabbar a.active { color: var(--teal); font-weight: 600; }
.tabbar a.add .ico {
    background: var(--coral); color: #fff; width: 2.4rem; height: 2.4rem; border-radius: 50%;
    display: grid; place-items: center; margin-top: -1.1rem; box-shadow: var(--shadow);
}

/* ---------- auth ---------- */
.auth-shell { min-height: 100vh; padding: calc(var(--safe-top) + 2rem) 1.2rem 2rem; max-width: 440px; margin: 0 auto; }
.auth-brand { text-align: center; margin-bottom: 1.4rem; }
.auth-brand h1 { margin: .4rem 0 .1rem; font-size: 2rem; color: var(--teal); }
.auth-brand p { margin: 0; color: var(--muted); }
.auth-card { background: var(--paper); border-radius: var(--radius); padding: 1.3rem; box-shadow: var(--shadow); }
.divider { display: flex; align-items: center; gap: .6rem; color: var(--muted); font-size: .8rem; margin: 1rem 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- forms ---------- */
label { display: block; margin: .6rem 0; font-weight: 600; font-size: .92rem; }
input:not([type=checkbox]):not([type=range]):not([type=color]), select, textarea {
    display: block; width: 100%; margin-top: .3rem;
    padding: .7rem .75rem; font: inherit; font-weight: 400;
    color: var(--ink); background: var(--paper);
    border: 1px solid var(--line); border-radius: 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--teal-2); outline-offset: 1px; }
textarea { resize: vertical; min-height: 6rem; }
input[type=color] { width: 2.6rem; height: 2.6rem; border: 0; padding: 0; background: none; }
label.check, label.switch { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.validation-message { color: var(--red); font-size: .82rem; }
fieldset { border: 0; margin: 0 0 1rem; }
legend { font-weight: 700; font-size: 1rem; color: var(--teal); padding: 0; margin-bottom: .2rem; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .7rem 1.1rem; border-radius: 10px; border: 1px solid transparent;
    font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:disabled { opacity: .55; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-ghost { background: transparent; color: var(--teal); border-color: var(--line); }
.btn-danger { background: var(--red); color: #fff; }
.btn-block { width: 100%; margin-top: .6rem; }
.btn.big { font-size: 1.2rem; padding: 1rem 1.6rem; }
.link { background: none; border: 0; color: var(--teal); padding: 0; font: inherit; text-decoration: underline; }
.icon-btn { border: 1px solid var(--line); background: var(--paper); color: var(--ink); border-radius: 10px; width: 2.6rem; height: 2.6rem; font-size: 1.3rem; }
.icon-btn.small { width: 2.1rem; height: 2.1rem; font-size: 1rem; }
.icon-btn:disabled { opacity: .35; }

.row { display: flex; gap: .6rem; align-items: flex-end; }
.row.wrap { flex-wrap: wrap; align-items: center; }
.actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1rem; }
.actions.sticky {
    position: sticky; bottom: calc(4.4rem + var(--safe-bottom));
    background: var(--sand); padding: .6rem 0; margin: 0;
}

.card { background: var(--paper); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card.danger { border: 1px solid color-mix(in srgb, var(--red) 40%, transparent); }

/* ---------- level slider ---------- */
.level { margin: .9rem 0; }
.level-head { display: flex; justify-content: space-between; align-items: baseline; }
.level-head label { margin: 0; }
.level-value { font-weight: 800; font-size: 1.1rem; color: color-mix(in srgb, var(--mood), var(--red) calc(var(--lv) * 100%)); }
.level-value small { font-weight: 500; color: var(--muted); margin-left: .25rem; }
.level input[type=range] { width: 100%; accent-color: var(--teal); height: 2rem; }
.level-ends { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); }

/* ---------- day view ---------- */
.day-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .6rem; }
.day-title { flex: 1; text-align: center; position: relative; }
.day-title h1 { margin: 0; }
.day-title input[type=date] { position: absolute; inset: 0; opacity: 0; }

.timeline-card { background: var(--paper); border-radius: var(--radius); padding: .6rem .4rem .4rem; box-shadow: var(--shadow); }
svg.timeline { width: 100%; height: auto; display: block; }
svg .grid { stroke: var(--line); stroke-width: 1; }
svg .grid.faint { stroke-dasharray: 2 4; }
svg .axis { fill: var(--muted); font-size: 9px; }
svg .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; opacity: .85; }
svg .line.anxiety, svg .pt.anxiety { stroke: var(--anxiety); fill: var(--anxiety); }
svg .line.stress, svg .pt.stress { stroke: var(--stress); fill: var(--stress); }
svg .line.mood, svg .pt.mood { stroke: var(--mood); fill: var(--mood); }
svg .line.anxiety, svg .line.stress, svg .line.mood { fill: none; }
svg .event-stem { stroke-width: 2; opacity: .35; }
svg .event-dot { stroke: var(--paper); stroke-width: 2; }
svg .event { cursor: pointer; }
svg .hr { font-size: 9px; fill: var(--red); font-weight: 700; }
svg .now { stroke: var(--teal); stroke-width: 1.5; stroke-dasharray: 3 3; }
.legend { display: flex; flex-wrap: wrap; gap: .3rem .9rem; font-size: .75rem; color: var(--muted); padding: .3rem .5rem; }
.legend .sw { display: inline-block; width: .9rem; height: .25rem; border-radius: 2px; margin-right: .3rem; vertical-align: middle; }
.sw.anxiety { background: var(--anxiety); } .sw.stress { background: var(--stress); } .sw.mood { background: var(--mood); }
.sw.dot { width: .6rem !important; height: .6rem !important; border-radius: 50% !important; background: var(--coral); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; margin: 1rem 0; }
.stat { background: var(--paper); border-radius: 12px; padding: .6rem .3rem; text-align: center; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 1.25rem; }
.stat span { font-size: .72rem; color: var(--muted); }

.section-title { margin-top: 1.2rem; color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; }

.event-list { list-style: none; padding: 0; margin: 0; }
.event-list li {
    display: flex; align-items: center; gap: .7rem;
    background: var(--paper); padding: .75rem .8rem; border-radius: 12px; margin-bottom: .5rem;
    box-shadow: var(--shadow); cursor: pointer;
}
.event-list .time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .85rem; width: 4.2rem; }
.swatch { width: .8rem; height: .8rem; border-radius: 50%; flex: none; }
.ev-body { flex: 1; min-width: 0; }
.ev-body strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-body small { color: var(--muted); }
.chev { color: var(--muted); font-size: 1.3rem; }

.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }

/* ---------- entries ---------- */
.filters { display: grid; grid-template-columns: 1fr; gap: .5rem; margin-bottom: .8rem; }
@media (min-width: 560px) { .filters { grid-template-columns: 2fr 1fr 1fr; } }

.back { display: inline-block; margin-bottom: .4rem; text-decoration: none; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.detail-grid span { display: block; font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.bar-row { display: grid; grid-template-columns: 4.5rem 1fr 1.6rem; align-items: center; gap: .6rem; margin: .4rem 0; font-size: .9rem; }
.bar-track { height: .55rem; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; }
.bar-fill.anxiety { background: var(--anxiety); } .bar-fill.stress { background: var(--stress); } .bar-fill.mood { background: var(--mood); }
.journal-text p { white-space: pre-wrap; margin: 0; }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; margin: .8rem 0; }
.media-item { position: relative; background: var(--sand); border-radius: 10px; overflow: hidden; min-height: 3.5rem; display: grid; place-items: center; }
.media-item img { width: 100%; height: 140px; object-fit: cover; display: block; }
.media-item audio { width: 100%; }
.media-item .remove { position: absolute; top: .3rem; right: .3rem; border: 0; border-radius: 50%; width: 1.8rem; height: 1.8rem; background: rgba(0,0,0,.6); color: #fff; }
.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.9); display: grid; place-items: center; }
.lightbox img { max-width: 100%; max-height: 100%; }

.modal-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 1rem; }
.modal { background: var(--paper); border-radius: var(--radius); padding: 1.2rem; max-width: 360px; width: 100%; }

.breath-counter { text-align: center; padding: .8rem; background: var(--sand); border-radius: 10px; margin-top: .6rem; }

/* ---------- journal ---------- */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin: 1rem 0 .6rem; }
.month-nav h2 { margin: 0; }
.diary-day { margin-bottom: 1.2rem; }
.diary-day h3 { color: var(--teal); border-bottom: 1px solid var(--line); padding-bottom: .3rem; }
.diary-entry { background: var(--paper); border-radius: 12px; padding: .8rem; margin-bottom: .5rem; box-shadow: var(--shadow); cursor: pointer; }
.diary-entry time { font-size: .8rem; color: var(--muted); margin-right: .5rem; }
.diary-entry p { margin: .3rem 0 0; white-space: pre-wrap; font-family: Georgia, "Times New Roman", serif; font-size: 1.02rem; }

/* ---------- lists ---------- */
.tabs { display: flex; gap: .3rem; background: var(--paper); padding: .3rem; border-radius: 12px; margin-bottom: 1rem; }
.tabs a { flex: 1; text-align: center; padding: .5rem; border-radius: 9px; text-decoration: none; color: var(--muted); font-weight: 600; }
.tabs a.active { background: var(--teal); color: #fff; }
.cat-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.cat-list li { display: flex; align-items: center; gap: .6rem; background: var(--paper); border-radius: 12px; padding: .6rem .7rem; margin-bottom: .45rem; box-shadow: var(--shadow); }
.cat-list li.inactive { opacity: .55; }
.cat-list small { display: block; }
.cat-edit { display: flex; flex-wrap: wrap; gap: .5rem; width: 100%; align-items: center; }
.cat-edit input:not([type=color]):not([type=checkbox]) { flex: 1; margin: 0; }
.cat-edit .full { flex-basis: 100% !important; }
.cat-edit .actions { width: 100%; margin-top: .2rem; }
.add-row { display: flex; gap: .5rem; align-items: center; }
.add-row input:not([type=color]) { margin: 0; }

/* ---------- emergency ---------- */
.contact-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.contact-list li { display: flex; gap: .5rem; align-items: center; margin-bottom: .6rem; }
.call-btn {
    flex: 1; display: flex; align-items: center; gap: .8rem; text-align: left;
    background: var(--paper); color: var(--ink); border: 1px solid var(--line); border-radius: 14px;
    padding: .9rem 1rem; font: inherit; box-shadow: var(--shadow);
}
.call-btn.primary { border: 2px solid var(--red); }
.call-btn .phone-ico { font-size: 1.6rem; color: #fff; background: var(--mood); width: 2.8rem; height: 2.8rem; border-radius: 50%; display: grid; place-items: center; flex: none; }
.call-btn.primary .phone-ico { background: var(--red); }
.call-btn .who { flex: 1; min-width: 0; }
.call-btn .who strong, .call-btn .who small { display: block; }
.call-btn .who small { color: var(--muted); }
.badge { background: var(--red); color: #fff; font-size: .7rem; font-weight: 800; padding: .15rem .45rem; border-radius: 99px; }

/* ---------- breathe ---------- */
.exercise-list { display: grid; gap: .6rem; }
.exercise { text-align: left; background: var(--paper); color: var(--ink); border: 1px solid var(--line); border-radius: 14px; padding: .9rem 1rem; font: inherit; box-shadow: var(--shadow); }
.exercise strong, .exercise small, .exercise .pattern { display: block; }
.exercise small { color: var(--muted); }
.exercise .pattern { font-size: .78rem; color: var(--teal); margin-top: .3rem; }
.rounds { max-width: 10rem; }
.breath-stage { display: flex; flex-direction: column; align-items: center; gap: 1rem; padding-top: 1rem; text-align: center; }
.breath-circle {
    width: min(70vw, 300px); aspect-ratio: 1; border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--mood) 55%, white), var(--teal));
    display: grid; place-items: center; box-shadow: 0 10px 40px color-mix(in srgb, var(--teal) 35%, transparent);
    will-change: transform;
}
.breath-inner { display: flex; flex-direction: column; color: #fff; }
.breath-inner .phase { font-size: 1.3rem; font-weight: 700; }
.breath-inner .count { font-size: 2.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.done { font-weight: 600; color: var(--mood); }

/* ---------- people ---------- */
.field-label { display: block; font-weight: 600; font-size: .92rem; margin: .6rem 0 .3rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
    border: 1.5px solid var(--chip, var(--teal)); background: transparent; color: var(--ink);
    border-radius: 99px; padding: .4rem .8rem; font: inherit; font-size: .9rem;
}
.chip.on { background: var(--chip, var(--teal)); color: #fff; }
.role-row { display: flex; align-items: center; gap: .6rem; margin-top: .5rem; }
.role-row select { width: auto; margin: 0; padding: .45rem .6rem; }
.people-pick .add-row { margin-top: .6rem; }
.people-pick .add-row input { margin: 0; }
.avatar {
    width: 2.2rem; height: 2.2rem; border-radius: 50%; flex: none;
    display: grid; place-items: center; color: #fff; font-weight: 700; font-size: .85rem;
}
.avatar.small { width: 1.8rem; height: 1.8rem; font-size: .72rem; }
.people-list { list-style: none; padding: 0; margin: 0; }
.people-list li { display: flex; align-items: center; gap: .6rem; padding: .4rem 0; }
.people-list small { display: block; }
.role-badge { font-size: .75rem; font-weight: 700; padding: .15rem .55rem; border-radius: 99px; background: var(--line); }
.role-badge.role-responsible { background: color-mix(in srgb, var(--red) 18%, transparent); color: var(--red); }
.role-badge.role-witness { background: color-mix(in srgb, var(--stress) 18%, transparent); color: var(--stress); }
.role-badge.role-supporter { background: color-mix(in srgb, var(--mood) 18%, transparent); color: var(--mood); }
.people-line { display: block; color: var(--muted); }

/* ---------- report ---------- */
.title-row { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.title-row .btn { padding: .45rem .8rem; font-size: .9rem; }
.report-count { margin: .8rem 0 0; padding: .7rem .8rem; background: var(--sand); border-radius: 10px; }
.report-preview { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: 12px; margin-top: 1rem; background: #fff; }

/* ---------- more ---------- */
.menu-list { display: grid; gap: .5rem; }
.menu-list a { display: flex; align-items: center; gap: .9rem; background: var(--paper); border-radius: 14px; padding: .9rem 1rem; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); }
.menu-list .ico { font-size: 1.3rem; width: 2.2rem; height: 2.2rem; display: grid; place-items: center; background: var(--sand); border-radius: 10px; color: var(--teal); }
.menu-list strong, .menu-list small { display: block; }
.menu-list small { color: var(--muted); }

.quick-note label { margin-top: 0; }
.advanced { margin-top: .8rem; }
.advanced summary { cursor: pointer; color: var(--muted); }

#blazor-error-ui {
    background: #fff3cd; bottom: 0; display: none; left: 0; padding: .6rem 1.25rem .7rem;
    position: fixed; width: 100%; z-index: 1000; color: #1F2A2C;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

@media (prefers-reduced-motion: reduce) {
    .breath-circle { transition: none !important; }
}

/* ---------- organisations (Account page) ---------- */
.org-row { border-top: 1px solid var(--line); padding-top: .6rem; margin-top: .6rem; }
.org-row:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.org-row p { margin: .25rem 0; }
