/* Copied from Notes (tokens, base, buttons, sign-in pages) so HQ looks the same. */

:root {
    --accent: #2563eb;
    --on-accent: #ffffff;
    --surface: #ffffff;
    --surface-2: #f4f4f5;
    --text: #18181b;
    --muted: #71717a;
    --line: #e4e4e7;
    --danger: #dc2626;
    --ok: #16a34a;
    --warn: #d97706;

    /* Shades derived from the one base color the theme picker sets. */
    --accent-tint: color-mix(in oklab, var(--accent) 12%, var(--surface));
    --accent-line: color-mix(in oklab, var(--accent) 45%, var(--surface));
    --accent-ink: color-mix(in oklab, var(--accent) 72%, var(--text));
    --accent-hover: color-mix(in oklab, var(--accent) 85%, var(--text));

    --radius: 12px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    color-scheme: light dark;
    -webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
    :root {
        --surface: #18181b;
        --surface-2: #232327;
        --text: #f4f4f5;
        --muted: #a1a1aa;
        --line: #34343a;
        --danger: #f87171;
        --ok: #4ade80;
        --warn: #fbbf24;
        --accent-tint: color-mix(in oklab, var(--accent) 22%, var(--surface));
    }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
    margin: 0;
    background: var(--surface);
    color: var(--text);
    font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

button, input, select, textarea { font: inherit; color: inherit; }

input[type="text"], input[type="email"], input[type="password"], input[type="search"], select, textarea {
    width: 100%;
    font-size: 16px; /* keeps iOS from zooming in on focus */
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
textarea { resize: vertical; min-height: 120px; }

.masked { -webkit-text-security: disc; }

.btn, .btn-primary {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 44px; padding: 0 18px;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: var(--surface);
    font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.link { background: none; border: 0; padding: 0; color: var(--accent-ink); cursor: pointer; font-weight: 500; font-size: inherit; }
.danger-text { color: var(--danger) !important; }
.error { color: var(--danger); font-size: 14px; margin: 0; }
.ok { color: var(--accent-ink); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* ---------- Sign-in and security pages ---------- */
.auth-page { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 360px; }
.auth-card.wide { max-width: 460px; }
.auth-card h1 { font-size: 26px; margin: 0 0 20px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.recovery { margin-top: 20px; font-size: 14px; color: var(--muted); }
.recovery summary { cursor: pointer; margin-bottom: 10px; }
.qr { background: #fff; padding: 12px; border-radius: var(--radius); width: max-content; margin: 8px 0 12px; }
.qr svg { display: block; width: 200px; height: 200px; }
.codes { font-family: ui-monospace, Menlo, monospace; columns: 2; padding: 12px 16px 12px 32px; background: var(--surface-2); border-radius: var(--radius); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 16px; }
.signout { margin-top: 28px; }
code { font-family: ui-monospace, Menlo, monospace; word-break: break-all; }

/* ---------- Settings ---------- */
.settings { max-width: 640px; margin: 0 auto; padding: calc(env(safe-area-inset-top, 0px) + 20px) 16px 48px; }
.settings-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.settings-head h1 { margin: 0; font-size: 26px; }
.card { border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin-bottom: 16px; background: var(--surface); }
.card h2 { margin: 0 0 8px; font-size: 18px; }
.card h3 { margin: 8px 0 0; font-size: 16px; }
.banner { background: var(--accent-tint); color: var(--accent-ink); padding: 10px 14px; border-radius: 10px; font-weight: 600; }
.stack.narrow { max-width: 360px; }
.rows { list-style: none; margin: 8px 0 12px; padding: 0; }
.rows li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.rows li > div:first-child { display: flex; flex-direction: column; min-width: 0; }
.row-actions { display: flex; gap: 14px; flex-wrap: wrap; justify-content: flex-end; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input[type="text"] { flex: 1; }
.inline-form input[type="color"] { width: 56px; height: 44px; padding: 0; border: 1px solid var(--line); border-radius: 10px; background: none; cursor: pointer; }
.invite { background: var(--surface-2); border-radius: 12px; padding: 12px; margin: 8px 0 12px; }
.invite p { margin: 0 0 8px; }
.add-person { margin-top: 12px; }
.passkey-login { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.passkey-login .btn, .passkey-login .btn-primary { width: 100%; }
/* On a device that has signed in with a passkey before, Face ID comes first. */
.auth-card.passkey-first { display: flex; flex-direction: column; }
.auth-card.passkey-first .passkey-login { order: -1; margin: 0 0 20px; }
.auth-card.passkey-first h1 { order: -2; }
.auth-card.passkey-first .passkey-login .btn-primary { min-height: 54px; font-size: 18px; }
.passkey-or { margin: 4px 0 0; text-align: center; }

/* ---------- Dashboard ---------- */
/* Full width on a PC (unlike Notes' column); one column of collapsible panels on a phone. */
.hq { padding: 24px clamp(16px, 2.5vw, 40px) 48px; }
.hq-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.hq-head h1 { margin: 0; font-size: 26px; }
.hq-head h1 span { color: var(--accent-ink); }
.hq-meta { margin: 4px 0 18px; color: var(--muted); font-size: 14px; }
.hq-meta.stale { color: var(--warn); font-weight: 600; }

/* --cols is set by dashboard.js from the width (one column per 320px) so widgets can span columns. */
.widgets { display: grid; grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr)); gap: 16px; align-items: start; }
.widget {
    border: 1px solid var(--line); border-radius: 16px; padding: 16px; background: var(--surface);
    display: flex; flex-direction: column; gap: 14px; min-width: 0;
    position: relative; border-top: 4px solid var(--status-color, var(--line));
}
/* The strip along the top matches the status dot. */
.widget.status-ok { --status-color: var(--ok); }
.widget.status-warn { --status-color: var(--warn); }
.widget.status-bad { --status-color: var(--danger); }
.widget.stale { opacity: 0.55; }
.widget.sized { overflow: auto; }
.widget.dragging { opacity: 0.35; }
.widget.resizing { outline: 2px dashed var(--accent-line); outline-offset: 2px; user-select: none; }
.resize-grip {
    position: absolute; right: 3px; bottom: 3px; width: 18px; height: 18px; cursor: nwse-resize; touch-action: none;
    opacity: 0; transition: opacity 0.15s; border-radius: 4px;
    background: linear-gradient(135deg, transparent 0 45%, var(--muted) 45% 52%, transparent 52% 64%, var(--muted) 64% 71%, transparent 71%);
}
.widget:hover .resize-grip, .widget.resizing .resize-grip { opacity: 0.8; }
@media (min-width: 640px) {
    .widget-head { cursor: grab; }
    .widget.dragging .widget-head { cursor: grabbing; }
}
@media (min-width: 640px) { .widget.wide { grid-column: span 2; } }
.widget-head {
    display: flex; align-items: flex-start; gap: 10px; width: 100%;
    padding: 0; border: 0; background: none; text-align: left; cursor: default;
}
.widget-body { display: flex; flex-direction: column; gap: 14px; }
.chevron { display: none; margin-left: auto; color: var(--muted); transition: transform 0.15s; }
.widget-head > div { min-width: 0; }
.widget-head h2 { margin: 0; font-size: 17px; line-height: 1.3; }
.widget-sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { flex: none; width: 10px; height: 10px; margin-top: 6px; border-radius: 50%; background: var(--line); }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--danger); }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 12px; }
.stat-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat.warn .stat-value { color: var(--warn); }
.stat.bad .stat-value { color: var(--danger); }

.spark { background: var(--surface-2); border-radius: var(--radius); padding: 10px 12px 8px; }
.spark svg { display: block; width: 100%; height: 56px; overflow: visible; }
.spark polyline { fill: none; stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.spark .line-1 { stroke: var(--accent); }
.spark .line-2 { stroke: var(--muted); }
.spark-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.spark-legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.spark-legend .key-1 { background: var(--accent); }
.spark-legend .key-2 { background: var(--muted); }

.wlist-title { margin: 0 0 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.wlist { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.wlist li { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 7px 0; border-top: 1px solid var(--line); }
.wlist li > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wlist .detail { color: var(--muted); font-size: 12px; margin-left: 6px; }
.wlist .value { flex: none; font-variant-numeric: tabular-nums; font-weight: 600; }

.empty { color: var(--muted); border: 1px dashed var(--line); border-radius: 16px; padding: 24px; text-align: center; }

@media (max-width: 639px) {
    .widgets { grid-template-columns: minmax(0, 1fr); gap: 12px; }
    .widget { padding: 14px; gap: 12px; }
    .widget-head { cursor: pointer; }
    .chevron { display: block; }
    .widget.collapsed .chevron { transform: rotate(-90deg); }
    .widget.collapsed .widget-body { display: none; }
    .resize-grip { display: none; }
}

/* ---------- Side menu (a drawer on a phone) ---------- */
.shell { display: flex; min-height: 100dvh; }
.sidenav {
    flex: none; width: 232px; position: sticky; top: 0; height: 100dvh;
    display: flex; flex-direction: column; gap: 4px;
    padding: calc(env(safe-area-inset-top, 0px) + 18px) 12px 16px;
    border-right: 1px solid var(--line); background: var(--surface-2); overflow-y: auto;
}
.brand { font-size: 24px; font-weight: 800; color: var(--accent-ink); text-decoration: none; padding: 2px 10px 14px; }
.nav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.nav-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.nav-item {
    width: 100%; display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 10px;
    border: 0; border-radius: 10px; background: none; color: var(--text); text-decoration: none;
    font-weight: 600; font-size: 15px; cursor: pointer; text-align: left;
}
.nav-item:hover { background: var(--surface); }
.nav-item.active { background: var(--accent-tint); color: var(--accent-ink); }
.nav-icon { flex: none; width: 22px; height: 22px; display: inline-flex; }
.nav-icon svg { width: 100%; height: 100%; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-icon svg.fill-icon { fill: currentColor; stroke: none; }
.nav-user { margin: 8px 10px 0; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page { flex: 1; min-width: 0; }
.topbar { display: none; }
.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / 0.35); z-index: 40; }
.icon-btn { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 10px; background: none; cursor: pointer; }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke-width: 2; stroke-linecap: round; }

@media (max-width: 899px) {
    .shell { display: block; }
    .topbar {
        display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 30;
        padding: calc(env(safe-area-inset-top, 0px) + 6px) 8px 6px; background: var(--surface); border-bottom: 1px solid var(--line);
    }
    .topbar-title { font-weight: 700; font-size: 18px; }
    .sidenav { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: 0 0 24px rgb(0 0 0 / 0.2); }
    .menu-open .sidenav { transform: none; }
    .hq { padding-top: 16px; }
}

/* ---------- Tiles (home, games) and tools ---------- */
.tile-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; max-width: 900px; }
.tile {
    display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 8px;
    border: 1px solid var(--line); border-radius: 16px; color: var(--text); text-decoration: none; font-weight: 600; font-size: 14px;
}
.tile:hover { background: var(--surface-2); }
.tile img, .tile-icon { width: 72px; height: 72px; border-radius: 16px; display: block; object-fit: cover; }
.tile-icon { display: flex; align-items: center; justify-content: center; background: var(--accent-tint); color: var(--accent-ink); }
.tile-icon svg { width: 46%; height: 46%; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tile-icon svg.fill-icon { fill: currentColor; stroke: none; }
.tile-icon.small { flex: none; width: 48px; height: 48px; border-radius: 12px; }
.tool-card { max-width: 640px; }
.tool-head { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.tool-head h2 { margin: 0; }
.tool-head p { margin: 2px 0 0; }
.sign-in-note { margin: -12px 0 18px; }
.shell-page .settings { max-width: 720px; padding-top: 24px; }
