:root {
  --bg-color: var(--tg-theme-bg-color, #0b0f19);
  --card-bg: var(--tg-theme-secondary-bg-color, #151d2f);
  --text-color: var(--tg-theme-text-color, #f8fafc);
  --hint-color: var(--tg-theme-hint-color, #94a3b8);
  --btn-color: var(--tg-theme-button-color, #3b82f6);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --accent: #10b981;
  --border: rgba(255, 255, 255, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-color);
  color: var(--text-color);
  line-height: 1.5;
  padding: 16px;
  padding-bottom: 32px;
}

.app-container {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  font-size: 24px;
  background: linear-gradient(135deg, #3b82f6, #10b981);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-info h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.subtitle {
  font-size: 12px;
  color: var(--hint-color);
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.status-badge.unverified {
  background: rgba(148, 163, 184, 0.15);
  color: var(--hint-color);
}

.status-badge.unverified .status-dot {
  background-color: var(--hint-color);
  box-shadow: none;
}

/* Mode Sections (Flex container for cards with 18px gap) */
.mode-section {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 100%;
}

@supports not (gap: 18px) {
  .mode-section > .card + .card {
    margin-top: 18px;
  }
}

/* Cards */
.card {
  background: var(--card-bg);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

.card h3 {
  font-size: 16px;
  font-weight: 700;
  color: #f8fafc;
  margin-bottom: 12px;
  letter-spacing: -0.2px;
}

/* Subscription Card */
.sub-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
  margin-bottom: 14px;
}

.meta-label, .expiry-label {
  display: block;
  font-size: 12px;
  color: var(--hint-color);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.meta-code {
  font-family: ui-monospace, monospace;
  font-size: 15px;
  font-weight: 700;
  color: #60a5fa;
}

.expiry-days {
  font-size: 15px;
  font-weight: 700;
  color: #34d399;
}

/* Action Buttons */
.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border-radius: 14px;
  text-decoration: none;
  color: #fff;
  transition: transform 0.1s ease, filter 0.15s ease, opacity 0.2s ease;
  position: relative;
  overflow: hidden;
}

.btn:active {
  transform: scale(0.98);
}

.btn.disabled, .btn-tool.disabled, .btn-copy-mini.disabled {
  opacity: 0.45 !important;
  pointer-events: none !important;
  filter: grayscale(0.8) !important;
  cursor: not-allowed !important;
}

/* Equal Vibrant App Buttons */
.btn-clash {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.35);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.btn-clash:hover {
  filter: brightness(1.1);
}

.btn-happ {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
  border: 1px solid rgba(129, 140, 248, 0.3);
}

.btn-happ:hover {
  filter: brightness(1.1);
}

.btn-hiddify {
  background: linear-gradient(135deg, #059669, #047857);
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
  border: 1px solid rgba(52, 211, 153, 0.3);
}

.btn-hiddify:hover {
  filter: brightness(1.1);
}

.btn-v2ray {
  background: linear-gradient(135deg, #d97706, #b45309);
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
  border: 1px solid rgba(251, 191, 36, 0.3);
}

.btn-v2ray:hover {
  filter: brightness(1.1);
}

.badge-recommend {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  margin-left: 6px;
  display: inline-block;
  vertical-align: middle;
  letter-spacing: 0.3px;
}

.btn-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-icon {
  font-size: 22px;
}

.btn-text strong {
  display: block;
  font-size: 15px;
  line-height: 1.2;
}

.btn-text small {
  display: block;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  margin-top: 2px;
}

/* Tools Bar */
.tools-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.btn-tool {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text-color);
  padding: 10px 8px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-tool:hover {
  background: rgba(255, 255, 255, 0.08);
}

.tool-icon {
  font-size: 15px;
}

/* Banner Card */
.banner-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.2);
}

.banner-icon {
  font-size: 24px;
}

.banner-content h4 {
  font-size: 14px;
  font-weight: 600;
  color: #34d399;
  margin-bottom: 2px;
}

.banner-content p {
  font-size: 12px;
  color: #cbd5e1;
  line-height: 1.4;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  background: rgba(0, 0, 0, 0.2);
  padding: 4px;
  border-radius: 10px;
  margin: 12px 0;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--hint-color);
  padding: 8px 4px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.step-item {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #3b82f6;
  color: #fff;
  font-size: 12px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.step-body strong {
  font-size: 13px;
  display: block;
}

.step-body p {
  font-size: 12px;
  color: var(--hint-color);
  margin-bottom: 6px;
}

.download-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.btn-inline {
  display: inline-block;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  text-decoration: none;
}

.btn-accent {
  background: #2563eb;
  color: #fff;
  font-weight: 600;
}

/* Locations */
.location-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.loc-pill {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}

.loc-hint {
  font-size: 12px;
  color: var(--hint-color);
  margin-top: 12px;
  line-height: 1.4;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-content {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  max-width: 320px;
  width: 100%;
  text-align: center;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.btn-close {
  background: transparent;
  border: none;
  font-size: 24px;
  color: var(--hint-color);
  cursor: pointer;
}

.modal-hint {
  font-size: 12px;
  color: var(--hint-color);
  margin-bottom: 14px;
}

.qr-box {
  background: #fff;
  padding: 12px;
  border-radius: 12px;
  display: inline-block;
}

.qr-box img {
  display: block;
  width: 200px;
  height: 200px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #10b981;
  color: #fff;
  padding: 10px 20px;
  border-radius: 30px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4);
  z-index: 2000;
  animation: fadeIn 0.2s ease;
}

.hidden {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* Mode Switcher */
.mode-switch {
  display: flex;
  gap: 8px;
  background: rgba(0, 0, 0, 0.25);
  padding: 5px;
  border-radius: 14px;
  border: 1px solid var(--border);
}

.mode-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  border: none;
  color: var(--hint-color);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.mode-btn.active {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.08));
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.mode-flag {
  font-size: 16px;
}

/* OpenFlux Credentials Box */
.credentials-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.cred-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.cred-row:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.cred-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.cred-label {
  font-size: 12px;
  color: var(--hint-color);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.cred-val {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  color: #93c5fd;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.btn-copy-mini {
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: #60a5fa;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.btn-copy-mini:active {
  transform: scale(0.95);
  background: rgba(59, 130, 246, 0.3);
}

/* Banner Flux */
.banner-flux {
  background: rgba(99, 102, 241, 0.08);
  border-color: rgba(99, 102, 241, 0.25);
}

.banner-flux .banner-content h4 {
  color: #818cf8;
}

/* Emergency Card */
.emergency-card {
  background: rgba(245, 158, 11, 0.06);
  border-color: rgba(245, 158, 11, 0.2);
}

.emergency-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.emergency-icon {
  font-size: 24px;
}

.emergency-header strong {
  display: block;
  font-size: 13px;
  color: #fbbf24;
}

.emergency-header p {
  font-size: 12px;
  color: var(--hint-color);
  margin-top: 2px;
}

.emergency-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Empty Key State Card */
.empty-key-card {
  text-align: center;
  padding: 24px 18px;
  background: rgba(30, 41, 59, 0.5);
  border: 1px dashed rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  margin-bottom: 4px;
}

.empty-key-icon {
  font-size: 38px;
  margin-bottom: 10px;
}

.empty-key-title {
  font-size: 16px;
  font-weight: 700;
  color: #f8fafc;
  margin-bottom: 6px;
}

.empty-key-desc {
  font-size: 13px;
  color: var(--hint-color);
  margin-bottom: 16px;
  line-height: 1.5;
}

.empty-key-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Persistent Navigation Bar */
.global-nav-bar,
.nav-bar-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}

.btn-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  color: #fff;
  transition: transform 0.1s ease, filter 0.15s ease;
  border: none;
  cursor: pointer;
}

.btn-nav:active {
  transform: scale(0.97);
}

.btn-nav-buy {
  background: linear-gradient(135deg, #10b981, #059669);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-nav-keys {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* Cabinet & Account Bar */
.cabinet-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
}

.cabinet-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  color: #e2e8f0;
}

.cabinet-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #10b981);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #fff;
}

.cabinet-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-cabinet-toggle {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  color: #93c5fd;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-cabinet-toggle:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* Cabinet Keys Dropdown / Drawer */
.cabinet-keys-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.cabinet-key-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s ease;
}

.cabinet-key-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.cabinet-key-item.active {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.12);
}

.key-item-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.key-item-name {
  font-size: 13px;
  font-weight: 600;
  color: #f8fafc;
}

.key-item-meta {
  font-size: 12px;
  color: var(--hint-color);
}

.key-item-badge {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 12px;
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  font-weight: 600;
}

/* Web Login Card (for non-authenticated visitors outside TG) & OTP Flow */
.web-login-card {
  text-align: center;
  padding: 24px 20px;
  max-width: 360px;
}

.web-login-icon {
  font-size: 38px;
  margin-bottom: 8px;
}

.login-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.login-input-group {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  text-align: left;
}

.login-label {
  font-size: 12px;
  color: var(--hint-color);
  font-weight: 500;
}

.input-with-icon {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
}

.input-with-icon .input-icon {
  position: absolute;
  left: 12px;
  font-size: 16px;
  pointer-events: none;
  color: var(--hint-color);
}

.login-input {
  width: 100%;
  box-sizing: border-box;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: #fff;
  padding: 12px 14px 12px 38px;
  font-size: 15px;
  outline: none;
  transition: all 0.2s ease;
}

.login-input:focus {
  border-color: #3b82f6;
  background: rgba(255, 255, 255, 0.1);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.otp-input {
  padding: 12px 16px !important;
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.login-error {
  font-size: 12px;
  color: #ef4444;
  margin-top: 4px;
  text-align: left;
}

.web-login-btn {
  width: 100%;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  padding: 13px 18px;
  border-radius: 12px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s ease;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}

.web-login-btn:hover {
  filter: brightness(1.1);
}

.web-login-btn:active {
  transform: scale(0.98);
}

.web-login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  filter: grayscale(0.5);
}

.btn-tg-contact {
  width: 100%;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(34, 158, 217, 0.15);
  border: 1px solid rgba(34, 158, 217, 0.4);
  color: #38bdf8;
  padding: 11px 16px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  margin-top: 8px;
  transition: all 0.2s ease;
}

.btn-tg-contact:hover {
  background: rgba(34, 158, 217, 0.25);
}

.login-bot-hint {
  font-size: 12px;
  color: var(--hint-color);
  line-height: 1.4;
  margin-top: 14px;
  text-align: center;
  background: rgba(255, 255, 255, 0.03);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.login-bot-hint code {
  background: rgba(255, 255, 255, 0.12);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  color: #38bdf8;
}

.login-bot-hint a {
  color: #38bdf8;
  text-decoration: none;
  font-weight: 600;
}

.login-step-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  font-size: 12px;
}

.btn-link-action {
  background: none;
  border: none;
  color: #38bdf8;
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  transition: opacity 0.2s;
}

.btn-link-action:hover {
  opacity: 0.8;
}

.dot-sep {
  color: var(--hint-color);
}

