:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --fg: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-weak: #eff6ff;
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
  --r-sm: 6px;
  --r-md: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 1px rgba(15, 23, 42, 0.04);
  --focus: 0 0 0 3px rgba(37, 99, 235, 0.35);
}

html {
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 13px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--fg);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
  color: var(--accent-hover);
}

h1 {
  margin: 0 0 6px;
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0 0 8px;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--fg);
}

h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 600;
}

h4 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--fg);
}

/* App bar */
.app-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 50;
}

.app-bar__brand {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--fg);
  text-decoration: none;
}

.app-bar__brand:hover {
  text-decoration: none;
  color: var(--accent);
}

.app-bar__nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
}

.nav-link {
  display: inline-block;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  color: var(--muted);
  font-weight: 500;
  font-size: 0.875rem;
  text-decoration: none;
}

.nav-link:hover {
  background: var(--accent-weak);
  color: var(--accent);
  text-decoration: none;
}

.nav-link.is-active {
  color: var(--accent);
  background: var(--accent-weak);
}

.app-bar__user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.875rem;
  color: var(--muted);
}

.logout-form {
  margin: 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 16px 32px;
}

.container--wide {
  max-width: min(1600px, 100%);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px;
  box-shadow: var(--shadow);
}

.card + .card {
  margin-top: 12px;
}

.card__title {
  margin: 0 0 12px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-bottom: 12px;
}

.toolbar--sticky {
  position: sticky;
  top: 48px;
  z-index: 40;
  background: var(--surface);
  padding: 12px;
  margin: -12px -12px 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  background: var(--muted);
}

.status-dot--ok {
  background: var(--ok);
}

.status-dot--err {
  background: var(--err);
}

.status-dot--warn {
  background: var(--warn);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 12px;
  box-shadow: var(--shadow);
}

.kpi__label {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 2px;
}

.kpi__value {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--fg);
  line-height: 1.15;
}

.kpi-grid--dense {
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}

.kpi-grid--dense .kpi {
  padding: 10px 12px;
}

.kpi-grid--dense .kpi__value {
  font-size: 1.05rem;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
}

table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.table th,
.table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.table th {
  background: #f1f5f9;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
}

.table th.sortable {
  cursor: pointer;
  user-select: none;
}

.table th.sortable:hover {
  background: #e2e8f0;
}

.table tbody tr:nth-child(even) {
  background: #fafbfc;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table td.num,
.table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.delivery-filters .toolbar {
  gap: 6px 10px;
}

.delivery-filters .field {
  font-size: 0.8125rem;
}

.delivery-input-flex {
  min-width: 120px;
  max-width: 220px;
  width: 100%;
}

.delivery-input-domain,
.delivery-input-vmta {
  min-width: 0;
  max-width: 150px;
  width: 100%;
}

/* Delivery table: no overflow on wrapper — overflow-x:auto breaks thead { position:sticky }
   in Chrome (header can paint below the first tbody row). Horizontal scroll is avoided by compact columns. */
.table-wrap.table-wrap--delivery {
  overflow: visible;
}

.table-wrap--delivery {
  margin-top: 12px;
}

.table-delivery.table--compact {
  font-size: 12px;
  table-layout: fixed;
  width: 100%;
}

.table-delivery.table--compact th,
.table-delivery.table--compact td {
  padding: 4px 8px;
  line-height: 1.35;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.table-delivery.table--compact thead th {
  position: sticky;
  top: 48px;
  z-index: 15;
  box-shadow: inset 0 -1px 0 var(--border);
}

.table-delivery.table--compact .badge {
  padding: 1px 6px;
  font-size: 10px;
}

.table-delivery .c-ts {
  width: 92px;
}

.table-delivery .c-type {
  width: 52px;
}

.table-delivery .c-rcpt {
  width: 200px;
}

.table-delivery .c-dsn {
  width: 88px;
}

.table-delivery .c-diag {
  width: auto;
}

.table-delivery .c-bcat {
  width: 88px;
}

.table-delivery .c-vmta {
  width: 100px;
}

.table-delivery .c-ip {
  width: 120px;
}

.table-delivery .c-env {
  width: 140px;
}

.table-delivery .cell-ts {
  font-variant-numeric: tabular-nums;
  vertical-align: top;
}

.table-delivery .ts-date {
  display: block;
  font-size: 10px;
  line-height: 1.15;
}

.table-delivery .ts-time {
  font-weight: 600;
}

.table-delivery .cell-type {
  text-align: center;
  vertical-align: middle;
}

.table-delivery .diag-cell {
  max-width: none;
  font-size: 11px;
}

.table-delivery .dsn-label {
  font-size: 10px;
  line-height: 1.2;
}

@media (max-width: 1200px) {
  .table-delivery .c-bcat-wide,
  .table-delivery .c-bcat-th,
  .table-delivery .c-bcat-td {
    display: none;
  }

  .table-delivery .c-env-wide,
  .table-delivery .c-env-th,
  .table-delivery .c-env-td {
    display: none;
  }

  .table-delivery .c-rcpt {
    width: 160px;
  }
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
  background: #f1f5f9;
  color: var(--fg);
}

.b-open,
.b-open_confirmed {
  background: #dcfce7;
  color: #166534;
}

.b-click,
.b-click_scanner {
  background: #dbeafe;
  color: #1e40af;
}

.b-unsubscribe {
  background: #ffedd5;
  color: #9a3412;
}

.b-acct,
.b-acct_header {
  background: #ede9fe;
  color: #5b21b6;
}

.b-acct-d {
  background: #dcfce7;
  color: #166534;
}

.b-acct-b {
  background: #fee2e2;
  color: #991b1b;
}

.b-acct-t {
  background: #ffedd5;
  color: #9a3412;
}

.b-acct-f {
  background: #ede9fe;
  color: #5b21b6;
}

.b-acct-r {
  background: #f1f5f9;
  color: #475569;
}

.b-prefetch,
.b-scanner {
  background: #f1f5f9;
  color: #475569;
}

.meta-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.meta-badge {
  display: inline-flex;
  align-items: flex-start;
  gap: 6px;
  max-width: 100%;
  padding: 6px 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 0.75rem;
}

.meta-badge strong {
  color: var(--muted);
  font-weight: 500;
  flex-shrink: 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  line-height: 1.25;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
  text-decoration: none;
}

.btn:hover {
  background: #f8fafc;
  text-decoration: none;
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.btn--sm {
  padding: 5px 10px;
  font-size: 0.8125rem;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
}

.btn--ghost:hover {
  background: var(--accent-weak);
}

.btn--danger {
  color: var(--err);
}

.btn--danger:hover {
  background: #fef2f2;
}

/* Inputs */
.input,
select.input {
  padding: 8px 10px;
  font-size: 0.875rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--fg);
  min-width: 0;
}

.input:focus-visible,
select.input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus);
}

.input--sm {
  padding: 5px 8px;
  font-size: 0.8125rem;
}

label.field {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8125rem;
  color: var(--muted);
}

label.field--inline {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.pill-row a {
  text-decoration: none;
}

.flex-spacer {
  flex: 1;
  min-width: 8px;
}

.pill {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
  border: 1px solid var(--border);
  color: var(--muted);
  background: var(--surface);
}

.pill:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.pill.is-active {
  background: var(--accent-weak);
  border-color: var(--accent);
  color: var(--accent);
}

small.muted,
.muted {
  color: var(--muted);
  font-size: 0.75rem;
}

.empty-state {
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.8125rem;
}

/* Live feed */
.live-feed-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 8px;
}

@media (max-width: 900px) {
  .live-feed-grid {
    grid-template-columns: 1fr;
  }
}

.live-col {
  min-height: 160px;
}

.live-col .live-lines {
  max-height: 280px;
  overflow-y: auto;
  overflow-x: hidden;
  margin: 0;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
}

.live-line {
  display: block;
  width: 100%;
  flex-shrink: 0;
  box-sizing: border-box;
  text-align: left;
  padding: 8px 10px;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: #f8fafc;
  font-size: 11px;
  line-height: 1.45;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  cursor: pointer;
  color: var(--fg);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.live-line:hover {
  border-color: var(--accent);
  background: var(--accent-weak);
}

.live-line:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.log-tail-pre {
  margin-top: 16px;
  max-height: min(80vh, 1200px);
  overflow: auto;
  padding: 12px;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: var(--r-md);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid #334155;
}

.nav-link-group {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
}

.nav-sublink {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 2px 6px;
  border-radius: 4px;
}

.nav-sublink:hover {
  background: var(--accent-weak);
  color: var(--accent);
  text-decoration: none;
}

.nav-sublink.is-active {
  color: var(--accent);
  font-weight: 600;
}

.nowrap {
  white-space: nowrap;
}

.diag-cell {
  max-width: 360px;
  font-size: 0.8125rem;
}

.delivery-types {
  border: 0;
  padding: 0;
  margin: 0;
}

.delivery-types legend {
  padding: 0;
  margin-bottom: 8px;
}

.live-acct-filters {
  margin-bottom: 12px;
}

.live-acct-filters .input--xs {
  max-width: 140px;
}

.live-line--acct {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  text-align: left;
}

.live-line__meta {
  flex: 1;
  min-width: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 11px;
}

.filter-details {
  margin-bottom: 12px;
}

.filter-details summary {
  cursor: pointer;
  font-weight: 500;
  color: var(--accent);
  user-select: none;
}

.filter-details summary:hover {
  text-decoration: underline;
}

/* Login */
.login-wrap {
  min-height: calc(100vh - 0px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
}

.login-card .field-block {
  margin-bottom: 14px;
}

.login-card label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--fg);
}

.login-card input[type="text"],
.login-card input[type="password"] {
  width: 100%;
}

.login-error {
  padding: 10px 12px;
  border-radius: var(--r-sm);
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  font-size: 0.875rem;
  margin-bottom: 14px;
}

/* Modal */
.modal::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.modal {
  border: none;
  border-radius: var(--r-md);
  padding: 0;
  max-width: min(720px, 96vw);
  box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.25);
}

.modal__inner {
  padding: 16px;
}

.modal pre {
  margin: 0;
  max-height: 60vh;
  overflow: auto;
  font-size: 12px;
  line-height: 1.45;
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px;
  border-radius: var(--r-sm);
  white-space: pre-wrap;
  word-break: break-word;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

/* Utility */
.mb-0 {
  margin-bottom: 0;
}

.mt-12 {
  margin-top: 12px;
}

code {
  font-size: 0.85em;
  background: #f1f5f9;
  padding: 1px 5px;
  border-radius: 4px;
}

.w-full {
  width: 100%;
}

/* Баунсы / подавленные строки в таблице */
.bounces-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: flex-end;
}

.table tbody tr.is-suppressed {
  opacity: 0.72;
}

.card--success-notice {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-radius: var(--r-sm);
  padding: 12px 16px;
}

.mb-12 {
  margin-bottom: 12px;
}
