:root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --text: #1d2330;
    --muted: #667085;
    --border: #e3e6eb;
    --accent: #2f6fde;
    --accent-text: #ffffff;
    --ok-bg: #e7f6ec;
    --ok-text: #1b6b35;
    --err-bg: #fdecec;
    --err-text: #9b1c1c;
    --radius: 6px;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 15px;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14171c;
        --panel: #1c2027;
        --text: #e6e8eb;
        --muted: #98a2b3;
        --border: #2c323c;
        --accent: #5b8ff0;
        --ok-bg: #12301d;
        --ok-text: #8fdaa6;
        --err-bg: #3a1616;
        --err-text: #f4a4a4;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header.top {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 24px;
    height: 52px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}
header.top .brand { font-weight: 700; color: var(--text); }
header.top nav { display: flex; gap: 16px; flex: 1; }
header.top .logout { display: flex; align-items: center; gap: 12px; margin: 0; }
header.top .who { color: var(--muted); }

main { max-width: 1100px; margin: 0 auto; padding: 24px; }
h1 { font-size: 22px; margin: 0 0 20px; }

label { display: block; margin-bottom: 14px; color: var(--muted); font-size: 13px; }
input, select, textarea {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 8px 10px;
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
    padding: 8px 16px;
    font: inherit;
    font-weight: 600;
    color: var(--accent-text);
    background: var(--accent);
    border: 0;
    border-radius: var(--radius);
    cursor: pointer;
}
button.link { padding: 0; color: var(--accent); background: none; font-weight: 400; }

.login {
    max-width: 360px;
    margin: 12vh auto 0;
    padding: 28px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.login button { width: 100%; margin-top: 6px; }

.flash { padding: 10px 14px; margin-bottom: 16px; border-radius: var(--radius); }
.flash-ok { background: var(--ok-bg); color: var(--ok-text); }
.flash-error { background: var(--err-bg); color: var(--err-text); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.card { padding: 16px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.card .label { color: var(--muted); font-size: 13px; }
.card .value { font-size: 20px; font-weight: 600; margin-top: 4px; overflow-wrap: anywhere; }

a.card { color: var(--text); text-decoration: none; }
a.card:hover { border-color: var(--accent); }

h2 { font-size: 17px; margin: 28px 0 12px; }
h3 { font-size: 15px; margin: 22px 0 10px; }
code, .mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; }
.muted { color: var(--muted); font-weight: 400; font-size: 14px; }

.head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.head h1 { margin: 0; }

a.button {
    display: inline-block;
    padding: 8px 16px;
    font-weight: 600;
    color: var(--accent-text);
    background: var(--accent);
    border-radius: var(--radius);
    text-decoration: none;
}
button.danger { background: var(--err-text); }
form.inline { display: inline; margin: 0; }

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-size: 13px; font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; }
td.actions button { padding: 4px 10px; font-size: 13px; }

.form { max-width: 560px; }
.form.row { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 12px; max-width: none; }
.form.row label { flex: 1 1 220px; }
.form.row button { margin-top: 21px; }
fieldset { margin: 6px 0 16px; padding: 12px 16px 2px; border: 1px solid var(--border); border-radius: var(--radius); }
legend { padding: 0 6px; color: var(--muted); font-size: 13px; font-weight: 600; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
label.check input { width: auto; margin: 0; }
.field-error { display: block; margin-top: 4px; color: var(--err-text); }
textarea { resize: vertical; }

.cols { display: grid; grid-template-columns: minmax(0, 560px) minmax(0, 1fr); gap: 40px; }
.cols h2:first-child { margin-top: 0; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 4px 0; }

.job, .state {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: pre-wrap;
    vertical-align: middle;
}
.job-queued, .job-running { background: var(--border); color: var(--muted); }
.job-done, .state-active { background: var(--ok-bg); color: var(--ok-text); }
.job-failed, .state-deleting { background: var(--err-bg); color: var(--err-text); }
.job-failed { border-radius: var(--radius); font-weight: 400; font-family: ui-monospace, Menlo, monospace; }

@media (max-width: 800px) {
    .cols { grid-template-columns: 1fr; }
    table { display: block; overflow-x: auto; }
}

@media (max-width: 600px) {
    header.top { padding: 0 16px; gap: 12px; }
    main { padding: 16px; }
}

/* DNS */
table.records td.content { overflow-wrap: anywhere; max-width: 520px; }
table.records td.content div + div { margin-top: 2px; }
table.records tr.editing td { background: var(--bg); }
table.records td.actions { white-space: nowrap; }
table.records td.actions a { margin-right: 8px; font-size: 13px; }
.record-form { max-width: 760px; }
.record-form .form.row { margin-bottom: 0; }
.record-form .form.row label:first-child { flex: 2 1 260px; }
.card form.inline { display: block; margin-top: 6px; }
.card .value .muted { font-size: 13px; }
select.compact { display: inline-block; width: auto; margin: 0 6px 0 0; padding: 3px 6px; }
details.hints { margin: -6px 0 14px; font-size: 13px; color: var(--muted); }
details.hints summary { cursor: pointer; }
details.hints dl { display: grid; grid-template-columns: max-content 1fr; gap: 2px 14px; margin: 8px 0 0; }
details.hints dt { font-weight: 600; }
details.hints dd { margin: 0; }
.form.row label.check { flex: 0 1 auto; margin-top: 26px; }

/* TLS */
table.kv { max-width: 760px; margin-bottom: 12px; }
table.kv th { width: 130px; vertical-align: top; }
table.kv td { overflow-wrap: anywhere; }
pre.error-text { margin: 0; white-space: pre-wrap; color: var(--err-text); font-size: 13px; }
h2 + table.kv + form.inline { display: block; margin-bottom: 16px; }
td.names code { display: inline-block; margin-right: 6px; }

/* Security: 2FA, impersonation, API */
.break-all { word-break: break-all; }
.qr { width: 220px; height: 220px; margin: 8px 0 16px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); }
.qr svg { display: block; width: 100%; height: 100%; }
ul.codes { display: grid; grid-template-columns: repeat(2, max-content); gap: 6px 28px; padding: 0; list-style: none; font-size: 16px; }
form.impersonating { margin: 0; padding: 8px 24px; background: #fff4d6; color: #5c4400; text-align: center; }
form.impersonating .muted { color: #7a6420; }
@media (prefers-color-scheme: dark) {
    form.impersonating { background: #3d3214; color: #f3dc93; }
    form.impersonating .muted { color: #c9b26a; }
}
header.top a.who { color: var(--muted); }
pre.example { margin: 6px 0 14px; padding: 10px 12px; overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; }
table.endpoints td:first-child { white-space: nowrap; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
