:root {
  --bg: #0d1117;
  --bg-panel: #151b23;
  --bg-panel-2: #1c232d;
  --border: #2a323d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #6366f1;
  --accent-hover: #4f52d6;
  --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: -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; }
}
