*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #0b0f15;
  --panel: #111722;
  --panel-raised: #171e2b;
  --panel-soft: #1b2432;
  --border: #263143;
  --border-soft: #1b2534;
  --text: #eef3f8;
  --muted: #8c9db1;
  --silver: #b9c4d1;
  --accent: #58a6ff;
  --accent-soft: rgba(88, 166, 255, .12);
  --success: #7ee2a8;
  --danger: #ff8585;
  --warning: #ffc96b;
  --sidebar-width: 236px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: dark;
}

html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, textarea, select { font: inherit; }
a { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.eyebrow { color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 18px;
  background:
    radial-gradient(circle at 50% 0, rgba(63, 106, 157, .22), transparent 38%),
    linear-gradient(145deg, #0b0f15 0%, #0e141d 100%);
}
.auth-panel { width: min(100%, 460px); padding: 36px; border: 1px solid var(--border); border-radius: 16px; background: rgba(17, 23, 34, .96); box-shadow: 0 28px 80px rgba(0,0,0,.38); }
.auth-brand { display: inline-flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; font-weight: 700; }
.auth-brand img { width: 42px; height: 42px; object-fit: contain; }
.auth-heading { margin: 34px 0 26px; }
.auth-heading h1 { margin: 8px 0 10px; font-size: clamp(25px, 5vw, 32px); line-height: 1.15; letter-spacing: -.035em; }
.auth-heading p, .auth-note { color: var(--muted); line-height: 1.65; }
.auth-note { margin: 22px 0 0; font-size: 12px; }
.auth-form, .stacked-form { display: grid; gap: 10px; }
.auth-form label, .stacked-form label, .attachment-field label { margin-top: 8px; color: var(--silver); font-size: 12px; font-weight: 600; }
.auth-form small, .attachment-field small { color: var(--muted); font-size: 11px; }

input, textarea, select {
  width: 100%;
  color: var(--text);
  background: #0d131c;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color .16s, box-shadow .16s;
}
input, select { min-height: 44px; padding: 0 13px; }
textarea { padding: 13px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(88,166,255,.13); }

.primary-button, .secondary-button, .danger-button, .compact-compose, .compose-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 650;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
  transition: transform .12s, opacity .12s, background .12s;
}
.primary-button { margin-top: 12px; color: #07111d; background: var(--accent); }
.primary-button:hover, .compose-button:hover { background: #75b6ff; }
.secondary-button { color: var(--silver); background: var(--panel-raised); border-color: var(--border); }
.secondary-button:hover { color: var(--text); border-color: #3b4a60; }
.danger-button { color: var(--danger); background: rgba(255,133,133,.07); border-color: rgba(255,133,133,.25); }
.quiet-link, .text-button, .quiet-button { color: var(--muted); background: none; border: 0; text-decoration: none; cursor: pointer; font-size: 12px; }
.quiet-link:hover, .text-button:hover, .quiet-button:hover { color: var(--text); }
.danger-text { color: var(--danger); }

.mail-alert { margin: 0 0 18px; padding: 12px 14px; border-radius: 8px; border: 1px solid; line-height: 1.5; }
.mail-alert-error { color: #ffaaaa; background: rgba(255,90,90,.08); border-color: rgba(255,100,100,.25); }
.mail-alert-success { color: var(--success); background: rgba(80,210,135,.08); border-color: rgba(80,210,135,.25); }

.mail-app { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); grid-template-rows: 68px minmax(0, 1fr); }
.mail-topbar { position: sticky; top: 0; z-index: 30; grid-column: 1 / -1; display: grid; grid-template-columns: var(--sidebar-width) minmax(240px, 680px) 1fr; align-items: center; height: 68px; padding: 0 22px 0 18px; border-bottom: 1px solid var(--border); background: rgba(11,15,21,.93); backdrop-filter: blur(14px); }
.mail-brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-size: 16px; letter-spacing: -.02em; }
.mail-brand img { width: 36px; height: 36px; object-fit: contain; }
.mail-brand strong { font-weight: 700; }
.mail-brand span { font-weight: 450; }
.mail-search { position: relative; display: flex; align-items: center; max-width: 680px; }
.mail-search svg { position: absolute; left: 15px; width: 17px; fill: none; stroke: var(--muted); stroke-width: 1.8; }
.mail-search input { min-height: 44px; padding-left: 44px; border-color: transparent; background: var(--panel-raised); }
.mail-identity { justify-self: end; display: flex; align-items: center; gap: 11px; min-width: 0; }
.identity-avatar, .sender-avatar { display: grid; place-items: center; flex: 0 0 auto; border: 1px solid rgba(88,166,255,.3); border-radius: 50%; color: #d7ebff; background: var(--accent-soft); font-weight: 700; }
.identity-avatar { width: 34px; height: 34px; }
.identity-copy { display: flex; flex-direction: column; min-width: 0; }
.identity-copy strong { font-size: 12px; }
.identity-copy small { max-width: 230px; color: var(--muted); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.mail-sidebar { position: sticky; top: 68px; z-index: 20; grid-row: 2; height: calc(100vh - 68px); display: flex; flex-direction: column; padding: 20px 13px 16px; border-right: 1px solid var(--border); background: #0d121a; }
.compose-button { min-height: 48px; margin: 0 5px 18px; color: #07111d; background: var(--accent); font-size: 14px; }
.compose-button span { font-size: 20px; line-height: 1; }
.mail-folders { display: grid; gap: 3px; }
.mail-folders a, .admin-link { display: flex; align-items: center; justify-content: space-between; min-height: 40px; padding: 0 14px; border-radius: 7px; color: var(--muted); text-decoration: none; font-size: 13px; }
.mail-folders a:hover, .admin-link:hover { color: var(--text); background: var(--panel); }
.mail-folders a.active, .admin-link.active { color: #d9ecff; background: var(--accent-soft); font-weight: 650; }
.mail-folders b { display: inline-grid; place-items: center; min-width: 22px; height: 20px; padding: 0 6px; border-radius: 10px; color: #beddff; background: rgba(88,166,255,.12); font-size: 10px; }
.sidebar-divider { height: 1px; margin: 16px 12px; background: var(--border-soft); }
.admin-link { justify-content: flex-start; }
.sidebar-footer { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 12px 14px 0; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 10px rgba(126,226,168,.45); }
.mail-sidebar-scrim, .mobile-menu-button { display: none; }

.mail-content { min-width: 0; padding: 26px; background: linear-gradient(180deg, rgba(20,28,40,.45), transparent 210px); }
.mailbox-panel, .compose-panel, .message-view, .admin-panel { width: min(100%, 1280px); margin: 0 auto; }
.mailbox-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin: 0 0 22px; }
.mailbox-heading h1 { margin: 5px 0 0; font-size: 25px; letter-spacing: -.035em; }
.compact-compose { display: none; background: var(--accent); color: #07111d; }
.search-summary { margin: -7px 0 18px; color: var(--muted); font-size: 12px; }
.search-summary a { margin-left: 6px; color: var(--accent); text-decoration: none; }

.message-list { overflow: hidden; border: 1px solid var(--border); border-radius: 12px; background: rgba(17,23,34,.72); }
.message-row { position: relative; display: grid; grid-template-columns: 44px minmax(0,1fr); min-height: 66px; border-bottom: 1px solid var(--border-soft); color: var(--muted); }
.message-row:last-child { border-bottom: 0; }
.message-row:hover { background: var(--panel-raised); }
.message-row.unread { color: var(--text); background: rgba(27,36,50,.78); }
.message-row.unread::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 2px; border-radius: 0 2px 2px 0; background: var(--accent); }
.star-form { display: grid; place-items: center; }
.star-button { padding: 8px; border: 0; color: #536176; background: none; cursor: pointer; font-size: 16px; }
.star-button:hover, .star-button.starred { color: var(--warning); }
.message-row-link { min-width: 0; display: grid; grid-template-columns: minmax(140px, .8fr) minmax(250px, 2.3fr) auto auto; align-items: center; gap: 18px; padding: 12px 18px 12px 0; color: inherit; text-decoration: none; }
.message-correspondent { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.message-summary { min-width: 0; display: flex; gap: 4px; overflow: hidden; white-space: nowrap; }
.message-summary strong, .message-summary span { overflow: hidden; text-overflow: ellipsis; }
.message-summary strong { flex: 0 0 auto; max-width: 55%; color: var(--silver); }
.message-summary span { color: var(--muted); }
.message-row time { color: var(--muted); font-size: 10px; white-space: nowrap; }
.draft-label { color: var(--danger); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.status-pill, .role-pill, .account-status { display: inline-flex; align-items: center; width: fit-content; padding: 3px 8px; border-radius: 999px; font-size: 9px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.status-pill { color: var(--silver); background: var(--panel-soft); }
.status-delivered, .status-sent { color: var(--success); background: rgba(126,226,168,.1); }
.status-failed, .status-bounced, .status-complained { color: var(--danger); background: rgba(255,133,133,.1); }
.status-queued, .status-delayed { color: var(--warning); background: rgba(255,201,107,.1); }
.empty-mailbox { min-height: 420px; display: grid; place-content: center; justify-items: center; padding: 32px; text-align: center; border: 1px dashed var(--border); border-radius: 12px; }
.empty-icon { display: grid; place-items: center; width: 54px; height: 54px; margin-bottom: 15px; border-radius: 50%; color: var(--accent); background: var(--accent-soft); font-size: 22px; }
.empty-mailbox h2 { margin: 0; font-size: 17px; }
.empty-mailbox p { color: var(--muted); }

.compose-panel { max-width: 980px; }
.compose-form { overflow: hidden; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); }
.compose-line { display: grid; grid-template-columns: 66px minmax(0,1fr) auto; align-items: center; min-height: 48px; padding: 0 16px; border-bottom: 1px solid var(--border-soft); }
.compose-line label { color: var(--muted); font-size: 12px; }
.compose-line input { min-height: 46px; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.optional-recipients { display: none; }
.optional-recipients.visible { display: block; }
.compose-form textarea { min-height: 340px; padding: 22px; border: 0; border-radius: 0; background: transparent; box-shadow: none; line-height: 1.7; }
.attachment-field { display: grid; grid-template-columns: 100px minmax(0, 1fr); align-items: center; gap: 4px 12px; padding: 16px 22px; border-top: 1px solid var(--border-soft); }
.attachment-field label { margin: 0; }
.attachment-field input { min-height: auto; padding: 8px; }
.attachment-field small { grid-column: 2; }
.compose-actions { display: flex; align-items: center; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border-soft); background: rgba(9,14,21,.4); }
.compose-actions .primary-button { min-width: 94px; margin: 0; }
.compose-actions .quiet-link { margin-left: auto; }

.message-view { max-width: 980px; overflow: hidden; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); }
.message-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border-soft); }
.back-link { color: var(--muted); text-decoration: none; font-size: 12px; }
.back-link:hover { color: var(--text); }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.toolbar-actions form { margin: 0; }
.toolbar-actions button { min-height: 34px; padding: 0 11px; font-size: 11px; }
.message-header { padding: 27px 30px 20px; }
.message-header h1 { margin: 0 0 22px; font-size: 23px; line-height: 1.3; letter-spacing: -.025em; }
.message-meta { display: grid; grid-template-columns: 42px minmax(0,1fr) auto; align-items: center; gap: 12px; color: var(--muted); }
.sender-avatar { width: 42px; height: 42px; }
.message-meta > div { min-width: 0; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.message-meta strong { color: var(--text); }
.message-meta small { flex-basis: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-meta time { font-size: 10px; white-space: nowrap; }
.delivery-line { margin-top: 14px; color: var(--muted); font-size: 11px; }
.message-body { min-height: 240px; margin: 0; padding: 24px 30px 36px; overflow-wrap: anywhere; white-space: pre-wrap; border: 0; color: var(--silver); background: #0e141e; font-family: Inter, sans-serif; font-size: 14px; line-height: 1.75; }
.attachment-list { padding: 20px 30px; border-top: 1px solid var(--border-soft); }
.attachment-list h2 { margin: 0 0 12px; font-size: 13px; }
.attachment-list > div { display: flex; flex-wrap: wrap; gap: 10px; }
.attachment-list a, .attachment-list span { display: flex; flex-direction: column; min-width: 190px; padding: 11px 13px; border: 1px solid var(--border); border-radius: 8px; color: var(--silver); background: var(--panel-raised); text-decoration: none; }
.attachment-list a:hover { border-color: var(--accent); }
.attachment-list small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.message-reply { padding: 0 30px 26px; }
.message-reply .primary-button { margin: 0; }

.admin-panel { max-width: 1180px; }
.admin-grid { display: grid; grid-template-columns: minmax(0,1.25fr) minmax(280px,.75fr); gap: 18px; margin-bottom: 26px; }
.admin-card, .credential-card { padding: 22px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); }
.admin-card h2, .credential-card h2, .accounts-section h2 { margin: 0 0 7px; font-size: 16px; }
.admin-card > p, .credential-card > p, .admin-stats p { color: var(--muted); line-height: 1.55; font-size: 12px; }
.credential-card { margin-bottom: 20px; border-color: rgba(126,226,168,.3); background: linear-gradient(135deg, rgba(126,226,168,.07), var(--panel)); }
.credential-card h2 { margin-top: 7px; }
.credential-card dl, .admin-stats dl { display: grid; grid-template-columns: minmax(110px, auto) 1fr; gap: 9px 18px; margin: 18px 0; }
.credential-card dt, .admin-stats dt { color: var(--muted); font-size: 11px; }
.credential-card dd, .admin-stats dd { margin: 0; }
.credential-card code { color: var(--text); word-break: break-all; }
.stacked-form { margin-top: 20px; }
.stacked-form .primary-button { justify-self: start; }
.domain-input { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; border: 1px solid var(--border); border-radius: 8px; background: #0d131c; }
.domain-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(88,166,255,.13); }
.domain-input input { border: 0; box-shadow: none; }
.domain-input span { padding-right: 12px; color: var(--muted); font-size: 11px; }
.accounts-section { overflow: hidden; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); }
.accounts-section > h2 { padding: 20px 22px 12px; }
.accounts-table-wrap { overflow-x: auto; }
.accounts-table { width: 100%; border-collapse: collapse; }
.accounts-table th { padding: 10px 14px; text-align: left; color: var(--muted); border-bottom: 1px solid var(--border); font-size: 10px; letter-spacing: .07em; text-transform: uppercase; }
.accounts-table td { padding: 14px; border-bottom: 1px solid var(--border-soft); color: var(--silver); vertical-align: middle; }
.accounts-table tr:last-child td { border-bottom: 0; }
.accounts-table td:first-child strong, .accounts-table td:first-child small { display: block; }
.accounts-table td:first-child strong { color: var(--text); }
.accounts-table td:first-child small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.role-pill { color: #c5ddfa; background: var(--accent-soft); }
.account-status.active { color: var(--success); background: rgba(126,226,168,.1); }
.account-status.inactive { color: var(--danger); background: rgba(255,133,133,.1); }
.account-actions { display: flex; gap: 8px; white-space: nowrap; }
.error-panel { text-align: center; }
.error-panel .error-code { display: block; color: var(--accent); font-size: 50px; font-weight: 700; letter-spacing: -.05em; }
.error-panel h1 { margin: 5px 0; }
.error-panel p { margin: 8px 0 24px; color: var(--muted); }

@media (max-width: 980px) {
  .mail-topbar { grid-template-columns: auto minmax(180px,1fr) auto; gap: 14px; }
  .mail-brand span, .identity-copy { display: none; }
  .mail-brand { width: 40px; }
  .mail-app { grid-template-columns: 210px minmax(0,1fr); --sidebar-width: 210px; }
  .message-row-link { grid-template-columns: minmax(120px,.8fr) minmax(190px,2fr) auto; gap: 12px; }
  .message-row-link .status-pill, .message-row-link .draft-label { position: absolute; right: 16px; bottom: 8px; }
  .admin-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .mail-app { display: block; }
  .mail-topbar { position: sticky; grid-template-columns: 42px 42px minmax(0,1fr) auto; height: 62px; padding: 0 12px; gap: 8px; }
  .mobile-menu-button { display: flex; width: 38px; height: 38px; flex-direction: column; align-items: center; justify-content: center; gap: 4px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); }
  .mobile-menu-button span { width: 15px; height: 1px; background: var(--silver); }
  .mail-search { min-width: 0; }
  .mail-search input { min-height: 38px; padding-left: 36px; }
  .mail-search svg { left: 12px; width: 15px; }
  .mail-identity .identity-avatar, .mail-identity .quiet-button { display: none; }
  .mail-sidebar { position: fixed; top: 0; bottom: 0; left: 0; z-index: 60; width: min(84vw, 270px); height: 100vh; transform: translateX(-105%); transition: transform .2s ease; box-shadow: 20px 0 60px rgba(0,0,0,.45); }
  .mail-sidebar.open { transform: translateX(0); }
  .mail-sidebar-scrim { position: fixed; inset: 0; z-index: 50; display: none; border: 0; background: rgba(0,0,0,.58); }
  .mail-sidebar-scrim.open { display: block; }
  .mail-content { padding: 18px 12px 28px; }
  .compact-compose { display: inline-flex; }
  .message-list { border-radius: 10px; }
  .message-row { grid-template-columns: 36px minmax(0,1fr); min-height: 76px; }
  .message-row-link { grid-template-columns: minmax(0,1fr) auto; grid-template-rows: auto auto; gap: 5px 9px; padding-right: 11px; }
  .message-correspondent { grid-column: 1; }
  .message-summary { grid-column: 1 / -1; }
  .message-summary strong { max-width: 65%; }
  .message-row time { grid-column: 2; grid-row: 1; }
  .message-row-link .status-pill, .message-row-link .draft-label { right: 10px; bottom: 6px; }
  .compose-line { grid-template-columns: 45px minmax(0,1fr) auto; padding: 0 12px; }
  .compose-form textarea { min-height: 300px; padding: 16px; }
  .attachment-field { grid-template-columns: 1fr; padding: 14px 16px; }
  .attachment-field small { grid-column: 1; }
  .compose-actions { padding: 14px 16px; }
  .message-toolbar { align-items: flex-start; flex-direction: column; }
  .message-header { padding: 22px 18px 16px; }
  .message-header h1 { font-size: 20px; }
  .message-meta { grid-template-columns: 38px minmax(0,1fr); }
  .message-meta time { grid-column: 2; }
  .sender-avatar { width: 38px; height: 38px; }
  .message-body { padding: 20px 18px 28px; }
  .attachment-list, .message-reply { padding-left: 18px; padding-right: 18px; }
  .auth-panel { padding: 28px 22px; }
  .credential-card dl, .admin-stats dl { grid-template-columns: 1fr; gap: 3px; }
  .credential-card dd, .admin-stats dd { margin-bottom: 8px; }
}
