:root {
  --primary: #4f46e5;
  --primary-light: #6366f1;
  --primary-dark: #4338ca;
  --primary-50: #eef2ff;
  --primary-100: #e0e7ff;
  --accent: #06b6d4;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --sidebar-width: 260px;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 25px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
  --shadow-xl: 0 20px 50px -12px rgba(0,0,0,0.12);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Inter', -apple-system, sans-serif; background: var(--gray-50); color: var(--gray-800); line-height: 1.5; -webkit-font-smoothing: antialiased; }

/* === LOGIN === */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #4338ca 100%); position: relative; overflow: hidden; }
.login-page::before { content: ''; position: absolute; width: 600px; height: 600px; background: radial-gradient(circle, rgba(99,102,241,0.3) 0%, transparent 70%); top: -200px; right: -200px; }
.login-page::after { content: ''; position: absolute; width: 400px; height: 400px; background: radial-gradient(circle, rgba(6,182,212,0.2) 0%, transparent 70%); bottom: -100px; left: -100px; }
.login-card { background: rgba(255,255,255,0.95); backdrop-filter: blur(20px); border-radius: 20px; padding: 48px 40px; width: 100%; max-width: 400px; box-shadow: var(--shadow-xl); position: relative; z-index: 1; }
.login-logo { width: 56px; height: 56px; background: var(--primary); border-radius: 14px; display: flex; align-items: center; justify-content: center; margin: 0 auto 24px; box-shadow: 0 8px 16px rgba(79,70,229,0.3); }
.login-logo svg { width: 28px; height: 28px; color: white; }
.login-title { font-size: 22px; font-weight: 700; text-align: center; color: var(--gray-900); margin-bottom: 6px; }
.login-subtitle { font-size: 14px; color: var(--gray-500); text-align: center; margin-bottom: 32px; }

/* === LAYOUT === */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-width); background: var(--gray-900); color: white; position: fixed; top: 0; left: 0; bottom: 0; display: flex; flex-direction: column; z-index: 40; transition: transform 0.3s; }
.sidebar-header { padding: 24px 20px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.sidebar-brand { display: flex; align-items: center; gap: 12px; }
.sidebar-brand-icon { width: 36px; height: 36px; background: var(--primary); border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.sidebar-brand-icon svg { width: 18px; height: 18px; color: white; }
.sidebar-brand-text { font-size: 16px; font-weight: 700; }
.sidebar-brand-badge { font-size: 10px; background: rgba(99,102,241,0.3); color: #a5b4fc; padding: 2px 8px; border-radius: 4px; margin-left: 4px; }
.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }
.nav-section { margin-bottom: 24px; }
.nav-section-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: var(--gray-500); padding: 0 12px; margin-bottom: 8px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; cursor: pointer; transition: all 0.15s; font-size: 13px; font-weight: 500; color: var(--gray-400); margin-bottom: 2px; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: white; }
.nav-item.active { background: var(--primary); color: white; box-shadow: 0 4px 12px rgba(79,70,229,0.4); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.08); }
.sidebar-user { display: flex; align-items: center; gap: 10px; }
.sidebar-avatar { width: 32px; height: 32px; background: var(--primary-light); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 14px; }
.sidebar-user-info { flex: 1; }
.sidebar-user-name { font-size: 13px; font-weight: 600; }
.sidebar-user-role { font-size: 11px; color: var(--gray-500); }

/* === MAIN === */
.main { margin-left: var(--sidebar-width); flex: 1; min-height: 100vh; }
.topbar { background: white; border-bottom: 1px solid var(--gray-200); padding: 16px 32px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 30; }
.topbar-title { font-size: 18px; font-weight: 700; color: var(--gray-900); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.content { padding: 28px 32px; }

/* === CARDS === */
.card { background: white; border-radius: var(--radius); border: 1px solid var(--gray-200); box-shadow: var(--shadow-sm); overflow: hidden; transition: box-shadow 0.2s; }
.card:hover { box-shadow: var(--shadow); }
.card-header { padding: 18px 24px; border-bottom: 1px solid var(--gray-100); display: flex; align-items: center; justify-content: space-between; }
.card-header h3 { font-size: 14px; font-weight: 600; color: var(--gray-900); }
.card-body { padding: 24px; }

/* === STATS === */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card { background: white; border-radius: var(--radius); border: 1px solid var(--gray-200); padding: 20px; position: relative; overflow: hidden; }
.stat-card::after { content: ''; position: absolute; top: 0; right: 0; width: 80px; height: 80px; border-radius: 50%; opacity: 0.06; }
.stat-card.blue::after { background: var(--primary); }
.stat-card.green::after { background: var(--success); }
.stat-card.cyan::after { background: var(--accent); }
.stat-card.gray::after { background: var(--gray-400); }
.stat-value { font-size: 28px; font-weight: 800; color: var(--gray-900); }
.stat-label { font-size: 12px; color: var(--gray-500); margin-top: 4px; font-weight: 500; }
.stat-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; margin-bottom: 12px; }
.stat-icon.blue { background: var(--primary-50); color: var(--primary); }
.stat-icon.green { background: #ecfdf5; color: var(--success); }
.stat-icon.cyan { background: #ecfeff; color: var(--accent); }
.stat-icon.gray { background: var(--gray-100); color: var(--gray-500); }

/* === BUTTONS === */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 18px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; border: none; transition: all 0.15s; font-family: inherit; }
.btn-primary { background: var(--primary); color: white; box-shadow: 0 2px 8px rgba(79,70,229,0.25); }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 12px rgba(79,70,229,0.35); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-secondary { background: white; color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-secondary:hover { background: var(--gray-50); border-color: var(--gray-400); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; }
.btn-lg { padding: 12px 24px; font-size: 14px; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* === INPUTS === */
.input { width: 100%; padding: 10px 14px; border: 1px solid var(--gray-300); border-radius: 8px; font-size: 14px; font-family: inherit; transition: all 0.15s; background: white; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }
.input-mono { font-family: 'JetBrains Mono', 'Fira Code', monospace; letter-spacing: 1px; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20' fill='%236b7280'%3E%3Cpath d='M7 7l3-3 3 3m0 6l-3 3-3-3'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 36px; }
.label { display: block; font-size: 12px; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; }

/* === TEMPLATES === */
.templates-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; max-height: 220px; overflow-y: auto; padding: 4px; }
.template-item { position: relative; border-radius: 8px; overflow: hidden; border: 2px solid transparent; cursor: pointer; transition: all 0.15s; aspect-ratio: 4/3; }
.template-item:hover { border-color: var(--primary-light); transform: scale(1.03); }
.template-item.selected { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.2); }
.template-item img { width: 100%; height: 100%; object-fit: cover; }
.template-item .delete-btn { position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; background: rgba(0,0,0,0.6); color: white; border: none; border-radius: 50%; font-size: 10px; cursor: pointer; opacity: 0; transition: opacity 0.15s; display: flex; align-items: center; justify-content: center; }
.template-item:hover .delete-btn { opacity: 1; }
.template-name { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(transparent, rgba(0,0,0,0.7)); padding: 12px 6px 4px; font-size: 9px; color: white; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* === QR PREVIEW === */
.preview-container { position: relative; display: inline-block; border-radius: 8px; overflow: hidden; border: 1px solid var(--gray-200); }
.preview-container img { display: block; width: 350px; max-width: 100%; height: auto; }
.qr-overlay { position: absolute; border: 2px solid var(--primary); background: rgba(79,70,229,0.08); cursor: move; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 9px; font-weight: 700; color: var(--primary); backdrop-filter: blur(1px); }

/* === PROGRESS === */
.progress { height: 6px; background: var(--gray-200); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 3px; transition: width 0.3s ease; }

/* === BADGE === */
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 6px; font-size: 11px; font-weight: 600; }
.badge-primary { background: var(--primary-50); color: var(--primary); }
.badge-success { background: #ecfdf5; color: var(--success); }
.badge-danger { background: #fef2f2; color: var(--danger); }
.badge-gray { background: var(--gray-100); color: var(--gray-500); }

/* === LOGS === */
.log-item { padding: 10px 14px; border-left: 3px solid var(--gray-200); margin-bottom: 4px; border-radius: 0 6px 6px 0; background: var(--gray-50); font-size: 13px; display: flex; align-items: center; gap: 10px; }
.log-item.generate { border-left-color: var(--primary); }
.log-item.delete { border-left-color: var(--danger); }
.log-item .log-time { font-size: 11px; color: var(--gray-400); white-space: nowrap; }
.log-item .log-msg { color: var(--gray-700); }

/* === RESPONSIVE === */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .mobile-menu-btn { display: flex !important; }
  .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 35; }
  .sidebar-overlay.open { display: block; }
}
@media (max-width: 640px) {
  .content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-value { font-size: 22px; }
}

/* Mobile menu button */
.mobile-menu-btn { display: none; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--gray-200); background: white; cursor: pointer; }
.mobile-menu-btn svg { width: 20px; height: 20px; color: var(--gray-600); }
.hide-mobile { }
@media (max-width: 1024px) { .hide-mobile { display: none !important; } }
