:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --text: #172033;
  --muted: #667085;
  --border: #d8dee9;
  --border-strong: #b8c2d1;
  --primary: #0d5aa7;
  --primary-dark: #084580;
  --primary-soft: #eaf3fc;
  --success: #16734a;
  --success-soft: #e8f6ef;
  --warning: #9a5b00;
  --warning-soft: #fff4dc;
  --danger: #b42318;
  --danger-soft: #ffebe9;
  --sidebar: #0d2746;
  --sidebar-muted: #a9bad0;
  --shadow: 0 1px 2px rgb(16 24 40 / 5%), 0 4px 14px rgb(16 24 40 / 5%);
  --radius: 10px;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body { min-height: 100vh; margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--primary); text-decoration-thickness: .08em; text-underline-offset: .15em; }
a:hover { color: var(--primary-dark); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 5px; font-size: clamp(1.45rem, 2vw, 1.85rem); line-height: 1.18; }
h2 { margin-bottom: 0; font-size: 1.05rem; }
h3 { margin: 16px 0 9px; font-size: .95rem; }

.skip-link { position: fixed; z-index: 1000; top: 8px; left: 8px; padding: 9px 12px; transform: translateY(-160%); background: #fff; border: 2px solid var(--primary); border-radius: 6px; }
.skip-link:focus { transform: none; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }
.muted { color: var(--muted); }

.app-shell { display: grid; grid-template-columns: 244px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; z-index: 30; top: 0; height: 100vh; display: flex; flex-direction: column; overflow-y: auto; padding: 15px 12px; color: #fff; background: var(--sidebar); }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 18px; color: #fff; text-decoration: none; }
.brand:hover { color: #fff; }
.brand-mark, .auth-logo { display: grid; flex: 0 0 auto; place-items: center; width: 40px; height: 40px; border-radius: 50%; color: #172033; background: linear-gradient(145deg, #ffd958, #f3a712); font-weight: 800; box-shadow: inset 0 0 0 3px rgb(255 255 255 / 35%); }
.brand strong { display: block; font-size: .96rem; }
.brand small { display: block; margin-top: 2px; color: var(--sidebar-muted); font-size: .75rem; }
.nav-list { display: flex; flex: 1; flex-direction: column; gap: 3px; }
.nav-list a { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; min-height: 39px; padding: 8px 10px; border-radius: 7px; color: #dce6f2; text-decoration: none; }
.nav-list a:hover { color: #fff; background: rgb(255 255 255 / 8%); }
.nav-list a[aria-current="page"] { color: #fff; background: #174f83; box-shadow: inset 3px 0 #ffd14d; }
.nav-list a b { min-width: 22px; padding: 1px 6px; border-radius: 10px; color: #dce6f2; background: rgb(255 255 255 / 10%); font-size: .72rem; text-align: center; }
.nav-heading { margin: 17px 10px 5px; color: var(--sidebar-muted); font-size: .7rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.sidebar-footer { display: grid; gap: 7px; margin-top: 16px; padding: 12px 6px 0; border-top: 1px solid rgb(255 255 255 / 12%); }
.sidebar-footer form { margin: 0; }
.sidebar-footer .button { color: #fff; border-color: rgb(255 255 255 / 30%); }
.user-name { overflow: hidden; color: #e8eef6; text-overflow: ellipsis; white-space: nowrap; }
.job-chip { padding: 5px 8px; border-radius: 6px; color: #ffe8a6; background: rgb(255 209 77 / 12%); font-size: .78rem; }
.mobile-header { display: none; }
.sidebar-scrim { display: none; }

.main-content { min-width: 0; width: 100%; max-width: 1640px; padding: 24px clamp(18px, 3vw, 42px) 50px; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.page-heading p { margin-bottom: 0; }
.heading-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.heading-actions form { margin: 0; }
.back-link { display: inline-block; margin-bottom: 8px; font-size: .84rem; }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 38px; padding: 8px 13px; border: 1px solid transparent; border-radius: 7px; font-weight: 650; line-height: 1.15; text-decoration: none; white-space: nowrap; }
.button:hover { text-decoration: none; }
.button-primary { color: #fff; background: var(--primary); border-color: var(--primary); }
.button-primary:hover { color: #fff; background: var(--primary-dark); border-color: var(--primary-dark); }
.button-secondary { color: #26354b; background: #fff; border-color: var(--border-strong); }
.button-secondary:hover { color: #132238; background: #f4f7fa; }
.button-ghost { color: var(--primary); background: transparent; border-color: transparent; }
.button-ghost:hover { background: var(--primary-soft); }
.button-danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.button-danger:hover { color: #fff; background: #8f1c13; }
.button-small { min-height: 32px; padding: 6px 9px; font-size: .82rem; }
.button-wide { width: 100%; }
.button-disabled { color: #98a2b3; background: #f2f4f7; border-color: #e4e7ec; cursor: not-allowed; }
.button:focus-visible, .icon-button:focus-visible, .icon-action:focus-visible, a:focus-visible { outline: 2px solid #ffc928; outline-offset: 1px; }

.panel { margin-bottom: 16px; padding: 17px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.table-panel { padding: 0; overflow: hidden; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.table-panel > .panel-heading { padding: 15px 16px 0; }
.narrow-panel, .form-panel { max-width: 920px; }
.details-panel { padding-block: 12px; }
.details-panel dl { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 0; }
.details-panel dl div { min-width: 0; }
.details-panel dt { color: var(--muted); font-size: .77rem; }
.details-panel dd { margin: 2px 0 0; overflow-wrap: anywhere; font-weight: 600; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric-grid-three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metric-card { display: flex; min-height: 112px; flex-direction: column; justify-content: center; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); background: var(--surface); box-shadow: var(--shadow); text-decoration: none; }
a.metric-card:hover { border-color: #9cbade; color: var(--text); box-shadow: 0 4px 15px rgb(13 90 167 / 10%); }
.metric-card span { color: var(--muted); font-size: .82rem; }
.metric-card strong { margin: 2px 0; font-size: 1.75rem; line-height: 1.15; }
.metric-card small { color: var(--muted); }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr); gap: 16px; }
.compact-list { display: grid; }
.compact-list > a { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 3px; border-bottom: 1px solid #e9edf3; color: var(--text); text-decoration: none; }
.compact-list > a:last-child { border-bottom: 0; }
.compact-list > a:hover strong { color: var(--primary); }
.compact-list span:first-child { min-width: 0; }
.compact-list strong, .compact-list small { display: block; }
.compact-list small { margin-top: 2px; color: var(--muted); }

.messages { display: grid; gap: 8px; margin-bottom: 14px; }
.message, .callout, .form-alert { padding: 11px 13px; border: 1px solid #bfd2e7; border-radius: 8px; background: #eef6ff; }
.message-success { color: #0f5d3c; border-color: #b6ddc8; background: var(--success-soft); }
.message-error, .form-alert { color: #8f1c13; border-color: #f0b4ae; background: var(--danger-soft); }
.message-warning, .callout-warning { color: #744400; border-color: #efd49c; background: var(--warning-soft); }
.callout { margin-bottom: 15px; }
.callout p:last-child { margin-bottom: 0; }
.warning-text { color: #8c361e; }

.tabs { display: flex; gap: 4px; overflow-x: auto; margin: -3px 0 16px; padding: 3px 2px 0; border-bottom: 1px solid var(--border); scrollbar-width: thin; }
.tabs a { flex: 0 0 auto; padding: 9px 13px 10px; border-bottom: 3px solid transparent; color: #44546a; text-decoration: none; }
.tabs a:hover { color: var(--primary); background: #f1f6fb; }
.tabs a[aria-current="page"] { color: var(--primary); border-bottom-color: var(--primary); font-weight: 700; }

.filter-bar { display: flex; flex-wrap: wrap; align-items: end; gap: 9px; margin-bottom: 12px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.filter-bar .field { min-width: 140px; margin: 0; }
.filter-bar .field-grow { flex: 1 1 250px; }
.filter-bar .field-small { min-width: 72px; }
.filter-actions { display: flex; gap: 5px; }
.field { min-width: 0; margin-bottom: 14px; }
.field > label:not(.check-label), .field > .label { display: block; margin-bottom: 5px; color: #344054; font-size: .82rem; font-weight: 650; }
.control, .file-control { width: 100%; min-height: 39px; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 6px; color: var(--text); background: #fff; }
textarea.control { min-height: 90px; resize: vertical; }
select.control { padding-right: 30px; }
.compact-control { width: auto; min-width: 180px; min-height: 34px; padding-block: 5px; }
.control:hover, .file-control:hover { border-color: #8da1b9; }
.fixed-value { color: #344054; background: #f2f4f7; font-weight: 700; }
.control:focus, .file-control:focus { border-color: var(--primary); outline: 2px solid rgb(13 90 167 / 18%); outline-offset: -3px; }
.field-invalid .control, .field-invalid .file-control { border-color: var(--danger); }
.check-label { display: inline-flex; align-items: flex-start; gap: 8px; cursor: pointer; font-weight: 600; }
.check-control, input[type="checkbox"] { flex: 0 0 auto; width: 17px; height: 17px; margin: 2px 0 0; accent-color: var(--primary); }
.field-checkbox { grid-column: 1 / -1; }
.help-text { margin-top: 4px; color: var(--muted); font-size: .78rem; }
.field-error { margin-top: 4px; color: var(--danger); font-size: .8rem; overflow-wrap: anywhere; }
.errorlist { margin: 0; padding-left: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 18px; }
.compact-grid { grid-template-columns: repeat(2, minmax(180px, 360px)); }
.stack-form > .panel:last-of-type { margin-bottom: 12px; }
.form-actions, .sticky-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.sticky-actions { position: sticky; z-index: 10; bottom: 0; margin: 15px 0 0; padding: 11px; border: 1px solid var(--border); border-radius: 8px; background: rgb(255 255 255 / 96%); box-shadow: 0 -3px 14px rgb(16 24 40 / 7%); }
.provider-fields[hidden], [hidden] { display: none !important; }

.bulk-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-height: 52px; padding: 9px 13px; border-bottom: 1px solid var(--border); background: var(--surface-muted); }
.bulk-toolbar > .muted { margin-left: auto; font-size: .78rem; }
.table-scroll { max-width: 100%; overflow: auto; }
.table-scroll:focus { outline: 2px solid var(--primary); outline-offset: -2px; }
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th, td { padding: 9px 10px; border-bottom: 1px solid #e6eaf0; text-align: left; vertical-align: middle; }
th { color: #475467; background: #f8fafc; font-size: .76rem; font-weight: 700; letter-spacing: .01em; white-space: nowrap; }
tbody tr:hover { background: #fbfcfe; }
tbody tr:last-child td { border-bottom: 0; }
td { max-width: 360px; overflow-wrap: anywhere; }
.check-cell { width: 43px; text-align: center; }
.actions-cell { width: 112px; text-align: right; }
.cell-meta { display: block; margin-top: 2px; color: var(--muted); font-size: .75rem; }
.row-actions { display: inline-flex; align-items: center; justify-content: flex-end; gap: 4px; white-space: nowrap; }
.icon-action, .icon-button { display: inline-grid; width: 34px; height: 34px; flex: 0 0 auto; place-items: center; padding: 0; border: 1px solid var(--border); border-radius: 6px; color: #31445c; background: #fff; font-size: 1rem; line-height: 1; text-decoration: none; }
.icon-action:hover, .icon-button:hover { color: var(--primary); border-color: #94b6dc; background: var(--primary-soft); }
.icon-danger { color: var(--danger); }
.icon-danger:hover { color: #8f1c13; border-color: #e5aba6; background: var(--danger-soft); }
.status { display: inline-flex; align-items: center; max-width: 240px; padding: 3px 7px; border-radius: 999px; color: #344054; background: #eef1f5; font-size: .72rem; font-weight: 700; line-height: 1.25; }
.status-active, .status-ready, .status-sent, .status-completed, .status-delivered, .status-read, .status-consent { color: var(--success); background: var(--success-soft); }
.status-warning, .status-partial, .status-unread, .status-official { color: var(--warning); background: var(--warning-soft); }
.status-error, .status-failed, .status-undelivered, .status-suppressed { color: var(--danger); background: var(--danger-soft); }
.status-running, .status-generating, .status-sending, .status-queued, .status-generation_queued, .status-send_queued { color: #174f83; background: var(--primary-soft); }
.status-muted, .status-purged, .status-unknown, .status-not_sent { color: #667085; background: #eef1f5; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 52px; padding: 9px 13px; border-top: 1px solid var(--border); color: var(--muted); font-size: .82rem; }
.pagination > div { display: flex; align-items: center; gap: 6px; }
.page-current { min-width: 58px; text-align: center; }
.empty-state { padding: 30px 16px; color: var(--muted); text-align: center; }
.empty-state strong { display: block; color: #344054; font-size: .96rem; }
.empty-state p { margin: 4px 0 0; }
.empty-state.compact { padding-block: 18px; }

.recipient-picker { margin-top: 5px; padding: 13px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-muted); }
.selection-summary { margin-bottom: 8px; color: #344054; font-weight: 700; }
.option-results { max-height: 310px; overflow-y: auto; border: 1px solid var(--border); border-radius: 7px; background: #fff; }
.recipient-option { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 7px; padding: 9px 10px; border-bottom: 1px solid #edf0f4; cursor: pointer; }
.recipient-option:last-child { border-bottom: 0; }
.recipient-option:hover { background: #f5f9fd; }
.recipient-option strong, .recipient-option small { display: block; }
.recipient-option small { color: var(--muted); }

.job-progress progress { width: 100%; height: 13px; overflow: hidden; border: 0; border-radius: 7px; accent-color: var(--primary); }
.job-numbers { margin: 8px 0 0; color: var(--muted); font-size: .82rem; }
.error-summary { color: var(--danger); cursor: pointer; font-size: .76rem; }
.hidden-form { display: none; }

.auth-shell { display: grid; min-height: 100vh; place-items: center; padding: 22px; background: radial-gradient(circle at 50% 0, #eaf3fc, #f5f7fb 52%); }
.auth-card { width: min(100%, 420px); padding: 30px; border: 1px solid var(--border); border-radius: 14px; background: #fff; box-shadow: 0 15px 50px rgb(13 39 70 / 13%); }
.auth-card .auth-logo { width: 58px; height: 58px; margin-bottom: 18px; font-size: 1.15rem; }
.auth-card h1 { font-size: 1.5rem; }

@media (forced-colors: active) {
  :focus-visible { outline: 2px solid Highlight !important; outline-offset: -2px !important; }
  .status { border: 1px solid CanvasText; }
}

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .details-panel dl { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .app-shell { display: block; padding-top: 54px; }
  .mobile-header { position: fixed; z-index: 35; top: 0; right: 0; left: 0; display: flex; height: 54px; align-items: center; gap: 12px; padding: 8px 13px; color: #fff; background: var(--sidebar); box-shadow: 0 2px 8px rgb(0 0 0 / 14%); }
  .mobile-header .icon-button { color: #fff; border-color: rgb(255 255 255 / 25%); background: transparent; }
  .mobile-title { font-weight: 700; }
  .sidebar { position: fixed; z-index: 45; top: 0; bottom: 0; left: 0; width: min(86vw, 280px); height: 100vh; transform: translateX(-105%); transition: transform .18s ease; box-shadow: 10px 0 30px rgb(0 0 0 / 22%); }
  body.sidebar-open { overflow: hidden; }
  body.sidebar-open .sidebar { transform: none; }
  .sidebar-scrim { position: fixed; z-index: 40; inset: 0; display: block; background: rgb(0 0 0 / 42%); }
  .main-content { padding: 18px 12px 42px; }
  .page-heading { align-items: stretch; flex-direction: column; gap: 12px; }
  .heading-actions { justify-content: flex-start; }
  .form-grid, .compact-grid { grid-template-columns: 1fr; }
  .filter-bar { align-items: stretch; }
  .filter-bar .field { flex: 1 1 190px; }
  .filter-actions { align-items: end; }
  .bulk-toolbar > .muted { width: 100%; margin-left: 0; }
}

@media (max-width: 560px) {
  body { font-size: 13.5px; }
  .metric-grid, .metric-grid-three { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric-card { min-height: 94px; padding: 12px; }
  .metric-card strong { font-size: 1.45rem; }
  .panel { padding: 13px; }
  .table-panel { padding: 0; }
  .details-panel dl { grid-template-columns: 1fr; }
  .pagination { align-items: stretch; flex-direction: column; }
  .pagination > div { justify-content: space-between; }
  .auth-card { padding: 22px; }
  .sticky-actions { position: static; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
