:root {
  --bg: #06090e;
  --bg-soft: #0b1119;
  --panel: rgba(15, 22, 32, 0.86);
  --panel-solid: #0f1620;
  --border: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.26);
  --text: #e7eef7;
  --muted: #8b9cb2;
  --accent: #2dd4a7;
  --accent-soft: rgba(45, 212, 167, 0.12);
  --info: #38bdf8;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 16px;
  --shadow: 0 24px 60px -30px rgba(0, 0, 0, 0.9);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

h1, h2, h3, p { margin: 0; }
code, .mono { font-family: var(--mono); font-size: 0.86em; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(900px 500px at 12% -10%, rgba(45, 212, 167, 0.14), transparent 60%),
    radial-gradient(760px 420px at 92% 0%, rgba(56, 189, 248, 0.1), transparent 62%),
    linear-gradient(180deg, #070c12 0%, #06090e 45%, #05080c 100%);
}

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.error-text { color: var(--bad); }

/* ---------- Login ---------- */

.login-view {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 18px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(180deg, rgba(20, 29, 41, 0.95), rgba(12, 18, 26, 0.97));
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 34px 32px 26px;
  box-shadow: var(--shadow);
  animation: rise 0.45s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 { font-size: 1.24rem; letter-spacing: -0.02em; }
.brand p { color: var(--muted); font-size: 0.86rem; margin-top: 2px; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  color: #04110d;
  background: linear-gradient(145deg, #5eead4, #22c58f);
  box-shadow: 0 10px 24px -12px rgba(45, 212, 167, 0.9);
  flex: none;
}
.brand-mark svg { width: 24px; height: 24px; }
.brand-mark.small { width: 38px; height: 38px; border-radius: 11px; }
.brand-mark.small svg { width: 20px; height: 20px; }

#login-form { margin-top: 28px; display: flex; flex-direction: column; }
#login-form label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 7px;
}
#login-form input {
  background: rgba(6, 11, 17, 0.8);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 12px 13px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  margin-bottom: 18px;
}
#login-form input:focus {
  border-color: rgba(45, 212, 167, 0.6);
  box-shadow: 0 0 0 3px rgba(45, 212, 167, 0.12);
}

#login-submit {
  margin-top: 4px;
  border: 0;
  border-radius: 11px;
  padding: 12px 16px;
  font-weight: 650;
  color: #03110c;
  background: linear-gradient(180deg, #4be3b8, #22c58f);
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s ease;
}
#login-submit:hover { filter: brightness(1.05); }
#login-submit:active { transform: translateY(1px); }
#login-submit:disabled { opacity: 0.6; cursor: progress; }

.form-error {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: #fca5a5;
  font-size: 0.86rem;
}
.form-note {
  margin-top: 14px;
  padding: 11px 12px;
  border-radius: 10px;
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.28);
  color: #fcd34d;
  font-size: 0.84rem;
}
.form-note code { color: #fde68a; }

.login-foot {
  margin-top: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.02em;
}

/* ---------- Layout ---------- */

#app-view { position: relative; z-index: 1; min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px clamp(16px, 4vw, 44px);
  background: rgba(6, 10, 15, 0.82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand.compact { gap: 11px; }
.brand-copy { display: flex; flex-direction: column; line-height: 1.25; }
.brand-copy h1 { font-size: 1rem; letter-spacing: -0.01em; }
.brand-copy .muted { font-size: 0.74rem; }

.topbar-meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: rgba(148, 163, 184, 0.07);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}
.pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.pill.ok { color: #6ee7c8; border-color: rgba(45, 212, 167, 0.35); background: var(--accent-soft); }
.pill.ok i { background: var(--accent); box-shadow: 0 0 10px rgba(45, 212, 167, 0.9); animation: pulse 2.2s ease-in-out infinite; }
.pill.warn { color: #fcd34d; border-color: rgba(251, 191, 36, 0.35); background: rgba(251, 191, 36, 0.1); }
.pill.warn i { background: var(--warn); }
.pill.bad { color: #fca5a5; border-color: rgba(248, 113, 113, 0.35); background: rgba(248, 113, 113, 0.1); }
.pill.bad i { background: var(--bad); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.uptime, .user-chip { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.uptime strong { color: var(--text); font-variant-numeric: tabular-nums; }
.user-chip {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(148, 163, 184, 0.05);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 6px 12px;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.8rem;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.ghost-btn:hover { color: var(--text); border-color: var(--border-strong); }

main {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 26px clamp(16px, 4vw, 44px) 44px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---------- Panels & stats ---------- */

.panel {
  background: linear-gradient(180deg, rgba(18, 26, 37, 0.85), rgba(11, 17, 24, 0.9));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.panel-head h2 { font-size: 0.98rem; letter-spacing: -0.01em; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

.stat {
  background: linear-gradient(180deg, rgba(18, 26, 37, 0.8), rgba(10, 16, 23, 0.9));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 15px 16px 13px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.stat-label { color: var(--muted); font-size: 0.72rem; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; }
.stat strong {
  font-size: 1.7rem;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}
.stat strong.ok { color: #6ee7c8; }
.stat strong.bad { color: #fca5a5; }
.stat strong.warn { color: #fcd34d; }
.stat-hint { color: var(--muted); font-size: 0.72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.two-col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
  gap: 18px;
  align-items: start;
}

.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 13px 22px; margin: 0; }
.kv > div { min-width: 0; }
.kv > div.full { grid-column: 1 / -1; }
.kv dt { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 650; margin-bottom: 2px; }
.kv dd { margin: 0; overflow-wrap: anywhere; font-size: 0.88rem; }
.kv dd.mono { font-size: 0.8rem; color: #c3d1e2; }

.targets { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.target {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(6, 11, 17, 0.55);
  padding: 12px 14px;
}
.target-top { display: flex; align-items: center; gap: 9px; }
.target-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.target-dot.ok { background: var(--accent); box-shadow: 0 0 8px rgba(45, 212, 167, 0.7); }
.target-dot.error { background: var(--bad); box-shadow: 0 0 8px rgba(248, 113, 113, 0.7); }
.target-url { font-family: var(--mono); font-size: 0.78rem; overflow-wrap: anywhere; color: #c9d8e8; }
.target-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 7px; color: var(--muted); font-size: 0.75rem; }
.target-meta b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.target-error { margin-top: 6px; color: #fca5a5; font-size: 0.75rem; overflow-wrap: anywhere; }

/* ---------- QR ---------- */

.qr-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 26px;
  align-items: center;
  border-color: rgba(45, 212, 167, 0.3);
  background:
    linear-gradient(120deg, rgba(45, 212, 167, 0.1), rgba(11, 17, 24, 0.92) 45%),
    linear-gradient(180deg, rgba(18, 26, 37, 0.85), rgba(11, 17, 24, 0.9));
  animation: rise 0.35s ease both;
}
.qr-copy h2 { font-size: 1.18rem; margin: 5px 0 8px; letter-spacing: -0.02em; }
.qr-copy p { color: var(--muted); font-size: 0.87rem; max-width: 56ch; }
.qr-copy p + p { margin-top: 8px; }
.qr-copy strong { color: var(--text); }
.eyebrow {
  display: inline-block;
  color: #6ee7c8;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
#qr-code {
  margin: 0;
  padding: 14px;
  border-radius: 12px;
  background: #05080c;
  color: #f8fafc;
  font-family: var(--mono);
  font-size: 9px;
  line-height: 1;
  letter-spacing: 0;
  white-space: pre;
  border: 1px solid rgba(45, 212, 167, 0.25);
  box-shadow: 0 0 40px -18px rgba(45, 212, 167, 0.6);
  user-select: all;
}

/* ---------- Feed ---------- */

.feed-panel { padding-bottom: 12px; }
.feed-head { align-items: center; }
.tabs { display: inline-flex; gap: 4px; background: rgba(6, 11, 17, 0.6); border: 1px solid var(--border); border-radius: 11px; padding: 3px; }
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 7px 15px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab:hover { color: var(--text); }
.tab.active { background: rgba(45, 212, 167, 0.14); color: #6ee7c8; }

.feed-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
#feed-search {
  background: rgba(6, 11, 17, 0.8);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 11px;
  min-width: 220px;
  font-size: 0.82rem;
  outline: none;
}
#feed-search:focus { border-color: rgba(45, 212, 167, 0.5); }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.78rem; cursor: pointer; user-select: none; }
.check input { accent-color: var(--accent); width: 14px; height: 14px; }
.count-chip { color: var(--muted); font-size: 0.75rem; border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px; font-variant-numeric: tabular-nums; }

.live { display: inline-flex; align-items: center; gap: 7px; font-size: 0.75rem; color: var(--muted); white-space: nowrap; }
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.live.on { color: #6ee7c8; }
.live.on i { background: var(--accent); box-shadow: 0 0 8px rgba(45, 212, 167, 0.8); animation: pulse 2.2s ease-in-out infinite; }
.live.retry { color: #fcd34d; }
.live.retry i { background: var(--warn); }

.feed { max-height: 620px; overflow-y: auto; padding-right: 4px; overscroll-behavior: contain; }
.feed::-webkit-scrollbar { width: 8px; }
.feed::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.2); border-radius: 8px; }
.feed::-webkit-scrollbar-track { background: transparent; }

.messages { display: flex; flex-direction: column; gap: 10px; }
.message {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(6, 11, 17, 0.5);
  padding: 13px 15px;
  animation: fadeIn 0.2s ease both;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-3px); }
  to { opacity: 1; transform: translateY(0); }
}
.message.is-problem { border-color: rgba(248, 113, 113, 0.35); }
.msg-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: 0.74rem; }
.msg-head .msg-id { color: #93a9c0; font-family: var(--mono); font-size: 0.72rem; overflow-wrap: anywhere; }
.msg-head .spacer { flex: 1; }
.msg-text {
  margin-top: 9px;
  font-size: 0.9rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 220px;
  overflow: hidden;
  position: relative;
}
.msg-text.empty { color: var(--muted); font-style: italic; }
.msg-text.expanded { max-height: none; }
.msg-expand {
  margin-top: 6px;
  border: 0;
  background: transparent;
  color: var(--info);
  font-size: 0.76rem;
  cursor: pointer;
  padding: 0;
}
.msg-links { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.msg-links a {
  color: #7dd3fc;
  font-size: 0.74rem;
  text-decoration: none;
  border: 1px solid rgba(56, 189, 248, 0.25);
  background: rgba(56, 189, 248, 0.07);
  padding: 3px 8px;
  border-radius: 7px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-links a:hover { border-color: rgba(56, 189, 248, 0.6); }
.msg-targets { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.target-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  border-radius: 999px;
  padding: 3px 9px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: rgba(148, 163, 184, 0.05);
  max-width: 100%;
}
.target-chip .host { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.target-chip.sent { color: #6ee7c8; border-color: rgba(45, 212, 167, 0.3); background: var(--accent-soft); }
.target-chip.failed { color: #fca5a5; border-color: rgba(248, 113, 113, 0.3); background: rgba(248, 113, 113, 0.08); }
.target-chip.sending { color: #fcd34d; border-color: rgba(251, 191, 36, 0.3); background: rgba(251, 191, 36, 0.08); }
.target-chip.skipped { color: #a5b4fc; border-color: rgba(165, 180, 252, 0.28); background: rgba(165, 180, 252, 0.08); }
.target-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: #7dd3fc;
  background: rgba(56, 189, 248, 0.08);
}

.events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.event {
  display: grid;
  grid-template-columns: 74px 76px minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.8rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.06);
  animation: fadeIn 0.2s ease both;
}
.event:hover { background: rgba(148, 163, 184, 0.05); }
.event time { color: var(--muted); font-family: var(--mono); font-size: 0.72rem; white-space: nowrap; }
.event .scope {
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.event .text { overflow-wrap: anywhere; }
.event.level-success .text { color: #8df0d3; }
.event.level-warn .text { color: #fcd34d; }
.event.level-error .text { color: #fca5a5; }
.event.level-info .text { color: #c9d8e8; }
.event-detail { margin-top: 3px; color: var(--muted); font-size: 0.72rem; font-family: var(--mono); overflow-wrap: anywhere; }

.empty-inline {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 26px 12px;
  border: 1px dashed var(--border);
  border-radius: 12px;
}

.page-foot {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.74rem;
  padding: 0 2px;
}
.page-foot code { color: #a9bdd3; }

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: #111c28;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 0.84rem;
  z-index: 50;
  max-width: min(90vw, 520px);
}

@media (max-width: 1080px) {
  .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .two-col { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .topbar { flex-direction: column; align-items: flex-start; gap: 10px; }
  .topbar-meta { justify-content: flex-start; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .qr-panel { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .qr-copy p { max-width: none; }
  #qr-code { font-size: 7px; }
  .kv { grid-template-columns: 1fr; }
  .event { grid-template-columns: 64px 68px minmax(0, 1fr); gap: 8px; }
  .feed-tools { width: 100%; }
  #feed-search { flex: 1; min-width: 140px; }
  .login-card { padding: 28px 22px 22px; }
}
