/* Pirama626 — app shell styling.
   Neutral Notion-ish surface, brand blue (#0B57D0, the manifest's theme_color) as the
   single accent. No framework, no build step, no npm dependency. */

:root {
    --bg: #ffffff;
    --bg-subtle: #f7f6f3;
    --bg-sunken: #f1f0ee;
    --text: #37352f;
    --text-muted: #787774;
    --text-faint: #9b9a97;
    --border: #e9e9e7;
    --border-strong: #dfdfdc;
    --blue: #0b57d0;
    --blue-dark: #0a49ad;
    --blue-bg: #e8f0fe;
    --green: #0f7b6c;
    --green-bg: #ddedea;
    --amber: #b07d17;
    --amber-bg: #faf3dd;
    --red: #d44c47;
    --red-bg: #fdebec;
    --radius: 6px;
    --radius-lg: 10px;
    --appbar-h: 56px;
    --tabbar-h: 58px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg-subtle);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, "Apple Color Emoji", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ── App bar — the persistent identity indicator ─────────────────────────── */

.appbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: var(--appbar-h);
    padding: calc(8px + var(--safe-top)) 16px 8px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

/* Signed in: the bar itself changes, so the state is visible from any scroll
   position without reading a word. */
.appbar.signed-in {
    background: var(--blue-bg);
    border-bottom-color: #c6d9f8;
    box-shadow: inset 0 -3px 0 var(--blue);
}

.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-mark { border-radius: var(--radius); display: block; }
.brand-name { font-weight: 700; letter-spacing: -0.01em; }

.account { display: flex; align-items: center; min-width: 0; }
.account-id { display: flex; align-items: center; gap: 8px; min-width: 0; }

.account-text, .rowitem-text {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
    min-width: 0;
}

.account-text b, .rowitem-text b { font-size: 14px; font-weight: 600; }
.account-text small, .rowitem-text small {
    color: var(--text-muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 420px) {
    .account-text small { display: none; }
}

.avatar {
    position: relative;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--blue);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    text-transform: uppercase;
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--blue);
}

.avatar.lg { width: 44px; height: 44px; font-size: 17px; }

/* The signed-in dot: small, but it is the thing people look for. */
.avatar::after {
    content: "";
    position: absolute;
    right: -2px;
    bottom: -2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--green);
    border: 2px solid #fff;
}

.avatar.guest {
    background: var(--bg-sunken);
    color: var(--text-faint);
    box-shadow: none;
}

.avatar.guest::after { display: none; }

/* ── Install prompt ─────────────────────────────────────────────────────── */

.promo {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin: 12px 16px 0;
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 1px 2px rgba(15, 15, 15, 0.06);
}

.promo[hidden] { display: none; }
.promo-mark { border-radius: var(--radius); flex: 0 0 auto; }
.promo-text { display: flex; flex-direction: column; flex: 1 1 200px; min-width: 0; }
.promo-text b { font-size: 14px; }
.promo-text span { color: var(--text-muted); font-size: 13px; }
.promo-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }

/* ── Alert (only when something is actually wrong) ──────────────────────── */

.alert {
    margin: 12px 16px 0;
    padding: 10px 12px;
    border-radius: var(--radius);
    background: var(--red-bg);
    color: var(--red);
    font-size: 13.5px;
}

.alert[hidden] { display: none; }

/* ── Main / views ───────────────────────────────────────────────────────── */

.main {
    max-width: 680px;
    margin: 0 auto;
    padding: 16px 16px calc(24px + var(--tabbar-h) + var(--safe-bottom));
}

.view[hidden] { display: none; }

.view-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 8px 0 14px;
}

h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; margin: 0; }
h2 { font-size: 20px; font-weight: 700; margin: 0; }

/* ── Buttons / inputs ───────────────────────────────────────────────────── */

.btn {
    font: inherit;
    font-size: 14px;
    padding: 8px 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
    transition: background 120ms ease;
}

.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.block { display: block; width: 100%; }
.btn:hover:not(:disabled) { background: var(--bg-subtle); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--blue-dark); }

.btn.ghost { background: transparent; }

.btn.link {
    border: none;
    background: none;
    padding: 8px 0;
    color: var(--blue);
    font-size: 13.5px;
}

.btn.link:hover:not(:disabled) { background: none; text-decoration: underline; }

input[type="email"], input[type="text"] {
    font: inherit;
    font-size: 15px;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    min-width: 0;
    width: 100%;
}

input:focus, .btn:focus-visible, .tab:focus-visible, .account-card:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 1px;
}

/* ── Rows (settings) ────────────────────────────────────────────────────── */

.rows {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.rowitem {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.rowitem:last-child { border-bottom: none; }
.rowitem .rowitem-text { flex: 1 1 auto; }
.rowitem .btn { margin-left: auto; }

/* ── Banners / states ───────────────────────────────────────────────────── */

.banner {
    display: none;
    padding: 10px 12px;
    border-radius: var(--radius);
    font-size: 13.5px;
    margin: 12px 0;
}

.banner.show { display: block; }
.banner.stale { background: var(--amber-bg); color: var(--amber); }
.banner.info { background: var(--blue-bg); color: var(--blue-dark); }
.banner.ok { background: var(--green-bg); color: var(--green); }
.banner.error { background: var(--red-bg); color: var(--red); }

.state {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px 20px;
    color: var(--text-muted);
    font-size: 14px;
    text-align: center;
}

.state strong { display: block; color: var(--text); margin-bottom: 4px; font-size: 15px; }
.state .btn { margin-top: 14px; }

.state.denied { border-color: #f0c9c7; background: var(--red-bg); color: #a3423d; }
.state.denied strong { color: var(--red); }

/* ── Cards ──────────────────────────────────────────────────────────────── */

.cards { display: grid; gap: 10px; }

.card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
}

.card-title { font-weight: 600; margin-bottom: 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11.5px;
    background: var(--bg-sunken);
    border-radius: var(--radius);
    padding: 2px 7px;
    color: var(--text-muted);
    word-break: break-all;
}

.chip b { color: var(--text); font-weight: 600; }

.count { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.count-number { font-size: 40px; font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.count-label { color: var(--text-muted); font-size: 14px; }

/* ── Diagnostics (collapsed by default) ─────────────────────────────────── */

.diag { margin-top: 20px; color: var(--text-muted); font-size: 13px; }
.diag summary { cursor: pointer; padding: 6px 0; }
.diag .chips { margin-top: 8px; }

/* ── Bottom navigation ──────────────────────────────────────────────────── */

.tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: flex;
    background: var(--bg);
    border-top: 1px solid var(--border);
    padding-bottom: var(--safe-bottom);
}

.tab {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    height: var(--tabbar-h);
    border: none;
    background: none;
    font: inherit;
    font-size: 11px;
    color: var(--text-faint);
    cursor: pointer;
}

.tab svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tab.is-active { color: var(--blue); }

/* ── Login screen ───────────────────────────────────────────────────────── */

.screen {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px calc(24px + var(--safe-bottom));
    background: rgba(15, 15, 15, 0.45);
    overflow-y: auto;
}

.screen[hidden] { display: none; }

.screen-card {
    position: relative;
    width: 100%;
    max-width: 400px;
    background: var(--bg);
    border-radius: 14px;
    padding: 28px 24px 20px;
    box-shadow: 0 18px 48px rgba(15, 15, 15, 0.24);
    text-align: center;
}

.screen-close {
    position: absolute;
    top: 8px;
    right: 10px;
    border: none;
    background: none;
    font-size: 26px;
    line-height: 1;
    color: var(--text-faint);
    cursor: pointer;
    padding: 4px 8px;
}

.screen-mark { border-radius: 12px; margin-bottom: 12px; }
.screen-sub { color: var(--text-muted); font-size: 14px; margin: 6px 0 20px; }

.accounts { display: grid; gap: 8px; text-align: left; }

.account-card {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    background: var(--bg);
    font: inherit;
    color: inherit;
    cursor: pointer;
    text-align: left;
    transition: background 120ms ease, border-color 120ms ease;
}

.account-card:hover:not(:disabled) { background: var(--bg-subtle); border-color: var(--blue); }
.account-card:disabled { opacity: 0.5; cursor: progress; }
.account-card .chevron { margin-left: auto; color: var(--text-faint); }

.manual { display: grid; gap: 8px; margin-top: 8px; text-align: left; }

.code-head { display: flex; align-items: center; gap: 12px; text-align: left; margin-bottom: 16px; }

.otp {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 26px;
    letter-spacing: 0.32em;
    text-align: center;
    margin-bottom: 12px;
}
