/* =====================================================================
   QUMEA Frailty Assessment Logger - styles
   Mobile-first, card-based, large touch targets.

   Brand colours are CSS variables (placeholder QUMEA palette). To match
   the official QUMEA brand, adjust the --brand* values below only.
   ===================================================================== */

:root {
    --brand:        #0ea5a5;
    --brand-600:    #0b8a8a;
    --brand-700:    #0a6e6e;
    --brand-tint:   #e6f6f6;

    --ink:          #0f2230;
    --text:         #1d2b36;
    --muted:        #5b6b76;
    --line:         #e2e8ec;
    --bg:           #f4f7f8;
    --card:         #ffffff;

    --start:        #16a34a;
    --start-700:    #15803d;
    --stop:         #dc2626;
    --stop-700:     #b91c1c;

    --ok:           #16a34a;
    --warn:         #d97706;
    --err:          #dc2626;
    --info:         #0ea5a5;

    --radius:       16px;
    --radius-sm:    10px;
    --shadow:       0 1px 2px rgba(15,34,48,.06), 0 6px 20px rgba(15,34,48,.06);
    --shadow-lg:    0 10px 40px rgba(15,34,48,.12);
    --tap:          52px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-700); }

/* ---------- Header / nav ---------- */
.app-header {
    background: var(--card);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 50;
    padding-top: env(safe-area-inset-top);
}
.app-header__inner {
    max-width: 920px;
    margin: 0 auto;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand__logo { display: block; height: 22px; width: auto; }
.brand__name { font-weight: 700; font-size: .98rem; color: var(--ink); }

/* Header status chips (session / running) shown left of the menu on every page */
.header-right { display: flex; align-items: center; gap: 8px; }
.header-status { display: flex; align-items: center; gap: 6px; }
.hstat {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 10px; border-radius: 999px;
    font-size: .74rem; font-weight: 700; text-decoration: none;
    white-space: nowrap; max-width: 38vw; overflow: hidden; text-overflow: ellipsis;
}
.hstat::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }
.hstat--on { background: #e9f7ef; color: #14622f; }
.hstat--off { background: #f3f0f0; color: #6b5b5b; }
.hstat--running { background: #fff4e5; color: #a85b00; }
@media (max-width: 560px) { .hstat { max-width: 30vw; } .brand__name { display: none; } }

.menu { position: relative; }
.menu__toggle {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--card);
    min-height: 44px;
}
.menu__toggle::-webkit-details-marker { display: none; }
.menu__user { font-weight: 600; font-size: .9rem; }
.menu__role { font-size: .72rem; color: var(--muted); display: none; }
.menu__icon { font-size: 1.1rem; color: var(--brand-700); }
.menu__panel {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    min-width: 220px;
    padding: 6px;
    display: flex;
    flex-direction: column;
}
.menu__link {
    display: block;
    width: 100%;
    text-align: left;
    padding: 12px 14px;
    color: var(--text);
    text-decoration: none;
    border-radius: 8px;
    font-size: .95rem;
    background: none;
    border: 0;
    cursor: pointer;
    font: inherit;
}
.menu__link:hover { background: var(--brand-tint); }
.menu__link--danger { color: var(--stop-700); }
.menu__logout { margin-top: 4px; border-top: 1px solid var(--line); padding-top: 4px; }

@media (min-width: 560px) {
    .menu__role { display: inline; }
}

/* ---------- Layout ---------- */
.container {
    max-width: 920px;
    margin: 0 auto;
    padding: 18px 16px 64px;
}
.stack > * + * { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
@media (min-width: 720px) {
    .grid--2 { grid-template-columns: 1fr 1fr; }
}

/* ---------- Cards ---------- */
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    margin-bottom: 16px;
}
.card__title {
    margin: 0 0 4px;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--ink);
}
.card__subtitle { margin: 0 0 14px; color: var(--muted); font-size: .9rem; }
.card--accent { border-top: 4px solid var(--brand); }

.page-title { font-size: 1.4rem; margin: 4px 0 16px; color: var(--ink); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--tap);
    padding: 0 20px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: var(--brand);
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: filter .12s ease, transform .04s ease;
    -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn:hover { filter: brightness(.96); }
.btn:disabled, .btn.is-loading { opacity: .65; cursor: not-allowed; }
.btn--primary { background: var(--brand); }
.btn--secondary { background: #fff; color: var(--brand-700); border-color: var(--line); }
.btn--ghost { background: transparent; color: var(--brand-700); border-color: transparent; }
.btn--danger { background: var(--stop); }
.btn--block { display: flex; width: 100%; }
.btn--lg { min-height: 60px; font-size: 1.1rem; }

/* Huge primary action buttons for the assessment screen */
.action-btn {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
    min-height: 150px;
    border: 0;
    border-radius: 22px;
    color: #fff;
    font-size: 1.9rem;
    font-weight: 800;
    letter-spacing: .04em;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    -webkit-tap-highlight-color: transparent;
}
.action-btn small { font-size: .85rem; font-weight: 600; letter-spacing: 0; opacity: .92; }
.action-btn:active { transform: translateY(1px); }
.action-btn--start { background: linear-gradient(180deg, var(--start), var(--start-700)); }
.action-btn--stop  { background: linear-gradient(180deg, var(--stop), var(--stop-700)); }
.action-btn:disabled, .action-btn.is-loading { opacity: .7; }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field__label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 6px; color: var(--ink); }
.field__req { color: var(--stop); margin-left: 2px; }
.field__help { color: var(--muted); font-size: .82rem; margin-top: 4px; }
.field__error { color: var(--err); font-size: .85rem; margin-top: 5px; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=search], select, textarea {
    width: 100%;
    min-height: var(--tap);
    padding: 12px 14px;
    font: inherit;
    color: var(--text);
    background: #fff;
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    appearance: none;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-tint);
}
.field--invalid input, .field--invalid select, .field--invalid textarea { border-color: var(--err); }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%235b6b76' d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }

.choice { display: flex; align-items: center; gap: 10px; padding: 10px 0; min-height: 44px; }
.choice input[type=radio], .choice input[type=checkbox] { width: 22px; height: 22px; min-height: 0; flex: 0 0 auto; }
.choice label { margin: 0; font-weight: 500; }

.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px; margin: 0 0 16px; }
legend { font-weight: 600; padding: 0 6px; color: var(--ink); }

/* ---------- Alerts ---------- */
.alert {
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 16px;
    font-size: .94rem;
    border: 1px solid transparent;
}
.alert--success { background: #e9f7ef; color: #14622f; border-color: #b7e3c6; }
.alert--error   { background: #fdeced; color: #8f1d1d; border-color: #f3c0c2; }
.alert--info    { background: var(--brand-tint); color: var(--brand-700); border-color: #b9e3e3; }
.alert--warning { background: #fef4e6; color: #8a5208; border-color: #f6dcab; }

/* ---------- Status pills ---------- */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.status-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status-prepared  { background: #eef2f6; color: #3a4a59; }
.status-running   { background: #fff4e5; color: #a85b00; }
.status-stopped   { background: #e7eef4; color: #2c4a63; }
.status-completed { background: #e9f7ef; color: #14622f; }
.status-cancelled { background: #f3f0f0; color: #6b5b5b; }

/* ---------- Timer ---------- */
.timer {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    font-size: 4rem;
    font-weight: 800;
    text-align: center;
    color: var(--ink);
    letter-spacing: .02em;
    margin: 8px 0;
}
.timer--running { color: var(--start-700); }
.meta-line { text-align: center; color: var(--muted); font-size: .92rem; }
.big-status { text-align: center; font-weight: 700; font-size: 1.1rem; margin: 4px 0 12px; }

/* ---------- Readiness panel (placeholder for future live view) ---------- */
.readiness { display: grid; gap: 10px; }
.readiness__row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fbfdfd; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: 0 0 auto; box-shadow: 0 0 0 3px rgba(0,0,0,.04); }
.dot--red { background: var(--err); }
.dot--yellow { background: var(--warn); }
.dot--green { background: var(--ok); }
.dot--idle { background: #c3cdd4; }
.readiness__label { font-weight: 600; }
.readiness__note { color: var(--muted); font-size: .85rem; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table.table { width: 100%; border-collapse: collapse; font-size: .9rem; min-width: 560px; }
.table th, .table td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { background: #f8fbfb; font-weight: 700; color: var(--ink); position: sticky; top: 0; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafdfd; }
/* Opt-in wrapping cell (e.g. free-text description columns) */
.table th.cell-wrap, .table td.cell-wrap { white-space: normal; min-width: 12rem; max-width: 26rem; }

/* ---------- Misc ---------- */
.muted { color: var(--muted); }
.text-center { text-align: center; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row--between { justify-content: space-between; }
.spacer { flex: 1; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--brand-tint); color: var(--brand-700); font-size: .76rem; font-weight: 700; }
.kv { display: grid; grid-template-columns: minmax(120px, 38%) 1fr; gap: 6px 14px; }
.kv dt { color: var(--muted); font-size: .85rem; }
.kv dd { margin: 0; font-weight: 600; }
.list-reset { list-style: none; margin: 0; padding: 0; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.divider { height: 1px; background: var(--line); border: 0; margin: 16px 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px; }
.toolbar .field { margin-bottom: 0; }
.drag-handle { cursor: grab; color: var(--muted); padding: 0 6px; font-size: 1.1rem; }

/* ---------- Auth ---------- */
.auth-wrap { max-width: 400px; margin: 8vh auto 0; }
.auth-logo { display: block; height: 40px; margin: 0 auto 18px; }

/* ---------- Footer ---------- */
.app-footer { border-top: 1px solid var(--line); background: var(--card); }
.app-footer__inner { max-width: 920px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 4px; font-size: .8rem; color: var(--muted); }
