:root {
    color-scheme: light;
    --ink: #20282d;
    --muted: #68757c;
    --line: #dce3e6;
    --line-strong: #bec9ce;
    --surface: #ffffff;
    --canvas: #f3f5f6;
    --sidebar: #17242a;
    --sidebar-line: #2d3b42;
    --accent: #176b5b;
    --accent-hover: #125548;
    --success: #1f765f;
    --warning: #9a6200;
    --danger: #a33a3a;
    font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
    font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--canvas); color: var(--ink); }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }

.portal-shell { min-height: 100vh; display: grid; grid-template-columns: 228px minmax(0, 1fr); }
.portal-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--sidebar);
    color: #edf2f4;
}
.brand-block {
    flex: 0 0 72px;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 0 18px;
    border-bottom: 1px solid var(--sidebar-line);
}
.brand-mark {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    background: #2a8a76;
    color: #fff;
    font-weight: 800;
}
.brand-block strong, .brand-block span { display: block; white-space: nowrap; }
.brand-block strong { font-size: 15px; }
.brand-block span { margin-top: 2px; color: #91a2aa; font-size: 10px; }
.portal-nav { flex: 1 1 auto; min-height: 0; padding: 16px 9px; }
.portal-nav a {
    display: flex;
    align-items: center;
    min-height: 40px;
    margin: 3px 0;
    padding: 8px 12px;
    border-radius: 5px;
    color: #bdc9ce;
    font-size: 14px;
    text-decoration: none;
    white-space: nowrap;
}
.portal-nav a:hover { background: #22333a; color: #fff; }
.portal-nav a.active { background: #234f48; color: #fff; }
.sidebar-footer { flex: 0 0 auto; padding: 14px; border-top: 1px solid var(--sidebar-line); }
.signout-button {
    width: 100%;
    border: 1px solid #45565f;
    border-radius: 4px;
    background: transparent;
    color: #cbd5da;
    padding: 8px;
    cursor: pointer;
}
.signout-button:hover { border-color: #8ba0a9; color: #fff; }
.portal-main { width: 100%; min-width: 0; }
.portal-topbar {
    height: 54px;
    display: flex;
    align-items: center;
    padding: 0 28px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
    color: var(--muted);
    font-size: 12px;
}
.portal-content { width: min(1180px, 100%); margin: 0 auto; padding: 28px; }

.page-heading {
    min-height: 62px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 20px;
}
.page-heading h1 { margin: 0; font-size: 24px; line-height: 1.25; font-weight: 700; }
.page-heading h1[tabindex="-1"]:focus { outline: none; }
.page-heading p { margin: 7px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.button {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line-strong);
    border-radius: 5px;
    padding: 7px 14px;
    background: #fff;
    color: #334047;
    font-weight: 600;
    font-size: 13px;
    text-decoration: none;
    cursor: pointer;
}
.button:hover:not(:disabled) { border-color: #84959d; background: #f8fafb; }
.button.primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.button.primary:hover:not(:disabled) { border-color: var(--accent-hover); background: var(--accent-hover); }
.button:disabled { cursor: not-allowed; opacity: .58; }
.notice {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 0 0 18px;
    padding: 11px 13px;
    border: 1px solid var(--line);
    border-left-width: 4px;
    border-radius: 4px;
    background: #fff;
    font-size: 13px;
    line-height: 1.5;
}
.notice.success { border-left-color: var(--success); color: #225e50; }
.notice.error { border-left-color: var(--danger); color: #8d3030; }
.notice.warning { border-left-color: var(--warning); color: #73511a; }

.form-section { padding: 22px 0; border-top: 1px solid var(--line); }
.form-section:first-child { border-top: 0; padding-top: 0; }
.form-section h2 { margin: 0 0 17px; font-size: 15px; }
.form-grid { display: grid; grid-template-columns: minmax(0, .7fr) minmax(320px, 1.3fr); gap: 18px; }
.field-group { min-width: 0; margin-bottom: 16px; }
.field-group:last-child { margin-bottom: 0; }
.field-group label, .field-label { display: block; margin-bottom: 7px; font-size: 12px; font-weight: 700; color: #455159; }
.optional { color: #8a969c; font-weight: 400; }
.text-input, .select-input, .text-area {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: 5px;
    outline: none;
    background: #fff;
    color: var(--ink);
    transition: border-color .15s, box-shadow .15s;
}
.text-input, .select-input { min-height: 39px; padding: 8px 10px; }
.text-area { min-height: 260px; resize: vertical; padding: 11px; line-height: 1.55; }
.text-input:focus, .select-input:focus, .text-area:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #176b5b18; }
.address-parts { display: grid; grid-template-columns: minmax(130px, .75fr) 22px minmax(180px, 1fr); align-items: center; gap: 6px; }
.address-parts > span { color: var(--muted); text-align: center; }
.locked-address { min-height: 39px; display: flex; align-items: center; flex-wrap: wrap; gap: 3px; border: 1px solid var(--line); border-radius: 5px; padding: 8px 10px; background: #f4f7f7; }
.locked-address small { width: 100%; margin-top: 3px; color: var(--muted); }
.validation-message { display: block; margin-top: 5px; color: var(--danger); font-size: 12px; }
.checkbox-line { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.checkbox-line input { width: 16px; height: 16px; accent-color: var(--accent); }
.form-actions { display: flex; align-items: center; gap: 14px; padding-top: 18px; border-top: 1px solid var(--line); }
.form-actions span { color: var(--muted); font-size: 12px; }
.reply-context {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
    padding: 12px 14px;
    border: 1px solid #bfd5cf;
    border-radius: 5px;
    background: #f3f9f7;
}
.reply-context span, .reply-context strong { display: block; }
.reply-context span { color: var(--muted); font-size: 11px; }
.reply-context strong { margin-top: 3px; font-size: 13px; }
.reply-context small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.reply-context a { color: var(--accent); font-size: 12px; font-weight: 600; }
.field-help { display: block; margin-top: 6px; color: var(--muted); font-size: 11px; }
.security-form { width: min(520px, 100%); }
.security-actions { width: min(720px, 100%); }

.data-panel { overflow: hidden; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.domain-table { min-width: 720px; }
.domain-table td { white-space: nowrap; }
.history-table { min-width: 980px; }
.data-table th { padding: 11px 12px; border-bottom: 1px solid var(--line); background: #f7f9fa; color: #56636a; text-align: left; white-space: nowrap; }
.data-table td { padding: 11px 12px; border-bottom: 1px solid #e8edef; vertical-align: top; overflow-wrap: anywhere; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #fafcfc; }
.status { display: inline-flex; min-width: 54px; justify-content: center; border-radius: 4px; padding: 3px 7px; font-size: 11px; font-weight: 700; }
.status.sent, .status.verified, .status.enabled { background: #e5f4ef; color: #1c7059; }
.status.failed { background: #f9e9e9; color: #963838; }
.status.pending { background: #fff2d9; color: #855900; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 11px; }
.empty-state { padding: 42px 20px; border: 1px dashed #cbd5d9; border-radius: 6px; background: #fafbfb; text-align: center; }
.empty-state strong, .empty-state span { display: block; }
.empty-state strong { font-size: 15px; }
.empty-state span { margin-top: 7px; color: var(--muted); font-size: 13px; }

.message-list { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: #fff; }
.message-row {
    min-height: 66px;
    display: grid;
    grid-template-columns: 10px minmax(145px, .65fr) minmax(260px, 1.8fr) auto 110px;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid #e7ecee;
    color: inherit;
    text-decoration: none;
}
.message-row:last-child { border-bottom: 0; }
.message-row:hover { background: #f7faf9; }
.message-row.unread { background: #fbfefd; }
.unread-dot { width: 7px; height: 7px; border-radius: 50%; background: transparent; }
.message-row.unread .unread-dot { background: var(--accent); }
.message-from { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.message-copy { min-width: 0; }
.message-copy strong, .message-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-copy strong { font-size: 13px; font-weight: 600; }
.message-copy small { margin-top: 5px; color: var(--muted); font-size: 11px; }
.attachment-mark { color: var(--muted); font-size: 11px; }
.message-row time { color: var(--muted); font-size: 11px; text-align: right; white-space: nowrap; }
.message-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 15px; }
.message-actions { display: flex; align-items: center; gap: 8px; }
.back-command { color: var(--accent); font-size: 13px; font-weight: 600; text-decoration: none; }
.message-detail { overflow: hidden; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.message-detail > header { padding: 22px; border-bottom: 1px solid var(--line); }
.message-detail h1 { margin: 0 0 17px; font-size: 21px; overflow-wrap: anywhere; }
.message-detail dl { margin: 0; }
.message-detail dl div { display: grid; grid-template-columns: 82px minmax(0, 1fr); gap: 8px; margin-top: 7px; font-size: 12px; }
.message-detail dt { color: var(--muted); }
.message-detail dd { margin: 0; overflow-wrap: anywhere; }
.attachment-strip { padding: 13px 22px; border-bottom: 1px solid var(--line); background: #f8fafb; }
.attachment-strip > strong { display: block; margin-bottom: 8px; font-size: 12px; }
.attachment-list { display: flex; flex-wrap: wrap; gap: 7px; }
.attachment-list a { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 4px; padding: 6px 9px; background: #fff; text-decoration: none; font-size: 12px; }
.attachment-list small { color: var(--muted); }
.message-frame { display: block; width: 100%; min-height: 480px; border: 0; background: #fff; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #edf1f2; }
.login-panel { width: min(390px, 100%); padding: 30px; border: 1px solid #d6dfe2; border-radius: 7px; background: #fff; box-shadow: 0 12px 32px #17242a14; }
.login-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 6px; background: var(--accent); color: #fff; font-weight: 800; }
.login-panel h1 { margin: 20px 0 6px; font-size: 22px; }
.login-panel > p { margin: 0 0 24px; color: var(--muted); font-size: 13px; }
.login-panel .button { width: 100%; margin-top: 4px; }
.loading-block { min-height: 160px; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.boot-loader { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); }
.boot-loader span { width: 28px; height: 28px; border: 3px solid #d2dcdf; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.boot-loader strong { font-size: 13px; }
@keyframes spin { to { transform: rotate(360deg); } }
#blazor-error-ui { display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000; padding: 12px 18px; background: #fff0d4; box-shadow: 0 -2px 8px #0002; }
#blazor-error-ui .reload { margin-left: 8px; color: #684500; }
#blazor-error-ui .dismiss { position: absolute; right: 16px; cursor: pointer; }

@media (max-width: 800px) {
    .portal-shell { display: block; }
    .portal-sidebar { position: relative; height: auto; overflow: visible; }
    .brand-block { height: 58px; min-height: 58px; flex-basis: 58px; }
    .portal-nav { flex: 0 0 auto; display: flex; align-items: center; padding: 7px; overflow-x: auto; }
    .portal-nav a { flex: 0 0 auto; margin: 0 2px; min-height: 36px; }
    .sidebar-footer, .portal-topbar { display: none; }
    .portal-content { padding: 18px 14px 28px; }
    .page-heading { min-height: 0; align-items: stretch; flex-direction: column; gap: 12px; }
    .page-actions .button { flex: 1 1 auto; }
    .form-grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
    .form-actions { align-items: stretch; flex-direction: column; }
    .message-row { grid-template-columns: 10px minmax(0, 1fr) auto; gap: 8px; }
    .message-from { grid-column: 2; }
    .message-copy { grid-column: 2 / 4; }
    .attachment-mark { grid-column: 2; }
    .message-row time { grid-column: 3; grid-row: 1; }
    .message-detail > header { padding: 17px; }
    .message-detail dl div { grid-template-columns: 70px minmax(0, 1fr); }
    .attachment-strip { padding: 12px 17px; }
}

@media (max-width: 480px) {
    .page-heading h1 { font-size: 21px; }
    .address-parts { grid-template-columns: minmax(0, 1fr); }
    .address-parts > span { display: none; }
    .login-panel { padding: 24px 20px; }
    .message-toolbar { gap: 12px; }
    .message-actions { flex: 0 0 auto; }
}
