:root {
    --bg: #f5f7fb;
    --card: #ffffff;
    --text: #151923;
    --muted: #687181;
    --line: #e1e6ef;
    --line-strong: #cbd3df;
    --brand: #005cab;
    --brand-dark: #004a89;
    --brand-soft: #eaf4fb;
    --brand-faint: #f5f9fc;
    --danger: #b4232f;
    --danger-dark: #951b26;
    --danger-soft: #fff3f4;
    --success: #237447;
    --success-soft: #f0faf4;
    --warn: #8a5c00;
    --warn-soft: #fff8e9;
    --shadow: 0 10px 32px rgba(25, 42, 75, .07);
    --shadow-soft: 0 4px 16px rgba(25, 42, 75, .05);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
    min-height: 100vh;
    margin: 0;
    background: radial-gradient(circle at 100% 0, rgba(0, 92, 171, .04), transparent 30rem), var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-weight: 400;
}
h1, h2, h3, h4, h5, h6 { font-weight: 600; }
strong, b { font-weight: 600; }
button, input, select, textarea { font: inherit; }
button:disabled, .button.disabled { cursor: not-allowed; opacity: .55; transform: none !important; }
a.disabled { pointer-events: none; }

.container { width: min(1160px, calc(100% - 32px)); margin-inline: auto; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(255, 255, 255, .96);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}
.nav-wrap { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 28px; }
.brand { display: flex; align-items: center; gap: 16px; color: inherit; text-decoration: none; min-width: 0; }
.brand-logo { display: block; width: 205px; height: auto; max-width: 100%; flex: 0 0 auto; }
.brand-product { display: flex; flex-direction: column; min-width: 0; padding-left: 16px; border-left: 1px solid var(--line); }
.brand-product strong { font-size: 14px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-product small { color: var(--muted); font-size: 11px; margin-top: 2px; }
.topbar nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.topbar nav > a, .link-button {
    border: 0; background: transparent; padding: 9px 11px; border-radius: 8px; color: #394151;
    text-decoration: none; font: inherit; cursor: pointer; transition: background .15s, color .15s;
}
.topbar nav > a:hover, .link-button:hover, .topbar nav > a.active { background: var(--brand-soft); color: var(--brand-dark); }
.topbar nav > a.active { font-weight: 600; }
.inline { display: inline; }

.page { padding-block: 38px 56px; min-height: calc(100vh - 132px); }
.auth-page { display: grid; place-items: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 26px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 24px; }
.page-head h1, h1 { margin: .1em 0 .25em; font-size: clamp(28px, 4vw, 38px); line-height: 1.15; letter-spacing: -.03em; }
.page-head p { margin: 0; }
.eyebrow { margin-bottom: 6px !important; text-transform: uppercase; letter-spacing: .12em; font-weight: 600; color: var(--brand-dark); font-size: 12px; }
.muted { color: var(--muted); }
.compact { margin-top: 6px; }
.helper { color: var(--muted); font-size: 13px; margin-top: -5px; }

.button {
    display: inline-flex; justify-content: center; align-items: center; gap: 7px; border: 1px solid transparent;
    border-radius: 9px; padding: 10px 14px; text-decoration: none; font: 600 14px/1.2 inherit;
    cursor: pointer; transition: background .15s, border-color .15s, box-shadow .15s, transform .08s, opacity .15s;
}
.button:active { transform: translateY(1px); }
.button.primary { background: var(--brand); color: #fff; box-shadow: 0 3px 10px rgba(0, 92, 171, .20); }
.button.primary:hover:not(:disabled) { background: var(--brand-dark); }
.button.secondary { background: #fff; color: #333b4b; border-color: var(--line-strong); }
.button.secondary:hover:not(:disabled) { background: var(--brand-faint); border-color: #aebbd2; color: var(--brand-dark); }
.button.danger { background: var(--danger); color: #fff; }
.button.danger:hover:not(:disabled) { background: var(--danger-dark); }
.button.small { padding: 7px 10px; font-size: 13px; }
.button.full { width: 100%; margin-top: 6px; }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.button.copied { background: var(--success-soft); border-color: #b9dfc9; color: var(--success); box-shadow: none; }

.stat-row { display: flex; gap: 14px; margin-bottom: 18px; }
.stat-row.three { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat-row.four { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { position: relative; min-width: 160px; overflow: hidden; box-shadow: var(--shadow-soft); }
.stat::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--brand); }
.stat.attention::before { background: #d18a00; }
.stat.healthy::before { background: var(--success); }
.stat strong { display: block; font-size: 28px; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 13px; }
.stat small { display: block; color: var(--muted); font-size: 11px; margin-top: 5px; }

.toolbar-card { padding: 18px 20px; margin-bottom: 18px; box-shadow: var(--shadow-soft); }
.toolbar { display: grid; grid-template-columns: minmax(240px, 1fr) minmax(180px, 260px); gap: 14px; align-items: end; }
.toolbar label { margin: 0; }
.toolbar .search-field:only-child { grid-column: 1 / -1; }
.filter-count { margin: 10px 0 0; font-size: 12px; }

.table-card { padding: 0; overflow: hidden; box-shadow: var(--shadow-soft); }
.table-scroll { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 15px 18px; text-align: left; border-bottom: 1px solid var(--line); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: #647083; background: #fafbfe; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: #fbfcff; }
tbody tr:last-child td { border-bottom: 0; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 34px; }
.empty strong { color: var(--text); }
.filtered-empty { border-top: 1px solid var(--line); }
.mailbox-link { color: var(--text); font-weight: 600; text-decoration: none; }
.mailbox-link:hover { color: var(--brand-dark); text-decoration: underline; }
.storage-cell { min-width: 135px; }
.storage-cell strong { display: block; font-size: 13px; margin-bottom: 5px; }
progress { display: block; width: 100%; height: 7px; border: 0; border-radius: 999px; overflow: hidden; background: #edf0f5; }
progress::-webkit-progress-bar { background: #edf0f5; border-radius: 999px; }
progress::-webkit-progress-value { background: var(--brand); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--brand); border-radius: 999px; }
.large-progress { height: 10px; margin-bottom: 3px; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 8px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge.success { background: #e8f6ee; color: var(--success); }
.badge.warning { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: #fdeced; color: var(--danger); }

.auth-card { width: min(450px, 100%); padding: 32px; border-top: 4px solid var(--brand); }
.wide-auth { width: min(720px, 100%); }
.auth-brand { display: block; margin-bottom: 28px; }
.auth-brand .brand-logo { width: min(290px, 100%); margin-bottom: 20px; }
.auth-brand .brand-product { border-left: 0; padding-left: 0; }
.auth-brand .brand-product strong { font-size: 16px; }
.auth-brand .brand-product small { font-size: 12px; }
.auth-card h1 { font-size: 30px; }
.auth-card form { margin-top: 20px; }
.quiet-link { display: block; text-align: center; color: var(--muted); font-size: 13px; margin-top: 15px; }

label { display: block; font-weight: 500; font-size: 14px; margin: 0 0 17px; }
input, select, textarea {
    width: 100%; margin-top: 7px; padding: 11px 12px; border: 1px solid #c8d0dc; border-radius: 9px;
    background: #fff; color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(0, 92, 171, .14); }
label small, fieldset small { display: block; color: var(--muted); font-weight: 400; margin-top: 6px; }
.code-input { font-size: 24px; letter-spacing: .2em; text-align: center; }
.check-label { display: flex; align-items: flex-start; gap: 9px; font-weight: 500; }
.check-label input { width: 18px; height: 18px; margin: 2px 0 0; flex: 0 0 auto; }
.confirm-save { margin-top: 24px; padding: 13px; background: var(--brand-faint); border: 1px solid #cfe0ee; border-radius: 10px; }

.notice { padding: 12px 14px; border-radius: 10px; margin: 0 0 18px; border: 1px solid; }
.notice.danger { background: var(--danger-soft); border-color: #efbbc1; color: #7e202b; }
.notice.success { background: var(--success-soft); border-color: #b9dfc9; color: #1f683e; }
.notice.warning { background: var(--warn-soft); border-color: #efd493; color: #72500a; }
.notice.info { background: var(--brand-soft); border-color: #bdd8eb; color: #164f7e; }

.secret-box { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; margin: 16px 0; padding: 13px; background: #f7f9fc; border: 1px solid var(--line); border-radius: 11px; }
.secret-box.prominent { background: var(--brand-faint); border-color: #c6dcea; padding: 18px; }
.secret-box span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.secret-box code { word-break: break-all; font-weight: 600; font-size: 15px; }
.wrap-code { display: block; white-space: normal; word-break: break-all; background: #f7f9fc; padding: 12px; border-radius: 8px; margin: 10px 0; }
.recovery-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 18px 0; }
.recovery-grid code { padding: 10px; background: #f6f8fb; border: 1px solid var(--line); border-radius: 8px; text-align: center; font-weight: 600; }
.secret-result { text-align: center; }
.secret-result .notice, .secret-result .secret-box { text-align: left; }

.narrow { width: min(680px, 100%); margin: 0 auto; text-align: center; }
.narrow.left { text-align: left; }
.status-icon { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 12px; font-size: 26px; font-weight: 600; }
.status-icon.success { background: #e7f6ed; color: var(--success); }
.status-icon.error { background: #fdeced; color: var(--danger); }

.form-card { max-width: 820px; }
.form-step { display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 16px; padding: 4px 0 26px; margin-bottom: 24px; border-bottom: 1px solid var(--line); }
.form-step:last-of-type { border-bottom: 0; margin-bottom: 6px; }
.step-number { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--brand); color: #fff; font-weight: 600; }
.step-content h2, .setup-step h2 { font-size: 19px; margin: 3px 0 3px; }
.step-content > p, .setup-step p { margin-top: 0; }
.email-builder { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: end; }
.email-builder .at { padding-bottom: 29px; font-size: 20px; color: var(--muted); }
.preview-line { margin-top: -4px; padding: 10px 12px; background: var(--brand-faint); border: 1px solid #d4e4ef; border-radius: 9px; font-size: 13px; }
.input-action { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.input-action input { flex: 1 1 260px; }
.input-action .button { margin-top: 7px; white-space: nowrap; }
.quota-custom-row { display: grid; grid-template-columns: 1fr 110px; gap: 10px; }
.quota-custom-row input, .quota-custom-row select { margin-top: 7px; }
.capacity-summary { max-width: 820px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; align-items: center; padding-top: 4px; }

.manage-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.manage-grid .danger-zone { grid-column: 1 / -1; border-color: #e5b9be; box-shadow: 0 4px 16px rgba(120, 20, 30, .04); }
.card h2 { font-size: 20px; margin-top: 0; }
.metric { margin: 8px 0 15px; }
.metric strong { display: block; font-size: 30px; }
.metric span { color: var(--muted); }
.danger-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.danger-heading h2 { margin-bottom: 3px; }
.danger-heading p { margin: 0 0 16px; }

.setup-steps { display: grid; gap: 18px; margin-top: 24px; }
.setup-step { display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 15px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.setup-step:last-child { border-bottom: 0; padding-bottom: 0; }
.setup-step form { margin-top: 10px; }

.system-list { display: grid; }
.system-row { display: grid; grid-template-columns: 32px minmax(190px, .8fr) 1.5fr; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.system-row:last-child { border-bottom: 0; }
.status-dot { width: 25px; height: 25px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; }
.status-dot.ok { background: #e8f6ee; color: var(--success); }
.status-dot.bad { background: #fdeced; color: var(--danger); }

.footer { display: flex; justify-content: space-between; gap: 20px; color: #7b8493; font-size: 12px; padding: 18px 0 30px; }
.footer strong { color: #4b5669; }
.footer a { color: #657083; text-decoration: none; }
.footer a:hover { color: var(--brand-dark); text-decoration: underline; }

.installer { padding: 34px 0; }
.install-wrap { width: min(820px, calc(100% - 32px)); margin: auto; }
.install-wrap > .brand { margin-bottom: 24px; }
.install-wrap > .brand .brand-logo { width: 230px; }
.install-card { border-top: 4px solid var(--brand); }
.install-card h1 { margin-top: 0; }
.install-card h2 { margin: 28px 0 10px; font-size: 18px; }
.install-card fieldset { border: 0; padding: 0; margin: 28px 0; }
.install-card legend { font-weight: 600; font-size: 18px; margin-bottom: 14px; }
.form-grid.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.check-grid { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.check-row { display: grid; grid-template-columns: 25px 1fr auto; gap: 9px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.check-row:last-child { border-bottom: 0; }
.check-row small { color: var(--muted); }
details { margin: 15px 0; }
summary { cursor: pointer; font-weight: 500; }

@media (max-width: 900px) {
    .brand-logo { width: 180px; }
    .brand-product { padding-left: 12px; }
    .stat-row.three { grid-template-columns: 1fr 1fr; }
    .stat-row.four { grid-template-columns: 1fr 1fr; }
    .stat-row.three .stat:last-child { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
    .nav-wrap { align-items: flex-start; padding: 14px 0; flex-direction: column; }
    .topbar { position: static; }
    .topbar .brand { width: 100%; }
    .topbar nav { width: 100%; overflow: auto; flex-wrap: nowrap; padding-bottom: 1px; }
    .page { padding-top: 24px; }
    .page-head { align-items: flex-start; flex-direction: column; }
    .page-head .button { width: 100%; }
    .stat-row, .stat-row.three, .stat-row.four { grid-template-columns: 1fr; display: grid; }
    .stat-row.three .stat:last-child { grid-column: auto; }
    .stat { min-width: 0; }
    .toolbar { grid-template-columns: 1fr; }
    .manage-grid { grid-template-columns: 1fr; }
    .manage-grid .danger-zone { grid-column: auto; }
    .email-builder { grid-template-columns: 1fr; }
    .email-builder .at { display: none; }
    .input-action { align-items: stretch; }
    .input-action input { flex-basis: 100%; }
    .input-action .button { flex: 1 1 auto; }
    .system-row { grid-template-columns: 32px 1fr; }
    .system-row > span:last-child { grid-column: 2; }
    .form-grid.two { grid-template-columns: 1fr; }
    .recovery-grid { grid-template-columns: 1fr; }
    .secret-box { grid-template-columns: 1fr; text-align: left; }
    .footer { flex-direction: column; gap: 4px; }

    .mailbox-table thead, .activity-table thead { display: none; }
    .mailbox-table, .mailbox-table tbody, .mailbox-table tr, .mailbox-table td,
    .activity-table, .activity-table tbody, .activity-table tr, .activity-table td { display: block; width: 100%; }
    .mailbox-table tr, .activity-table tr { padding: 12px 16px; border-bottom: 1px solid var(--line); }
    .mailbox-table tr:last-child, .activity-table tr:last-child { border-bottom: 0; }
    .mailbox-table td, .activity-table td { display: grid; grid-template-columns: minmax(90px, .38fr) 1fr; gap: 12px; padding: 7px 0; border: 0; text-align: left; }
    .mailbox-table td::before, .activity-table td::before { content: attr(data-label); color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
    .mailbox-table td.right { text-align: left; }
    .mailbox-table td.right .button { width: 100%; }
    .mailbox-table .empty { display: block; text-align: center; padding: 24px 8px; }
    .mailbox-table .empty::before { display: none; }
}

@media (max-width: 520px) {
    .container { width: min(100% - 22px, 1160px); }
    .card { padding: 20px; border-radius: 14px; }
    .auth-card { padding: 24px 20px; }
    .brand-logo { width: 168px; }
    .brand-product strong { font-size: 13px; }
    .brand-product small { font-size: 10px; }
    .form-step, .setup-step { grid-template-columns: 30px 1fr; gap: 11px; }
    .step-number { width: 30px; height: 30px; font-size: 13px; }
    .form-actions { flex-direction: column-reverse; }
    .form-actions .button { width: 100%; }
    .danger-heading { align-items: flex-start; }
}

/* Mail setup */
.setup-layout { display:grid; grid-template-columns:minmax(0,1.2fr) minmax(320px,.8fr); gap:20px; margin-bottom:20px; }
.section-heading { display:flex; justify-content:space-between; gap:16px; align-items:flex-start; margin-bottom:16px; }
.settings-grid { border:1px solid var(--line); border-radius:12px; overflow:hidden; margin:16px 0; }
.setting-row { display:grid; grid-template-columns:minmax(135px,.7fr) minmax(0,1.3fr) auto; gap:14px; align-items:center; padding:12px 14px; border-bottom:1px solid var(--line); }
.setting-row:last-child { border-bottom:0; }
.setting-row > span:first-child { color:var(--muted); font-size:13px; font-weight:600; }
.setting-row strong { overflow-wrap:anywhere; }
.setup-guides { margin-bottom:20px; }
.setup-guide { border:1px solid var(--line); border-radius:12px; margin:10px 0; background:#fff; }
.setup-guide summary { cursor:pointer; list-style:none; padding:15px 16px; font-weight:600; position:relative; padding-right:44px; }
.setup-guide summary::-webkit-details-marker { display:none; }
.setup-guide summary::after { content:'+'; position:absolute; right:16px; top:11px; font-size:24px; color:var(--brand); }
.setup-guide[open] summary::after { content:'−'; }
.setup-guide ol, .setup-guide p { margin:0; padding:0 22px 18px 42px; }
.setup-guide li { margin:8px 0; line-height:1.5; }
.notice.subtle { background:#f7f9fc; border-color:var(--line); color:var(--text); }
.credential-email-box { margin:20px 0 26px; padding:18px; border:1px solid var(--line); background:#f6fafd; border-radius:12px; }
.credential-email-box > .check-label { margin-bottom:0; }
.credential-email-fields { margin-top:14px; }
@media (max-width: 820px) { .setup-layout { grid-template-columns:1fr; } }
@media (max-width: 620px) { .setting-row { grid-template-columns:1fr auto; } .setting-row > span:first-child { grid-column:1 / -1; } }

.optional-label { font-size:12px; font-weight:600; color:var(--muted); margin-left:6px; }
.credential-email-fields[hidden] { display:none !important; }

.row-actions { display:flex; justify-content:flex-end; gap:7px; flex-wrap:wrap; }
@media (max-width: 720px) { .row-actions { justify-content:stretch; } .row-actions .button { flex:1 1 auto; } }

/* v1.5 authentication/support refinements */
.credential-email-box + .button { margin-top: 12px; }
.role-pill { display:inline-flex; align-items:center; margin-left:7px; padding:2px 7px; border-radius:999px; background:var(--brand-soft); color:var(--brand-dark); font-size:11px; font-weight:600; vertical-align:middle; }
.totp-qr-wrap { display:flex; align-items:center; gap:20px; flex-wrap:wrap; margin:16px 0 6px; }
.totp-qr { width:220px; max-width:100%; aspect-ratio:1; padding:12px; background:#fff; border:1px solid var(--line); border-radius:12px; box-shadow:var(--shadow-soft); }
.totp-qr svg { display:block; width:100%; height:auto; }
.totp-qr-error { width:100%; height:100%; display:grid; place-items:center; text-align:center; color:var(--danger); font-size:13px; padding:14px; }
@media (max-width: 560px) { .totp-qr-wrap { align-items:flex-start; } .totp-qr { width:min(220px,100%); } }

.authenticator-name { margin:12px 0 14px; padding:11px 13px; border:1px solid var(--line); border-radius:10px; background:var(--surface-subtle,#f7f9fb); display:grid; gap:2px; }
.authenticator-name span { font-size:12px; color:var(--muted); }
.authenticator-name strong { font-size:14px; font-weight:600; color:var(--text); overflow-wrap:anywhere; }
.authenticator-name small { font-size:12px; color:var(--muted); overflow-wrap:anywhere; }
