:root {
  --bg: #f4f6f8;
  --card: #fff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #017DFC;
  --brand-hover: #0066d6;
  --ok: #047857;
  --err: #b91c1c;
  --warn: #b45309;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-hover); text-decoration: underline; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 1.25rem; }
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.85rem 1.25rem; background: #0b1220; color: #f8fafc;
}
.top a { color: #e2e8f0; text-decoration: none; margin-right: 1rem; font-size: 0.92rem; }
.top a:hover { color: #fff; text-decoration: none; }
.top .brand { font-weight: 700; color: #fff; margin-right: 1.25rem; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 1.1rem 1.15rem; margin: 0 0 1rem;
}
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stat { font-size: 1.6rem; font-weight: 700; }
.muted { color: var(--muted); font-size: 0.9rem; }
h1 { font-size: 1.4rem; margin: 0 0 0.75rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.65rem; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.45rem 0.4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.02em; }
.flash { padding: 0.7rem 0.85rem; border-radius: 8px; margin: 0 0 1rem; }
.flash.ok { background: #ecfdf5; color: var(--ok); border: 1px solid #a7f3d0; }
.flash.error { background: #fef2f2; color: var(--err); border: 1px solid #fecaca; }
label { display: block; font-size: 0.85rem; color: var(--muted); margin: 0 0 0.3rem; }
input[type=text], input[type=password], textarea, select {
  width: 100%; padding: 0.55rem 0.65rem; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; margin: 0 0 0.85rem; background: #fff;
}
textarea { min-height: 280px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85rem; }
.btn {
  display: inline-block; border: none; border-radius: 8px; padding: 0.55rem 0.9rem;
  background: var(--brand); color: #fff; font-weight: 600; cursor: pointer; font: inherit;
}
.btn:hover { background: var(--brand-hover); }
.btn.secondary { background: #e5e7eb; color: #111827; }
.btn.danger { background: #dc2626; }
.btn.small { padding: 0.3rem 0.55rem; font-size: 0.8rem; }
.tabs a {
  display: inline-block; padding: 0.4rem 0.75rem; margin: 0 0.35rem 0.75rem 0;
  border-radius: 999px; background: #e5e7eb; color: #111827; text-decoration: none;
}
.tabs a.active { background: var(--brand); color: #fff; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.84rem; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-box { width: 100%; max-width: 22rem; }
pre.msg {
  white-space: pre-wrap; background: #f9fafb; border: 1px solid var(--line);
  border-radius: 8px; padding: 0.65rem; margin: 0.35rem 0 0; font-size: 0.85rem;
}
.stats-toolbar {
  display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end;
  justify-content: space-between; margin-top: 0.5rem;
}
.stats-toolbar .field { margin: 0; }
.stats-toolbar select { width: auto; min-width: 10rem; margin: 0; }
.stat-chips { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: center; }
.pill {
  display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 650;
}
.pill.ok { background: #d1fae5; color: #065f46; }
.pill.bad { background: #fee2e2; color: #991b1b; }
.stats-table-wrap { overflow-x: auto; margin-top: 0.75rem; }
table.stats-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.stats-table th, table.stats-table td {
  text-align: left; padding: 0.5rem 0.4rem; border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
td.stats-ip-cell { white-space: nowrap; }
.stats-ip-trigger {
  cursor: help; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.78rem; font-weight: 650; padding: 0.18rem 0.45rem; border-radius: 7px;
  border: 1px solid var(--line); background: #eff6ff; color: var(--brand);
  display: inline-flex; align-items: center;
}
.stats-ip-trigger:hover, .stats-ip-trigger:focus-visible {
  border-color: #93c5fd; outline: none; box-shadow: 0 0 0 2px rgba(1, 125, 252, 0.25);
}
.stats-ip-popover {
  position: fixed; z-index: 10050; width: min(390px, calc(100vw - 24px));
  overflow: hidden; border-radius: 14px; border: 1px solid var(--line);
  background: #fff; box-shadow: 0 12px 40px rgba(0,0,0,0.18);
  pointer-events: none; opacity: 0; visibility: hidden;
  transition: opacity 0.14s ease, visibility 0.14s ease;
}
.stats-ip-popover.is-visible { pointer-events: auto; opacity: 1; visibility: visible; }
.stats-ip-popover header {
  border-bottom: 1px solid var(--line); padding: 0.65rem 1rem;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 0.65rem;
  background: #f8fafc;
}
.stats-ip-popover header .ip-line { font-size: 0.82rem; font-weight: 650; font-family: ui-monospace, monospace; }
.stats-ip-popover header .acc-line { font-size: 0.72rem; color: var(--muted); margin-top: 0.15rem; }
.stats-ip-popover .geo-tag {
  flex-shrink: 0; font-size: 0.65rem; font-weight: 650; text-transform: uppercase;
  letter-spacing: 0.06em; padding: 0.2rem 0.45rem; border-radius: 999px;
  background: var(--brand); color: #fff;
}
.stats-ip-popover .stats-ip-map {
  height: 208px; background: #f1f5f9; border-bottom: 1px solid var(--line);
}
.stats-ip-popover .geo-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.65rem 0.85rem;
  padding: 0.85rem 1rem 1rem; font-size: 0.78rem; align-items: center;
}
.stats-ip-popover .geo-grid > div {
  display: flex; flex-direction: column; justify-content: center; min-height: 2.35rem;
}
.stats-ip-popover .geo-k {
  margin: 0 0 0.15rem; font-size: 0.65rem; font-weight: 650;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
}
.stats-ip-popover .geo-v { margin: 0; font-weight: 600; word-break: break-word; line-height: 1.35; }
.stats-ip-popover .geo-msg { padding: 0.85rem 1rem 1rem; font-size: 0.82rem; color: var(--muted); }
td.ua-cell { max-width: 12rem; font-size: 0.78rem; color: var(--muted); word-break: break-word; }
td.stats-meta-cell { max-width: 14rem; font-size: 0.78rem; color: var(--muted); word-break: break-word; }
td.stats-doc-cell { max-width: 20rem; word-break: break-word; }

.pill.source-form { background: #dbeafe; color: #1e40af; }
.pill.source-email { background: #ede9fe; color: #5b21b6; }
.ticket-table { margin: 0; }
.ticket-table th, .ticket-table td { padding: 0.7rem 0.85rem; }
.ticket-row { cursor: pointer; }
.ticket-row:hover { background: #f8fafc; }
.ticket-preview { max-width: 22rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticket-detail-head {
  display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start;
  flex-wrap: wrap; margin: 0 0 1rem;
}
.ticket-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.ticket-actions form { margin: 0; }
.ticket-meta {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem 1rem; margin: 0;
}
.ticket-meta dt {
  margin: 0; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted);
}
.ticket-meta dd { margin: 0.15rem 0 0; word-break: break-word; }
