:root {
  /* Trace-X navy palette (matches the main site) */
  --bg: #03061a;
  --bg-panel: #060d2e;
  --bg-panel-2: #0a1650;
  --border: rgba(37, 99, 235, 0.25);
  --text: #f5f5f5;
  --text-dim: #94a3b8;
  --accent: #2563eb;
  --accent-hover: #3b82f6;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --radius: 10px;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Prevent horizontal scroll on mobile. This is set on <html>, not <body>:
     overflow-x on body forces the browser to also compute its overflow-y as
     "auto", turning body into its own nested scroll container. That breaks
     position:sticky (the topbar) and can make touch/tap handling flaky on
     mobile (menus/buttons stop responding). */
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
}

img { max-width: 100%; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ---------- Topbar ---------- */
.topbar {
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 28px;
}
.brand { font-weight: 700; font-size: 18px; color: var(--text); display: flex; align-items: center; flex-shrink: 0; }
.brand span { color: var(--accent); }
.brand-logo { height: 40px; width: 40px; object-fit: contain; display: block; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  display: inline-block;
  color: var(--text-dim);
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 500;
  white-space: nowrap;
}
.nav a:hover { color: var(--text); background: var(--bg-panel-2); }
.nav a.active { color: var(--text); background: var(--bg-panel-2); }
.topbar-right { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.username { color: var(--text-dim); font-size: 13px; }
.username em { color: var(--accent); font-style: normal; }

.nav-toggle {
  display: none;
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  padding: 8px 11px;
  border-radius: 8px;
  cursor: pointer;
}

/* ---------- Mobile topbar / nav ---------- */
@media (max-width: 860px) {
  .topbar-inner { flex-wrap: wrap; padding: 12px 16px; gap: 10px; }
  .nav-toggle { display: block; order: 2; }
  .topbar-right { order: 3; margin-left: auto; }
  .nav {
    display: none;
    order: 4;
    flex-basis: 100%;
    width: 100%;
    flex-direction: column;
    gap: 2px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
  }
  .nav.nav-open { display: flex; }
  .nav a { padding: 12px 14px; }
}
@media (max-width: 480px) {
  .username em { display: none; }
}

/* ---------- Layout ---------- */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}
.page-title {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 20px;
}
.page-sub { color: var(--text-dim); margin-top: -14px; margin-bottom: 24px; }

.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

/* Two-column "list + form" layouts (reseller/package pages).
   Use class="grid split-grid split-340" (or split-380) instead of an inline
   grid-template-columns style so they can collapse on mobile. */
.split-grid { display: grid; gap: 24px; align-items: start; }
.split-340 { grid-template-columns: 1fr 340px; }
.split-380 { grid-template-columns: 1fr 380px; }
@media (max-width: 900px) {
  .split-340, .split-380 { grid-template-columns: 1fr; }
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 100%;
}
.stat-card .label { color: var(--text-dim); font-size: 13px; margin-bottom: 6px; }
.stat-card .value { font-size: 26px; font-weight: 700; }
.stat-card.accent .value { color: var(--accent); }
.stat-card.green .value { color: var(--green); }
.stat-card.red .value { color: var(--red); }

.section-title { font-size: 16px; font-weight: 600; margin: 0 0 14px; }

/* ---------- Forms ---------- */
label { display: block; margin-bottom: 6px; color: var(--text-dim); font-size: 13px; }
input, select {
  width: 100%;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 14px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
.form-row { display: flex; gap: 14px; }
.form-row > div { flex: 1; }

.btn {
  display: inline-block;
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); border-color: var(--text-dim); background: transparent; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-red { background: var(--red); }
.btn-red:hover { background: #c93c34; }
.btn-green { background: var(--green); }
.btn-green:hover { background: #2f9e43; }
.inline-form { display: inline; }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: var(--bg-panel-2); }
.key-code { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12.5px; }

/* Lets wide tables scroll horizontally inside their card on narrow screens
   instead of squeezing every column unreadably thin. */
.table-scroll { width: 100%; }
@media (max-width: 760px) {
  .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-scroll > table { min-width: 640px; }
  .modal { overflow-x: auto; }
  .modal table { min-width: 480px; }
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.badge-active { background: rgba(63,185,80,0.15); color: var(--green); }
.badge-banned { background: rgba(248,81,73,0.15); color: var(--red); }
.badge-admin { background: rgba(99,102,241,0.15); color: var(--accent); }
.badge-reseller { background: rgba(210,153,34,0.15); color: var(--yellow); }

/* ---------- Alerts ---------- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; font-size: 13px; }
.alert-error { background: rgba(248,81,73,0.1); border: 1px solid rgba(248,81,73,0.3); color: #ff9891; }
.alert-success { background: rgba(63,185,80,0.1); border: 1px solid rgba(63,185,80,0.3); color: #8ee69f; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-wrap { padding: 20px; }
.login-card {
  width: 360px;
  max-width: 100%;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
}
@media (max-width: 480px) {
  .login-card { padding: 24px 20px; }
}
.login-card h1 { font-size: 20px; text-align: center; margin-bottom: 4px; }
.login-logo { display: block; height: 84px; width: auto; margin: 0 auto 16px; }
.login-card .sub { text-align: center; color: var(--text-dim); margin-bottom: 24px; font-size: 13px; }
.login-card .btn { width: 100%; margin-top: 4px; }

.filters { display: flex; gap: 12px; margin-bottom: 18px; align-items: end; }
.filters form { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.filters label { margin-bottom: 4px; }
.filters .field { min-width: 160px; flex: 1 1 160px; }
.filters input, .filters select { margin-bottom: 0; }

.text-dim { color: var(--text-dim); }
.mt-24 { margin-top: 24px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* Fixed-height chart containers (use instead of inline height: styles so the
   height can be tuned per breakpoint). Add "chart-box-center" to also center
   a doughnut canvas inside it. */
.chart-box { height: 260px; }
.chart-box-center { display: flex; align-items: center; justify-content: center; }
@media (max-width: 600px) {
  .chart-box { height: 220px; }
  .page-title { font-size: 19px; }
  .container { padding: 18px 14px 48px; }
  .card { padding: 16px; }
  .grid { gap: 12px; }
}

.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  align-items: center; justify-content: center;
  z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 480px;
  max-width: 92vw;
  max-height: 80vh;
  overflow-y: auto;
}
.modal h3 { margin-top: 0; }
.close-modal { float: right; cursor: pointer; color: var(--text-dim); font-size: 20px; line-height: 1; padding: 4px; margin: -4px -4px 0 0; }

@media (max-width: 480px) {
  .modal-backdrop { padding: 14px; }
  .modal { padding: 18px; width: 100%; }
  .btn-sm { padding: 8px 12px; }
}
.badge-manual { background: rgba(160,160,176,0.15); color: var(--text-dim); margin-left: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Buy Keys: grouped products ---------- */
.product-group { margin-bottom: 18px; }
.product-group-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.variant-row {
  display: grid;
  grid-template-columns: minmax(160px, 2fr) 1fr 110px 1fr 120px;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  margin: 0;
}
.variant-row input[type=number] { margin: 0; }
.variant-row .btn { width: 100%; }
.variant-head { border-top: none; padding-top: 0; color: var(--text-dim); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.variant-name { display: flex; flex-direction: column; gap: 2px; }
.variant-name .text-dim { font-size: 12px; }
.variant-price strong { font-size: 18px; color: var(--accent); }
.variant-price .old-price { text-decoration: line-through; color: var(--text-dim); font-size: 12px; margin-right: 4px; }
.variant-total { font-size: 13px; }
.variant-row.is-out { opacity: .6; }
@media (max-width: 700px) {
  .variant-head { display: none; }
  .variant-row { grid-template-columns: 1fr 1fr; }
  .variant-name { grid-column: 1 / -1; }
  .variant-row > div:last-child { grid-column: 1 / -1; }
}

/* ---------- Bulk copy window (after purchase) ---------- */
.bulk-modal { width: 560px; }
.bulk-sub { margin: -6px 0 14px; font-size: 13px; }
.bulk-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bulk-toolbar label { margin: 0; }
.bulk-toolbar select { width: auto; padding: 6px 10px; margin: 0; }
.bulk-text {
  width: 100%;
  min-height: 200px;
  max-height: 45vh;
  resize: vertical;
  box-sizing: border-box;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
}
.bulk-text:focus { outline: none; border-color: var(--accent); }
.bulk-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.btn.btn-copied { background: var(--green); }
@media (max-width: 480px) {
  .bulk-actions .btn { flex: 1 1 auto; }
}

/* ---------- Reseller: My Keys list with inline details ---------- */
.keys-filters { flex-wrap: wrap; }
.keys-filters .field { max-width: 320px; }
.keys-table td { vertical-align: middle; }
.keys-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.keys-scroll > table.keys-table { min-width: 900px; }
.nowrap { white-space: nowrap; }
.text-red { color: var(--red); }
.copy-key { cursor: pointer; border-bottom: 1px dashed transparent; }
.copy-key:hover { border-bottom-color: var(--text-dim); }
.copy-key.copied { color: var(--green); }
.copy-key.copied::after { content: " copied"; font-family: Inter, sans-serif; font-size: 11px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; }
.link-btn:hover { color: var(--accent-hover); text-decoration: underline; }
.device-row > td { background: var(--bg-panel-2); padding: 12px 16px; }
.device-box p { margin: 0; }
.device-table { width: 100%; }
.device-table th, .device-table td { padding: 6px 10px; font-size: 12.5px; }

/* ---------- Key usage badges ---------- */
.badge-unused { background: rgba(63,185,80,0.15); color: var(--green); }
.badge-used { background: rgba(210,153,34,0.15); color: var(--yellow); }

/* ---------- Admin keys: selection & package groups ---------- */
.check-col { width: 34px; padding-right: 0 !important; }
.check-col input { width: 16px; height: 16px; margin: 0; padding: 0; cursor: pointer; accent-color: var(--accent); appearance: auto; -webkit-appearance: checkbox; background: none; border: 0; }
.bulk-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 4px 0 12px; font-size: 13px; }
.bulk-count { margin-left: auto; font-weight: 600; }
.group-row td { background: var(--bg-panel-2); padding-top: 9px; padding-bottom: 9px; }
.keys-table tr.is-selected td { background: rgba(248, 81, 73, 0.08); }

/* ---------- Sign-up / applications ---------- */
.login-switch { text-align: center; margin: 18px 0 0; font-size: 13px; color: var(--text-dim); }
.login-card textarea, .app-note {
  width: 100%; box-sizing: border-box; background: var(--bg-panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 10px 12px; font: inherit; font-size: 14px; resize: vertical; margin-bottom: 14px;
}
.login-card textarea:focus { outline: none; border-color: var(--accent); }
.hp-field { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.app-card { border-color: rgba(210,153,34,0.45); }
.app-meta { font-size: 12px; color: var(--text-dim); }
.app-note-text { font-size: 13px; color: var(--text-dim); white-space: pre-wrap; word-break: break-word; max-width: 360px; }
.nav-count { display: inline-block; min-width: 18px; padding: 1px 6px; margin-left: 6px; border-radius: 10px; background: var(--yellow); color: #111; font-size: 11px; font-weight: 700; text-align: center; line-height: 16px; }
.badge-pending { background: rgba(210,153,34,0.15); color: var(--yellow); }

/* ---------- Account / password ---------- */
a.username:hover, a.username.is-active { color: var(--text); }
.account-card { max-width: 460px; }
.pw-row { display: flex; gap: 8px; }
.pw-row input { margin-bottom: 0; }

/* ---------- Bulk custom prices ---------- */
.bulk-price-modal { width: 680px; max-height: 88vh; }
.bp-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 2px 0 12px; }
.bp-tool { display: flex; gap: 6px; align-items: center; }
.bp-tool input { width: 80px; margin: 0; padding: 6px 8px; }
.bp-table-wrap { max-height: 46vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.bp-table th { position: sticky; top: 0; background: var(--bg-panel); z-index: 1; }
.bp-table td { padding-top: 6px; padding-bottom: 6px; }
.bp-table .bp-input { width: 110px; margin: 0; padding: 6px 8px; }
.text-green { color: var(--green); }

/* ---------- Telegram support bot page ---------- */
.tg-stat { font-size: 18px !important; word-break: break-word; }
.tg-step { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px; margin-right: 6px; vertical-align: 1px; }
.tg-howto { padding-left: 20px; margin: 0 0 14px; line-height: 1.7; font-size: 13.5px; color: var(--text-dim); }
.tg-howto strong, .tg-howto code { color: var(--text); }
.tg-page code { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12.5px; background: var(--bg-panel-2); padding: 1px 5px; border-radius: 4px; }
.tg-row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.tg-small { font-size: 12px; }
.tg-detected { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 12px; margin-bottom: 14px; border: 1px dashed var(--accent); border-radius: 8px; font-size: 13px; }
.qr-preview img { width: 160px; height: auto; border-radius: 10px; background: #fff; padding: 6px; display: block; }

/* ---------- Reseller API page ---------- */
.api-key-box { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.api-key-box code { font-family: "SFMono-Regular", Consolas, monospace; font-size: 13px; word-break: break-all; flex: 1 1 260px; }
.api-docs h3 { font-size: 15px; margin: 26px 0 8px; }
.api-docs ul { padding-left: 20px; line-height: 1.8; }
.api-docs code { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12.5px; background: var(--bg-panel-2); padding: 1px 5px; border-radius: 4px; }
.api-docs pre { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; overflow-x: auto; font-family: "SFMono-Regular", Consolas, monospace; font-size: 12.5px; line-height: 1.55; margin: 8px 0; }
.api-docs .method { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 4px; margin-right: 6px; vertical-align: 1px; }
.api-docs .method.get { background: rgba(63,185,80,0.15); color: var(--green); }
.api-docs .method.post { background: rgba(37,99,235,0.2); color: var(--accent-hover); }
.param-table td { font-size: 13px; vertical-align: top; }
.param-table td:first-child { white-space: nowrap; }
.refresh-btn { font-size: 15px; line-height: 1; margin-left: 4px; opacity: .65; vertical-align: -1px; }
.refresh-btn:hover { opacity: 1; text-decoration: none; }
