:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #6d7789;
  --faint: #98a2b3;
  --line: #e6eaf0;
  --canvas: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --navy: #17243c;
  --navy-soft: #eaf0fb;
  --accent: #4b6cf0;
  --accent-dark: #3b55cf;
  --success: #16856a;
  --success-soft: #e8f7f1;
  --warning: #a86812;
  --warning-soft: #fff5df;
  --danger: #c2414d;
  --danger-soft: #fff0f1;
  --shadow: 0 12px 35px rgba(30, 48, 82, 0.07);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--canvas); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
button.is-loading { pointer-events: none; }
.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; }

.app-shell { min-height: 100vh; display: flex; }
.sidebar {
  width: 248px; flex: 0 0 248px; display: flex; flex-direction: column;
  padding: 24px 16px 18px; background: var(--navy); color: #f8fbff;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 2px 10px 30px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center;
  color: #fff; font-weight: 800; background: linear-gradient(145deg, #8197ff, #4059d4);
  box-shadow: 0 7px 18px rgba(64, 89, 212, .35);
}
.brand strong, .brand span { display: block; }
.brand strong { font-size: 14px; letter-spacing: .02em; }
.brand span { margin-top: 3px; color: #aebbd2; font-size: 11px; }
.nav { display: grid; gap: 5px; min-height: 0; overflow-y: auto; }
.nav-item {
  border: 0; border-radius: 10px; display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; color: #b7c3d8; background: transparent; text-align: left; font-size: 13px;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,.08); }
.nav-item.is-active { color: #fff; background: rgba(117, 143, 255, .2); box-shadow: inset 3px 0 0 #8da0ff; }
.nav-icon { width: 18px; text-align: center; color: #94a7ff; font-size: 16px; }
.sidebar-footer { margin-top: auto; padding-top: 18px; display: grid; gap: 12px; }
.security-note { display: flex; align-items: center; gap: 9px; padding: 12px; border: 1px solid rgba(255,255,255,.09); border-radius: 11px; background: rgba(255,255,255,.045); }
.security-note strong, .security-note span { display: block; }
.security-note strong { font-size: 11px; font-weight: 650; }
.security-note span:last-child { margin-top: 3px; color: #aebbd2; font-size: 10px; }
.status-dot { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; background: #9aa6b8; }
.status-dot.ok { background: #55d7aa; box-shadow: 0 0 0 4px rgba(85,215,170,.12); }
.status-dot.warn { background: #f3b85c; box-shadow: 0 0 0 4px rgba(243,184,92,.11); }
.status-dot.bad { background: #f27982; box-shadow: 0 0 0 4px rgba(242,121,130,.12); }

.main-content { min-width: 0; flex: 1; padding: 34px clamp(22px, 4vw, 62px) 60px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; max-width: 1320px; margin: 0 auto 26px; }
.eyebrow { margin: 0 0 6px; color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: .18em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(25px, 3vw, 34px); letter-spacing: -.035em; }
h2 { margin-bottom: 5px; font-size: 18px; letter-spacing: -.02em; }
h3 { margin-bottom: 5px; font-size: 14px; }
.page-subtitle { margin: 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; padding-top: 4px; }
.connection-pill { display: inline-flex; align-items: center; gap: 8px; min-height: 31px; padding: 0 11px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: var(--surface); font-size: 11px; white-space: nowrap; }
.icon-button { width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: var(--surface); font-size: 18px; line-height: 1; }
.icon-button:hover { color: var(--accent); border-color: #bdc8ee; background: var(--navy-soft); }
.page-root { max-width: 1320px; margin: 0 auto; }
.toast-region { position: fixed; z-index: 30; top: 20px; right: 24px; display: grid; gap: 8px; width: min(360px, calc(100vw - 32px)); }
.toast { padding: 12px 14px; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 10px; color: var(--ink); background: var(--surface); box-shadow: var(--shadow); font-size: 12px; animation: toast-in .2s ease-out; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card, .panel, .empty-state { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.stat-card { padding: 17px 18px; }
.stat-label { color: var(--muted); font-size: 11px; }
.stat-value { margin-top: 8px; font-size: 25px; font-weight: 750; letter-spacing: -.04em; }
.stat-note { margin-top: 4px; color: var(--faint); font-size: 10px; }
.panel { padding: 20px; }
.panel + .panel { margin-top: 16px; }
.panel-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 17px; }
.panel-header p { margin-bottom: 0; color: var(--muted); font-size: 12px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.toolbar-title { margin: 0; font-size: 14px; }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.button, .ghost-button, .danger-button {
  min-height: 34px; border: 1px solid transparent; border-radius: 8px; padding: 0 13px;
  font-size: 12px; font-weight: 650; transition: background .16s ease, border .16s ease, color .16s ease, transform .16s ease;
}
.button { color: #fff; background: var(--accent); box-shadow: 0 4px 10px rgba(75,108,240,.18); }
.button:hover { background: var(--accent-dark); transform: translateY(-1px); }
.ghost-button { color: var(--ink); border-color: var(--line); background: var(--surface); }
.ghost-button:hover { color: var(--accent); border-color: #b9c5ed; background: var(--navy-soft); }
.ghost-button.full-width { width: 100%; color: #bec9dc; border-color: rgba(255,255,255,.12); background: transparent; }
.ghost-button.full-width:hover { color: #fff; border-color: rgba(255,255,255,.25); background: rgba(255,255,255,.06); }
.danger-button { color: var(--danger); border-color: #f3c7cb; background: var(--danger-soft); }
.danger-button:hover { color: #fff; border-color: var(--danger); background: var(--danger); }
.button.small, .ghost-button.small, .danger-button.small { min-height: 29px; padding: 0 9px; font-size: 11px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 650px; }
th { padding: 9px 11px; color: var(--faint); border-bottom: 1px solid var(--line); text-align: left; font-size: 10px; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; }
td { padding: 13px 11px; border-bottom: 1px solid #eef1f5; color: var(--muted); font-size: 12px; vertical-align: middle; }
tbody tr { transition: background .14s ease; }
tbody tr:hover { background: #fbfcfe; }
tbody tr.is-selected { background: #f1f4ff; }
.primary-text { color: var(--ink); font-weight: 650; }
.secondary-text { margin-top: 3px; color: var(--faint); font-size: 10px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.text-button { border: 0; padding: 0 0 0 5px; color: var(--accent); background: transparent; font-size: 10px; font-weight: 700; }
.risk-summary { max-width: 150px; line-height: 1.4; }
.mail-address { font-family: "SFMono-Regular", Consolas, monospace; font-size: 11px; overflow-wrap: anywhere; }
.status-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 999px; font-size: 10px; font-weight: 700; }
.status-badge.active { color: var(--success); background: var(--success-soft); }
.status-badge.pending { color: var(--warning); background: var(--warning-soft); }
.status-badge.error { color: var(--danger); background: var(--danger-soft); }
.status-badge.off { color: var(--muted); background: #eef1f5; }
.status-badge::before { width: 5px; height: 5px; border-radius: 50%; background: currentColor; content: ""; }
.empty-state { padding: 48px 24px; text-align: center; box-shadow: none; }
.empty-state .empty-icon { display: grid; place-items: center; width: 42px; height: 42px; margin: 0 auto 13px; border-radius: 13px; color: var(--accent); background: var(--navy-soft); font-size: 20px; }
.empty-state h3 { margin-bottom: 7px; }
.empty-state p { max-width: 380px; margin: 0 auto; color: var(--muted); font-size: 12px; line-height: 1.65; }

.split-layout { display: grid; grid-template-columns: minmax(0, 1.06fr) minmax(330px, .94fr); align-items: start; gap: 16px; }
.detail-card { position: sticky; top: 20px; }
.detail-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.detail-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin: 17px 0; }
.meta-box { padding: 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-soft); }
.meta-box label { display: block; margin-bottom: 4px; color: var(--faint); font-size: 10px; }
.meta-box span { display: block; overflow: hidden; color: var(--ink); font-size: 11px; font-weight: 620; text-overflow: ellipsis; white-space: nowrap; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field { display: grid; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { color: var(--ink); font-size: 11px; font-weight: 650; }
.field label span { color: var(--faint); font-weight: 450; }
input, textarea, select { width: 100%; border: 1px solid #dfe4eb; border-radius: 8px; outline: none; color: var(--ink); background: #fff; font-size: 12px; transition: border .16s ease, box-shadow .16s ease; }
input, select { height: 36px; padding: 0 10px; }
textarea { min-height: 105px; padding: 10px; resize: vertical; line-height: 1.55; }
input:focus, textarea:focus, select:focus { border-color: #9eb0f7; box-shadow: 0 0 0 3px rgba(75,108,240,.12); }
.form-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.form-help { color: var(--muted); font-size: 11px; line-height: 1.55; }
.form-section { padding-top: 17px; margin-top: 17px; border-top: 1px solid var(--line); }
.form-section h3 { margin-bottom: 10px; }
.segmented { display: inline-flex; gap: 2px; padding: 3px; border-radius: 9px; background: #eef1f6; }
.segmented button { border: 0; border-radius: 7px; padding: 7px 10px; color: var(--muted); background: transparent; font-size: 11px; }
.segmented button.is-active { color: var(--ink); background: #fff; box-shadow: 0 1px 4px rgba(23,32,51,.09); }
.account-tabs { display: flex; gap: 5px; margin-bottom: 13px; border-bottom: 1px solid var(--line); }
.mailbox-tabs { overflow-x: auto; margin-bottom: 20px; }
.mailbox-tabs .tab-button { flex: 0 0 auto; }
.tab-button { border: 0; border-bottom: 2px solid transparent; padding: 0 8px 9px; color: var(--muted); background: transparent; font-size: 12px; }
.tab-button.is-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }

.mailbox-toolbar { align-items: flex-start; margin-bottom: 14px; }
.list-search { display: grid; grid-template-columns: minmax(180px, 1fr) auto auto; gap: 8px; margin-bottom: 14px; padding: 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-soft); }
.filter-bar { display: grid; grid-template-columns: minmax(210px, 1.4fr) minmax(130px, .6fr) minmax(190px, 1fr) auto; align-items: end; gap: 10px; margin-bottom: 14px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-soft); }
.filter-actions { display: flex; gap: 7px; padding-bottom: 1px; }
.mailbox-toolbar .muted { max-width: 680px; margin: 5px 0 0; font-size: 11px; line-height: 1.55; }
.mailbox-summary { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 13px; }
.mailbox-summary span { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); background: var(--surface-soft); font-size: 10px; }
.mailbox-summary strong { margin-left: 4px; color: var(--ink); font-size: 12px; }
.mailbox-table { min-width: 860px; }
.mailbox-row-actions { min-width: 390px; }
.risk-table { min-width: 1360px; }
.risk-row-actions { min-width: 250px; }
.risk-issue-list { display: grid; gap: 7px; }
.health-issues { display: grid; gap: 7px; margin-top: 13px; }
.risk-issue { display: block; width: max-content; max-width: 210px; padding: 4px 7px; border-radius: 6px; color: var(--warning); background: var(--warning-soft); font-size: 10px; line-height: 1.4; }
.risk-issue.critical { color: var(--danger); background: var(--danger-soft); }
.risk-critical { color: var(--danger); }
.risk-warning { color: var(--warning); }
.risk-healthy { color: var(--success); }
.risk-run-notice { margin-bottom: 14px; }
.data-freshness { margin: 13px 0 0; color: var(--faint); font-size: 10px; text-align: right; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 15px; color: var(--muted); font-size: 10px; }
.pagination-actions { display: flex; align-items: center; gap: 9px; }
.verification-target { display: grid; gap: 4px; margin-bottom: 14px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-soft); }
.verification-target span, .code-result-label { color: var(--faint); font-size: 10px; font-weight: 700; }
.verification-target strong { overflow-wrap: anywhere; font-family: "SFMono-Regular", Consolas, monospace; font-size: 11px; }
.code-result { display: grid; justify-items: center; gap: 11px; padding: 22px; border: 1px solid #c9d4ff; border-radius: 12px; background: #f4f6ff; text-align: center; }
.verification-code { color: var(--navy); font-family: "SFMono-Regular", Consolas, monospace; font-size: clamp(31px, 8vw, 44px); letter-spacing: .16em; line-height: 1; }
.code-result-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-top: 13px; }
.code-result-meta > div { min-width: 0; padding: 10px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-soft); }
.code-result-meta .full { grid-column: 1 / -1; }
.code-result-meta span, .code-result-meta strong { display: block; }
.code-result-meta span { margin-bottom: 4px; color: var(--faint); font-size: 9px; }
.code-result-meta strong { overflow: hidden; color: var(--ink); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }

.key-token { padding: 13px; border: 1px solid #c9d4ff; border-radius: 10px; background: #f1f4ff; }
.key-token label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 10px; font-weight: 700; }
.key-token code { display: block; overflow-wrap: anywhere; color: var(--navy); font-size: 12px; line-height: 1.6; }
.key-warning { margin: 11px 0 0; color: var(--warning); font-size: 11px; line-height: 1.5; }
.code-area { min-height: 240px; font-family: "SFMono-Regular", Consolas, monospace; font-size: 11px; }
.debug-grid { display: grid; grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); gap: 16px; }
.debug-output { min-height: 330px; overflow: auto; padding: 14px; border-radius: 10px; color: #d7e2f5; background: #101827; font: 11px/1.6 "SFMono-Regular", Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.notice { display: flex; gap: 10px; padding: 12px 13px; border-radius: 9px; color: #526174; background: #f1f4f8; font-size: 11px; line-height: 1.55; }
.notice.warning { color: #825719; background: var(--warning-soft); }
.notice.danger { color: #963540; background: var(--danger-soft); }
.notice.health-ok { color: var(--success); background: var(--success-soft); }
.notice strong { color: inherit; }
.loading { padding: 35px; color: var(--muted); text-align: center; font-size: 12px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

#modal-root:empty { display: none; }
.modal-backdrop { position: fixed; z-index: 50; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(15, 23, 42, .42); backdrop-filter: blur(3px); }
.modal { width: min(560px, 100%); max-height: min(760px, calc(100vh - 40px)); overflow: auto; border: 1px solid rgba(255,255,255,.75); border-radius: 15px; background: var(--surface); box-shadow: 0 25px 70px rgba(11, 20, 38, .24); animation: modal-in .18s ease-out; }
.modal.wide { width: min(760px, 100%); }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 20px 21px 0; }
.modal-header h2 { margin-bottom: 4px; }
.modal-header p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.modal-close { width: 28px; height: 28px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; font-size: 20px; }
.modal-close:hover { color: var(--ink); background: #f0f2f5; }
.modal-body { padding: 19px 21px 21px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 0 21px 21px; }

@media (max-width: 1050px) {
  .sidebar { width: 210px; flex-basis: 210px; }
  .split-layout, .debug-grid { grid-template-columns: 1fr; }
  .detail-card { position: static; }
}
@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { width: 100%; padding: 14px 14px 10px; }
  .brand { padding: 2px 7px 14px; }
  .nav { display: flex; overflow-x: auto; }
  .nav-item { flex: 0 0 auto; padding: 9px 11px; }
  .nav-icon { display: none; }
  .sidebar-footer { display: none; }
  .main-content { padding: 24px 14px 40px; }
  .topbar { margin-bottom: 20px; }
  .topbar-actions { align-items: flex-end; flex-direction: column; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel { padding: 15px; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .detail-meta { grid-template-columns: 1fr; }
  .mailbox-toolbar { align-items: stretch; flex-direction: column; }
  .mailbox-toolbar .button { width: 100%; }
  .list-search { grid-template-columns: 1fr auto; }
  .list-search .ghost-button { grid-column: 1 / -1; }
  .filter-bar { grid-template-columns: 1fr; }
  .filter-actions .button, .filter-actions .ghost-button { flex: 1; }
  .risk-panel-header { align-items: stretch; flex-direction: column; }
  .risk-panel-header .toolbar-actions { width: 100%; }
  .risk-panel-header .toolbar-actions button { flex: 1 1 120px; }
  .pagination { align-items: stretch; flex-direction: column; }
  .pagination-actions { justify-content: space-between; }
  .code-result-meta { grid-template-columns: 1fr; }
  .code-result-meta .full { grid-column: auto; }
}
