/* ========================================================================
   Маркеты · панель управления — тёмная тема, mobile-first.
   Цвета подхватываются из Telegram theme params (см. app.js), с фолбэком.
   ======================================================================== */
:root {
  --bg: #0e1117;
  --bg-elev: #161b24;
  --bg-elev-2: #1d2430;
  --card: #161b24;
  --border: #28303d;
  --text: #e8ecf2;
  --text-dim: #8b97a8;
  --accent: #3d8bfd;
  --accent-ink: #ffffff;
  --good: #2fb872;
  --bad: #e5484d;
  --warn: #e0a234;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 8px 28px rgba(0, 0, 0, .38);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

button, input, select { font-family: inherit; font-size: inherit; }
input, select { color-scheme: dark; }

/* ---- Topbar ------------------------------------------------------------ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top, 0)) 16px 12px;
  background: rgba(14, 17, 23, .92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  font-size: 20px;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: linear-gradient(150deg, #3d8bfd, #6f5bff);
  border-radius: 10px;
}
.brand-text { display: flex; flex-direction: column; font-weight: 700; line-height: 1.15; }
.brand-sub { font-size: 11px; font-weight: 500; color: var(--text-dim); letter-spacing: .02em; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }
.portals-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--text-dim);
  box-shadow: 0 0 0 3px rgba(139, 151, 168, .15);
}
.portals-dot.is-on { background: var(--good); box-shadow: 0 0 0 3px rgba(47, 184, 114, .18); }
.portals-dot.is-off { background: var(--bad); box-shadow: 0 0 0 3px rgba(229, 72, 77, .18); }

.icon-btn {
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 10px;
  font-size: 17px;
  cursor: pointer;
  transition: transform .12s ease, background .12s ease;
}
.icon-btn:active { transform: scale(.92); }
.icon-btn.is-spinning { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Tabs -------------------------------------------------------------- */
.tabs {
  position: sticky;
  top: calc(59px + env(safe-area-inset-top, 0));
  z-index: 15;
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  padding: 8px 15px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-dim);
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  transition: color .12s ease, background .12s ease, border-color .12s ease;
}
.tab.is-active {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

/* ---- Layout ------------------------------------------------------------ */
.app { padding: 14px 12px 40px; max-width: 720px; margin: 0 auto; }
.panel { display: none; flex-direction: column; gap: 14px; }
.panel.is-active { display: flex; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-dim);
  margin: 0 0 12px;
}
.card-title .count {
  margin-left: auto;
  font-size: 12px;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  padding: 2px 9px;
  border-radius: 999px;
  letter-spacing: 0;
  text-transform: none;
}
.card-hint { color: var(--text-dim); font-size: 12.5px; margin: 10px 0 0; }

/* ---- Hero (buys toggle) ------------------------------------------------ */
.hero {
  background: linear-gradient(155deg, var(--bg-elev-2), var(--card));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.hero-row { display: flex; align-items: center; gap: 14px; }
.hero-state { flex: 1; min-width: 0; }
.hero-label { font-size: 12px; color: var(--text-dim); letter-spacing: .04em; text-transform: uppercase; }
.hero-value { font-size: 22px; font-weight: 800; margin-top: 2px; }
.hero-value.on { color: var(--good); }
.hero-value.off { color: var(--bad); }
.hero-sub { font-size: 12.5px; color: var(--text-dim); margin-top: 6px; }

/* ---- Switch ------------------------------------------------------------ */
.switch { position: relative; flex: 0 0 auto; width: 60px; height: 34px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track {
  position: absolute; inset: 0;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background .16s ease;
}
.switch .thumb {
  position: absolute; top: 3px; left: 3px;
  width: 28px; height: 28px;
  background: #fff;
  border-radius: 50%;
  transition: transform .18s cubic-bezier(.3,.9,.4,1.2);
}
.switch input:checked ~ .track { background: var(--good); border-color: var(--good); }
.switch input:checked ~ .thumb { transform: translateX(26px); }
.switch.is-danger input:checked ~ .track { background: var(--bad); border-color: var(--bad); }

/* ---- Forms ------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.form-grid { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; }
.row > * { min-width: 0; }
.row .grow { flex: 1; }

input[type=text], input[type=number], select {
  width: 100%;
  padding: 11px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  transition: border-color .12s ease;
}
input::placeholder { color: #5b6675; }
input:focus, select:focus { border-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: var(--radius-sm);
  font-weight: 700;
  cursor: pointer;
  transition: transform .1s ease, opacity .12s ease, filter .12s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--bg-elev); color: var(--text); border-color: var(--border); }
.btn.danger { background: var(--bad); border-color: var(--bad); }
.btn.full { width: 100%; }
.btn.sm { padding: 8px 13px; font-size: 13px; }

/* ---- Lists ------------------------------------------------------------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 600; word-break: break-word; }
.item-sub { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; word-break: break-word; }
.item-price {
  flex: 0 0 auto;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.pill {
  flex: 0 0 auto;
  font-size: 12px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px;
  background: var(--bg-elev-2); color: var(--text-dim);
}
.pill.good { background: rgba(47,184,114,.16); color: var(--good); }
.pill.warn { background: rgba(224,162,52,.16); color: var(--warn); }
.del-btn {
  flex: 0 0 auto;
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--bad);
  border-radius: 9px;
  font-size: 16px;
  cursor: pointer;
  transition: background .12s ease, transform .1s ease;
}
.del-btn:active { transform: scale(.9); }
.empty { color: var(--text-dim); font-size: 13px; text-align: center; padding: 14px 0; }

.divider { height: 1px; background: var(--border); margin: 4px 0; border: 0; }
.section-sub {
  font-size: 12px; font-weight: 700; letter-spacing: .03em;
  color: var(--text-dim); text-transform: uppercase;
  margin: 2px 0 2px;
}

/* ---- Gate (auth / loading) -------------------------------------------- */
.gate {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  padding: 24px;
  background: var(--bg);
}
.gate.is-hidden { display: none; }
.gate-card {
  width: 100%; max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 22px;
  text-align: center;
  box-shadow: var(--shadow);
}
.gate-spinner {
  width: 34px; height: 34px;
  margin: 0 auto 16px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.gate.error .gate-spinner, .gate.denied .gate-spinner { display: none; }
.gate-title { font-size: 18px; font-weight: 800; }
.gate-text { color: var(--text-dim); font-size: 13.5px; margin-top: 8px; }
.gate-id {
  margin-top: 16px;
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px;
}
.gate-id code { flex: 1; font-size: 17px; font-weight: 800; color: var(--text); }

/* ---- Toasts ------------------------------------------------------------ */
.toasts {
  position: fixed; left: 0; right: 0; z-index: 200;
  bottom: calc(16px + env(safe-area-inset-bottom, 0));
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.toast {
  max-width: 90vw;
  padding: 11px 16px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 13.5px; font-weight: 600;
  animation: toastIn .22s ease;
}
.toast.good { border-color: rgba(47,184,114,.5); }
.toast.bad { border-color: rgba(229,72,77,.5); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
