:root {
  --bg: #07070c;
  --card: #12121a;
  --card2: #0e0e16;
  --border: #2a2a38;
  --text: #ececf4;
  --muted: #8b8ba3;
  --accent: #6366f1;
  --accent2: #22d3ee;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 14px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "SF Pro Text", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.45;
}
.bg-glow {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(ellipse 70% 45% at 20% -10%, rgba(99, 102, 241, 0.2), transparent),
    radial-gradient(ellipse 50% 40% at 90% 10%, rgba(34, 211, 238, 0.12), transparent);
}
.wrap { position: relative; z-index: 1; max-width: 1180px; margin: 0 auto; padding: 1.25rem 1rem 2.5rem; }
header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.25rem; flex-wrap: wrap; gap: 0.75rem;
}
.logo-lockup {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  user-select: none;
}
.logo-mark {
  display: block;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}
.logo-text {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--text);
  line-height: 1;
}
.logo-k { color: var(--accent2); }
.login-box .logo-lockup {
  justify-content: center;
  margin-bottom: 0.15rem;
}
.login-box .logo-mark {
  width: 40px;
  height: 40px;
}
.login-tagline {
  text-align: center;
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.25rem;
}
.user-pill {
  font-size: 0.8rem; color: var(--muted);
  padding: 0.35rem 0.65rem; border-radius: 999px;
  background: var(--card2); border: 1px solid var(--border);
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.2rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.card h2 {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--muted); margin-bottom: 0.85rem; font-weight: 600;
}
.stats-lead {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
  margin: -0.35rem 0 0.65rem;
}
.stats-card-compact h2 { margin-bottom: 0.35rem; }
.stats-note {
  font-size: 0.68rem;
  color: var(--muted);
  margin: -0.2rem 0 0.5rem;
}
.stats-compact {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
}
@media (min-width: 520px) {
  .stats-compact { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
@media (min-width: 900px) {
  .stats-compact { grid-template-columns: repeat(9, minmax(0, 1fr)); }
}
.stat-c {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.35rem;
  text-align: center;
  cursor: default;
}
.stat-c-today {
  border-color: rgba(34, 211, 238, 0.3);
}
.stat-c b {
  display: block;
  font-size: clamp(1rem, 2.2vw, 1.2rem);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stat-c b.accent { color: var(--accent2); }
.stat-c b.ok { color: var(--ok); }
.stat-c > span {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.62rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  line-height: 1.2;
}
.stat-c > em {
  display: block;
  margin-top: 0.1rem;
  font-size: 0.62rem;
  font-style: normal;
  color: var(--ok);
  font-variant-numeric: tabular-nums;
}
.chart-refresh-hint {
  font-size: 0.65rem;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
  font-weight: 400;
}
.geo-layout {
  display: grid;
  gap: 0.85rem;
}
@media (min-width: 820px) {
  .geo-layout {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}
.geo-tops {
  display: grid;
  gap: 0.75rem;
  min-width: 0;
}
@media (min-width: 520px) {
  .geo-tops { grid-template-columns: 1fr 1fr; }
}
.geo-side { min-width: 0; }
.geo-side .chart-title { margin-bottom: 0.35rem; }
.geo-top-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: 220px;
  overflow-y: auto;
}
.geo-row {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  font-size: 0.78rem;
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
  background: var(--card2);
  border: 1px solid var(--border);
}
.geo-rank {
  flex: 0 0 1.1rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: center;
  line-height: 1.35;
  font-size: 0.72rem;
}
.geo-main {
  flex: 1;
  min-width: 0;
}
.geo-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}
.geo-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.35;
}
.geo-bar-wrap {
  margin-top: 0.3rem;
  height: 4px;
  background: #1a1a28;
  border-radius: 999px;
  overflow: hidden;
}
.geo-bar {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 999px;
  min-width: 2px;
}
.geo-num {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  white-space: nowrap;
  font-size: 0.75rem;
  line-height: 1.35;
}
.geo-num small {
  margin-left: 0.25rem;
  color: var(--muted);
  font-weight: 400;
  font-size: 0.68rem;
}
.geo-empty {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
  padding: 0.5rem 0;
}
.live-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 10px var(--ok);
  animation: pulse 2s ease infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
.charts-section { display: grid; gap: 0.85rem; }
.chart-panel {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.65rem 0.5rem 0.25rem;
  min-height: 0;
}
.chart-panel .chart-title {
  font-size: 0.72rem;
  color: var(--muted);
  padding: 0 0.5rem 0.35rem;
  letter-spacing: 0.04em;
}
.chart-box { width: 100%; height: 240px; }
.chart-box.tall { height: 280px; }
.chart-box.compact { height: 200px; }
@media (min-width: 820px) {
  .charts-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.85rem;
  }
  .charts-row-3 {
    display: grid;
    grid-template-columns: 1.2fr 0.9fr 0.9fr;
    gap: 0.85rem;
  }
}
input, button, select {
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0a0a12;
  color: var(--text);
  padding: 0.55rem 0.75rem;
}
input { width: 100%; }
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}
button {
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  border: none;
  font-weight: 600;
  white-space: nowrap;
}
button:disabled { opacity: 0.5; cursor: wait; }
button.secondary {
  background: transparent;
  border: 1px solid var(--border);
  font-weight: 500;
}
button.danger { background: #991b1b; border: none; }
.form-row { display: grid; gap: 0.35rem; margin-bottom: 0.5rem; }
.form-row label { font-size: 0.72rem; color: var(--muted); }
.form-grid {
  display: grid;
  gap: 0.65rem;
  align-items: end;
}
@media (min-width: 600px) {
  .form-grid { grid-template-columns: 1fr 2fr auto; }
}
.links-table-wrap { overflow-x: auto; margin: 0 -0.25rem; }
table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
th, td {
  text-align: left;
  padding: 0.55rem 0.45rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th { color: var(--muted); font-weight: 500; font-size: 0.72rem; }
td.num {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}
.link-cell {
  max-width: 0;
  width: 28%;
  min-width: 140px;
}
a.link-url {
  display: block;
  color: var(--accent2);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
a.link-url:hover { text-decoration: underline; }
.status-cell { white-space: nowrap; }
.col-actions,
.actions-cell {
  width: 112px;
  padding-left: 0.25rem;
  padding-right: 0.25rem;
}
.modal-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.85rem;
  line-height: 1.4;
}
.edit-preview em {
  color: var(--accent2);
  font-style: normal;
  font-weight: 500;
}
.row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  background: var(--card2);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn:hover {
  color: var(--text);
  border-color: #3d3d52;
}
.icon-btn.danger {
  font-size: 1.1rem;
  line-height: 1;
  font-weight: 400;
}
.icon-btn.danger:hover {
  color: #fecaca;
  border-color: #991b1b;
  background: #450a0a;
}
.btn-copy .icon-done { display: none; }
.btn-copy.copied {
  border-color: var(--ok);
  color: var(--ok);
  background: rgba(52, 211, 153, 0.12);
}
.btn-copy.copied .icon-copy { display: none; }
.btn-copy.copied .icon-done { display: block; }
.target-cell {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.78rem;
}
/* Toggle switch */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  user-select: none;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-track {
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: #2d2d3d;
  border: 1px solid var(--border);
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}
.switch-thumb {
  display: block;
  width: 18px;
  height: 18px;
  margin: 2px;
  border-radius: 50%;
  background: #6b6b80;
  transition: transform 0.2s, background 0.2s;
}
.switch input:checked + .switch-track {
  background: rgba(52, 211, 153, 0.25);
  border-color: var(--ok);
}
.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(20px);
  background: var(--ok);
}
.switch input:disabled + .switch-track { opacity: 0.5; }
.switch-label {
  font-size: 0.72rem;
  color: var(--muted);
  min-width: 2.5rem;
}
.switch input:checked ~ .switch-label { color: var(--ok); }
.badge {
  font-size: 0.68rem;
  padding: 0.12rem 0.4rem;
  border-radius: 6px;
  background: #1a1a28;
  display: inline-block;
}
.badge.on { color: var(--ok); }
.badge.off { color: var(--err); }
.feed {
  max-height: 280px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.feed-wide {
  max-height: 320px;
}
.feed-empty {
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0.5rem;
}
.feed-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.38rem 0.5rem;
  border-radius: 8px;
  background: var(--card2);
  border: 1px solid var(--border);
  font-size: 0.75rem;
  line-height: 1.25;
  white-space: nowrap;
  min-width: min(100%, 52rem);
}
.feed-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
}
.feed-link {
  flex: 0 0 auto;
  max-width: 11rem;
  overflow: hidden;
  text-overflow: ellipsis;
}
.feed-link strong { color: var(--text); font-weight: 600; }
.feed-badge {
  flex: 0 0 auto;
  font-size: 0.65rem;
  min-width: 2.2rem;
  text-align: center;
}
.feed-chip {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.68rem;
}
.feed-geo {
  max-width: 10rem;
  overflow: hidden;
  text-overflow: ellipsis;
}
.feed-lat {
  color: var(--accent2);
  font-variant-numeric: tabular-nums;
}
.feed-ref {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
  font-size: 0.68rem;
}
.feed-item {
  padding: 0.5rem 0.55rem;
  border-radius: 8px;
  background: var(--card2);
  border: 1px solid var(--border);
  font-size: 0.78rem;
}
.feed-item strong { color: var(--text); }
.feed-meta { color: var(--muted); font-size: 0.72rem; margin-top: 0.15rem; }
.login-box { max-width: 380px; margin: 4rem auto; }
.err { color: var(--err); font-size: 0.85rem; margin-top: 0.5rem; }
.hidden { display: none !important; }
.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal .card { max-width: 400px; width: 100%; margin: 0; }
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: end;
  margin-bottom: 0.85rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.filter-bar .form-row { margin: 0; min-width: 120px; }
.admin-tabs { display: flex; gap: 0.4rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.admin-tabs .tab.active { border-color: var(--accent); color: var(--accent2); }
.link-extra {
  margin: 0.65rem 0;
  padding: 0.5rem 0;
  border-top: 1px solid var(--border);
}
.link-extra summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 0.5rem;
}
select { width: 100%; }
.links-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1rem;
}
