:root {
  --bg: #07080c;
  --ink: #f6f3ec;
  --muted: #8d8c96;
  --line: rgba(255, 255, 255, 0.08);
  --card: rgba(16, 18, 24, 0.72);
  --mint: #7dffb3;
  --gold: #ffd166;
  --rose: #ff8fab;
  --blue: #8ab4ff;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --radius: 22px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  --tg-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  letter-spacing: -0.02em;
}
button, input { font: inherit; }

.bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(125, 255, 179, 0.12), transparent 55%),
    radial-gradient(900px 500px at 110% 10%, rgba(255, 209, 102, 0.1), transparent 50%),
    linear-gradient(#07080c, #0b0d13 60%);
}
.orb {
  position: absolute;
  width: 42vw;
  height: 42vw;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.35;
  animation: drift 18s ease-in-out infinite;
}
.orb-a { left: -8%; top: 18%; background: #173328; }
.orb-b { right: -12%; top: -8%; background: #3a2a12; animation-delay: -8s; }
@keyframes drift {
  50% { transform: translate(6%, 8%) scale(1.12); }
}

#login, #app, #boot { position: relative; z-index: 1; }
#login[hidden], #app[hidden], #boot[hidden] { display: none !important; }
#app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 18px 64px;
  animation: rise 0.45s ease;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 26px 24px 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}
.login-card:hover {
  transform: translateY(-3px);
  border-color: rgba(125, 255, 179, 0.28);
  box-shadow: 0 28px 90px rgba(0,0,0,0.55);
}
.login-card h1, #app h1, .card h2, .admin h2 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.04em;
}
.login-card h1 { font-size: 34px; }
.lead { color: var(--muted); line-height: 1.45; margin: 10px 0 22px; }
.lead code {
  color: var(--gold);
  background: rgba(255, 209, 102, 0.08);
  padding: 1px 6px;
  border-radius: 8px;
}
.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 11px;
  color: var(--mint);
}
label { display: grid; gap: 8px; margin-bottom: 14px; color: var(--muted); font-size: 13px; }
input {
  width: 100%;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 14px;
  padding: 13px 14px;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}
input:hover { border-color: rgba(255,255,255,0.16); }
input:focus { border-color: rgba(125, 255, 179, 0.55); background: rgba(125,255,179,0.04); }
.login-card button, .ghost {
  border: 0;
  cursor: pointer;
  border-radius: 14px;
  transition: transform 0.15s ease, filter 0.15s ease, background 0.2s ease;
}
.login-card button {
  width: 100%;
  margin-top: 4px;
  padding: 13px 16px;
  background: linear-gradient(180deg, #b6ffd4, var(--mint));
  color: #082214;
  font-weight: 700;
}
.login-card button:hover { filter: brightness(1.06); transform: translateY(-1px); }
.login-card button:active { transform: translateY(1px); }
.err { color: var(--rose); font-size: 13px; margin: 0 0 8px; }

.top {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin-bottom: 14px;
}
#who { font-size: 26px; }
.ghost {
  background: rgba(255,255,255,0.04);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 8px 12px;
}
.ghost:hover { background: rgba(255,255,255,0.08); }

.kpis {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}
.kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 12px 11px;
  min-width: 0;
  cursor: default;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.kpi:hover {
  border-color: rgba(125, 255, 179, 0.28);
  background: rgba(20, 24, 32, 0.88);
}
.kpi span {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 6px;
  min-width: 0;
}
.kpi span .t {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kpi b {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.05em;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
}
.kpi em {
  display: block;
  margin-top: 5px;
  font-style: normal;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi.mint b { color: var(--mint); }
.kpi.gold b { color: var(--gold); }
.kpi.blue b { color: var(--blue); }
.kpi.rose b { color: var(--rose); }

.strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
}
.strip b { color: var(--ink); font-weight: 650; }
.strip .sep { opacity: 0.35; }

.grid {
  display: grid;
  grid-template-columns: 1.7fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}
.admin-grid { grid-template-columns: 1.1fr 0.9fr 1fr; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 14px 12px;
  margin-bottom: 10px;
  transition: border-color 0.2s ease;
}
.card:hover { border-color: rgba(255,255,255,0.14); }
.grid .card { margin-bottom: 0; }
.span-2 { grid-column: span 1 / span 1; }
.grid .span-2 { grid-column: 1; }
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
}
.card h2 { font-size: 15px; display: flex; align-items: center; gap: 6px; }
.muted { color: var(--muted); font-size: 11px; margin: 0; }

.funnel {
  display: flex;
  align-items: stretch;
  gap: 8px;
  flex-wrap: wrap;
}
.fn-step, .fn-gap {
  border-radius: 14px;
  padding: 10px 12px;
  min-width: 110px;
  flex: 1;
}
.fn-step {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--line);
}
.fn-step:hover { border-color: rgba(125, 255, 179, 0.3); }
.fn-step .lbl {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
}
.fn-step b {
  display: block;
  margin-top: 4px;
  font-size: 22px;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.fn-gap {
  display: grid;
  place-items: center;
  min-width: 72px;
  flex: 0.4;
  color: var(--gold);
  font-weight: 700;
  padding: 8px 4px;
}
.fn-gap small { display: block; color: var(--muted); font-weight: 500; font-size: 10px; text-align: center; }

.chart {
  display: flex;
  align-items: stretch;
  gap: 3px;
  height: 148px;
  padding-top: 4px;
  padding-bottom: 18px;
}
.chart.days { height: 128px; }
.bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: end;
  align-items: center;
  gap: 4px;
  min-width: 0;
  position: relative;
  cursor: pointer;
}
.bar i {
  display: block;
  width: 100%;
  border-radius: 6px 6px 3px 3px;
  background: linear-gradient(180deg, #b9ffd8, #3d8f64);
  min-height: 4px;
  transform-origin: bottom;
  animation: grow 0.7s cubic-bezier(.2,.8,.2,1) both;
  transition: filter 0.15s ease, background 0.15s ease;
}
.bar:hover i { filter: brightness(1.18); }
.bar.active i { background: linear-gradient(180deg, #ffe7a3, var(--gold)); }
.bar small {
  position: absolute;
  bottom: -16px;
  color: var(--muted);
  font-size: 9px;
  line-height: 1;
  white-space: nowrap;
}
@keyframes grow {
  from { transform: scaleY(0.08); opacity: 0.3; }
}

.geo-card { margin-bottom: 10px; }
.geo-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 28px;
}
.geo { display: grid; gap: 2px; }
.geo-row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) 44px auto;
  gap: 8px;
  align-items: center;
  padding: 4px 6px;
  margin: 0 -6px;
  border-radius: 10px;
  cursor: default;
  min-width: 0;
}
.geo-row:hover { background: rgba(255,255,255,0.05); }
.apple-emoji {
  width: 16px;
  height: 16px;
  object-fit: contain;
  flex: 0 0 auto;
  display: inline-block;
  vertical-align: -3px;
  pointer-events: none;
}
.apple-emoji.flag {
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: none;
  overflow: visible;
}
.kpi .apple-emoji { width: 14px; height: 14px; }
.geo-meta { min-width: 0; }
.geo-meta b {
  display: block;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.geo-bar {
  height: 3px;
  border-radius: 99px;
  background: rgba(255,255,255,0.06);
  margin-top: 4px;
  overflow: hidden;
}
.geo-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #7dffb3, #ffd166);
  border-radius: 99px;
  transform-origin: left;
  animation: growX 0.7s ease both;
}
@keyframes growX { from { transform: scaleX(0); } }
.geo-share {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.geo-count {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  font-size: 12px;
  color: var(--ink);
  text-align: right;
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  padding: 0 8px 8px;
  white-space: nowrap;
}
td {
  padding: 7px 8px;
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
  vertical-align: middle;
}
tr:hover td { background: rgba(255,255,255,0.03); }
.bot-name { font-weight: 650; }
.good { color: var(--mint); }
.warn { color: var(--gold); }
.bad { color: var(--rose); }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  max-width: 180px;
}
.pill span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin { margin-top: 6px; }
.rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.rank li {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 5px 6px;
  margin: 0 -6px;
  border-radius: 10px;
}
.rank li:hover { background: rgba(255,255,255,0.05); }
.rank .n {
  width: 22px; height: 22px;
  display: grid; place-items: center;
  border-radius: 7px;
  background: rgba(255,255,255,0.05);
  color: var(--gold);
  font-weight: 700;
  font-size: 11px;
}
.rank b {
  display: block;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rank strong { font-variant-numeric: tabular-nums; font-size: 13px; }

.empty { color: var(--muted); padding: 12px 0; font-size: 12px; }

#tip {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  background: rgba(12, 14, 18, 0.96);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.4;
  box-shadow: var(--shadow);
  max-width: 220px;
}
#tip[hidden] { display: none !important; }
#tip b { color: var(--mint); }

body.in-tg #logout { display: none; }
body.in-tg #app {
  padding-top: calc(12px + var(--tg-top));
}
body.in-tg .login-wrap { min-height: 100dvh; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .admin-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .grid, .geo-cols, .admin-grid { grid-template-columns: 1fr; }
  .grid .span-2 { grid-column: auto; }
}
@media (max-width: 640px) {
  #app { padding: 14px 12px 40px; }
  #who { font-size: 22px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .chart { height: 132px; }
  .login-card { padding: 26px 20px; }
  .fn-gap { min-width: 100%; flex: 1 1 100%; padding: 2px 0; }
}
