:root {
  --bg: #0f172a;
  --card: #1e293b;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #7c3aed;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --header-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: linear-gradient(160deg, #0f172a, #1e1b4b);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  padding-bottom: var(--safe-bottom);
}

body.menu-open {
  overflow: hidden;
}

/* Site header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: calc(var(--header-h) + var(--safe-top));
  padding: calc(8px + var(--safe-top)) calc(12px + var(--safe-right)) 8px calc(12px + var(--safe-left));
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.site-logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  min-height: 44px;
}

.logo-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #8b5cf6, #6366f1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}

.logo-text {
  font-weight: 700;
  font-size: 0.92rem;
}

.header-nav {
  display: none;
  gap: 4px;
}

.header-nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 8px;
}

.header-nav a:hover,
.header-nav a.active {
  color: var(--text);
  background: rgba(124, 58, 237, 0.18);
}

.menu-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
}

.menu-btn span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

.menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.menu-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

.mobile-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 300;
  width: min(280px, 86vw);
  height: 100dvh;
  padding: calc(12px + var(--safe-top)) 16px calc(20px + var(--safe-bottom));
  background: #151c30;
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform 0.28s ease;
  overflow-y: auto;
}

.mobile-drawer.open {
  transform: translateX(0);
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.drawer-head button {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
}

.mobile-drawer a {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 12px;
  margin-bottom: 4px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}

.mobile-drawer a.active,
.mobile-drawer a:hover {
  background: rgba(124, 58, 237, 0.14);
}

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px calc(16px + var(--safe-right)) calc(40px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

.header {
  text-align: center;
  padding: 12px 0 20px;
}

.header h1 {
  font-size: 1.25rem;
  margin-bottom: 4px;
}

.header p {
  color: var(--muted);
  font-size: 0.85rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
}

.tabs-scroll {
  margin-bottom: 16px;
  margin-left: calc(-1 * var(--safe-left));
  margin-right: calc(-1 * var(--safe-right));
  padding: 0 calc(16px + var(--safe-right)) 0 calc(16px + var(--safe-left));
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tabs-scroll::-webkit-scrollbar {
  display: none;
}

.tabs {
  display: flex;
  gap: 8px;
  min-width: min-content;
}

.tab {
  flex: 0 0 auto;
  min-width: 110px;
  min-height: 44px;
  padding: 10px 14px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
}

.tab.active {
  background: var(--primary);
  color: #fff;
}

.panel { display: none; }
.panel.active { display: block; }

label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  min-height: 48px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 16px;
  margin-bottom: 14px;
  -webkit-appearance: none;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  min-height: 48px;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.92rem;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  width: 100%;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-block {
  width: 100%;
  margin-top: 10px;
}

.btn-sm {
  padding: 8px 12px;
  font-size: 0.8rem;
  min-height: 40px;
  width: auto;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.stat {
  background: rgba(124, 58, 237, 0.12);
  border-radius: 12px;
  padding: 12px 10px;
  text-align: center;
}

.stat-val {
  font-size: 1.4rem;
  font-weight: 800;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 2px;
}

.license-card { position: relative; }

.license-key {
  font-family: monospace;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  background: rgba(0, 0, 0, 0.3);
  padding: 12px;
  border-radius: 10px;
  text-align: center;
  margin: 10px 0;
  word-break: break-all;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}

.badge-green { background: rgba(16, 185, 129, 0.2); color: #6ee7b7; }
.badge-amber { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
.badge-red { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
.badge-blue { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }

.meta-row {
  display: grid;
  grid-template-columns: 38% 1fr;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
  margin: 6px 0;
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.actions .btn {
  flex: 1 1 auto;
  min-width: 120px;
}

.toast {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: #334155;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 0.88rem;
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.show { opacity: 1; }

.login-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.login-tab {
  flex: 1;
  min-height: 44px;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.82rem;
}

.login-tab.active {
  border-color: var(--primary);
  color: #fff;
  background: rgba(124, 58, 237, 0.12);
}

#appView { display: none; }
#loginView.hidden { display: none; }

.hidden-panel { display: none; }

.form-hint {
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 14px;
  line-height: 1.45;
}

.checkout-summary {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 12px 0;
  line-height: 1.45;
}

.ticket-list {
  margin-top: 14px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
  font-size: 0.9rem;
}

.product-block { margin-bottom: 14px; }
.product-block h3 { font-size: 0.95rem; margin-bottom: 8px; }

.plan-option {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  min-height: 48px;
}

.plan-option.selected {
  border-color: var(--primary);
  background: rgba(124, 58, 237, 0.1);
}

.plan-option input {
  width: auto;
  min-height: auto;
  margin: 0 8px 0 0;
}

.coupon-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.coupon-row input {
  flex: 1;
  margin-bottom: 0;
}

.coupon-row .btn {
  width: auto;
  white-space: nowrap;
  flex-shrink: 0;
}

.user-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  font-size: 0.85rem;
}

.user-bar span {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 640px) {
  .header-nav { display: flex; }
  .menu-btn { display: none; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .header h1 { font-size: 1.5rem; }
}

@media (min-width: 768px) {
  .tabs-scroll {
    margin-left: 0;
    margin-right: 0;
    padding: 0;
    overflow: visible;
  }

  .tabs { width: 100%; }
  .tab { flex: 1; min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-drawer,
  .menu-backdrop {
    transition: none;
  }
}
