:root {
  --bg: #0f1412;
  --panel: #18211d;
  --card: #1e2a25;
  --line: #2c3b34;
  --text: #e8f0eb;
  --muted: #93a69b;
  --accent: #3dcc8a;
  --accent-dim: #1f6b48;
  --danger: #f07167;
  --warn: #f4c15d;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
  --sidebar-width: 240px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { overflow-x: hidden; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(circle at top left, #1c3329, var(--bg) 38%);
  color: var(--text);
}

body:not(.login-body) {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
h1, h2 { margin: 0 0 16px; font-weight: 650; }
h1 { font-size: 28px; }
h2 { font-size: 18px; }

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  min-height: 100vh;
  max-height: 100vh;
  overflow-y: auto;
  padding: 24px 18px;
  background: rgba(15, 22, 19, 0.96);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.sidebar form { margin-top: auto; }
.sidebar-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(6, 10, 8, 0.62);
  pointer-events: none;
}

.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }
.brand small, .muted { color: var(--muted); }
.brand strong, .brand small { display: block; }
.logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #073221;
  font-weight: 800;
  flex-shrink: 0;
}

nav { display: grid; gap: 6px; }
nav a, button, .ghost {
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  background: transparent;
  text-align: left;
}
nav a { min-height: 42px; display: flex; align-items: center; }
nav a:hover, nav a.active { background: var(--card); }
button {
  background: var(--accent);
  color: #073221;
  font-weight: 700;
  cursor: pointer;
}
button.secondary { background: #31463c; color: var(--text); }
button.danger { background: #6b2a24; color: #ffe8e6; }
button.danger:hover { background: #8a3530; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.small, .ghost { background: #31463c; color: var(--text); width: auto; }
.ghost { width: 100%; }

.icon-btn {
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  display: none;
  place-items: center;
  flex-shrink: 0;
  cursor: pointer;
}
.icon-btn span,
.icon-btn span::before,
.icon-btn span::after {
  display: block;
  width: 16px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  position: relative;
}
.icon-btn span::before,
.icon-btn span::after {
  content: "";
  position: absolute;
  left: 0;
}
.menu-toggle span::before { top: -5px; }
.menu-toggle span::after { top: 5px; }
.sidebar-close span { background: transparent; }
.sidebar-close span::before,
.sidebar-close span::after {
  top: 0;
  width: 16px;
}
.sidebar-close span::before { transform: rotate(45deg); }
.sidebar-close span::after { transform: rotate(-45deg); }

.content { padding: 32px; min-width: 0; }
.top { margin-bottom: 24px; }
.top-bar { display: flex; align-items: center; gap: 12px; }
.top-bar h1 { margin: 0; min-width: 0; }

.card, .stats article, .login-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.grid.two { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stats span, .stats small { color: var(--muted); display: block; }
.stats strong { font-size: 32px; display: block; margin: 8px 0 4px; }

.table-scroll,
.card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 480px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { color: var(--muted); font-weight: 600; }
td { word-break: break-word; }

label { display: grid; gap: 6px; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #121a17;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
}
.stack { display: grid; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.filters > * { width: auto; min-width: 0; flex: 1 1 160px; }
.filters button { flex: 0 0 auto; }

.bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.bulk-bar [data-bulk-count] { margin-right: auto; }
.check-col { width: 36px; }
.check-col input[type="checkbox"],
#select-all-vouchers {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}
tr:has(.voucher-check:checked) { background: rgba(61, 204, 138, 0.08); }
.pill.sold { background: #3a3f3c; }

.package-row {
  display: grid;
  grid-template-columns: 1fr 90px 1fr 70px 110px auto auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  background: #31463c;
  font-size: 12px;
  text-transform: capitalize;
}
.pill.fulfilled, .pill.available, .pill.sent { background: #1f6b48; }
.pill.pending, .pill.awaiting_otp, .pill.reserved { background: #6b541f; }
.pill.failed, .pill.expired { background: #6b2a24; }

.flash { padding: 10px 12px; border-radius: 10px; }
.flash.ok { background: #1f6b48; }
.flash.bad { background: #6b2a24; }

.login-body { display: grid; place-items: center; padding: 20px; }
.login-card { width: min(420px, 92vw); }
.login-card button { width: 100%; }
.phone pre {
  min-height: 220px;
  background: #0b0f0d;
  border-radius: 12px;
  padding: 16px;
  white-space: pre-wrap;
  overflow-x: auto;
}

@media (max-width: 1100px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stats strong { font-size: 26px; }
}

@media (max-width: 960px) {
  body:not(.login-body) { grid-template-columns: 1fr; }
  body.sidebar-open { overflow: hidden; }

  body.sidebar-open .sidebar-backdrop {
    display: block;
    pointer-events: auto;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 40;
    width: min(var(--sidebar-width), 86vw);
    min-height: 100vh;
    transform: translateX(-100%);
    visibility: hidden;
    pointer-events: none;
    transition: transform 0.22s ease, visibility 0.22s ease;
    box-shadow: var(--shadow);
  }
  body.sidebar-open .sidebar {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
  }

  .menu-toggle,
  .sidebar-close { display: grid; }
  .menu-toggle { position: relative; z-index: 25; }

  .content { padding: 16px; }
  .top {
    position: sticky;
    top: 0;
    z-index: 20;
    margin: -16px -16px 16px;
    padding: 12px 16px;
    background: rgba(15, 20, 18, 0.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(10px);
  }
  h1 { font-size: 22px; }
  .grid.two { grid-template-columns: 1fr; }
  .package-row { grid-template-columns: 1fr 1fr; }
  .package-row input:first-child,
  .package-row button { grid-column: 1 / -1; }
  .package-row button { width: 100%; }
  .card, .stats article { padding: 16px; }
  input, select, textarea, button { font-size: 16px; }
}

@media (max-width: 640px) {
  .stats { grid-template-columns: 1fr; }
  .stats strong { font-size: 28px; }
  .filters { flex-direction: column; }
  .filters > *,
  .filters button { width: 100%; flex: none; }
  .bulk-bar [data-bulk-count] { margin-right: 0; width: 100%; }
  .bulk-bar button { width: 100%; }
  table { min-width: 560px; }
}
