/* ============================================================
   Assistora AI - Main Stylesheet
   Premium SaaS Dashboard Design
   ============================================================ */

:root {
  /* Brand Colors */
  --brand-primary: #3b82f6;
  --brand-secondary: #8b5cf6;
  --brand-accent: #06b6d4;
  --brand-gradient: linear-gradient(135deg, #3b82f6, #8b5cf6);
  --brand-gradient-soft: linear-gradient(135deg, rgba(59,130,246,0.15), rgba(139,92,246,0.15));

  /* Dark Theme (default) */
  --bg-root: #070b14;
  --bg-surface: #0d1526;
  --bg-card: #111827;
  --bg-card-hover: #162033;
  --bg-input: #1e293b;
  --bg-sidebar: #0a1120;

  --border-color: #1e3a5f;
  --border-subtle: #1a2d4a;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --sidebar-width: 260px;
  --header-height: 64px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.5);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.6);
  --shadow-glow: 0 0 30px rgba(59,130,246,0.15);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --transition: all 0.2s ease;
}

[data-theme="light"] {
  --bg-root: #f0f4ff;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f8faff;
  --bg-input: #f1f5f9;
  --bg-sidebar: #0a1120;

  --border-color: #e2e8f0;
  --border-subtle: #f1f5f9;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.15);
  --shadow-glow: 0 0 30px rgba(59,130,246,0.1);
}

/* ============================================================
   Base
   ============================================================ */

* { box-sizing: border-box; }

body {
  font-family: 'Sora', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-root);
  color: var(--text-primary);
  margin: 0;
  padding: 0;
  font-size: 14px;
  line-height: 1.6;
  overflow-x: hidden;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-surface); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--brand-primary); }

/* ============================================================
   Layout
   ============================================================ */

.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ============================================================
   Sidebar
   ============================================================ */

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid rgba(30,58,95,0.5);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 1000;
  transition: transform 0.3s ease;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-brand {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(30,58,95,0.5);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: var(--header-height);
}

.brand-logo {
  width: 36px;
  height: 36px;
  background: var(--brand-gradient);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  box-shadow: 0 4px 15px rgba(59,130,246,0.4);
}

.brand-text {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
}

.brand-badge {
  font-size: 0.6rem;
  background: var(--brand-gradient);
  color: #fff;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.sidebar-nav {
  padding: 1rem 0;
  flex: 1;
}

.nav-section-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding: 0.75rem 1.5rem 0.25rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1.5rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 0;
  transition: var(--transition);
  position: relative;
  margin: 1px 0.75rem;
  border-radius: var(--radius-sm);
}

.sidebar-link:hover {
  color: var(--text-primary);
  background: rgba(59,130,246,0.08);
}

.sidebar-link.active {
  color: var(--brand-primary);
  background: rgba(59,130,246,0.12);
}

.sidebar-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--brand-gradient);
  border-radius: 0 2px 2px 0;
  margin-left: -0.75rem;
}

.sidebar-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1rem;
}

.sidebar-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid rgba(30,58,95,0.5);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

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

.user-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
}

.user-role {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ============================================================
   Main Content
   ============================================================ */

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg-root);
}

/* ============================================================
   Top Header
   ============================================================ */

.top-header {
  height: var(--header-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 1rem;
}

.header-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn-icon {
  width: 36px;
  height: 36px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: var(--transition);
  text-decoration: none;
  font-size: 0.9rem;
}

.btn-icon:hover {
  background: var(--bg-card-hover);
  color: var(--brand-primary);
  border-color: var(--brand-primary);
}

/* ============================================================
   Page Content
   ============================================================ */

.page-content {
  padding: 1.5rem;
  flex: 1;
}

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

.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 0.25rem;
  letter-spacing: -0.02em;
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin: 0;
}

/* ============================================================
   Cards
   ============================================================ */

.card-ai {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.card-ai:hover {
  border-color: rgba(59,130,246,0.3);
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}

.card-ai .card-header {
  background: transparent;
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 1.25rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.card-ai .card-body {
  padding: 1.25rem;
}

/* Stat Cards */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  opacity: 0.06;
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
  border-color: rgba(59,130,246,0.3);
}

.stat-card:hover::before { opacity: 0.1; }

.stat-card.blue::before { background: #3b82f6; }
.stat-card.purple::before { background: #8b5cf6; }
.stat-card.cyan::before { background: #06b6d4; }
.stat-card.green::before { background: #10b981; }

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  margin-bottom: 1rem;
}

.stat-icon.blue { background: rgba(59,130,246,0.15); color: #3b82f6; }
.stat-icon.purple { background: rgba(139,92,246,0.15); color: #8b5cf6; }
.stat-icon.cyan { background: rgba(6,182,212,0.15); color: #06b6d4; }
.stat-icon.green { background: rgba(16,185,129,0.15); color: #10b981; }

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 0.25rem;
  letter-spacing: -0.03em;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.stat-change {
  font-size: 0.75rem;
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.stat-change.up { color: #10b981; }
.stat-change.down { color: #ef4444; }

/* ============================================================
   Forms
   ============================================================ */

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}

.form-control, .form-select, .form-control-ai {
  background: var(--bg-input) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: var(--radius-sm) !important;
  color: var(--text-primary) !important;
  font-size: 0.875rem;
  padding: 0.6rem 0.9rem;
  transition: var(--transition);
  font-family: 'Sora', sans-serif;
}

.form-control:focus, .form-select:focus {
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15) !important;
  border-color: var(--brand-primary) !important;
  outline: none;
}

.form-control::placeholder { color: var(--text-muted) !important; }

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

/* ============================================================
   Buttons
   ============================================================ */

.btn-primary-ai {
  background: var(--brand-gradient);
  border: none;
  color: #fff;
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.65rem 1.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  font-family: 'Sora', sans-serif;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary-ai:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(59,130,246,0.4);
  color: #fff;
}

.btn-primary-ai:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary-ai {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.65rem 1.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  font-family: 'Sora', sans-serif;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
}

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

.btn-danger-ai {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  color: #ef4444;
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.65rem 1.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  font-family: 'Sora', sans-serif;
}

.btn-danger-ai:hover {
  background: rgba(239,68,68,0.2);
  color: #f87171;
}

/* ============================================================
   Badges & Status
   ============================================================ */

.badge-ai {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.65rem;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.badge-success { background: rgba(16,185,129,0.15); color: #10b981; border: 1px solid rgba(16,185,129,0.2); }
.badge-danger { background: rgba(239,68,68,0.15); color: #ef4444; border: 1px solid rgba(239,68,68,0.2); }
.badge-warning { background: rgba(245,158,11,0.15); color: #f59e0b; border: 1px solid rgba(245,158,11,0.2); }
.badge-info { background: rgba(6,182,212,0.15); color: #06b6d4; border: 1px solid rgba(6,182,212,0.2); }
.badge-primary { background: rgba(59,130,246,0.15); color: #3b82f6; border: 1px solid rgba(59,130,246,0.2); }

/* Status dot */
.status-dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block;
}
.status-dot.online { background: #10b981; box-shadow: 0 0 6px #10b981; animation: pulse 2s infinite; }
.status-dot.offline { background: #ef4444; }
.status-dot.warning { background: #f59e0b; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ============================================================
   Tables
   ============================================================ */

.table-ai {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.85rem;
}

.table-ai th {
  padding: 0.75rem 1rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  background: transparent;
  white-space: nowrap;
}

.table-ai td {
  padding: 0.85rem 1rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.table-ai tbody tr:hover td { background: rgba(59,130,246,0.03); }
.table-ai tbody tr:last-child td { border-bottom: none; }

/* ============================================================
   Code/Output areas
   ============================================================ */

.output-area {
  background: var(--bg-root);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  color: var(--text-primary);
  min-height: 200px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.7;
  overflow-y: auto;
  max-height: 600px;
}

/* ============================================================
   Loading States
   ============================================================ */

.loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-card-hover) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================================
   Alert boxes
   ============================================================ */

.alert-ai {
  border-radius: var(--radius-md);
  padding: 0.85rem 1.1rem;
  font-size: 0.875rem;
  border: 1px solid;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.alert-ai.success { background: rgba(16,185,129,0.08); border-color: rgba(16,185,129,0.2); color: #10b981; }
.alert-ai.error { background: rgba(239,68,68,0.08); border-color: rgba(239,68,68,0.2); color: #ef4444; }
.alert-ai.info { background: rgba(59,130,246,0.08); border-color: rgba(59,130,246,0.2); color: #3b82f6; }
.alert-ai.warning { background: rgba(245,158,11,0.08); border-color: rgba(245,158,11,0.2); color: #f59e0b; }

/* ============================================================
   API Key display
   ============================================================ */

.api-key-display {
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
  background: var(--bg-root);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.75rem;
  color: var(--brand-accent);
  letter-spacing: 0.05em;
}

/* ============================================================
   System Status Bar
   ============================================================ */

.system-status-bar {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ============================================================
   Login Page
   ============================================================ */

.login-wrapper {
  min-height: 100vh;
  background: var(--bg-root);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  position: relative;
  overflow: hidden;
}

.login-bg-glow {
  position: absolute;
  width: 600px;
  height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(59,130,246,0.08) 0%, transparent 70%);
  top: -200px;
  left: -200px;
  pointer-events: none;
}

.login-bg-glow.right {
  top: auto;
  left: auto;
  bottom: -200px;
  right: -200px;
  background: radial-gradient(circle, rgba(139,92,246,0.08) 0%, transparent 70%);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 2.5rem;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: 1;
}

/* ============================================================
   Chart Container
   ============================================================ */

.chart-container {
  position: relative;
  height: 200px;
  width: 100%;
}

/* ============================================================
   Generator forms
   ============================================================ */

.generator-form {
  display: grid;
  gap: 1rem;
}

.generator-output {
  margin-top: 1.5rem;
}

.copy-btn {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: var(--transition);
}
.copy-btn:hover { color: var(--brand-primary); border-color: var(--brand-primary); }

/* ============================================================
   Sidebar Toggle (Mobile)
   ============================================================ */

.sidebar-toggle {
  display: none;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 999;
  backdrop-filter: blur(4px);
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 991px) {
  .sidebar {
    transform: translateX(-100%);
    z-index: 1001;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.active { display: block; }
  .main-content { margin-left: 0; }
  .sidebar-toggle { display: flex; }
  .stat-value { font-size: 1.4rem; }
}

@media (max-width: 575px) {
  .page-content { padding: 1rem; }
  .login-card { padding: 1.75rem 1.25rem; }
}

/* ============================================================
   Utilities
   ============================================================ */

.text-gradient {
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.border-gradient {
  border: 1px solid transparent;
  background-clip: padding-box;
  position: relative;
}

.divider {
  height: 1px;
  background: var(--border-color);
  margin: 1rem 0;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mono { font-family: 'Courier New', monospace; }

/* Progress bar */
.progress-ai {
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
}
.progress-ai-bar {
  height: 100%;
  background: var(--brand-gradient);
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* Toast notifications */
.toast-container-ai {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast-ai {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 1.1rem;
  font-size: 0.85rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 280px;
  animation: slideIn 0.3s ease;
}

.toast-ai.success { border-left: 3px solid #10b981; }
.toast-ai.error { border-left: 3px solid #ef4444; }
.toast-ai.info { border-left: 3px solid #3b82f6; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
