*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f0f4f8;
  color: #1a202c;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  background: #1a365d;
  color: #fff;
  padding: 14px 0;
}

.logo { font-size: 1.2rem; font-weight: 600; letter-spacing: .02em; }

footer {
  margin-top: auto;
  padding: 20px 0;
  text-align: center;
  font-size: .8rem;
  color: #718096;
}

.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 16px;
}

main.container { padding-top: 32px; padding-bottom: 32px; }

h1 { font-size: 1.6rem; margin: 0 0 6px; }
.subtitle { color: #4a5568; margin: 0 0 28px; }

/* Plan grid */
.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
  justify-items: center;
}

.plan-card {
  background: #fff;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  padding: 24px 20px;
  position: relative;
  transition: box-shadow .15s;
  width: 100%;
  max-width: 300px;
}

.plan-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.1); }

.plan-card--popular { border-color: #3182ce; }

.badge {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  background: #3182ce;
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  padding: 3px 12px;
  border-radius: 12px;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.plan-card h2 { margin: 0 0 8px; font-size: 1.15rem; }

.plan-price {
  font-size: 2rem;
  font-weight: 700;
  color: #1a365d;
  margin-bottom: 16px;
}

.plan-features {
  list-style: none;
  padding: 0;
  margin: 0 0 20px;
  font-size: .9rem;
  color: #4a5568;
}

.plan-features li { padding: 4px 0; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: .95rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: #e2e8f0;
  color: #1a202c;
  transition: background .15s;
}

.btn:hover { background: #cbd5e0; }

.btn--buy {
  width: 100%;
  background: #2b6cb0;
  color: #fff;
  padding: 12px;
  font-size: 1rem;
}

.btn--buy:hover { background: #2c5282; }

/* Notice */
.notice {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: .9rem;
}

.notice--warn { background: #fffbeb; border: 1px solid #f6e05e; color: #744210; }

/* Success page */
.success-box {
  background: #fff;
  border-radius: 12px;
  padding: 40px 32px;
  max-width: 480px;
  margin: 0 auto;
  text-align: center;
  box-shadow: 0 2px 12px rgba(0,0,0,.08);
}

.success-icon {
  font-size: 3rem;
  color: #38a169;
  margin-bottom: 12px;
}

.success-box h1 { margin: 0 0 12px; }

.success-box ol {
  text-align: left;
  display: inline-block;
  margin: 16px 0;
  padding-left: 20px;
  line-height: 1.9;
}

.hint { color: #718096; font-size: .85rem; margin-bottom: 24px; }

.voucher-code {
  font-family: monospace;
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: .18em;
  color: #1a365d;
  background: #ebf8ff;
  border: 2px solid #90cdf4;
  border-radius: 10px;
  padding: 14px 24px;
  margin: 12px auto 20px;
  display: inline-block;
}

/* Terms page */
.terms-box {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 28px 32px;
  margin-bottom: 28px;
  font-size: .92rem;
  color: #2d3748;
  line-height: 1.7;
  max-height: 480px;
  overflow-y: auto;
}

.terms-box h2 { font-size: 1rem; margin: 20px 0 6px; color: #1a365d; }
.terms-box h2:first-child { margin-top: 0; }
.terms-box p { margin: 0 0 10px; }
.terms-box ul { margin: 0 0 10px; padding-left: 20px; }
.terms-box li { margin-bottom: 4px; }
.terms-updated { font-size: .8rem; color: #a0aec0; margin-top: 20px; }

.terms-accept {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 480px;
}

.terms-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: .95rem;
  cursor: pointer;
  color: #2d3748;
}

.terms-checkbox input[type="checkbox"] {
  margin-top: 3px;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  cursor: pointer;
}

/* ── Admin layout ─────────────────────────────────────────────────────────── */

.admin-body { background: #f7f8fa; }

.admin-header {
  background: #1a365d;
  color: #fff;
  padding: 0;
}

.admin-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
}

.admin-nav { display: flex; gap: 4px; }

.admin-nav__link {
  color: rgba(255,255,255,.75);
  text-decoration: none;
  font-size: .9rem;
  padding: 6px 14px;
  border-radius: 6px;
  transition: background .12s, color .12s;
}

.admin-nav__link:hover    { background: rgba(255,255,255,.12); color: #fff; }
.admin-nav__link--active  { background: rgba(255,255,255,.18); color: #fff; font-weight: 600; }

.admin-main { padding-top: 28px; padding-bottom: 40px; }

/* ── Admin toolbar ────────────────────────────────────────────────────────── */

.admin-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.admin-toolbar h1 { margin: 0; font-size: 1.4rem; }

.admin-filter { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.admin-toolbar__actions { display: flex; align-items: center; gap: 8px; }

.admin-count { font-size: .85rem; color: #718096; }

/* ── Tables ───────────────────────────────────────────────────────────────── */

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

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,.07);
}

.admin-table th {
  background: #edf2f7;
  text-align: left;
  padding: 10px 14px;
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #4a5568;
  border-bottom: 1px solid #e2e8f0;
}

.admin-table td {
  padding: 10px 14px;
  border-bottom: 1px solid #f0f4f8;
  vertical-align: middle;
}

.admin-table tbody tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover { background: #f7faff; }
.admin-table tfoot td { border-top: 2px solid #e2e8f0; background: #f7fafc; }

.admin-table th.num,
.admin-table td.num { text-align: right; }

.admin-code { font-family: monospace; font-size: .85rem; cursor: default; }
.admin-ts   { font-size: .8rem; color: #718096; white-space: nowrap; }
.mono       { font-family: monospace; font-size: .85rem; }
.muted      { color: #a0aec0; }
.admin-empty { color: #718096; padding: 20px 0; }

/* ── Status badges ────────────────────────────────────────────────────────── */

.status-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.status-badge--unused   { background: #edf2f7; color: #718096; }
.status-badge--active   { background: #c6f6d5; color: #276749; }
.status-badge--expired  { background: #fed7d7; color: #9b2c2c; }
.status-badge--depleted { background: #feebc8; color: #7b341e; }

/* ── Buttons (admin additions) ────────────────────────────────────────────── */

.btn--primary       { background: #2b6cb0; color: #fff; }
.btn--primary:hover { background: #2c5282; }

.btn--danger       { background: #e53e3e; color: #fff; }
.btn--danger:hover { background: #c53030; }

.btn--sm { padding: 6px 14px; font-size: .82rem; }

/* ── Pagination ───────────────────────────────────────────────────────────── */

.pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
  justify-content: center;
}

.pagination__info { font-size: .85rem; color: #718096; }

/* ── Admin form elements ──────────────────────────────────────────────────── */

.admin-select,
.admin-input {
  padding: 8px 12px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: .9rem;
  background: #fff;
  color: #1a202c;
  outline: none;
}

.admin-select:focus,
.admin-input:focus { border-color: #4299e1; box-shadow: 0 0 0 2px rgba(66,153,225,.25); }

.admin-card {
  background: #fff;
  border-radius: 10px;
  padding: 28px 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.07);
}

.form-row { display: flex; gap: 20px; flex-wrap: wrap; margin-bottom: 20px; }

.form-group { display: flex; flex-direction: column; gap: 6px; min-width: 180px; }

.form-group label { font-size: .85rem; font-weight: 600; color: #4a5568; }

.form-actions { display: flex; gap: 12px; }

.admin-codes {
  width: 100%;
  font-family: monospace;
  font-size: .9rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 12px;
  resize: vertical;
  background: #f7f8fa;
  color: #1a202c;
}

/* ── Notice additions ─────────────────────────────────────────────────────── */

.notice--ok { background: #f0fff4; border: 1px solid #9ae6b4; color: #276749; }

/* ── Dashboard ────────────────────────────────────────────────────────────── */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: #fff;
  border-radius: 10px;
  padding: 20px 20px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,.07);
  border-left: 4px solid #e2e8f0;
}

.stat-card--blue  { border-left-color: #3182ce; }
.stat-card--green { border-left-color: #38a169; }

.stat-label { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: #718096; margin-bottom: 6px; }
.stat-value { font-size: 2rem; font-weight: 700; color: #1a202c; line-height: 1; margin-bottom: 4px; }
.stat-sub   { font-size: .8rem; color: #a0aec0; }

.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

/* ── Usage bar ────────────────────────────────────────────────────────────── */

.usage-bar {
  height: 5px;
  background: #e2e8f0;
  border-radius: 3px;
  margin-top: 5px;
  overflow: hidden;
}

.usage-bar__fill {
  height: 100%;
  background: #3182ce;
  border-radius: 3px;
  transition: width .3s;
}

.usage-bar__fill--warn { background: #e53e3e; }

/* ── Code entry (portal) ──────────────────────────────────────────────────── */

.portal-section {
  background: #fff;
  border-radius: 12px;
  padding: 28px 24px;
  box-shadow: 0 2px 10px rgba(0,0,0,.07);
  margin: 0 auto 32px;
  max-width: 460px;        /* ~50% of a typical desktop viewport */
  text-align: center;
}

.portal-section h1 { font-size: 1.5rem; margin: 0 0 6px; }

.code-input {
  display: block;
  width: 100%;
  padding: 14px 16px;
  border: 2px solid #cbd5e0;
  border-radius: 8px;
  font-size: 1.3rem;
  font-family: monospace;
  letter-spacing: .15em;
  text-align: center;
  outline: none;
  color: #1a202c;
  background: #fff;
  text-transform: uppercase;
  margin-top: 16px;
}

.code-input:focus { border-color: #4299e1; box-shadow: 0 0 0 3px rgba(66,153,225,.2); }

.btn--connect {
  display: inline-block;
  margin-top: 12px;
  padding: 11px 32px;
  background: #2b6cb0;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */

/* Prevent iOS auto-zoom on input focus */
input[type="text"],
input[type="email"],
select,
textarea {
  font-size: max(16px, 1rem);
}

/* Ensure buttons are easy to tap */
.btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }

@media (max-width: 640px) {
  .container { padding: 0 14px; }
  main.container { padding-top: 20px; padding-bottom: 24px; }

  h1 { font-size: 1.35rem; }

  .plan-card { padding: 20px 16px; }

  /* Success box */
  .success-box { padding: 28px 18px; }
  .voucher-code { font-size: 1.7rem; letter-spacing: .1em; padding: 12px 16px; word-break: break-all; }

  /* Terms */
  .terms-box { padding: 20px 16px; max-height: 360px; }
  .terms-accept { max-width: 100%; }

  /* Portal section */
  .portal-section { padding: 22px 16px; max-width: 100%; }

  /* Header */
  .logo { font-size: 1rem; }

  /* Admin stat grid: 2-up on phones */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-value { font-size: 1.5rem; }

  /* Admin nav: allow wrap */
  .admin-header__inner { flex-wrap: wrap; height: auto; padding: 10px 0; gap: 8px; }
  .admin-nav { flex-wrap: wrap; gap: 2px; }
  .admin-nav__link { font-size: .82rem; padding: 5px 10px; }

  /* Admin table: allow horizontal scroll */
  .admin-table-wrap { -webkit-overflow-scrolling: touch; }
}

@media (max-width: 400px) {
  .voucher-code { font-size: 1.4rem; }
  .stat-grid { grid-template-columns: 1fr; }
}
