/* === Reset & Variables === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary: #0b0f15;
  --bg-secondary: #131820;
  --bg-card: #1a1f2b;
  --bg-card-hover: #1f2533;
  --bg-input: #111620;
  --border: #252b36;
  --border-focus: #3b82f6;
  --text-primary: #e8ecf1;
  --text-secondary: #8b92a0;
  --text-muted: #5a6170;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-glow: rgba(59, 130, 246, 0.15);
  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.1);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.1);
  --gradient: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
  --transition: 0.2s ease;
}

html { font-size: 15px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Layout === */
.app { display: none; min-height: 100vh; }
.app.active { display: flex; }

/* === Auth Layout === */
.app.auth-page.active {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 2rem;
}
.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow-lg);
}
.auth-card .logo {
  display: flex; align-items: center; gap: 0.6rem;
  justify-content: center; margin-bottom: 2rem;
}
.auth-card .logo-icon {
  width: 42px; height: 42px;
  background: var(--gradient); border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; color: #fff; font-weight: 700;
}
.auth-card .logo-text { font-size: 1.3rem; font-weight: 700; }
.auth-card .logo-text span { color: var(--accent); }
.auth-card h2 {
  text-align: center; font-size: 1.5rem;
  margin-bottom: 0.4rem;
}
.auth-card .subtitle {
  text-align: center; color: var(--text-secondary);
  margin-bottom: 1.8rem; font-size: 0.9rem;
}

/* === Form === */
.form-group { margin-bottom: 1.1rem; }
.form-group label {
  display: block; margin-bottom: 0.35rem;
  font-size: 0.85rem; color: var(--text-secondary);
  font-weight: 500;
}
.form-group input {
  width: 100%; padding: 0.7rem 0.85rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none; transition: border var(--transition);
}
.form-group input:focus { border-color: var(--border-focus); }
.form-group input::placeholder { color: var(--text-muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 0.4rem; padding: 0.7rem 1.4rem;
  border-radius: var(--radius-sm); font-size: 0.9rem;
  font-weight: 500; cursor: pointer; border: none;
  transition: all var(--transition); white-space: nowrap;
}
.btn-primary {
  background: var(--accent); color: #fff;
  width: 100%; padding: 0.8rem;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-primary);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }
.btn-gradient {
  background: var(--gradient); color: #fff;
}
.btn-gradient:hover { opacity: 0.9; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-ghost {
  background: transparent; color: var(--text-secondary);
  border: none; padding: 0.4rem;
}
.btn-ghost:hover { color: var(--text-primary); }

.auth-switch {
  text-align: center; margin-top: 1.2rem;
  font-size: 0.85rem; color: var(--text-secondary);
}
.auth-switch a { cursor: pointer; font-weight: 500; }
.auth-switch a:hover { text-decoration: underline; }

.error-msg {
  background: var(--danger-bg); color: var(--danger);
  padding: 0.6rem 0.8rem; border-radius: var(--radius-sm);
  font-size: 0.82rem; margin-bottom: 1rem; display: none;
}

/* === Main App Layout === */
.main-app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 240px; min-width: 240px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 1.2rem 0;
}
.sidebar .logo-area {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0 1.2rem 1.2rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.6rem;
}
.sidebar .logo-area .logo-icon {
  width: 34px; height: 34px;
  background: var(--gradient); border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; color: #fff; font-weight: 700;
}
.sidebar .logo-area .logo-text { font-size: 1.1rem; font-weight: 700; }
.sidebar .logo-area .logo-text span { color: var(--accent); }

.nav-list { list-style: none; padding: 0.4rem 0; flex: 1; }
.nav-item { margin: 0.15rem 0; }
.nav-link {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.65rem 1.2rem; margin: 0 0.5rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.88rem; font-weight: 500;
  cursor: pointer; transition: all var(--transition);
  text-decoration: none;
}
.nav-link:hover { background: var(--bg-card); color: var(--text-primary); }
.nav-link.active { background: var(--accent-glow); color: var(--accent); }
.nav-link .nav-icon { font-size: 1.1rem; width: 22px; text-align: center; }

.sidebar-footer {
  padding: 0.8rem 1.2rem; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 0.6rem;
}
.sidebar-footer .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--gradient); display: flex; align-items: center;
  justify-content: center; font-size: 0.8rem; font-weight: 600;
}
.sidebar-footer .user-info { font-size: 0.82rem; color: var(--text-secondary); flex: 1; }
.sidebar-footer .btn-logout {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 0.85rem; padding: 0.2rem;
}
.sidebar-footer .btn-logout:hover { color: var(--danger); }

/* Main Content */
.main-content {
  flex: 1; padding: 2rem 2.5rem;
  overflow-y: auto; max-height: 100vh;
}
.page { display: none; }
.page.active { display: block; }
.page-header { margin-bottom: 1.8rem; }
.page-header h1 { font-size: 1.6rem; font-weight: 600; }
.page-header p { color: var(--text-secondary); margin-top: 0.25rem; font-size: 0.88rem; }

/* === Dashboard Cards === */
.stats-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 1rem; margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.2rem;
}
.stat-card .stat-label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.4rem; }
.stat-card .stat-value { font-size: 1.7rem; font-weight: 700; }
.stat-card .stat-sub { font-size: 0.78rem; color: var(--text-secondary); margin-top: 0.2rem; }
.stat-card.accent { border-color: rgba(59, 130, 246, 0.3); background: linear-gradient(135deg, #1a1f2b 0%, rgba(59,130,246,0.05) 100%); }
.stat-card.accent .stat-value { background: var(--gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

/* === Cards & Table === */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.card-header h3 { font-size: 1rem; font-weight: 600; }

.table-wrap { overflow-x: auto; }
table {
  width: 100%; border-collapse: collapse;
  font-size: 0.86rem;
}
th, td {
  text-align: left; padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border);
}
th { color: var(--text-muted); font-weight: 500; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:hover { background: rgba(255,255,255,0.02); }
td .mono { font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; font-size: 0.8rem; }

/* === API Keys === */
.api-key-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0; }
.api-key-row:not(:last-child) { border-bottom: 1px solid var(--border); }
.api-key-value {
  flex: 1; font-family: 'SF Mono', 'Consolas', monospace;
  font-size: 0.82rem; padding: 0.4rem 0.6rem;
  background: var(--bg-input); border-radius: var(--radius-sm);
  color: var(--text-secondary); word-break: break-all;
}
.api-key-meta { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.2rem; }
.generate-bar {
  display: flex; gap: 0.5rem; margin-top: 1rem;
}
.generate-bar input {
  flex: 1; padding: 0.6rem 0.8rem;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  font-size: 0.85rem; outline: none;
}
.generate-bar input:focus { border-color: var(--border-focus); }

/* === Billing Plans === */
.plans-grid {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 0.8rem;
}
.plan-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.3rem;
  text-align: center; position: relative;
  transition: border var(--transition);
}
.plan-card:hover { border-color: var(--accent); }
.plan-card.current {
  border-color: var(--accent);
  background: linear-gradient(135deg, #1a1f2b 0%, rgba(59,130,246,0.08) 100%);
}
.plan-card .plan-badge {
  display: inline-block; padding: 0.15rem 0.6rem;
  border-radius: 20px; font-size: 0.7rem; font-weight: 600;
  background: var(--accent-glow); color: var(--accent);
  margin-bottom: 0.6rem;
}
.plan-card .plan-name { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.3rem; }
.plan-card .plan-price { font-size: 1.6rem; font-weight: 700; margin-bottom: 0.15rem; }
.plan-card .plan-price span { font-size: 0.85rem; color: var(--text-muted); font-weight: 400; }
.plan-card .plan-desc { font-size: 0.78rem; color: var(--text-secondary); margin-bottom: 0.8rem; }
.plan-card .plan-features {
  text-align: left; font-size: 0.78rem; color: var(--text-secondary);
  margin-bottom: 1rem;
}
.plan-card .plan-features li {
  list-style: none; padding: 0.2rem 0; display: flex; align-items: center; gap: 0.4rem;
}
.plan-card .plan-features li::before { content: '✓'; color: var(--success); font-weight: 700; }

/* Toast */
.toast {
  position: fixed; bottom: 2rem; right: 2rem;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.8rem 1.2rem;
  color: var(--text-primary); font-size: 0.85rem;
  box-shadow: var(--shadow-lg); z-index: 9999;
  opacity: 0; transform: translateY(10px);
  transition: all 0.3s ease; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }

/* === Responsive === */
@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .plans-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 768px) {
  .sidebar { width: 200px; min-width: 200px; }
  .main-content { padding: 1.5rem; }
  .stats-grid { grid-template-columns: 1fr; }
  .plans-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .sidebar { display: none; }
  .plans-grid { grid-template-columns: 1fr; }
}
