:root {
  --bg: #0a0f1f;
  --surface: rgba(255, 255, 255, 0.05);
  --surface-light: rgba(255, 255, 255, 0.08);
  --fg: #e8eef8;
  --muted: #a0a8b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --accent: #06b6d4;
  --success: #10b981;
  --error: #ef4444;
  --border: rgba(255, 255, 255, 0.1);
  --radius: 12px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: linear-gradient(135deg, #1e1e1e 0%, #1e1e1e 100%);
  color: var(--fg);
  margin: 0;
  padding: 20px;
  min-height: 100vh;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
}

/* HEADER */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 40px;
}

.brand img {
  height: 48px;
}

.account {
  position: relative;
  display: flex;
  align-items: center;
}

.account-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.account-btn:hover {
  background: var(--surface-light);
  border-color: var(--primary);
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  min-width: 200px;
  z-index: 1000;
}

.dropdown-menu.visible {
  display: block;
}

.dropdown-menu p {
  margin: 0 0 8px;
  font-size: 14px;
}

.logout-btn {
  width: 100%;
  padding: 8px;
  background: var(--error);
  border: none;
  color: white;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.3s ease;
}

.logout-btn:hover {
  background: #dc2626;
}

/* CARDS GRID */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
  margin-bottom: 40px;
}

.action-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.action-card:hover {
  background: var(--surface-light);
  border-color: var(--primary);
  transform: translateY(-4px);
  box-shadow: var(--shadow);
}

.card-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.action-card h3 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 600;
  color: var(--fg);
}

.action-card p {
  margin: 0 0 16px;
  font-size: 14px;
  color: var(--muted);
}

.card-footer {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* CARDS (for loading, auth) */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  margin-bottom: 24px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.card h3 {
  margin: 0 0 16px;
  font-size: 22px;
  font-weight: 600;
}

/* MODAL OVERLAY */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  animation: fadeIn 0.3s ease;
}

.modal-overlay.visible {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* MODALS */
.modal {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 90%;
  width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  z-index: 1000;
  box-shadow: var(--shadow);
  animation: slideIn 0.3s ease;
  background: rgba(20, 25, 45, 0.95); /* خلفية غامقة شبه مصمتة */
  background: #1e1e1e; /* خلفية داكنة صلبة لمنع الشفافية الزائدة */
  border: 1px solid rgba(99, 102, 241, 0.5);
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
}
/* 2. تنسيق صندوق النتيجة المكتملة */
.result-container {
  margin-top: 25px !important;
  border: 2px solid var(--accent) !important;
  background: rgba(6, 182, 212, 0.05) !important;
  padding: 20px !important;
  animation: fadeInScale 0.4s ease-out;
}

/* 3. صندوق التعليمات */
.instructions-box {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 15px;
  text-align: center;
  border-right: 4px solid var(--accent);
}

.instruction-title {
  color: var(--accent);
  font-weight: bold;
  margin-bottom: 5px;
}

.slots-display {
  font-family: monospace;
  font-size: 18px;
  color: var(--success);
  letter-spacing: 3px;
  margin-top: 5px;
  font-weight: bold;
}

/* 4. تنسيق رمز التفعيل (الكبير والواضح) */
.key-code-large {
  display: block;
  background: #000;
  color: #ff0000; /* لون فسفوري واضح */
  font-family: 'Courier New', monospace;
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  padding: 20px;
  border-radius: 10px;
  margin: 15px 0;
  border: 2px dashed var(--accent);
  word-break: break-all;
  box-shadow: inset 0 0 10px rgba(6, 182, 212, 0.5);
}

.result-label {
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  margin: 0;
}

.copy-full-btn {
  width: 100%;
  padding: 15px !important;
  font-size: 16px !important;
}

.success-glow {
  color: var(--success);
  text-align: center;
  margin-top: 10px;
  font-weight: bold;
  animation: pulse 1.5s infinite;
}

/* أنيميشن لظهور النتيجة */
@keyframes fadeInScale {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.5; }
  100% { opacity: 1; }
}
.modal:not(.hidden) {
  display: block;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translate(-50%, -48%);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

.modal-content {
  position: relative;
}

.modal-close {
  position: absolute;
  top: 0;
  left: 0;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  transition: color 0.3s ease;
}

.modal-close:hover {
  color: var(--error);
}

.modal h2 {
  margin: 0 0 20px;
  font-size: 24px;
  font-weight: 600;
  text-align: center;
  padding-top: 8px;
}

.modal-balance {
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 16px;
}

.modal-balance strong {
  color: var(--success);
  font-size: 16px;
}

/* FORMS */
label {
  display: block;
  margin-top: 16px;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 14px;
  color: var(--fg);
}

input,
select,
textarea {
  width: 100%;
  padding: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font-family: inherit;
  font-size: 14px;
  transition: all 0.3s ease;
  direction: ltr;
  text-align: right;
}

input::placeholder {
  direction: rtl;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--primary);
}

.form-row {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.form-row button {
  flex: 1;
}

.action-btn {
  padding: 12px 16px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  background: var(--muted);
  cursor: not-allowed;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
}

.btn-outline:hover {
  background: var(--surface-light);
  border-color: var(--primary);
}

/* KEY DISPLAY */
/* تنسيق مطور لعرض رمز التفعيل */
.key-code {
  display: block;
  font-family: 'Courier New', monospace;
  font-weight: 800; /* خط عريض جداً */
  word-break: break-all;
  background: rgba(6, 182, 212, 0.15); /* خلفية بلون الأكسنت خفيفة */
  color: #00f2ff; /* لون سماوي مضيء وواضح جداً */
  padding: 20px;
  border-radius: 10px;
  font-size: 22px; /* حجم كبير */
  text-align: center;
  border: 2px dashed var(--accent); /* إطار متقطع ليوحي بأنه رمز */
  letter-spacing: 2px;
  margin-top: 10px;
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.3); /* توهج خفيف للرمز */
}

/* تحسين حاوية النتيجة */
.key-box {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--accent);
  padding: 20px;
  margin-top: 20px;
  border-radius: var(--radius);
  animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.copy-small {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
  transition: all 0.3s ease;
}

.copy-small:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* HISTORY LIST */
.history-list {
  list-style: none;
  padding: 0;
  margin: 16px 0;
}

.history-list li {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

/* MESSAGES */
.message {
  margin-top: 12px;
  font-size: 14px;
  padding: 8px;
  border-radius: 6px;
}

.message.error {
  color: var(--error);
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.message.success {
  color: var(--success);
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.error {
  color: var(--error);
}

.success {
  color: var(--success);
}

.muted {
  color: var(--muted);
}

/* SKELETON */
.skeleton {
  display: block;
  height: 20px;
  background: linear-gradient(90deg, var(--surface) 0%, var(--surface-light) 50%, var(--surface) 100%);
  border-radius: 6px;
  margin-bottom: 12px;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* UTILITIES */
.hidden {
  display: none !important;
}

/* RESPONSIVE */
@media (max-width: 768px) {
  .cards-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .modal {
    width: 95%;
    padding: 24px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .action-card {
    padding: 24px;
  }

  .form-row {
    flex-direction: column;
  }

  .form-row button {
    width: 100%;
  }
}

@media (max-width: 480px) {
  body {
    padding: 12px;
  }

  .app {
    margin: 0;
  }

  .modal {
    width: 100%;
    border-radius: 12px;
    max-height: 85vh;
  }

  .action-card {
    padding: 20px;
  }

  .card-icon {
    font-size: 36px;
  }

  .modal h2 {
    font-size: 20px;
  }
}

/* تنسيق رابط الـ PDF البسيط */
.pdf-guide-wrapper {
    text-align: center;
    margin-bottom: 20px; /* مسافة بسيطة قبل الكاردات */
    padding: 10px;
}

.simple-pdf-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #007bff;
    text-decoration: none;
    font-weight: bold;
    font-size: 15px;
    padding: 8px 16px;
    border: 1px dashed #007bff; /* إطار منقط بسيط */
    border-radius: 8px;
    transition: background 0.3s;
}

.simple-pdf-link:hover {
    background-color: #f0f7ff;
    text-decoration: underline;
}