/* =========================================================
   Talifund member app: shared design kit
   Grows one page at a time. Every rule here is in use.
   ========================================================= */

:root {
    /* Brand colours (same as the landing page) */
    --ink: #0e2f2b;
    --teal: #14625c;
    --teal-press: #0f4f4a;
    --teal-soft: #d9ebe7;
    --gold: #e2a336;
    --gold-deep: #b97f14;
    --paper: #f3f7f5;
    --white: #ffffff;
    --muted: #4f6662;
    --placeholder: #8aa19d;
    --line: #d9ebe7;
    --danger: #b42318;
    --danger-soft: #fdecea;

    /* Shape and sizing */
    --radius-md: 14px;
    --radius-lg: 20px;
    --tap: 52px;                 /* minimum height for anything a thumb presses */

    /* Space taken by the iPhone notch and home bar when opened from the home screen */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    --font-body: 'DM Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-display: 'Bricolage Grotesque', 'DM Sans', system-ui, sans-serif;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;   /* no grey flash on tap; we draw our own pressed states */
}

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--paper);
    color: var(--ink);
    font: 400 1rem/1.5 var(--font-body);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
    margin: 0;
    font-family: var(--font-display);
    letter-spacing: -0.02em;
    line-height: 1.15;
}

p { margin: 0; }

a { color: var(--teal); font-weight: 700; text-decoration: none; }
a:active { opacity: 0.7; }

:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- Auth screens (login, reset password) ---------- */
.auth {
    min-height: 100dvh;
    max-width: 440px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    padding: calc(var(--safe-top) + 2rem) 1.5rem calc(var(--safe-bottom) + 1.5rem);
}
.auth-head { text-align: center; margin: 1rem 0 2.25rem; }
.auth-head h1 { font-size: 2rem; font-weight: 800; margin-top: 1.5rem; }
.auth-head p { color: var(--muted); margin: 0.5rem auto 0; max-width: 30ch; }
.auth-foot {
    margin-top: auto;
    padding-top: 2.5rem;
    text-align: center;
    color: var(--muted);
    font-size: 0.95rem;
}

/* The turning ring around the logo: same motion as the landing page hero */
.mark-ring {
    --size: 132px;
    --radius: 56px;
    --dot: 10px;
    position: relative;
    width: var(--size);
    height: var(--size);
    margin: 0 auto;
}
.mark-ring::before {
    content: '';
    position: absolute;
    inset: calc((var(--size) - var(--radius) * 2) / 2);
    border: 1.5px dashed var(--teal-soft);
    border-radius: 50%;
}
.mark-ring img {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 64px;
    height: 64px;
    margin: -32px 0 0 -32px;
}
.mark-ring span {
    position: absolute;
    top: 50%;
    left: 50%;
    width: var(--dot);
    height: var(--dot);
    margin: calc(var(--dot) / -2) 0 0 calc(var(--dot) / -2);
    border-radius: 50%;
    background: var(--teal-soft);
    transform: rotate(calc(var(--i) * 30deg)) translateY(calc(var(--radius) * -1));
    animation: ring-turn 12s infinite;
    animation-delay: calc(var(--i) * 1s);
}
@keyframes ring-turn {
    0%, 7% {
        background: var(--gold);
        transform: rotate(calc(var(--i) * 30deg)) translateY(calc(var(--radius) * -1)) scale(1.5);
    }
    8.5%, 100% {
        background: var(--teal-soft);
        transform: rotate(calc(var(--i) * 30deg)) translateY(calc(var(--radius) * -1)) scale(1);
    }
}

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 1.15rem; }

.field-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
}
.field-label {
    display: block;
    font-weight: 700;
    font-size: 0.92rem;
    margin-bottom: 0.45rem;
}
.field-link { font-size: 0.92rem; }

/* A control is the white box; the input inside it has no border of its own */
.control {
    display: flex;
    align-items: center;
    min-height: var(--tap);
    background: var(--white);
    border: 1.5px solid var(--line);
    border-radius: var(--radius-md);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.control:focus-within {
    border-color: var(--teal);
    box-shadow: 0 0 0 4px rgba(20, 98, 92, 0.12);
}
.control.is-invalid { border-color: var(--danger); }
.control.is-invalid:focus-within { box-shadow: 0 0 0 4px rgba(180, 35, 24, 0.12); }

.control input {
    flex: 1;
    min-width: 0;
    height: var(--tap);
    padding: 0 1rem;
    border: 0;
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-size: 1.0625rem;        /* 17px: iPhone zooms the page on focus if this is under 16px */
    outline: none;
}
.control input::placeholder { color: var(--placeholder); }

.control-prefix {
    display: flex;
    align-items: center;
    align-self: stretch;
    padding: 0 0.85rem 0 1rem;
    border-right: 1.5px solid var(--line);
    font-weight: 700;
    font-size: 1.0625rem;
}
.control-prefix + input { padding-left: 0.85rem; }

.control-action {
    flex: none;
    width: var(--tap);
    height: var(--tap);
    display: grid;
    place-items: center;
    border: 0;
    background: none;
    color: var(--muted);
    border-radius: var(--radius-md);
    cursor: pointer;
}
.control-action:active { color: var(--ink); }
.control-action svg { width: 22px; height: 22px; }
svg[hidden] { display: none; }   /* browsers don't hide SVG icons with the hidden attribute on their own */

/* ---------- Buttons ---------- */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    width: 100%;
    min-height: var(--tap);
    padding: 0 1.25rem;
    border: 0;
    border-radius: var(--radius-md);
    font: 700 1.0625rem/1 var(--font-body);
    cursor: pointer;
    transition: transform 0.12s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn[disabled] { cursor: default; opacity: 0.75; }
.btn[disabled]:active { transform: none; }

.btn-primary { background: var(--teal); color: var(--white); }
.btn-primary:active { background: var(--teal-press); }

.spinner {
    width: 18px;
    height: 18px;
    border: 2.5px solid rgba(255, 255, 255, 0.4);
    border-top-color: var(--white);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
.spinner[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Messages ---------- */
.alert {
    display: flex;
    gap: 0.65rem;
    align-items: flex-start;
    padding: 0.85rem 1rem;
    border-radius: var(--radius-md);
    background: var(--danger-soft);
    color: var(--danger);
    font-size: 0.95rem;
}
.alert[hidden] { display: none; }
.alert svg { flex: none; width: 20px; height: 20px; margin-top: 1px; }

/* ---------- Motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
    .mark-ring span { animation: none; }
    .mark-ring span:first-of-type { background: var(--gold); }
    .btn, .control { transition: none; }
}

/* =========================================================
   Added in Step 2: multi-step flows (reset password)
   ========================================================= */

/* Flow screens start closer to the top to make room for the back button */
.auth.flow { padding-top: calc(var(--safe-top) + 0.5rem); }

/* Top bar: back button, progress, and an empty cell that keeps the progress centred */
.flow-bar {
    display: grid;
    grid-template-columns: 44px 1fr 44px;
    align-items: center;
    margin: 0 -0.5rem 1.75rem;
}
.icon-btn {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--ink);
    cursor: pointer;
}
.icon-btn:active { background: var(--teal-soft); }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn.is-invisible { visibility: hidden; }

.progress { display: flex; justify-content: center; gap: 6px; }
.progress span {
    width: 28px;
    height: 4px;
    border-radius: 2px;
    background: var(--line);
    transition: background 0.3s ease;
}
.progress span.is-done { background: var(--teal); }

/* Steps share one grid cell so the page keeps its height while they slide */
.steps { display: grid; }
.step {
    grid-area: 1 / 1;
    opacity: 0;
    visibility: hidden;
    transform: translateX(32px);
    transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.25s ease, visibility 0s linear 0.35s;
}
.step.is-before { transform: translateX(-32px); }
.step.is-active {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition-delay: 0s;
}
.step h1 { font-size: 1.9rem; font-weight: 800; }
.step h1:focus { outline: none; }
.step-lead { color: var(--muted); margin: 0.6rem 0 1.75rem; max-width: 36ch; }
.step-lead strong { color: var(--ink); white-space: nowrap; }

/* A button that looks like a link, for small secondary actions */
.btn-text {
    border: 0;
    background: none;
    padding: 0.2rem 0;
    font: inherit;
    font-weight: 700;
    color: var(--teal);
    cursor: pointer;
}
.btn-text:active { opacity: 0.7; }

/* ---------- Code entry: one real input over six drawn boxes ----------
   A single input lets iPhone and Android fill the code straight from the SMS
   and lets members paste it; the boxes are only how it looks. */
.otp { position: relative; }
.otp input {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    border: 0;
    background: transparent;
    color: transparent;
    caret-color: transparent;
    font-size: 16px;
    outline: none;
}
.otp input::selection { background: transparent; }
.otp-cells {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.5rem;
}
.otp-cells span {
    height: 60px;
    display: grid;
    place-items: center;
    background: var(--white);
    border: 1.5px solid var(--line);
    border-radius: var(--radius-md);
    font: 800 1.6rem var(--font-display);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.otp.is-focused .otp-cells span.is-current {
    border-color: var(--teal);
    box-shadow: 0 0 0 4px rgba(20, 98, 92, 0.12);
}
.otp.is-focused .otp-cells span.is-current:empty::after {
    content: '';
    width: 2px;
    height: 26px;
    background: var(--teal);
    animation: caret-blink 1s steps(1) infinite;
}
.otp.is-invalid .otp-cells span { border-color: var(--danger); }
@keyframes caret-blink { 50% { opacity: 0; } }

.resend {
    min-height: 1.6rem;
    text-align: center;
    color: var(--muted);
    font-size: 0.95rem;
}
.note { color: var(--teal); font-weight: 700; font-size: 0.95rem; text-align: center; }
.note[hidden], .resend [hidden] { display: none; }

/* ---------- A code that comes from an admin ---------- */
.step-lead-tight { margin-bottom: 1.1rem; max-width: none; }
.relay {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    margin-top: 1.1rem;
    padding: 0.7rem 0.85rem;
    border-radius: var(--radius-md);
    background: var(--teal-soft);
    color: var(--muted);
    font-size: 0.85rem;
    line-height: 1.35;
}
.relay-ico {
    flex: none;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--white);
    color: var(--teal);
}
.relay-ico svg { width: 18px; height: 18px; }
.relay-text { flex: 1; }
.relay-text strong { display: block; color: var(--ink); font-size: 0.92rem; }
.relay-call {
    flex: none;
    padding: 0.45rem 0.8rem;
    border-radius: 999px;
    background: var(--white);
    color: var(--teal);
    font-weight: 700;
    text-decoration: none;
}

/* ---------- Live password checks ---------- */
.checks {
    list-style: none;
    margin: -0.25rem 0 0;
    padding: 0;
    display: grid;
    gap: 0.45rem;
    color: var(--muted);
    font-size: 0.92rem;
}
.checks li { display: flex; align-items: center; gap: 0.55rem; }
.checks li::before {
    content: '';
    flex: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1.5px solid var(--line);
    background: var(--white) center / 12px no-repeat;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}
.checks li.is-met { color: var(--ink); }
.checks li.is-met::before {
    border-color: var(--teal);
    background-color: var(--teal);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E");
}

/* ---------- Success screen ---------- */
.step-done { text-align: center; padding-top: 3rem; }
.step-done .step-lead { margin-left: auto; margin-right: auto; }
.done-mark {
    width: 88px;
    height: 88px;
    margin: 0 auto 1.75rem;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--teal);
    color: var(--white);
}
.done-mark svg { width: 44px; height: 44px; }
.done-mark path { stroke-dasharray: 30; stroke-dashoffset: 30; }
.step-done.is-active .done-mark path { animation: draw-check 0.45s 0.25s ease forwards; }
@keyframes draw-check { to { stroke-dashoffset: 0; } }

@media (prefers-reduced-motion: reduce) {
    .step { transition: none; }
    .done-mark path { stroke-dashoffset: 0; }
    .step-done.is-active .done-mark path { animation: none; }
    .otp.is-focused .otp-cells span.is-current:empty::after { animation: none; }
}