:root {
    --bg: #f5f5f4;
    --card: #ffffff;
    --text: #1c1917;
    --muted: #78716c;
    --border: #e7e5e4;
    --accent: #1c1917;
    --accent-text: #ffffff;
    --error-bg: #fef2f2;
    --error-text: #b91c1c;
    --info-bg: #f0f9ff;
    --info-text: #0369a1;
    --radius: 12px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0c0a09;
        --card: #1c1917;
        --text: #fafaf9;
        --muted: #a8a29e;
        --border: #292524;
        --accent: #fafaf9;
        --accent-text: #1c1917;
        --error-bg: #450a0a;
        --error-text: #fca5a5;
        --info-bg: #082f49;
        --info-text: #7dd3fc;
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 16px;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

.card {
    width: 100%;
    max-width: 400px;
    padding: 40px 32px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.brand {
    text-align: center;
    margin-bottom: 28px;
}

.brand-logo {
    max-height: 48px;
    max-width: 160px;
    margin-bottom: 20px;
}

.brand-initial {
    width: 48px;
    height: 48px;
    margin: 0 auto 20px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
    font-size: 20px;
}

h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
}

.subtitle {
    margin: 4px 0 0;
    color: var(--muted);
}

.alert {
    padding: 10px 12px;
    margin-bottom: 20px;
    border-radius: 8px;
    font-size: 14px;
}

.alert-error {
    background: var(--error-bg);
    color: var(--error-text);
}

.alert-info {
    background: var(--info-bg);
    color: var(--info-text);
}

.form {
    display: grid;
    gap: 16px;
}

.field {
    display: grid;
    gap: 6px;
    font-size: 14px;
    font-weight: 500;
}

.field input {
    width: 100%;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    font: inherit;
}

.field input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.button {
    width: 100%;
    margin-top: 8px;
    padding: 11px 16px;
    border: 1px solid var(--accent);
    border-radius: 8px;
    background: var(--accent);
    color: var(--accent-text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.button:hover {
    opacity: 0.9;
}

.button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.button-secondary {
    background: transparent;
    color: var(--text);
    border-color: var(--border);
}

.details {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 16px;
    margin: 0 0 24px;
}

.details dt {
    color: var(--muted);
}

.details dd {
    margin: 0;
    overflow-wrap: anywhere;
}

a {
    color: inherit;
    text-underline-offset: 2px;
}

h2 {
    margin: 0 0 12px;
    font-size: 16px;
    font-weight: 600;
}

.field-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.field-row a {
    font-weight: 400;
    color: var(--muted);
}

.field-group {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
}

@media (max-width: 420px) {
    .field-group {
        grid-template-columns: 1fr;
    }
}

fieldset.field {
    border: 0;
    padding: 0;
    margin: 0;
    min-width: 0;
}

fieldset.field legend {
    padding: 0;
    margin-bottom: 6px;
}

.optional,
.field-hint {
    color: var(--muted);
    font-weight: 400;
}

.field-hint,
.field-error {
    font-size: 13px;
}

.field-error {
    color: var(--error-text);
    font-weight: 400;
}

.phone {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 8px;
}

.phone input,
.inline-form input,
.setting input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    font: inherit;
}

.code-input {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 20px !important;
    letter-spacing: 6px;
    text-align: center;
}

.footnote {
    margin: 24px 0 0;
    text-align: center;
    color: var(--muted);
    font-size: 14px;
}

.message {
    margin: 0 0 24px;
    text-align: center;
    color: var(--muted);
}

a.button {
    display: block;
    text-align: center;
    text-decoration: none;
    box-sizing: border-box;
}

.button-small {
    width: auto;
    margin-top: 0;
    padding: 7px 14px;
    font-size: 14px;
}

.link-button {
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

.inline-form {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 10px;
}

.secondary-action {
    margin-top: 16px;
    text-align: center;
    font-size: 14px;
}

.section {
    margin: 0 0 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.setting {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px 12px;
    padding: 12px 0;
}

.setting > div {
    display: flex;
    gap: 8px;
    align-items: center;
}

.setting details {
    font-size: 14px;
}

.setting details[open] {
    flex-basis: 100%;
}

.setting summary {
    cursor: pointer;
    color: var(--muted);
    text-align: right;
}

.setting details .form {
    margin-top: 10px;
    gap: 8px;
}

.status {
    padding: 1px 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    font-size: 12px;
}

.qr {
    width: 200px;
    margin: 0 auto 16px;
    padding: 8px;
    background: #fff;
    border-radius: 8px;
}

.qr svg {
    display: block;
    width: 100%;
    height: auto;
}

.secret {
    margin-bottom: 20px;
    font-size: 14px;
    color: var(--muted);
    text-align: center;
}

.secret code {
    display: block;
    margin-top: 8px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 13px;
    overflow-wrap: anywhere;
}

/* ---------- Admin console ---------- */

body.admin {
    display: block;
    /* Recent browsers apply justify-items to block layout too: undo the centered login layout */
    place-items: normal;
    padding: 0;
}

.topbar {
    border-bottom: 1px solid var(--border);
    background: var(--card);
}

.topbar-inner {
    max-width: 1040px;
    margin: 0 auto;
    padding: 12px 16px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 24px;
}

.topbar-brand {
    font-weight: 600;
    text-decoration: none;
}

.topbar-nav {
    display: flex;
    gap: 16px;
    flex: 1;
}

.topbar-nav a {
    color: var(--muted);
    text-decoration: none;
    font-size: 14px;
}

.topbar-nav a.active,
.topbar-nav a:hover {
    color: var(--text);
}

.topbar-signout {
    font-size: 14px;
    color: var(--muted);
}

.page {
    max-width: 1040px;
    margin: 0 auto;
    padding: 32px 16px 64px;
}

.page-narrow {
    max-width: 640px;
}

.page h1 {
    margin-bottom: 20px;
}

.page h2 {
    margin-top: 28px;
}

.page-header,
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
}

.page-header h1 {
    margin: 0;
    margin-right: auto;
}

.section-header {
    margin: 28px 0 12px;
}

.section-header h2 {
    margin: 0;
}

.columns > section > h2:first-child,
.columns > section > .section-header:first-child {
    margin-top: 0;
}

.breadcrumb {
    margin: 0 0 8px;
    font-size: 14px;
    color: var(--muted);
}

.columns {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 32px;
}

@media (max-width: 760px) {
    .columns {
        grid-template-columns: minmax(0, 1fr);
    }
}

.panel {
    padding: 20px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.panel.list {
    padding: 0;
}

.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    text-decoration: none;
}

.list-item:first-child {
    border-top: 0;
}

a.list-item:hover {
    background: color-mix(in srgb, var(--border) 40%, transparent);
}

.list-item > span:first-child {
    display: grid;
    min-width: 0;
}

.list-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    font-size: 14px;
}

.empty {
    margin: 0;
    padding: 16px;
    color: var(--muted);
    font-size: 14px;
}

.muted {
    color: var(--muted);
    font-size: 14px;
    overflow-wrap: anywhere;
}

.mono,
code {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 13px;
}

.list-item code {
    color: var(--muted);
    overflow-wrap: anywhere;
}

textarea.mono {
    font-size: 13px;
}

.field textarea,
.field select {
    width: 100%;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    font: inherit;
    resize: vertical;
}

.field select option {
    background: var(--card);
}

.checkbox {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 14px;
    font-weight: 400;
}

/* Inside a .field the text-input rules (full width, padding) must not stretch radios and checkboxes */
.field .checkbox input {
    flex: none;
    width: auto;
    margin: 0;
    padding: 0;
    accent-color: var(--accent);
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.table th,
.table td {
    padding: 12px 16px;
    text-align: left;
    border-top: 1px solid var(--border);
    white-space: nowrap;
}

.table thead th {
    border-top: 0;
    color: var(--muted);
    font-weight: 500;
}

.table td code {
    color: var(--muted);
}

.badge {
    display: inline-block;
    padding: 1px 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.badge-ok {
    color: var(--info-text);
    border-color: color-mix(in srgb, var(--info-text) 40%, transparent);
}

.badge-off {
    color: var(--error-text);
    border-color: color-mix(in srgb, var(--error-text) 40%, transparent);
}

.pager {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-top: 16px;
    font-size: 14px;
    color: var(--muted);
}

.details-stacked {
    grid-template-columns: 1fr;
    gap: 4px;
    margin: 0 0 20px;
}

.details-stacked dd {
    margin-bottom: 8px;
}

.secret-value {
    color: var(--text);
    font-size: 14px;
}

.alert-line {
    margin: 0;
}

.danger-zone {
    margin-top: 32px;
}

.danger-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-top: 12px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
}

.button-danger {
    background: var(--error-text);
    border-color: var(--error-text);
    color: var(--card);
}

.danger-link {
    color: var(--error-text);
}

.panel + .button,
a.button + form {
    margin-top: 16px;
}

.captcha {
    min-height: 65px;
}

.card-wide {
    max-width: 520px;
}

.account-links {
    display: grid;
    margin: 0 0 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.account-links a {
    padding: 12px 16px;
    text-decoration: none;
    border-top: 1px solid var(--border);
}

.account-links a:first-child {
    border-top: 0;
}

.account-links a::after {
    content: "›";
    float: right;
    color: var(--muted);
}

.section-first {
    padding-top: 0;
    border-top: 0;
}

.session-info {
    display: grid !important;
    gap: 2px !important;
    min-width: 0;
}

.recovery-codes {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 16px;
    margin: 0 0 24px;
    padding: 16px 16px 16px 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
}

.recovery-codes code {
    font-size: 15px;
    letter-spacing: 1px;
}

.mfa-alternatives {
    display: grid;
    gap: 8px;
}

.status-warn {
    color: var(--error-text);
    border-color: color-mix(in srgb, var(--error-text) 40%, transparent);
}

a.button-small {
    display: inline-block;
    width: auto;
}

.avatar {
    display: block;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}

.avatar-large {
    width: 96px;
    height: 96px;
}

.avatar-empty {
    display: grid;
    place-items: center;
    background: var(--border);
    color: var(--muted);
    font-size: 2rem;
    font-weight: 600;
}

.avatar[hidden] {
    display: none;
}

.photo-current {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-bottom: 16px;
}

/* Account deletion */

.delete-account {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: fit-content;
    max-width: 100%;
    margin: -12px auto 24px;
    padding: 6px 14px 6px 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 14px;
    font-weight: 500;
}

.delete-account-icon {
    display: grid;
    place-items: center;
    flex: none;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--bg);
    color: var(--muted);
}

.delete-account-email {
    min-width: 0;
    overflow-wrap: anywhere;
}

.delete-warning {
    display: flex;
    gap: 12px;
    padding: 14px 16px;
    margin-bottom: 20px;
    border-radius: 10px;
    background: var(--error-bg);
    color: var(--error-text);
    font-size: 14px;
}

.delete-warning-icon {
    flex: none;
    margin-top: 1px;
}

.delete-warning div {
    display: grid;
    gap: 2px;
}

.delete-consequences {
    display: grid;
    gap: 14px;
    margin: 0 0 16px;
    padding: 0;
    list-style: none;
    font-size: 14px;
}

.delete-consequences li {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.delete-consequences svg {
    flex: none;
    margin-top: 1px;
    color: var(--muted);
}

.delete-note {
    margin: 0 0 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 13px;
}

.delete-keep {
    display: block;
    margin-top: 12px;
    text-align: center;
    text-decoration: none;
}
