:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #1d2939;
  background: #f3f5f7;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #d8e0e8;
  --border-strong: #b8c4d0;
  --text-muted: #66768a;
  --header: #102a43;
  --primary: #1261a0;
  --primary-hover: #0d4f84;
  --ok: #087443;
  --ok-bg: #dff5e9;
  --off: #52667a;
  --off-bg: #edf1f5;
  --danger: #b42318;
  --danger-bg: #fee4e2;
  --warn-border: #d6a43b;
  --warn-bg: #fffbeb;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body { min-height: 100vh; margin: 0; font-size: 14px; line-height: 1.45; }
a { color: var(--primary); }

header { min-height: 56px; background: var(--header); color: #fff; border-bottom: 1px solid rgb(255 255 255 / 12%); }
.header-inner { min-height: 56px; display: flex; align-items: center; gap: 20px; width: 100%; padding: 0 24px; }
header a { color: #fff; text-decoration: none; }
.brand { flex: 0 0 auto; font-size: 15px; font-weight: 700; letter-spacing: .01em; white-space: nowrap; }
header nav { display: flex; align-self: stretch; align-items: center; gap: 2px; }
header nav a { display: flex; align-items: center; height: 100%; padding: 0 12px; border-bottom: 3px solid transparent; color: #d9e5ef; font-size: 13px; font-weight: 550; }
header nav a:hover { color: #fff; background: rgb(255 255 255 / 7%); }
header nav a.active { color: #fff; border-bottom-color: #6cb6e8; background: rgb(255 255 255 / 9%); }
header form { display: block; margin: 0; }
.timezone-note { margin-left: auto; color: #b8c9d8; font-size: 12px; white-space: nowrap; }

main { width: 100%; margin: 0; padding: 20px 24px 32px; }
.public main { width: min(480px, calc(100% - 32px)); margin: 0 auto; padding: 0; }

h1, h2, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-size: 24px; line-height: 1.25; letter-spacing: -.015em; }
h2 { margin: 0; font-size: 15px; line-height: 1.3; }
.page-header { min-height: 42px; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.page-header p, .card-header p { margin: 3px 0 0; color: var(--text-muted); font-size: 13px; }
.crumb { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 10px; color: var(--text-muted); text-decoration: none; font-size: 13px; }
.crumb:hover { color: var(--primary); text-decoration: underline; }

.card { margin: 0 0 14px; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 1px 3px rgb(16 42 67 / 5%); }
.card.warn { border-color: var(--warn-border); background: var(--warn-bg); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.count { display: inline-flex; align-items: center; justify-content: center; min-width: 24px; height: 20px; margin-left: 5px; padding: 0 7px; border-radius: 10px; background: var(--off-bg); color: var(--off); font-size: 12px; font-weight: 600; vertical-align: 1px; }
.form-card { padding: 14px 16px; }
.data-card { padding: 0; }
.data-card .card-header { min-height: 46px; margin: 0; padding: 12px 14px 10px; border-bottom: 1px solid var(--border); }
.login-card { max-width: 440px; margin: 10vh auto; padding: 24px; }
.login-card h1 { margin-bottom: 20px; }

label { display: grid; gap: 5px; color: #344054; font-size: 12px; font-weight: 650; }
input, select, button { min-height: 36px; padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: 4px; background: #fff; color: inherit; font: inherit; }
input, select { width: 100%; }
input:hover, select:hover { border-color: #98a8b8; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid #3486c5; outline-offset: 2px; }
button { width: auto; cursor: pointer; border-color: var(--primary); background: var(--primary); color: #fff; font-weight: 600; white-space: nowrap; }
button:hover { border-color: var(--primary-hover); background: var(--primary-hover); }
button.secondary { border-color: #8fa1b3; background: transparent; color: inherit; }
header button.secondary { border-color: #71869a; color: #eaf1f7; }
button.secondary:hover { background: #edf2f6; }
header button.secondary:hover { background: rgb(255 255 255 / 10%); }
button.danger { border-color: #d09a95; background: transparent; color: var(--danger); }
button.danger:hover { border-color: var(--danger); background: var(--danger-bg); }
button:disabled { cursor: not-allowed; opacity: .6; }
.compact-button { min-height: 30px; padding: 4px 10px; font-size: 12px; }
.button-link { display: inline-flex; min-height: 36px; align-items: center; padding: 7px 10px; border: 1px solid var(--primary); border-radius: 4px; background: var(--primary); color: #fff; font-weight: 600; text-decoration: none; white-space: nowrap; }
.button-link:hover { border-color: var(--primary-hover); background: var(--primary-hover); }
.button-link.secondary { border-color: var(--border-strong); background: transparent; color: var(--primary); }
.button-link.secondary:hover { border-color: #98a8b8; background: #edf2f6; }

form { display: grid; gap: 12px; }
.grid-form { display: grid; align-items: end; gap: 12px; }
.blacklist-form { grid-template-columns: 180px minmax(280px, 1fr) minmax(320px, 1.4fr) auto; }
.app-create-form { grid-template-columns: minmax(280px, 520px) auto; justify-content: start; }
.sender-form { grid-template-columns: 180px minmax(300px, 600px) auto; justify-content: start; }
.audit-filter { grid-template-columns: minmax(320px, 1fr) 180px 220px auto; align-items: end; }
.filter-actions { display: flex; align-items: center; gap: 10px; min-height: 36px; }
.filter-actions a { font-size: 13px; font-weight: 600; text-decoration: none; }
.filter-actions a:hover { text-decoration: underline; }
.button-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.button-row form, td form { display: inline-flex; }
.hint { margin: 8px 0 0; color: var(--text-muted); font-size: 12px; }

.metrics { display: grid; gap: 12px; }
.metrics-grid { grid-template-columns: repeat(4, minmax(180px, 1fr)); }
.metrics a.card { min-height: 104px; display: flex; flex-direction: column; justify-content: center; margin: 0; padding: 16px 18px; color: inherit; text-decoration: none; }
.metrics a.card:hover { border-color: #aebdca; box-shadow: 0 2px 7px rgb(16 42 67 / 9%); }
.metrics strong { display: block; font-size: 28px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.metrics span { margin-top: 7px; color: var(--text-muted); font-size: 13px; }

.detail-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 18px 40px; padding: 13px 16px; }
.summary-item { display: grid; gap: 3px; min-width: 180px; }
.summary-item > span { color: var(--text-muted); font-size: 12px; font-weight: 600; }
.detail-summary .button-row { margin-left: auto; }

.flash, .error { margin-bottom: 14px; padding: 9px 12px; border: 1px solid transparent; border-radius: 4px; }
.flash { border-color: #a9dfc4; background: var(--ok-bg); color: #075d36; }
.error { border-color: #f5b7b2; background: var(--danger-bg); color: #912018; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
th, td { padding: 8px 10px; text-align: left; vertical-align: top; border-bottom: 1px solid #e7ecf0; }
th { position: sticky; top: 0; z-index: 1; background: #f5f7f9; color: #526274; font-size: 11px; font-weight: 700; letter-spacing: .035em; text-transform: uppercase; white-space: nowrap; }
tbody tr:nth-child(even) { background: #fbfcfd; }
tbody tr:hover { background: #f3f7fa; }
tbody tr:last-child td { border-bottom: 0; }
td { max-width: 420px; }
td a { font-weight: 600; text-decoration: none; }
td a:hover { text-decoration: underline; }
.datetime-cell, .cell-status, .cell-action, .cell-queue, .cell-number, .cell-compact, .cell-app { white-space: nowrap; }
.datetime-cell { width: 150px; font-variant-numeric: tabular-nums; }
.cell-status { width: 96px; }
.cell-action { width: 88px; text-align: right; }
.cell-number { width: 84px; text-align: right; font-variant-numeric: tabular-nums; }
.cell-queue { width: 110px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.cell-compact { width: 88px; }
.cell-address { overflow-wrap: anywhere; }
.audit-table { min-width: 1420px; table-layout: fixed; }
.audit-table th:nth-child(2), .audit-table td:nth-child(2) { width: 260px; }
.audit-table th:nth-child(3), .audit-table td:nth-child(3) { width: 160px; }
.audit-table th:nth-child(4), .audit-table td:nth-child(4) { width: 220px; }
.audit-table th:nth-child(5), .audit-table td:nth-child(5) { width: 260px; }
.audit-table th:nth-child(9), .audit-table td:nth-child(9) { width: 112px; }
.content-summary { display: grid; grid-template-columns: 180px 180px minmax(260px, 1fr) minmax(360px, 1.5fr); gap: 18px; }
.content-summary div { min-width: 0; }
.content-summary span { display: block; margin-bottom: 4px; color: var(--text-muted); font-size: 12px; font-weight: 600; }
.content-summary strong { overflow-wrap: anywhere; }
.content-card { margin-top: 14px; }
.content-preview { min-height: 360px; max-height: 680px; margin: 0; padding: 16px; overflow: auto; border: 1px solid var(--border); border-radius: 5px; background: #f8fafc; color: var(--text); font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.cell-subject span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-app { overflow: hidden; text-overflow: ellipsis; }
.cell-provider { width: 76px; text-align: center; }
.provider-icon { display: inline-grid; width: 22px; height: 22px; place-items: center; border-radius: 50%; font-size: 15px; font-weight: 800; line-height: 1; }
.provider-ok { background: var(--ok-bg); color: var(--ok); }
.provider-warning { background: var(--warn-bg); color: #8a5700; }
.provider-error { background: var(--danger-bg); color: var(--danger); }

.badge { display: inline-flex; align-items: center; min-height: 22px; padding: 2px 8px; border-radius: 11px; font-size: 11px; font-weight: 700; line-height: 1; white-space: nowrap; text-transform: capitalize; }
.badge-on { background: var(--ok-bg); color: var(--ok); }
.badge-off { background: var(--off-bg); color: var(--off); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.recipient-list { display: grid; gap: 3px; min-width: 180px; margin: 0; padding: 0; list-style: none; }
.recipient-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.recipient-address { overflow-wrap: anywhere; }

.pagination { display: flex; justify-content: space-between; align-items: center; gap: 16px; min-height: 44px; padding: 10px 14px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 12px; }
.pagination a { color: var(--primary); font-weight: 650; text-decoration: none; }
.pagination a:hover { text-decoration: underline; }
.pagination .disabled { color: #a8b4c0; }

.credential code { display: block; margin: 7px 0; padding: 10px 12px; border: 1px dashed var(--warn-border); border-radius: 4px; background: #fff; font-size: 14px; word-break: break-all; }
.credential .copy-row { display: flex; align-items: center; gap: 8px; }
.copy-row { display: flex; align-items: center; gap: 8px; }
.copy-feedback { color: var(--ok); font-size: 12px; }
.developer-guide { margin: 0; overflow-x: auto; color: #1d2939; font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; }

@media (max-width: 1100px) {
  .header-inner { flex-wrap: wrap; gap: 0 14px; padding: 8px 16px; }
  header nav { order: 3; width: 100%; height: 40px; overflow-x: auto; }
  header nav a { flex: 0 0 auto; }
  .timezone-note { margin-left: auto; }
  main { padding: 18px 16px 28px; }
  .metrics-grid { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
  .blacklist-form { grid-template-columns: 160px 1fr 1fr auto; }
  .audit-filter { grid-template-columns: minmax(280px, 1fr) 160px 200px auto; }
}

@media (max-width: 760px) {
  body { font-size: 13px; }
  .header-inner { align-items: center; }
  .timezone-note { order: 2; margin-left: auto; }
  header form { order: 2; margin-left: 0; }
  header nav { order: 3; }
  main { padding: 16px 12px 24px; }
  h1 { font-size: 21px; }
  .page-header { margin-bottom: 12px; }
  .card { margin-bottom: 12px; }
  .metrics-grid { grid-template-columns: 1fr; }
  .metrics a.card { min-height: 86px; }
  .grid-form, .blacklist-form, .app-create-form, .sender-form, .audit-filter { grid-template-columns: 1fr; }
  .grid-form button { justify-self: start; }
  .detail-summary { align-items: flex-start; }
  .detail-summary .button-row { width: 100%; margin-left: 0; }
  .audit-table { min-width: 1320px; }
  .content-summary { grid-template-columns: 1fr; }
  .pagination { align-items: flex-start; }
}

@media (max-width: 480px) {
  .brand { width: 100%; }
  .timezone-note { margin-left: 0; }
  .public main { width: calc(100% - 24px); }
  .login-card { margin-top: 5vh; padding: 18px; }
}
