/* ==========================================================================
   KeyShop — Giao diện chính (khách hàng + dùng chung)
   Phong cách: dark gaming / glassmorphism, mobile-first
   ========================================================================== */
:root {
  --bg: #090b14;
  --bg-2: #0e1120;
  --surface: rgba(255, 255, 255, .045);
  --surface-2: rgba(255, 255, 255, .075);
  --border: rgba(255, 255, 255, .09);
  --border-2: rgba(255, 255, 255, .16);
  --text: #eef0fa;
  --muted: #8f95b2;
  --primary: #7c5cff;
  --primary-2: #00c8ff;
  --grad: linear-gradient(135deg, #7c5cff 0%, #00c8ff 100%);
  --ok: #22e6a8;
  --warn: #ffb02e;
  --danger: #ff5577;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; }
a { color: var(--primary-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; letter-spacing: -.01em; }
p { margin: 0 0 .8em; }
code, .mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.dot { opacity: .45; margin: 0 2px; }
.link { font-weight: 600; font-size: 14px; }
::selection { background: rgba(124, 92, 255, .45); }

/* ---------- Nền ánh sáng ---------- */
.bg-orbs { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.bg-orbs::before, .bg-orbs::after {
  content: ''; position: absolute; width: 60vmax; height: 60vmax; border-radius: 50%;
  filter: blur(90px); opacity: .22;
}
.bg-orbs::before { background: #6a4dff; top: -25vmax; left: -15vmax; }
.bg-orbs::after { background: #00a6ff; bottom: -30vmax; right: -20vmax; }

.container { width: 100%; max-width: 1040px; margin: 0 auto; padding: 0 16px; }
.page { flex: 1 0 auto; width: 100%; padding-bottom: 40px; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(9, 11, 20, .72);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1040px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 800; font-size: 18px; }
.brand:hover { text-decoration: none; }
.brand-logo {
  width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center;
  background: var(--grad); font-size: 18px; box-shadow: 0 6px 20px rgba(124, 92, 255, .4);
}
.nav { display: flex; align-items: center; gap: 6px; flex: 1; }
.nav-link { color: var(--muted); font-weight: 600; font-size: 14px; padding: 8px 12px; border-radius: 10px; }
.nav-link:hover { color: var(--text); background: var(--surface); text-decoration: none; }
.nav-link.active { color: var(--text); background: var(--surface-2); }
.nav-spacer { flex: 1; }
.user-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px;
  border: 1px solid var(--border); border-radius: 99px; font-size: 13.5px; font-weight: 600;
}
.uc-avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--grad); display: grid; place-items: center; font-size: 12px; font-weight: 800; }
.nav-toggle { display: none; margin-left: auto; width: 42px; height: 42px; border-radius: 11px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; padding: 0; flex-direction: column; justify-content: center; align-items: center; gap: 4px; }
.nav-toggle span { display: block; width: 18px; height: 2px; background: var(--text); border-radius: 2px; transition: .2s; }
.topbar.nav-open .nav-toggle span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.topbar.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
.topbar.nav-open .nav-toggle span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

@media (max-width: 760px) {
  .nav-toggle { display: flex; }
  .nav { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; gap: 6px; padding: 8px 0 6px; }
  .topbar.nav-open .nav { display: flex; }
  .nav-spacer { display: none; }
  .nav .btn, .user-chip { justify-content: center; }
}

/* ---------- Nút ---------- */
.btn {
  --b: var(--surface-2);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: var(--radius-sm); border: 1px solid transparent;
  background: var(--b); color: var(--text); font: inherit; font-weight: 700; font-size: 14.5px;
  cursor: pointer; transition: transform .12s, box-shadow .2s, background .2s, opacity .2s;
  text-decoration: none; line-height: 1.2; -webkit-tap-highlight-color: transparent;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.98); }
.btn:disabled, .btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none !important; }
.btn-primary { background: var(--grad); box-shadow: 0 8px 24px rgba(124, 92, 255, .35); color: #fff; }
.btn-primary:hover:not(:disabled) { box-shadow: 0 10px 30px rgba(124, 92, 255, .55); }
.btn-ghost { background: var(--surface); border-color: var(--border-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-success { background: linear-gradient(135deg, #14c98f, #22e6a8); color: #04281d; }
.btn-danger { background: rgba(255, 85, 119, .14); border-color: rgba(255, 85, 119, .45); color: #ff8aa1; }
.btn-danger:hover { background: rgba(255, 85, 119, .24); }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn-lg { padding: 14px 26px; font-size: 16px; border-radius: 13px; }
.btn-block { display: flex; width: 100%; }

/* ---------- Card / Alert / Badge ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.card.empty { text-align: center; padding: 38px 20px; }
.card.empty.small { padding: 20px; }
.card.empty.small p { margin: 0; }
.empty-ico { font-size: 40px; margin-bottom: 6px; }

.flash-wrap { position: sticky; top: 62px; z-index: 40; max-width: 1040px; width: 100%; margin: 12px auto 0; padding: 0 16px; }
.alert {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border-radius: 12px; font-size: 14px; margin-bottom: 10px;
  border: 1px solid var(--border-2); background: var(--surface-2);
}
.alert-success { background: rgba(34, 230, 168, .1); border-color: rgba(34, 230, 168, .4); color: #b6f7e2; }
.alert-error { background: rgba(255, 85, 119, .1); border-color: rgba(255, 85, 119, .4); color: #ffc0cd; }
.alert-info { background: rgba(0, 200, 255, .08); border-color: rgba(0, 200, 255, .3); color: #bdeeff; }
.alert-x { background: none; border: 0; color: inherit; font-size: 20px; line-height: 1; cursor: pointer; opacity: .6; padding: 0 2px; }
.alert-x:hover { opacity: 1; }
.flash-wrap .alert { box-shadow: var(--shadow); backdrop-filter: blur(10px); animation: slideIn .35s ease; }
@keyframes slideIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 700;
  white-space: nowrap; border: 1px solid transparent;
}
.b-pending { background: rgba(255, 176, 46, .14); color: #ffc766; border-color: rgba(255, 176, 46, .35); }
.b-approved, .b-available { background: rgba(34, 230, 168, .12); color: #4ff0bd; border-color: rgba(34, 230, 168, .35); }
.b-cancelled, .b-disabled { background: rgba(143, 149, 178, .14); color: #aab0cb; border-color: rgba(143, 149, 178, .3); }
.b-sold { background: rgba(124, 92, 255, .16); color: #b3a0ff; border-color: rgba(124, 92, 255, .4); }

/* ---------- Form ---------- */
.field { margin-bottom: 14px; flex: 1; min-width: 0; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #cfd3ea; }
.input {
  width: 100%; padding: 12px 14px; font: inherit; font-size: 15px; color: var(--text);
  background: rgba(0, 0, 0, .28); border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  outline: none; transition: border-color .2s, box-shadow .2s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(124, 92, 255, .25); }
.input::placeholder { color: #5f6482; }
select.input { appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%238f95b2' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 38px; }
select.input option { background: #14172a; color: var(--text); }
textarea.input { resize: vertical; min-height: 90px; }
.hint { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; }
.input-group { position: relative; }
.input-group .input { padding-right: 46px; }
.input-btn { position: absolute; right: 4px; top: 4px; bottom: 4px; width: 40px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; font-size: 16px; opacity: .7; }
.input-btn:hover { opacity: 1; background: var(--surface); }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: calc(100dvh - 140px); display: grid; place-items: center; padding: 24px 16px; width: 100%; }
body.auth > .auth-wrap { min-height: 100dvh; }
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; padding: 30px 26px; box-shadow: var(--shadow); backdrop-filter: blur(14px);
}
.auth-logo { width: 56px; height: 56px; border-radius: 16px; background: var(--grad); display: grid; place-items: center; font-size: 26px; margin-bottom: 14px; box-shadow: 0 10px 30px rgba(124, 92, 255, .45); }
.auth-card h1 { font-size: 24px; }
.auth-alt { text-align: center; margin: 18px 0 0; color: var(--muted); font-size: 14px; }
.install-steps { padding-left: 20px; margin: 16px 0; color: #cfd3ea; }
.install-steps li { margin-bottom: 8px; }

/* ---------- Hero ---------- */
.hero { padding: 44px 0 22px; text-align: center; }
.eyebrow { display: inline-block; padding: 6px 14px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border-2); font-size: 12.5px; font-weight: 600; color: #cfd3ea; margin-bottom: 16px; }
.hero h1 { font-size: clamp(28px, 6vw, 46px); font-weight: 800; margin-bottom: 12px; }
.grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-fill-color: transparent; }
.hero-sub { max-width: 560px; margin: 0 auto 16px; color: var(--muted); font-size: 16px; }
.hero-badges { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding: 0; margin: 0; }
.hero-badges li { font-size: 13px; color: #cfd3ea; padding: 6px 12px; border-radius: 99px; background: var(--surface); border: 1px solid var(--border); }

/* ---------- Chọn game / gói ---------- */
.step { margin: 26px 0; }
.step-title { display: flex; align-items: center; gap: 10px; font-size: 19px; margin-bottom: 14px; }
.step-no { width: 28px; height: 28px; border-radius: 9px; background: var(--grad); display: grid; place-items: center; font-size: 14px; font-weight: 800; }

.game-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.game-card, .plan-card { position: relative; display: block; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.game-card input, .plan-card input { position: absolute; opacity: 0; pointer-events: none; }
.gc-body {
  position: relative; display: flex; flex-direction: column; gap: 4px; height: 100%;
  padding: 18px; border-radius: var(--radius); background: var(--surface); border: 1.5px solid var(--border);
  transition: transform .15s, border-color .2s, background .2s, box-shadow .2s;
}
.game-card:hover .gc-body { transform: translateY(-3px); border-color: var(--border-2); background: var(--surface-2); }
.game-card input:checked + .gc-body { border-color: var(--primary); background: linear-gradient(160deg, rgba(124, 92, 255, .2), rgba(0, 200, 255, .08)); box-shadow: 0 0 0 3px rgba(124, 92, 255, .22), 0 12px 34px rgba(124, 92, 255, .22); }
.game-card input:focus-visible + .gc-body, .plan-card input:focus-visible + .pc-body { outline: 2px solid var(--primary-2); outline-offset: 2px; }
.gc-icon { font-size: 30px; }
.gc-name { font-weight: 700; font-size: 16px; }
.gc-desc { color: var(--muted); font-size: 13px; }
.gc-check { position: absolute; top: 12px; right: 12px; width: 24px; height: 24px; border-radius: 50%; background: var(--grad); display: grid; place-items: center; font-size: 13px; font-weight: 800; transform: scale(0); transition: transform .2s cubic-bezier(.3, 1.6, .5, 1); }
.game-card input:checked + .gc-body .gc-check { transform: scale(1); }

.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.pc-body {
  display: flex; flex-direction: column; gap: 2px; align-items: center; text-align: center;
  padding: 18px 12px; border-radius: var(--radius); background: var(--surface); border: 1.5px solid var(--border);
  transition: transform .15s, border-color .2s, background .2s, box-shadow .2s;
}
.plan-card:hover .pc-body { transform: translateY(-3px); border-color: var(--border-2); }
.plan-card input:checked + .pc-body { border-color: var(--primary-2); background: linear-gradient(160deg, rgba(0, 200, 255, .16), rgba(124, 92, 255, .12)); box-shadow: 0 0 0 3px rgba(0, 200, 255, .2); }
.pc-name { font-weight: 700; }
.pc-days { font-size: 13px; color: var(--muted); }
.pc-price { font-size: 22px; font-weight: 800; margin: 6px 0 2px; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-fill-color: transparent; }
.pc-stock { font-size: 12px; color: var(--muted); }
.pc-stock.low { color: var(--warn); }
.pc-stock.out { color: var(--danger); font-weight: 700; }
.plan-card.disabled { cursor: not-allowed; }
.plan-card.disabled .pc-body { opacity: .45; filter: grayscale(.6); transform: none; }

.summary-bar {
  position: sticky; bottom: 12px; z-index: 30; margin-top: 26px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 14px 16px; border-radius: 18px; background: rgba(14, 17, 32, .9);
  border: 1px solid var(--border-2); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); box-shadow: var(--shadow);
}
.sum-info { flex: 1; min-width: 160px; }
.sum-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.sum-text { font-weight: 600; }
.sum-price { font-size: 24px; font-weight: 800; }
@media (max-width: 560px) {
  .summary-bar { padding: 12px; gap: 10px; bottom: 8px; }
  .summary-bar .btn { width: 100%; }
  .sum-price { font-size: 20px; }
}

/* ---------- Thanh toán ---------- */
.pay-panel { margin: 26px 0; padding: 22px; }
.pay-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.pay-head h2 { font-size: 20px; margin-bottom: 2px; }
.pay-grid { display: grid; grid-template-columns: 290px 1fr; gap: 22px; align-items: start; }
@media (max-width: 760px) { .pay-grid { grid-template-columns: 1fr; } }
.qr-box { text-align: center; background: #fff; border-radius: 18px; padding: 14px; color: #3a3f5c; }
.qr-box img { display: block; margin: 0 auto 6px; border-radius: 10px; }
.qr-box .muted { color: #6b7090; margin: 0; }
.copy-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--border); }
.cr-label { width: 108px; flex: none; color: var(--muted); font-size: 13px; }
.cr-val { flex: 1; min-width: 0; word-break: break-all; }
.cr-val.price { font-size: 20px; color: var(--ok); }
.pay-info .alert { margin-top: 14px; }
.waiting { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13.5px; margin-top: 6px; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 0 rgba(255, 176, 46, .6); animation: pulse 1.6s infinite; flex: none; }
@keyframes pulse { 70% { box-shadow: 0 0 0 10px rgba(255, 176, 46, 0); } 100% { box-shadow: 0 0 0 0 rgba(255, 176, 46, 0); } }
.pay-back { margin: 18px 0 0; font-size: 14px; }

/* ---------- Danh sách đơn ---------- */
.recent { margin-top: 36px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.section-head h2 { font-size: 19px; margin: 0; }
.order-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.order-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.order-item.st-approved { border-color: rgba(34, 230, 168, .25); }
.oi-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.oi-code { font-weight: 700; font-size: 14px; color: #cfd3ea; }
.oi-title { font-weight: 700; }
.oi-meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.oi-meta b { color: var(--text); }
.keybox { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 12px; border-radius: 12px; background: rgba(0, 0, 0, .35); border: 1px dashed var(--border-2); }
.kb-val { flex: 1; min-width: 0; word-break: break-all; font-size: 14px; color: var(--ok); user-select: all; }
.oi-exp { font-size: 13px; font-weight: 600; }
.oi-exp.is-ok { color: var(--ok); }
.oi-exp.is-warn { color: var(--warn); }
.oi-exp.is-expired { color: var(--danger); }
.oi-actions { margin-top: 2px; }

/* ---------- Trang lịch sử ---------- */
.page-head { padding: 28px 0 10px; }
.page-head h1 { font-size: 26px; }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 8px 0 18px; }
@media (max-width: 640px) { .stat-row { grid-template-columns: repeat(2, 1fr); } }
.stat-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; }
.sb-num { font-size: 26px; font-weight: 800; }
.sb-num.sm { font-size: 18px; padding: 4px 0; }
.sb-label { font-size: 12.5px; color: var(--muted); }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; -webkit-overflow-scrolling: touch; }
.tab { flex: none; padding: 8px 16px; border-radius: 99px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); font-weight: 600; font-size: 14px; }
.tab:hover { text-decoration: none; color: var(--text); }
.tab.active { background: var(--grad); color: #fff; border-color: transparent; }

.pager { display: flex; justify-content: center; gap: 6px; margin: 20px 0 0; flex-wrap: wrap; }
.pg { min-width: 38px; height: 38px; padding: 0 10px; display: inline-grid; place-items: center; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); color: var(--text); font-weight: 600; font-size: 14px; }
a.pg:hover { text-decoration: none; background: var(--surface-2); }
.pg.active { background: var(--grad); border-color: transparent; }
.pg.disabled, .pg.gap { opacity: .4; }

/* ---------- Footer / Toast ---------- */
.site-footer { margin-top: auto; border-top: 1px solid var(--border); padding: 20px 0; color: var(--muted); font-size: 13px; }
.footer-inner { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #1b1f36; border: 1px solid var(--border-2); color: var(--text); padding: 10px 18px; border-radius: 99px;
  font-size: 14px; font-weight: 600; z-index: 200; box-shadow: var(--shadow); transition: .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
