:root {
  color-scheme: dark;
  --bg: #0f1117;
  --panel: #171a22;
  --panel-2: #1f2430;
  --line: #303746;
  --text: #f4f6fb;
  --muted: #9ba4b6;
  --blue: #3488ff;
  --green: #47d989;
  --amber: #f5b942;
  --red: #ff6464;
  --shadow: 0 20px 55px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  padding: 11px 16px;
  font-weight: 700;
  cursor: pointer;
}

button:hover,
.small-button:hover,
.copy-btn:hover {
  filter: brightness(1.08);
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 240px;
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  background: #12151d;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 18px;
}

.brand span,
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #fff;
  color: #10131a;
  font-weight: 900;
}

nav {
  display: grid;
  gap: 8px;
}

nav a,
.logout button {
  color: var(--muted);
  padding: 11px 12px;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

nav a.active,
nav a:hover {
  background: var(--panel-2);
  color: var(--text);
}

.logout {
  margin-top: auto;
}

.logout button {
  width: 100%;
}

.content {
  margin-left: 240px;
  padding: 28px;
  display: grid;
  gap: 20px;
}

.panel,
.table-wrap,
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 24px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 20px;
}

.panel-head.compact {
  margin-bottom: 14px;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: 19px;
  line-height: 1.25;
  letter-spacing: 0;
}

p {
  margin: 8px 0 0;
  color: var(--muted);
}

code {
  color: #c9ddff;
  background: rgba(52, 136, 255, 0.12);
  border: 1px solid rgba(52, 136, 255, 0.2);
  border-radius: 6px;
  padding: 2px 6px;
}

.copy-code {
  cursor: pointer;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 650;
}

.field-hint {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11141b;
  color: var(--text);
  padding: 12px 13px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(52, 136, 255, 0.18);
}

.wide {
  grid-column: 1 / -1;
}

.form-actions {
  align-self: end;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

th,
td {
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0;
}

td small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

tr:last-child td {
  border-bottom: 0;
}

.right {
  text-align: right;
}

.small-button,
.copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 12px;
  font-weight: 700;
}

.copy-btn.compact-btn {
  padding: 7px 10px;
  white-space: nowrap;
}

.copy-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.plus-button {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 999px;
  background: var(--green);
  color: #04140b;
  font-size: 24px;
  line-height: 1;
  font-weight: 900;
}

.icon-link,
.text-danger {
  background: transparent;
  color: var(--muted);
  padding: 2px 0 0 10px;
  font-weight: 700;
}

.icon-link {
  white-space: nowrap;
}

.text-danger {
  color: var(--red);
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
  background: var(--panel-2);
}

.pill.ok {
  color: #04140b;
  background: var(--green);
}

.pill.warn {
  color: #170f00;
  background: var(--amber);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.stats-grid.compact {
  grid-template-columns: minmax(260px, 420px);
}

.stat {
  padding: 18px;
  display: grid;
  gap: 4px;
}

.stat span,
.stat small {
  color: var(--muted);
}

.stat strong {
  font-size: 28px;
  line-height: 1.15;
}

.secret-card {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
  padding: 16px;
  background: #10141d;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.secret-card span {
  color: var(--muted);
  font-weight: 700;
}

.secret-card code {
  word-break: break-all;
}

.referral-card {
  display: grid;
  grid-template-columns: max-content max-content;
  align-items: center;
  gap: 10px;
  width: fit-content;
  margin-bottom: 20px;
  padding: 12px;
  background: #10141d;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.referral-card span {
  color: var(--muted);
  font-weight: 750;
}

.inline-tool {
  justify-self: start;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 7px 10px;
  font-size: 13px;
}

.head-actions,
.danger-zone {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.danger-zone {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.config-block {
  display: grid;
  gap: 12px;
  margin-top: 22px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.sales-ledger table {
  min-width: 1680px;
}

.notice {
  margin-bottom: 18px;
  padding: 12px;
  border-radius: 8px;
  font-weight: 750;
}

.notice.ok {
  color: #052011;
  background: var(--green);
}

.notice.error {
  color: #fff;
  background: rgba(255, 100, 100, 0.25);
  border: 1px solid rgba(255, 100, 100, 0.4);
}

.kv-grid {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 12px 18px;
  margin-top: 18px;
}

.kv-grid span {
  color: var(--muted);
  font-weight: 750;
}

.secondary {
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.danger {
  background: var(--red);
}

.empty {
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  opacity: 0;
  transform: translateY(8px);
  transition: 0.18s ease;
  background: #fff;
  color: #10131a;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 800;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
  display: grid;
  gap: 18px;
}

.login-card h1 {
  font-size: 28px;
}

.login-card form {
  display: grid;
  gap: 16px;
}

.alert {
  padding: 12px;
  background: rgba(255, 100, 100, 0.12);
  border: 1px solid rgba(255, 100, 100, 0.28);
  border-radius: 8px;
  color: #ffbaba;
}

@media (max-width: 920px) {
  .sidebar {
    position: static;
    width: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 16px 18px;
  }

  nav {
    order: 2;
    width: 100%;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    overflow: visible;
  }

  nav a {
    text-align: center;
  }

  .logout {
    margin: 0 0 0 auto;
  }

  .content {
    margin-left: 0;
    padding: 18px;
  }

  .grid-form,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .referral-card {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .panel-head {
    display: grid;
  }
}
