/* TG Admin. Dark-first, Telegram blue for actions, VIP gold for VIP and Stars.
   Layout: left rail on desktop, bottom tab bar on phones. Tokens: docs/ADMIN_PANEL.md §5. */
:root {
  --bg: #0b0f17;
  --surface: #121826;
  --surface-2: #1a2233;
  --border: #263045;
  --text: #e6eaf2;
  --muted: #8a94a8;
  --primary: #2aabee;
  --primary-ink: #04121c;
  --vip: #f5b83d;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --font-ui:
    system-ui, -apple-system, 'Segoe UI', 'Noto Sans Armenian', 'Noto Sans', Roboto, sans-serif;
  --font-num: ui-monospace, 'SF Mono', 'Cascadia Mono', Consolas, 'Roboto Mono', monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-2: #f0f2f7;
    --border: #e3e7ef;
    --text: #0f172a;
    --muted: #5b6577;
    --primary: #1d8fd0;
    --primary-ink: #ffffff;
    --vip: #b07607;
    --success: #15803d;
    --warning: #b45309;
    --danger: #b91c1c;
    color-scheme: light;
  }
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
button,
input,
select {
  font: inherit;
  color: inherit;
}
a {
  color: var(--primary);
}
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}
.muted {
  color: var(--muted);
}
.boot {
  padding: 24px;
  color: var(--muted);
}
[hidden] {
  display: none !important;
}

/* ---------- Login ---------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px max(16px, env(safe-area-inset-left));
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login-card h1 {
  margin: 0;
  font-size: 22px;
}
.login-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 15px;
}
.input:disabled {
  opacity: 0.6;
}
.input.code {
  font-family: var(--font-num);
  letter-spacing: 0.4em;
  font-size: 22px;
  text-align: center;
}
.error {
  color: var(--danger);
  font-size: 14px;
}
.btn {
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14px;
}
.btn:hover {
  background: var(--surface-2);
}
.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
  font-weight: 600;
}
.btn.primary:hover {
  filter: brightness(1.08);
}
.btn:disabled {
  opacity: 0.55;
  cursor: default;
}
.btn.small {
  padding: 4px 10px;
  font-size: 13px;
}

/* ---------- Shell ---------- */
.shell {
  display: grid;
  grid-template-columns: 228px minmax(0, 1fr);
  min-height: 100vh;
}
.rail {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  padding: 0 6px;
}
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--primary);
  color: var(--primary-ink);
  display: grid;
  place-items: center;
  font-family: var(--font-num);
  font-size: 12px;
}
.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.nav a:hover {
  background: var(--surface-2);
  color: var(--text);
}
.nav a.active {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: inset 2px 0 0 var(--primary);
}
.badge {
  font-family: var(--font-num);
  font-size: 12px;
  color: var(--warning);
}
.who {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding: 14px 6px 0;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.who b {
  color: var(--text);
}
.role {
  align-self: flex-start;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--vip);
  border: 1px solid var(--vip);
  border-radius: 4px;
  padding: 0 6px;
}

main {
  padding: 24px max(16px, env(safe-area-inset-right)) 96px max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 1200px;
  width: 100%;
  min-width: 0;
}
.head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
}
h1 {
  margin: 0;
  font-size: 24px;
}
h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.kpi .label {
  font-size: 12px;
  color: var(--muted);
}
.kpi .value {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: 26px;
  font-weight: 600;
  line-height: 1.25;
}
.kpi .note {
  font-size: 12px;
  color: var(--muted);
}
.kpi.vip .value {
  color: var(--vip);
}
.kpi.warn .value {
  color: var(--warning);
}
.kpi.good .value {
  color: var(--success);
}
a.kpi {
  text-decoration: none;
  color: inherit;
}
a.kpi:hover {
  border-color: var(--primary);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.panel-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.chart svg {
  width: 100%;
  height: auto;
  display: block;
}
.chart text {
  fill: var(--muted);
  font-family: var(--font-num);
  font-size: 10px;
}
.chart .grid {
  stroke: var(--border);
}
.chart .bar {
  fill: var(--primary);
  opacity: 0.55;
}
.chart .bar.vip {
  fill: var(--vip);
}
.chart .bar.last {
  opacity: 1;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.toolbar .input {
  max-width: 260px;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
}
.chip.on {
  border-color: var(--primary);
  color: var(--text);
  background: var(--surface-2);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th {
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
  padding: 10px 12px;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 9px 12px;
  border-top: 1px solid var(--border);
  white-space: nowrap;
  vertical-align: middle;
}
tbody tr:first-child td {
  border-top: 0;
}
td.num,
th.num {
  text-align: right;
}
.empty {
  padding: 28px;
  text-align: center;
  color: var(--muted);
}
.more {
  display: flex;
  justify-content: center;
}

.pill {
  display: inline-block;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 2px 8px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
}
.pill.ok {
  color: var(--success);
}
.pill.warn {
  color: var(--warning);
}
.pill.bad {
  color: var(--danger);
}
.pill.vip {
  color: var(--vip);
}
.pill.info {
  color: var(--primary);
}

/* ---------- Settings ---------- */
.plans td {
  white-space: normal;
}
.plans .input {
  padding: 6px 8px;
  font-size: 14px;
  min-width: 90px;
}
.plans .input.n {
  max-width: 96px;
  font-family: var(--font-num);
}
.switch {
  position: relative;
  display: inline-flex;
  cursor: pointer;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.switch span {
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  transition: background 0.15s;
}
.switch span::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 0.15s;
}
.switch input:checked + span {
  background: var(--primary);
}
.switch input:checked + span::after {
  transform: translateX(16px);
  background: var(--primary-ink);
}
.switch input:focus-visible + span {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.switch input:disabled + span {
  opacity: 0.5;
}
.preview {
  display: inline-block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px 10px;
  font-size: 13px;
}
.preview.hot {
  border-color: var(--vip);
}
.star {
  color: var(--vip);
}
.ref {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
}
.ref .input {
  max-width: 110px;
  font-family: var(--font-num);
}
.sentence {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
}
.confirm {
  border: 1px solid var(--warning);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 14px;
}
.confirm ul {
  margin: 0;
  padding-left: 18px;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
}
.toast {
  color: var(--success);
  font-size: 14px;
}
.issues {
  margin: 0;
  padding-left: 18px;
  color: var(--danger);
  font-size: 13px;
}
.notice {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
}

.health {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

/* ---------- Phone ---------- */
.tabbar {
  display: none;
}
.sheet {
  display: none;
}
@media (max-width: 760px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .rail {
    display: none;
  }
  .grid-2 {
    grid-template-columns: minmax(0, 1fr);
  }
  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .kpi .value {
    font-size: 22px;
  }
  main {
    padding-top: 16px;
  }
  .tabbar {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 6px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }
  .tabbar a,
  .tabbar button {
    background: none;
    border: 0;
    color: var(--muted);
    text-decoration: none;
    font-size: 10.5px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 4px 0;
    cursor: pointer;
  }
  .tabbar svg {
    width: 21px;
    height: 21px;
  }
  .tabbar .active {
    color: var(--primary);
  }
  .sheet.open {
    display: flex;
    flex-direction: column;
    gap: 2px;
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(64px + env(safe-area-inset-bottom));
    z-index: 11;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px;
  }
  .sheet a,
  .sheet button {
    color: var(--text);
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 8px;
    background: none;
    border: 0;
    text-align: left;
    font-size: 15px;
  }
  .sheet a:hover,
  .sheet button:hover {
    background: var(--surface-2);
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
