:root {
  --portal-accent: #6558e8;
  --portal-accent-2: #3f8fe9;
  --portal-ink: #19243c;
  --portal-muted: #6f7890;
  --portal-line: #e5e9f2;
  --portal-canvas: #f5f7fb;
  --portal-surface: #fff;
  --portal-sidebar: #101a31;
  --portal-sidebar-soft: #202a44;
  --portal-success: #1aaa78;
  --portal-warning: #e19b39;
  --portal-danger: #d85d68;
  --portal-shadow: 0 12px 34px rgba(29, 38, 66, .08);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--portal-canvas); }
body {
  min-height: 100vh;
  margin: 0;
  background: var(--portal-canvas);
  color: var(--portal-ink);
  font: 13px/1.42 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, .button { cursor: pointer; }

.portal-shell { min-height: 100vh; display: grid; grid-template-columns: 196px minmax(0, 1fr); }
.portal-sidebar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 100vh;
  padding: 18px 12px;
  background: var(--portal-sidebar);
  color: #d8def1;
  overflow-y: auto;
}
.portal-brand { display: flex; align-items: center; gap: 9px; padding: 0 7px 17px; text-decoration: none; }
.portal-brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 850;
  letter-spacing: -.03em;
  background: linear-gradient(140deg, #7567ff, #477de7);
  box-shadow: 0 8px 20px rgba(87, 103, 237, .32);
}
.portal-brand-text strong { display: block; color: #fff; font-size: 15px; letter-spacing: -.02em; }
.portal-brand-text small { display: block; color: #8290ad; font-size: 9px; text-transform: uppercase; letter-spacing: .16em; }
.portal-nav-label { margin: 18px 9px 6px; color: #5e6b88; font-size: 8px; font-weight: 800; letter-spacing: .17em; text-transform: uppercase; }
.portal-nav { display: grid; gap: 3px; }
.portal-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 8px 9px;
  border-radius: 9px;
  color: #9eabc6;
  font-size: 13px;
  font-weight: 680;
  text-decoration: none;
}
.portal-nav a:hover, .portal-nav a.active { color: #fff; background: var(--portal-sidebar-soft); }
.portal-nav-icon { width: 16px; color: #7d72f2; text-align: center; font-size: 14px; }
.portal-nav-count {
  min-width: 20px;
  margin-left: auto;
  padding: 2px 6px;
  border-radius: 99px;
  color: #fff;
  background: var(--portal-warning);
  font-size: 9px;
  font-weight: 850;
  line-height: 1.45;
  text-align: center;
}
.portal-nav-count[hidden] { display: none; }
.portal-sidebar-footer { position: absolute; inset: auto 14px 22px; }
.portal-sidebar-footer a { color: #8d9ab6; font-size: 12px; text-decoration: none; }

.portal-app { min-width: 0; }
.portal-topbar {
  min-height: 58px;
  padding: 9px clamp(18px, 3vw, 38px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid var(--portal-line);
  backdrop-filter: blur(10px);
}
.portal-topbar-title { min-width: 0; }
.portal-topbar-title strong { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.portal-topbar-title small { color: var(--portal-muted); }
.portal-topbar-actions { display: flex; align-items: center; gap: 10px; }
.portal-menu-button { display: none; }
.portal-content { width: min(1440px, 100%); margin: 0 auto; padding: 22px clamp(16px, 3vw, 38px) 48px; }
.portal-content > h1, .page-heading h1 { margin: 0; font-size: clamp(23px, 2.5vw, 31px); line-height: 1.16; letter-spacing: -.035em; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.page-heading p { margin: 4px 0 0; }
.eyebrow { margin: 0 0 5px; color: var(--portal-accent); font-size: 10px; font-weight: 850; letter-spacing: .16em; text-transform: uppercase; }
.muted, .subvalue { color: var(--portal-muted); }
.subvalue { display: block; margin-top: 2px; font-size: 12px; }

.portal-hero {
  position: relative;
  overflow: hidden;
  min-height: 118px;
  padding: 22px 24px;
  margin-bottom: 13px;
  border-radius: 17px;
  color: #fff;
  background: linear-gradient(115deg, #6254df 0%, #4c69df 48%, #3c92e6 100%);
  box-shadow: 0 18px 36px rgba(77, 90, 217, .18);
}
.portal-hero::before, .portal-hero::after { content: ""; position: absolute; border-radius: 50%; border: 34px solid rgba(255,255,255,.055); }
.portal-hero::before { width: 220px; height: 220px; right: 9%; top: -85px; }
.portal-hero::after { width: 155px; height: 155px; right: 1%; top: -45px; }
.portal-hero h1 { position: relative; z-index: 1; margin: 7px 0 3px; font-size: 25px; letter-spacing: -.035em; }
.portal-hero p { position: relative; z-index: 1; margin: 0; color: #e7e9ff; }
.portal-hero .button { position: absolute; z-index: 2; right: 22px; bottom: 22px; background: #fff; color: #4e56c7; }
.hero-kicker { position: relative; z-index: 1; display: inline-block; padding: 5px 9px; border-radius: 99px; color: #f0efff; background: rgba(255,255,255,.16); font-size: 9px; font-weight: 850; letter-spacing: .12em; text-transform: uppercase; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin-bottom: 13px; }
.metrics-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric, .card, section {
  background: var(--portal-surface);
  border: 1px solid var(--portal-line);
  border-radius: 13px;
  box-shadow: 0 3px 12px rgba(30, 39, 70, .035);
}
.metric { min-height: 72px; padding: 12px 14px; display: flex; align-items: center; gap: 10px; }
.metric-icon { flex: 0 0 34px; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; color: #705fdf; background: #efecff; font-size: 16px; }
.metric:nth-child(2) .metric-icon { color: #377fd5; background: #e8f3ff; }
.metric:nth-child(3) .metric-icon { color: #d7852d; background: #fff3e3; }
.metric:nth-child(4) .metric-icon { color: #15966d; background: #e5f8f0; }
.metric span { display: block; color: var(--portal-muted); font-size: 12px; }
.metric strong { display: block; margin-top: 1px; font-size: 20px; line-height: 1.12; letter-spacing: -.035em; }
.card, section { padding: 14px; margin-bottom: 12px; }
section h2, .card h2 { margin: 0 0 6px; font-size: 17px; letter-spacing: -.018em; }
section h3 { margin: 18px 0 8px; font-size: 14px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-heading h2 { margin: 0; }

label { display: block; margin-bottom: 9px; color: #4c5870; font-size: 12px; font-weight: 750; }
input, select, textarea {
  display: block;
  width: 100%;
  min-height: 36px;
  margin-top: 5px;
  padding: 9px 11px;
  border: 1px solid #ccd4e3;
  border-radius: 8px;
  outline: none;
  color: var(--portal-ink);
  background: #fff;
}
textarea { min-height: 88px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--portal-accent); box-shadow: 0 0 0 3px rgba(101,88,232,.1); }
button, .button {
  display: inline-flex;
  min-height: 35px;
  align-items: center;
  justify-content: center;
  padding: 9px 14px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--portal-accent);
  font-weight: 780;
  text-decoration: none;
}
.button.secondary, button.secondary { color: #42506a; background: #edf1f7; }
.button.ghost { color: var(--portal-accent); background: transparent; border: 1px solid #d9dced; }
.toolbar { display: flex; align-items: end; gap: 10px; }
.toolbar label { flex: 1; margin: 0; }
.search-filters { display: grid; grid-template-columns: minmax(260px, 2fr) repeat(4, minmax(130px, 1fr)) auto; align-items: end; gap: 8px; margin-bottom: 12px; }
.search-filters label { margin: 0; }

.table-wrap { overflow-x: auto; border: 1px solid var(--portal-line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid #edf0f5; text-align: left; vertical-align: middle; }
th { color: #7b8499; background: #fafbfe; font-size: 9px; font-weight: 850; letter-spacing: .105em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover > td { background: #fbfcff; }
.result-title { color: #202a43; font-weight: 820; text-decoration: none; }
.result-title:hover { color: var(--portal-accent); }
.identifier { font-weight: 760; }
.details-row td { padding-top: 0; background: #fbfcfe; }
.details-row details { margin: 0; }
.details-row summary { cursor: pointer; color: var(--portal-accent); font-size: 12px; font-weight: 760; }
.details-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 13px 0 4px; }
.details-grid dt { color: var(--portal-muted); font-size: 9px; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
.details-grid dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.pagination span, .pagination small { color: var(--portal-muted); }
.pagination.compact button { min-height: 31px; padding: 6px 10px; }

.badge, .status {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 99px;
  color: #536078;
  background: #edf1f6;
  font-size: 10px;
  font-weight: 830;
  white-space: nowrap;
}
.status.delivered, .badge.delivered { color: #0d815a; background: #e2f7ee; }
.badge-success { color: #0d815a; background: #e2f7ee; }
.badge-info { color: #326bb2; background: #e7f1ff; }
.status.transit, .status.in-transit, .badge.in-transit { color: #326bb2; background: #e7f1ff; }
.status.returned, .status.undeliverable { color: #b14955; background: #fdebed; }
.status.status-button {
  min-height: 0;
  border: 1px solid transparent;
  cursor: pointer;
  font: inherit;
  font-size: 10px;
  font-weight: 830;
  line-height: 1.42;
}
.status.status-button:hover { border-color: currentColor; filter: saturate(1.08); }
.status.status-button:focus-visible { outline: 2px solid var(--portal-accent); outline-offset: 2px; }
.badge-close { margin-left: 6px; color: #846120; background: #fff1c9; }
.progress { min-width: 110px; height: 6px; overflow: hidden; border-radius: 99px; background: #edf0f6; }
.progress span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #6254df, #27b686); }
.error { padding: 11px 13px; border-left: 3px solid var(--portal-danger); border-radius: 7px; color: #8a3540; background: #fff0f1; }
mark { padding: 0 2px; background: #fff0a6; }
.snippet { color: #44516a; }

.delivery-layout { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(260px, .8fr); gap: 16px; }
.delivery-bars { display: grid; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 96px 1fr 76px; gap: 10px; align-items: center; font-size: 12px; }
.bar { height: 13px; overflow: hidden; border-radius: 4px; background: #edf0f6; }
.bar span { display: block; height: 100%; min-width: 2px; border-radius: inherit; background: linear-gradient(90deg, #6857e7, #4f8de8); }
.mailing-summary { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 9px; margin-bottom: 12px; }
.summary-tile { padding: 11px 12px; border: 1px solid var(--portal-line); border-radius: 10px; background: #fff; }
.summary-tile small { display: block; color: var(--portal-muted); }
.summary-tile strong { font-size: 18px; letter-spacing: -.03em; }

.geo-shell { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(320px, .85fr); gap: 14px; }
.geo-map {
  position: relative;
  z-index: 0;
  isolation: isolate;
  min-height: 365px;
  overflow: hidden;
  border-radius: 11px;
  background: linear-gradient(160deg, #dff3f8, #eff5f9 58%, #dcebf2);
  border: 1px solid #d8e4eb;
}
.geo-map .leaflet-container { font-family: inherit; }
.geo-map .leaflet-control-attribution { font-size: 9px; }
.geo-panel { min-height: 365px; max-height: 365px; padding: 10px; overflow: auto; border: 1px solid var(--portal-line); border-radius: 11px; background: #fbfcfe; }
.geo-state-button { width: 100%; display: grid; grid-template-columns: 1fr auto; min-height: 36px; margin-bottom: 4px; padding: 6px 8px; border: 1px solid transparent; color: var(--portal-ink); background: #fff; text-align: left; }
.geo-state-button:hover, .geo-state-button.selected { border-color: #cfc9ff; color: #5142c1; background: #f2f0ff; }
.geo-state-button small { display: block; color: var(--portal-muted); font-weight: 500; }
.geo-loading, .geo-empty { padding: 35px 10px; color: var(--portal-muted); text-align: center; }
.geo-drilldown { margin-top: 10px; }
.geo-drilldown h3 { margin: 0 0 9px; }
.route-map { min-height: 235px; height: 235px; }
.route-line { fill: none; stroke: #715be5; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.route-halo { fill: none; stroke: rgba(255,255,255,.8); stroke-width: 8; stroke-linecap: round; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; margin-left: 8px; padding: 1px 0 14px 18px; border-left: 2px solid #dfe3ee; }
.timeline li::before { content: ""; position: absolute; width: 10px; height: 10px; left: -6px; top: 5px; border: 2px solid #fff; border-radius: 50%; background: var(--portal-accent); box-shadow: 0 0 0 2px #dcd7ff; }
.timeline li:last-child { border-left-color: transparent; }
.viewer { width: 100%; height: 72vh; border: 1px solid var(--portal-line); border-radius: 10px; background: #fff; }

.modal[hidden] { display: none; }
.modal { position: fixed; inset: 0; z-index: 2000; isolation: isolate; display: grid; place-items: center; padding: 22px; background: rgba(9, 16, 34, .68); }
.modal-card { position: relative; z-index: 1; width: min(1050px, 96vw); max-height: 92vh; overflow: auto; border-radius: 16px; background: #fff; box-shadow: 0 28px 80px rgba(5,11,30,.35); }
.document-modal { z-index: 2100; }
.document-modal-card { width: min(1240px, 98vw); overflow: hidden; }
.document-modal-viewer { display: block; width: 100%; height: min(82vh, 980px); border: 0; background: #f3f5f8; }
.modal-head { position: sticky; top: 0; z-index: 1001; display: flex; justify-content: space-between; align-items: center; padding: 11px 15px; border-bottom: 1px solid var(--portal-line); background: #fff; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-head-actions { display: flex; align-items: center; gap: 7px; }
.modal-head-actions [hidden] { display: none; }
.modal-body { padding: 13px; }
.modal-grid { display: grid; grid-template-columns: 1.25fr .75fr; gap: 14px; }
body.modal-open { overflow: hidden; }
.text-button { min-height: 0; padding: 0; color: var(--portal-accent); background: transparent; border: 0; font-weight: 780; }
.rate-pill { display: inline-flex; padding: 3px 7px; border-radius: 99px; color: #195f4b; background: #e1f5ed; font-size: 10px; font-weight: 800; }
.geo-zip-row.selected td { background: #f1efff; }
.mailpiece-summary-card p { margin-top: 0; }
.tracking-history { padding-top: 12px; }
.mailpiece-documents { padding-top: 12px; }
.document-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.proof-samples { padding-bottom: 16px; }
.proof-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.proof-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--portal-line);
  border-radius: 11px;
  background: #fff;
}
.proof-thumbnail {
  position: relative;
  height: 220px;
  overflow: hidden;
  border-bottom: 1px solid var(--portal-line);
  background: #e9edf4;
}
.proof-thumbnail iframe {
  width: 100%;
  height: 100%;
  border: 0;
  pointer-events: none;
  background: #fff;
}
.proof-thumbnail > a { position: absolute; inset: 0; z-index: 2; }
.proof-thumbnail > span {
  position: absolute;
  right: 9px;
  bottom: 9px;
  z-index: 1;
  padding: 5px 8px;
  border-radius: 7px;
  color: #fff;
  background: rgba(16, 26, 49, .82);
  font-size: 10px;
  font-weight: 800;
}
.proof-thumbnail:hover > span { background: var(--portal-accent); }
.proof-card-label { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 10px; }
.proof-card-label strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proof-card-label a { color: var(--portal-accent); font-size: 11px; font-weight: 750; }

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 85% 15%, rgba(88,111,230,.26), transparent 32%), var(--portal-sidebar); }
.auth-card { width: min(460px, 100%); padding: 30px; border-radius: 16px; background: #fff; box-shadow: 0 30px 80px rgba(3,10,28,.35); }
.auth-card h1 { margin: 16px 0 5px; font-size: 28px; letter-spacing: -.04em; }
.auth-brand { display: inline-flex; align-items: center; gap: 10px; }

.portal-toasts { position: fixed; right: 22px; bottom: 22px; z-index: 900; display: grid; gap: 10px; width: min(390px, calc(100vw - 32px)); pointer-events: none; }
.portal-toast { position: relative; padding: 15px 38px 14px 17px; border: 1px solid var(--portal-line); border-left: 4px solid #20a675; border-radius: 12px; background: #fff; color: #14243d; box-shadow: 0 10px 36px rgba(20,36,61,.18); pointer-events: auto; }
.portal-toast-proof { border-left-color: var(--portal-accent); }
.portal-toast strong { display: block; font-size: 13px; line-height: 1.4; }
.portal-toast p { margin: 6px 0 8px; font-size: 12px; line-height: 1.45; color: var(--portal-muted); }
.portal-toast a { color: var(--portal-accent); font-size: 12px; font-weight: 750; }
.portal-toast-dismiss { position: absolute; top: 7px; right: 7px; width: 26px; min-width: 26px; height: 26px; padding: 0; border: 0; border-radius: 6px; color: #61718c; background: transparent; font-size: 22px; line-height: 1; }
.portal-toast-dismiss:hover { background: #edf1f8; color: #14243d; }
@media (max-width: 1050px) {
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mailing-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .search-filters { grid-template-columns: 1fr 1fr; }
  .geo-shell, .delivery-layout { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .portal-shell { display: block; }
  .portal-sidebar { position: fixed; left: -230px; width: 214px; transition: left .2s ease; box-shadow: 18px 0 45px rgba(3,9,25,.25); }
  .portal-sidebar.open { left: 0; }
  .portal-sidebar-footer { position: static; margin: 28px 10px 0; }
  .portal-menu-button { display: inline-flex; min-width: 40px; padding: 8px; }
  .portal-content { padding-top: 22px; }
  .portal-hero { padding: 23px; }
  .portal-hero .button { position: static; margin-top: 20px; }
  .metrics-grid, .mailing-summary { grid-template-columns: 1fr 1fr; }
  .toolbar, .search-filters { display: block; }
  .toolbar label, .search-filters label { margin-bottom: 10px; }
  .page-heading { display: block; }
  .modal-grid { grid-template-columns: 1fr; }
  .document-modal { padding: 0; }
  .document-modal-card { display: flex; flex-direction: column; width: 100vw; height: 100dvh; max-height: none; border-radius: 0; }
  .document-modal-viewer { flex: 1; min-height: 0; height: auto; }
  .document-modal .modal-head { flex: 0 0 auto; flex-direction: column; align-items: stretch; gap: 9px; }
  .document-modal .modal-head h2 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .document-modal .modal-head-actions { flex-wrap: wrap; gap: 6px; }
  .document-modal .modal-head-actions .button, .document-modal .modal-head-actions button { padding: 8px 10px; font-size: 12px; }
}
@media (max-width: 460px) {
  .metrics-grid, .mailing-summary { grid-template-columns: 1fr; }
}
