/* Client Portal — mobile-first, light/dark via prefers-color-scheme.
   Deliberately framework-free: this app has no Syncfusion dependency. */

:root {
    --teal: #0d7377;
    --navy: #1e3a5f;
    --bg: #f5f7fa;
    --surface: #ffffff;
    --surface-2: #eef1f5;
    --text: #1a222c;
    --text-2: #5b6675;
    --border: #d8dee6;
    --ok: #15803d;
    --ok-bg: #ecfdf3;
    --err: #b91c1c;
    --err-bg: #fef2f2;
    --warn: #b45309;
    --warn-bg: #fffbeb;
}
@media (prefers-color-scheme: dark) {
    :root {
        --teal: #14b8a6;
        --navy: #7da3cc;
        --bg: #0f1419;
        --surface: #1a2129;
        --surface-2: #232c36;
        --text: #e7ecf2;
        --text-2: #9aa7b5;
        --border: #33404d;
        --ok: #4ade80;
        --ok-bg: #12291c;
        --err: #f87171;
        --err-bg: #2b1414;
        --warn: #fbbf24;
        --warn-bg: #2b2109;
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.5;
}
h1 { font-size: 1.5rem; margin: 0 0 .75rem; }
h2 { font-size: 1.15rem; margin: 1.25rem 0 .5rem; }
a { color: var(--teal); }
.muted { color: var(--text-2); }
.small { font-size: .85rem; }

/* ── Auth shell ─────────────────────────────────────────────── */
.auth-shell { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; box-shadow: 0 10px 30px rgba(0,0,0,.08); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.auth-logo { width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(135deg, var(--navy), var(--teal)); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.auth-practice { font-weight: 600; }
.auth-sub { color: var(--text-2); font-size: .85rem; }
.auth-crisis { color: var(--text-2); font-size: .8rem; max-width: 420px; text-align: center; }
.auth-form { display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }
.auth-form label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--text-2); }
.auth-form input[type=email], .auth-form input[type=password], .auth-form input[type=text] {
    padding: 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 1rem;
    background: var(--surface); color: var(--text);
}
.code-input { letter-spacing: 6px; font-size: 1.4rem !important; text-align: center; }
.check-label { flex-direction: row !important; align-items: center; gap: 8px !important; }
.resend-row { display: flex; gap: 16px; margin-top: 10px; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn-primary { background: var(--teal); color: #fff; border: none; border-radius: 10px; padding: 12px 18px; font-size: 1rem; font-weight: 600; cursor: pointer; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .55; cursor: default; }
.btn-outline { background: none; border: 1px solid var(--teal); color: var(--teal); border-radius: 10px; padding: 9px 16px; font-size: .92rem; cursor: pointer; }
.btn-ghost { background: none; border: none; color: var(--text-2); cursor: pointer; padding: 9px 12px; }
.btn-link { background: none; border: none; color: var(--teal); cursor: pointer; padding: 0; font-size: .9rem; text-decoration: underline; }
.btn-signout { background: none; border: 1px solid var(--border); color: var(--text-2); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.link-button { background:none; border:none; padding:0; color: var(--teal); cursor:pointer; text-decoration:underline; font:inherit; }

.ok-box { background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; }
.error-box { background: var(--err-bg); color: var(--err); border: 1px solid var(--err); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; }
.warn-box { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; }

/* ── Portal shell ───────────────────────────────────────────── */
.portal-shell { min-height: 100vh; display: flex; flex-direction: column; }
.portal-header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.portal-header-inner { max-width: 1000px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 600; }
.brand-logo { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, var(--navy), var(--teal)); color: #fff; display: flex; align-items: center; justify-content: center; font-size: .8rem; font-weight: 700; }
.portal-nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.portal-nav a { padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--text-2); font-size: .95rem; position: relative; }
.portal-nav a:hover { background: var(--surface-2); }
.portal-nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.nav-badge { display: inline-block; min-width: 18px; text-align: center; margin-left: 6px; padding: 1px 6px; border-radius: 10px; background: var(--teal); color: #fff; font-size: .72rem; font-weight: 700; }
.portal-actions { display: flex; align-items: center; gap: 10px; }
.settings-link { text-decoration: none; font-size: 1.1rem; }
.portal-main { flex: 1; width: 100%; max-width: 1000px; margin: 0 auto; padding: 20px 16px 40px; }
.portal-footer { border-top: 1px solid var(--border); color: var(--text-2); font-size: .8rem; text-align: center; padding: 14px; }

/* ── Cards / lists / tables ─────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px; margin-bottom: 16px; }
.card h2 { margin-top: 0; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.stat { font-size: 1.6rem; font-weight: 700; }
.stat-label { color: var(--text-2); font-size: .85rem; }

.table-scroll { overflow-x: auto; }
.ptable { width: 100%; border-collapse: collapse; }
.ptable th { text-align: left; padding: 8px 10px; font-size: .75rem; text-transform: uppercase; color: var(--text-2); border-bottom: 1px solid var(--border); }
.ptable td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.ptable .num { text-align: right; white-space: nowrap; }
.row-click { cursor: pointer; }
.row-click:hover { background: var(--surface-2); }

.pill { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--text-2); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.err { background: var(--err-bg); color: var(--err); }

.empty { color: var(--text-2); font-style: italic; padding: 12px 0; }

/* ── Forms in portal ────────────────────────────────────────── */
.pform { display: flex; flex-direction: column; gap: 12px; }
.pform label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--text-2); }
.pform input, .pform select, .pform textarea {
    padding: 11px; border: 1px solid var(--border); border-radius: 10px; font-size: 1rem;
    background: var(--surface); color: var(--text); font-family: inherit;
}
.pform textarea { min-height: 110px; resize: vertical; }

/* Messages */
.msg-thread { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 14px; }
.msg.mine { align-self: flex-end; background: var(--teal); color: #fff; border-bottom-right-radius: 4px; }
.msg.theirs { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.msg-meta { font-size: .72rem; opacity: .75; margin-top: 4px; }

/* Screener */
.q-block { border-bottom: 1px solid var(--border); padding: 14px 0; }
.q-text { font-weight: 600; margin-bottom: 8px; }
.q-options { display: flex; flex-direction: column; gap: 6px; }
.q-option { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.q-option:hover { background: var(--surface-2); }
.q-option.selected { border-color: var(--teal); background: var(--surface-2); font-weight: 600; }

/* Signature pad */
.sig-pad { border: 2px dashed var(--border); border-radius: 10px; background: #fff; touch-action: none; width: 100%; height: 160px; }
.sig-actions { display: flex; gap: 10px; margin-top: 8px; }

/* Calendar-ish appointment list */
.appt { display: flex; gap: 14px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.appt-date { min-width: 64px; text-align: center; background: var(--surface-2); border-radius: 10px; padding: 8px 6px; }
.appt-date .d { font-size: 1.3rem; font-weight: 700; line-height: 1.1; }
.appt-date .m { font-size: .75rem; text-transform: uppercase; color: var(--text-2); }
.appt-info { flex: 1; }
.appt-info .t { font-weight: 600; }
.appt-info .s { color: var(--text-2); font-size: .88rem; }

@media (max-width: 640px) {
    .portal-header-inner { gap: 8px; }
    .portal-nav { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
    .portal-nav a { white-space: nowrap; }
}
