:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --text: #1d2330;
    --muted: #677084;
    --border: #dde1e8;
    --primary: #2f6fde;
    --primary-text: #ffffff;
    --danger: #c9372c;
    --ok: #1f8a4c;
    --warn: #b7791f;
    --ok-bg: #e5f5ec;
    --err-bg: #fdecea;
    --warn-bg: #fdf4e3;
    --info-bg: #e8f0fd;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(20, 30, 50, .06);
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12151b;
        --surface: #1b2029;
        --text: #e4e7ee;
        --muted: #98a1b3;
        --border: #2d3441;
        --primary: #5b8ff0;
        --danger: #ef6a5e;
        --ok: #4cc083;
        --warn: #e0a84a;
        --ok-bg: #173325;
        --err-bg: #3a1d1b;
        --warn-bg: #3a2e17;
        --info-bg: #1a2a45;
        --shadow: none;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 0 .3em; word-break: break-all; }
ul, ol { padding-left: 1.3rem; }
[hidden] { display: none !important; }

/* Layout */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: .6rem 16px; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .45rem; font-weight: 650; color: var(--text); }
.brand:hover { text-decoration: none; }
.mainnav { display: flex; align-items: center; gap: .25rem; margin-left: auto; flex-wrap: wrap; }
.mainnav a, .mainnav .linklike { padding: .35rem .65rem; border-radius: 6px; color: var(--muted); font-size: .95rem; }
.mainnav a:hover, .mainnav .linklike:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.mainnav a.active { color: var(--text); background: var(--bg); font-weight: 600; }
.nav-toggle { display: none; margin-left: auto; }
.container { max-width: 1100px; margin: 0 auto; padding: 1.25rem 16px 3rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card.narrow { max-width: 440px; margin: 2rem auto; }
.card.narrow-left { max-width: 640px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .5rem; }
.card-head h2 { margin: 0; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-top: .75rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; align-items: start; }
.grid-2 .card { margin-bottom: 0; }
.stack { display: flex; flex-direction: column; gap: .9rem; }
.row { display: flex; gap: .9rem; flex-wrap: wrap; }
.row > .field { flex: 1 1 160px; }
.row > .grow { flex: 3 1 220px; }
.w-sm { max-width: 110px; }
.w-md { max-width: 220px; }
.button-row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.actions { display: inline-flex; gap: .4rem; flex-wrap: wrap; align-items: center; justify-content: flex-end; }
.inline { display: inline; margin: 0; }
.inline-form { display: flex; gap: .5rem; align-items: center; }

/* Forms */
.field { display: flex; flex-direction: column; gap: .3rem; font-weight: 550; font-size: .93rem; margin: 0; border: 0; padding: 0; min-width: 0; }
fieldset.field { gap: .45rem; }
legend { font-weight: 600; padding: 0; margin-bottom: .35rem; }
input[type=text], input[type=email], input[type=password], input[type=number], select {
    font: inherit; font-weight: 400; color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: 7px; padding: .5rem .65rem; width: 100%; min-height: 40px;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
    outline: 2px solid var(--primary); outline-offset: 1px;
}
.check { display: flex; gap: .5rem; align-items: baseline; font-size: .95rem; font-weight: 400; }
.check input { flex: none; transform: translateY(1px); }
.hint { font-weight: 400; color: var(--muted); font-size: .85rem; margin: 0; }
.input-suffix { display: flex; align-items: center; gap: .4rem; }
.input-suffix span { color: var(--muted); font-weight: 400; }
.account-picker { margin-left: 1.5rem; display: flex; flex-direction: column; gap: .3rem; max-height: 280px; overflow: auto; padding: .5rem; border: 1px solid var(--border); border-radius: 7px; }
details > summary { cursor: pointer; color: var(--primary); margin-bottom: .5rem; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: .75rem 0; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    font: inherit; font-weight: 550; font-size: .93rem; line-height: 1.2;
    padding: .55rem .95rem; min-height: 38px; border-radius: 7px; cursor: pointer;
    background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost-danger { color: var(--danger); }
.btn-small { padding: .3rem .6rem; min-height: 30px; font-size: .85rem; }
.linklike { background: none; border: 0; font: inherit; cursor: pointer; }

/* Switch */
.switch { display: inline-flex; align-items: center; gap: .5rem; background: none; border: 0; cursor: pointer; font: inherit; color: var(--muted); padding: .2rem; }
.switch-knob { width: 38px; height: 22px; border-radius: 11px; background: var(--border); position: relative; transition: background .15s; flex: none; }
.switch-knob::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch.on .switch-knob { background: var(--ok); }
.switch.on .switch-knob::after { transform: translateX(16px); }
.switch.on { color: var(--text); }
.switch-label { font-size: .88rem; }

/* Alerts & badges */
.alert { border-radius: 8px; padding: .7rem .9rem; margin-bottom: 1rem; border: 1px solid transparent; }
.alert ul { margin: .35rem 0 0; }
.alert-success { background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.alert-error { background: var(--err-bg); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.alert-warning { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.alert-info { background: var(--info-bg); border-color: color-mix(in srgb, var(--primary) 30%, transparent); }
.badge { display: inline-block; font-size: .75rem; font-weight: 650; padding: .1rem .5rem; border-radius: 99px; text-transform: uppercase; letter-spacing: .02em; vertical-align: middle; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-error { background: var(--err-bg); color: var(--danger); }
.badge-partial { background: var(--warn-bg); color: var(--warn); }
.badge-muted { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.error-text { color: var(--danger); }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -.25rem; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 650; padding: .5rem; border-bottom: 1px solid var(--border); }
.table td { padding: .55rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table-compact td { padding: .35rem .5rem; }
.table .clip { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table tr.unread td { font-weight: 600; }
.is-disabled { opacity: .6; }
.nowrap { white-space: nowrap; }

/* Installer, OAuth */
.card.wide-ish { max-width: 620px; }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
.install-steps { display: flex; gap: .5rem; list-style: none; padding: 0; margin: .75rem 0 1rem; flex-wrap: wrap; }
.install-steps li { padding: .25rem .7rem; border-radius: 99px; border: 1px solid var(--border); color: var(--muted); font-size: .85rem; }
.install-steps li.current { border-color: var(--primary); color: var(--text); font-weight: 600; }
.install-steps li.done { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.code-block { width: 100%; font: .82rem/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 7px; padding: .7rem; }
.connect-card { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); }
.connect-card p { margin: .25rem 0 0; }
.setup-help ol { padding-left: 1.2rem; }
.small-heading { font-size: .9rem; margin: 1rem 0 .4rem; }
.setup-help li { margin-bottom: .4rem; }
a.badge:hover { text-decoration: none; filter: brightness(.95); }

/* Provider picker */
.provider-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; }
.provider-tile { display: flex; flex-direction: column; align-items: flex-start; gap: .35rem; padding: 1.1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); box-shadow: var(--shadow); min-height: 130px; }
.provider-tile:hover { text-decoration: none; border-color: var(--primary); }
.provider-mark { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; font-size: 1.2rem; color: #fff; background: var(--muted); }
.provider-google .provider-mark { background: #1a73e8; }
.provider-microsoft .provider-mark { background: #0f6cbd; }
.provider-icloud .provider-mark { background: #3a8ee6; }
.provider-yahoo .provider-mark { background: #6001d2; }
.provider-fastmail .provider-mark { background: #0067b9; }
.provider-name { font-weight: 650; }
.provider-desc { color: var(--muted); font-size: .86rem; }

/* Misc */
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.empty { color: var(--muted); text-align: center; padding: 1.5rem 0; margin: 0; }
.summary { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; display: flex; flex-direction: column; color: var(--text); box-shadow: var(--shadow); }
.stat:hover { text-decoration: none; border-color: var(--primary); }
.stat-num { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: .88rem; }
.steps li { margin-bottom: .35rem; }
.steps li.done { color: var(--muted); text-decoration: line-through; }
.checklist { list-style: none; padding: 0; display: flex; flex-direction: column; gap: .45rem; }
.copyable { user-select: all; }
.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1rem; }
.test-result { border-radius: 8px; padding: .7rem .9rem; }
.test-result.ok { background: var(--ok-bg); }
.test-result.fail { background: var(--err-bg); }
.run-output:empty { display: none; }
.run-output { margin-top: .75rem; border-top: 1px solid var(--border); padding-top: .75rem; }
.preview p { margin-top: 0; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: .4rem; }
@keyframes spin { to { transform: rotate(360deg); } }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 760px) {
    .nav-toggle { display: inline-flex; background: none; border: 1px solid var(--border); border-radius: 6px; padding: .3rem .7rem; font: inherit; color: var(--text); }
    .mainnav { display: none; width: 100%; flex-direction: column; align-items: stretch; }
    .mainnav.open { display: flex; }
    .mainnav form, .mainnav .linklike { width: 100%; text-align: left; }
    .card { padding: 1rem; }
    .table .clip { max-width: 180px; }
    .w-sm, .w-md { max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
    .spinner { animation: none; }
    .switch-knob, .switch-knob::after { transition: none; }
}
