/* =============================================
   CSS Variables & Reset
   ============================================= */
:root {
  --bg-primary: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-card: #242424;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-light: rgba(124, 58, 237, 0.15);
  --text-primary: #f1f1f1;
  --text-secondary: #a0a0a0;
  --border: #333;
  --border-light: #2a2a2a;
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.1);
  --error: #ef4444;
  --error-bg: rgba(239, 68, 68, 0.1);
  --warning: #f59e0b;
  --sidebar-width: 260px;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --transition: 0.2s ease;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  overflow: hidden;
}

/* =============================================
   Scrollbar
   ============================================= */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* =============================================
   Auth Modal
   ============================================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity var(--transition);
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
  animation: modalIn 0.25s ease;
}

@keyframes modalIn {
  from { transform: translateY(-20px); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}

.modal-logo {
  text-align: center;
  margin-bottom: 1.75rem;
}

.modal-logo h1 {
  font-size: 1.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-logo p {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.modal-tab {
  flex: 1;
  padding: 0.75rem;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
}

.modal-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.modal-tab:hover:not(.active) {
  color: var(--text-primary);
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-form.hidden {
  display: none;
}

.auth-error {
  color: var(--error);
  font-size: 0.85rem;
  background: var(--error-bg);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.9rem;
  display: none;
}

.auth-error.visible {
  display: block;
}

/* =============================================
   Sidebar
   ============================================= */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-logo {
  padding: 1.5rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border-light);
}

.sidebar-logo h2 {
  font-size: 1.35rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.sidebar-logo span {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  padding: 0.5rem 0.5rem 0.25rem;
  margin-top: 0.5rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.875rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: background var(--transition), color var(--transition);
}

.nav-link:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.nav-link.active {
  background: var(--accent-light);
  color: var(--accent);
}

.nav-link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-user {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-light);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: #fff;
  flex-shrink: 0;
}

.user-details {
  overflow: hidden;
  flex: 1;
}

.user-email {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-tier-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.1rem 0.5rem;
  border-radius: 100px;
  margin-top: 0.15rem;
}

.user-tier-badge.free {
  background: rgba(160, 160, 160, 0.15);
  color: var(--text-secondary);
}

.user-tier-badge.premium {
  background: rgba(124, 58, 237, 0.2);
  color: #a78bfa;
}

.docs-counter {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.docs-counter span {
  color: var(--text-primary);
  font-weight: 600;
}

.btn-logout {
  width: 100%;
  padding: 0.5rem;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  transition: all var(--transition);
}

.btn-logout:hover {
  border-color: var(--error);
  color: var(--error);
  background: var(--error-bg);
}

/* =============================================
   Main Content
   ============================================= */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  height: 100vh;
  overflow-y: auto;
  padding: 2rem;
}

.page {
  display: none;
  max-width: 860px;
  margin: 0 auto;
  animation: fadeIn 0.2s ease;
}

.page.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.page-header {
  margin-bottom: 1.75rem;
}

.page-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.page-header p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

/* =============================================
   Cards
   ============================================= */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* =============================================
   Forms
   ============================================= */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.form-control {
  width: 100%;
  padding: 0.65rem 0.875rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.2);
}

.form-control::placeholder {
  color: var(--text-secondary);
  opacity: 0.6;
}

textarea.form-control {
  resize: vertical;
  min-height: 90px;
}

select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a0a0a0' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.5rem;
  cursor: pointer;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* =============================================
   Buttons
   ============================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.4);
}

.btn-secondary {
  background: none;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
  background: var(--bg-secondary);
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-success:hover {
  background: #0da070;
  transform: translateY(-1px);
}

.btn-sm {
  padding: 0.4rem 0.875rem;
  font-size: 0.8rem;
}

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--radius-sm);
}

/* =============================================
   Document Type Selector
   ============================================= */
.doc-type-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.doc-type-card {
  padding: 1rem;
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
}

.doc-type-card:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.doc-type-card.selected {
  border-color: var(--accent);
  background: var(--accent-light);
}

.doc-type-card .doc-type-icon {
  font-size: 1.5rem;
  margin-bottom: 0.4rem;
  display: block;
}

.doc-type-card .doc-type-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.doc-type-card .doc-type-desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}

/* =============================================
   Result Area
   ============================================= */
.result-area {
  display: none;
  margin-top: 1.25rem;
}

.result-area.visible {
  display: block;
  animation: fadeIn 0.3s ease;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.result-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--success);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.result-actions {
  display: flex;
  gap: 0.5rem;
}

.result-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  font-size: 0.85rem;
  line-height: 1.8;
  white-space: pre-wrap;
  max-height: 500px;
  overflow-y: auto;
  color: var(--text-primary);
}

/* =============================================
   Limit Warning
   ============================================= */
.limit-warning {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--warning);
  margin-bottom: 1rem;
  display: none;
}

.limit-warning.visible {
  display: block;
}

/* =============================================
   History List
   ============================================= */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.history-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
}

.history-empty svg {
  width: 48px;
  height: 48px;
  margin-bottom: 1rem;
  opacity: 0.3;
}

.history-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  transition: border-color var(--transition);
}

.history-item:hover {
  border-color: var(--accent);
}

.history-item-icon {
  width: 40px;
  height: 40px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.history-item-body {
  flex: 1;
  overflow: hidden;
}

.history-item-type {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.history-item-date {
  font-size: 0.775rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}

.history-item-preview {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.4rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
}

/* =============================================
   Billing / Plans
   ============================================= */
.current-plan-banner {
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.2), rgba(167, 139, 250, 0.1));
  border: 1px solid rgba(124, 58, 237, 0.4);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.plan-icon {
  font-size: 2.5rem;
}

.plan-details h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.plan-details p {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: 0.2rem;
}

.plans-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.plan-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  position: relative;
  transition: border-color var(--transition), transform var(--transition);
}

.plan-card:hover {
  transform: translateY(-2px);
}

.plan-card.premium {
  border-color: var(--accent);
}

.plan-badge {
  position: absolute;
  top: -12px;
  right: 1rem;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.25rem 0.75rem;
  border-radius: 100px;
}

.plan-name {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.plan-price {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 0.25rem;
}

.plan-price span {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.plan-period {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 1.25rem;
}

.plan-features {
  list-style: none;
  margin-bottom: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.plan-features li {
  font-size: 0.875rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.plan-features li::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-secondary);
  flex-shrink: 0;
}

.plan-card.premium .plan-features li {
  color: var(--text-primary);
}

.plan-card.premium .plan-features li::before {
  background: var(--success);
}

.plan-current {
  width: 100%;
  padding: 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-secondary);
  font-size: 0.875rem;
  text-align: center;
  cursor: default;
}

/* =============================================
   Loading Spinner
   ============================================= */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: var(--text-secondary);
  gap: 0.75rem;
}

.loading-overlay .spinner {
  border-color: rgba(124, 58, 237, 0.3);
  border-top-color: var(--accent);
}

/* =============================================
   Toast Notification
   ============================================= */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.875rem 1.25rem;
  font-size: 0.875rem;
  color: var(--text-primary);
  box-shadow: var(--shadow);
  z-index: 2000;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease;
  max-width: 320px;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.success {
  border-left: 3px solid var(--success);
}

.toast.error {
  border-left: 3px solid var(--error);
}

/* =============================================
   Responsive — Mobile
   ============================================= */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 200;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow);
  }

  .main-content {
    margin-left: 0;
    padding: 1rem;
    padding-top: 4rem;
  }

  .mobile-menu-btn {
    display: flex;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .doc-type-grid {
    grid-template-columns: 1fr;
  }

  .plans-grid {
    grid-template-columns: 1fr;
  }

  .history-item {
    flex-wrap: wrap;
  }

  .history-item-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .modal {
    margin: 1rem;
    padding: 1.75rem;
  }
}

@media (max-width: 480px) {
  .result-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
}
