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

:root {
  --bg: #0b1220;
  --panel: #121a2b;
  --panel-2: #182338;
  --border: rgba(148, 163, 184, 0.14);
  --text: #e8eefc;
  --muted: #8b9bb8;
  --accent: #38bdf8;
  --green: #34d399;
  --red: #f87171;
  --purple: #818cf8;
  --orange: #fbbf24;
  --radius: 14px;
  --shadow: 0 12px 40px rgba(0,0,0,.35);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", sans-serif;
}

html, body {
  min-height: 100%;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(56,189,248,.12), transparent 60%),
    radial-gradient(700px 400px at 100% 0%, rgba(129,140,248,.12), transparent 55%),
    var(--bg);
  color: var(--text);
}

body { line-height: 1.5; }

/* ========== Login ========== */
.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.login-brand {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 14px;
  letter-spacing: .02em;
}
.login-card h1 {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -.03em;
  margin-bottom: 6px;
}
.login-sub {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 24px;
}
.login-card label {
  display: block;
  margin-bottom: 14px;
}
.login-card label span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}
.login-card input {
  width: 100%;
  height: 46px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 0 14px;
  font-size: 15px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.login-card input:focus {
  border-color: rgba(56,189,248,.55);
  box-shadow: 0 0 0 3px rgba(56,189,248,.15);
}
.login-error {
  color: var(--red);
  font-size: 13px;
  margin: -4px 0 12px;
}
.btn {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  border-radius: 12px;
  padding: 0 16px;
  height: 44px;
  font-size: 14px;
  transition: transform .12s, opacity .15s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn.primary {
  width: 100%;
  background: linear-gradient(135deg, #38bdf8, #6366f1);
  color: #fff;
  margin-top: 6px;
  box-shadow: 0 8px 24px rgba(56,189,248,.25);
}
.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  height: 38px;
}
.btn.ghost:hover { background: rgba(255,255,255,.04); }
.btn.danger { color: var(--red); border-color: rgba(248,113,113,.35); }

/* ========== Dashboard ========== */
.dash { min-height: 100dvh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  background: rgba(11, 18, 32, 0.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-title { font-weight: 800; font-size: 16px; letter-spacing: -.02em; }
.topbar-sub { font-size: 12px; color: var(--muted); }
.topbar-right { display: flex; gap: 8px; }
.live-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(52, 211, 153, .6);
  animation: pulse 1.6s infinite;
}
.live-dot.off { background: var(--red); animation: none; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(52,211,153,.55); }
  70% { box-shadow: 0 0 0 10px rgba(52,211,153,0); }
  100% { box-shadow: 0 0 0 0 rgba(52,211,153,0); }
}

.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
@media (min-width: 720px) {
  .kpi-row { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1100px) {
  .kpi-row { grid-template-columns: repeat(6, 1fr); }
}
.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.kpi-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
}
.kpi-value {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1.1;
}
.kpi-value.accent { color: var(--green); }
.kpi-hint {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.panel-head h2 {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -.02em;
}
.badge {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  color: #052e1c;
  background: var(--green);
  padding: 4px 8px;
  border-radius: 999px;
}
.muted { color: var(--muted); font-size: 12px; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
  font-size: 13px;
}
.table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 700;
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 12px 10px;
  border-bottom: 1px solid rgba(148,163,184,.08);
  vertical-align: middle;
}
.table tbody tr:hover { background: rgba(255,255,255,.02); }
.table .empty, .feed .empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
}
.name-cell { font-weight: 700; }
.handle { color: var(--muted); font-size: 12px; }
.url a {
  color: var(--accent);
  text-decoration: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}
.url a:hover { text-decoration: underline; }
.num { font-variant-numeric: tabular-nums; font-weight: 700; }
.num.live { color: var(--green); font-size: 16px; }
.num.click { color: var(--orange); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(52,211,153,.12);
  color: var(--green);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
}
.chip.off {
  background: rgba(148,163,184,.1);
  color: var(--muted);
}

.ip-row {
  margin-top: 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 260px;
}
.ip-tag {
  display: inline-block;
  background: rgba(129,140,248,.12);
  color: var(--purple);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  line-height: 1.4;
  white-space: nowrap;
}
.geo-tag {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  background: rgba(56,189,248,.1);
  color: var(--accent);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .02em;
  line-height: 1.4;
  white-space: nowrap;
}
.visitor-row {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin: 1px 2px 1px 0;
}

.feed {
  list-style: none;
  max-height: 420px;
  overflow-y: auto;
}
.feed li {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 10px 4px;
  border-bottom: 1px solid rgba(148,163,184,.08);
  font-size: 13px;
}
.feed li:last-child { border-bottom: none; }
.ev-type {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .04em;
  border-radius: 8px;
  padding: 4px 8px;
  text-align: center;
  align-self: center;
}
.ev-type.view { background: rgba(56,189,248,.15); color: var(--accent); }
.ev-type.click { background: rgba(251,191,36,.15); color: var(--orange); }
.ev-main { min-width: 0; }
.ev-title { font-weight: 700; }
.ev-meta { color: var(--muted); font-size: 12px; word-break: break-all; }
.ev-meta .ip-tag { font-size: 10px; vertical-align: middle; }
.ev-time {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  align-self: center;
}


/* ========== Chat monitoring ========== */
.badge.hot {
  background: rgba(248, 113, 113, .18);
  color: #fca5a5;
  border-color: rgba(248, 113, 113, .35);
}
.chip.hot {
  background: #ef4444;
  color: #fff;
  border-color: transparent;
}
.chat-feed {
  list-style: none;
  max-height: 480px;
  overflow-y: auto;
  padding: 4px 2px;
}
.chat-feed-item {
  display: grid;
  gap: 6px;
  padding: 12px 10px;
  border-bottom: 1px solid rgba(148, 163, 184, .1);
  border-radius: 10px;
  transition: background .15s;
}
.chat-feed-item:last-child { border-bottom: none; }
.chat-feed-item:hover {
  background: rgba(56, 189, 248, .06);
}
.chat-feed-item.has-unread {
  background: rgba(248, 113, 113, .06);
  box-shadow: inset 3px 0 0 #ef4444;
}
.chat-feed-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.chat-feed-mgr {
  font-weight: 800;
  font-size: 13px;
}
.chat-feed-handle {
  color: var(--muted);
  font-size: 12px;
}
.chat-feed-time {
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}
.chat-feed-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.chat-feed-visitor {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}
.chat-feed-preview {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-feed-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}

[hidden] { display: none !important; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; }
  .kpi-value { font-size: 24px; }
  .feed li { grid-template-columns: 64px 1fr; }
  .ev-time { grid-column: 2; }
}
