:root {
    color-scheme: light;
    --ink: #17211b;
    --muted: #69756e;
    --line: #dce3de;
    --paper: #ffffff;
    --wash: #f3f6f3;
    --green: #176b48;
    --green-dark: #0f5337;
    --red: #a4382e;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--wash); font-size: 15px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.65rem, 4vw, 2.25rem); letter-spacing: -.035em; }
h2 { margin-bottom: 0; font-size: 1.35rem; letter-spacing: -.02em; }
.eyebrow { margin-bottom: .25rem; color: var(--green); font-size: .72rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.muted, .signed-in { color: var(--muted); }

.topbar { display: flex; justify-content: space-between; align-items: center; gap: 2rem; padding: 1.4rem max(1.2rem, calc((100vw - 1400px) / 2)); background: var(--paper); border-bottom: 1px solid var(--line); }
.topbar form { display: flex; align-items: center; gap: .8rem; }
.container { width: min(1180px, calc(100% - 2rem)); margin: 2rem auto 4rem; }
.app-shell { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 1.25rem; width: min(1400px, calc(100% - 2rem)); margin: 1.5rem auto 4rem; align-items: start; }
.domain-sidebar { position: sticky; top: 1rem; padding: 1rem; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 8px 28px rgba(20, 45, 30, .04); }
.sidebar-heading { display: flex; justify-content: space-between; align-items: center; padding: .25rem .25rem 1rem; }
.count-badge { display: grid; place-items: center; min-width: 30px; height: 30px; padding: 0 .45rem; color: var(--green); background: #e4f1e9; border-radius: 999px; font-size: .8rem; font-weight: 800; }
.domain-add-form { display: grid; gap: .55rem; padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
.domain-add-form button { width: 100%; }
.domain-list { display: grid; gap: .35rem; margin-top: 1rem; }
.admin-navigation { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.domain-link { display: grid; gap: .3rem; padding: .75rem; color: var(--ink); border: 1px solid transparent; border-radius: 9px; text-decoration: none; }
.domain-link:hover { background: var(--wash); }
.domain-link.selected { background: #e7f1ea; border-color: #bcd5c5; }
.domain-link-title { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.domain-link-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.domain-meta { padding-left: 1rem; color: var(--muted); font-size: .73rem; }
.status-dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; }
.status-dot.active { background: #1c895c; }
.status-dot.inactive { background: #a69a98; }
.admin-icon { display: grid; place-items: center; flex: 0 0 auto; width: 22px; height: 22px; color: white; background: var(--ink); border-radius: 6px; font-size: .7rem; font-weight: 800; }
.sidebar-empty { margin: .5rem 0; padding: 1rem; color: var(--muted); text-align: center; }
.domain-content { min-width: 0; }
.domain-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1.4rem; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; }
.domain-title-row, .domain-actions { display: flex; align-items: center; gap: .65rem; }
.domain-title-row h2 { font-size: 1.65rem; }
.domain-stats { grid-template-columns: repeat(2, 1fr); margin-top: 1rem; }
.empty-state { padding: 4rem 2rem; color: var(--muted); background: var(--paper); border: 1px solid var(--line); border-radius: 14px; text-align: center; }
.empty-state h2 { margin-bottom: .65rem; color: var(--ink); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1rem; }
.stats div { padding: 1.25rem; background: var(--ink); color: white; border-radius: 12px; }
.stats strong, .stats span { display: block; }
.stats strong { font-size: 1.7rem; }
.stats span { margin-top: .2rem; color: #bac6bf; }
.panel { margin-top: 1rem; padding: 1.4rem; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 8px 28px rgba(20, 45, 30, .04); }
.section-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }

form { margin: 0; }
label { display: grid; gap: .4rem; color: #47534c; font-size: .8rem; font-weight: 700; }
input, select, button { min-height: 42px; border-radius: 8px; font: inherit; }
input, select { width: 100%; padding: .65rem .75rem; color: var(--ink); background: white; border: 1px solid #bfc9c2; }
input:focus, select:focus { outline: 3px solid rgba(23, 107, 72, .15); border-color: var(--green); }
button { padding: .62rem 1rem; border: 1px solid var(--green); background: var(--green); color: white; font-weight: 750; cursor: pointer; white-space: nowrap; }
button:hover { background: var(--green-dark); }
button.secondary { color: var(--ink); background: white; border-color: #bfc9c2; }
button.danger { color: var(--red); background: white; border-color: #e1b9b5; }
.add-form { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: .75rem; padding: 1rem; background: var(--wash); border-radius: 10px; }
.mailbox-form, .alias-form { grid-template-columns: minmax(260px, 1fr) minmax(220px, .8fr) auto; }
.admin-form { grid-template-columns: minmax(180px, .8fr) minmax(300px, 1.4fr) auto; }
.inline-form { display: inline; }
.address-input { display: flex; align-items: center; min-width: 0; background: white; border: 1px solid #bfc9c2; border-radius: 8px; overflow: hidden; }
.address-input:focus-within { outline: 3px solid rgba(23, 107, 72, .15); border-color: var(--green); }
.address-input input { min-width: 80px; border: 0; border-radius: 0; }
.address-input input:focus { outline: 0; }
.address-input span { overflow: hidden; padding-right: .7rem; color: var(--muted); font-size: .82rem; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.password-control { display: flex; align-items: stretch; min-width: 0; }
.password-control input { min-width: 100px; border-radius: 8px 0 0 8px; }
.password-control .password-visibility { display: grid; place-items: center; flex: 0 0 42px; min-height: 42px; padding: 0; color: var(--muted); background: white; border-color: #bfc9c2; border-left: 0; border-radius: 0; }
.password-visibility svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.password-visibility .hide-icon, .password-visibility[aria-pressed="true"] .show-icon { display: none; }
.password-visibility[aria-pressed="true"] .hide-icon { display: block; }
.password-control .password-visibility:hover { color: var(--green); background: #f2f7f4; }
.password-control .generate-button { min-height: 42px; padding: .55rem .7rem; color: var(--green); background: white; border-color: #bfc9c2; border-left: 0; border-radius: 0 8px 8px 0; font-size: .76rem; }
.password-control .generate-button:hover { color: white; background: var(--green); border-color: var(--green); }

.table-wrap { margin-top: 1rem; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .85rem .7rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; }
th.actions, td.actions { text-align: right; }
td.actions { display: flex; justify-content: flex-end; align-items: center; gap: .4rem; }
td.actions button { min-height: 34px; padding: .35rem .6rem; font-size: .78rem; }
.badge { display: inline-block; padding: .25rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 750; }
.badge.active { color: #11623f; background: #dcefe5; }
.badge.inactive { color: #6c514f; background: #eee6e5; }
.you-label { display: inline-block; margin-left: .35rem; padding: .16rem .4rem; color: var(--green); background: #e4f1e9; border-radius: 999px; font-size: .68rem; font-weight: 800; text-transform: uppercase; }
.empty { padding: 2rem; color: var(--muted); text-align: center; }
.notice { padding: .9rem 1rem; color: var(--muted); background: var(--wash); border-radius: 8px; }
.reset, .delete-confirm { position: relative; text-align: left; }
.reset summary, .delete-confirm summary { color: var(--green); font-size: .8rem; font-weight: 700; cursor: pointer; }
.delete-confirm summary { color: var(--red); }
.reset form, .delete-confirm form { position: absolute; z-index: 2; right: 0; display: flex; gap: .4rem; width: 330px; padding: .65rem; background: white; border: 1px solid var(--line); border-radius: 9px; box-shadow: 0 10px 30px rgba(10, 30, 20, .14); }
.reset input { min-height: 36px; }
.delete-confirm form { display: grid; }
.delete-confirm label { display: flex; align-items: center; }
.delete-confirm input[type="checkbox"] { width: auto; min-height: auto; }
.flash { margin-bottom: 1rem; padding: .85rem 1rem; border-radius: 9px; border: 1px solid; }
.flash.success { color: #12583b; background: #e4f3ea; border-color: #b7d9c5; }
.flash.error { color: #842d26; background: #fae9e7; border-color: #e8c0bc; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: radial-gradient(circle at top left, #e3eee7, var(--wash) 45%); }
.login-card { width: min(420px, 100%); padding: 2rem; background: white; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 20px 60px rgba(20, 45, 30, .10); }
.login-card .muted { margin: .5rem 0 1.5rem; }
.stack { display: grid; gap: 1rem; }

@media (max-width: 760px) {
    .topbar { align-items: flex-start; }
    .signed-in { display: none; }
    .app-shell { grid-template-columns: 1fr; }
    .domain-sidebar { position: static; }
    .domain-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .domain-header { align-items: flex-start; flex-direction: column; }
    .domain-actions { flex-wrap: wrap; }
    .stats { gap: .5rem; }
    .stats div { padding: .9rem; }
    .panel { padding: 1rem; }
    .add-form, .mailbox-form, .alias-form, .admin-form { grid-template-columns: 1fr; }
    td.actions { min-width: 230px; }
}

@media (max-width: 460px) {
    .domain-list { grid-template-columns: 1fr; }
}
