/* ============================================================
   Vela CMS — Admin Panel Styles
   Design: Clean SaaS admin (Linear/Notion/Vercel inspired)
   ============================================================ */

/* --- CSS Variables --- */
:root {
  --navy: #1B2B4B;
  --navy-light: #2a3f63;
  --navy-hover: #34495e;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --bg: #f9fafb;
  --white: #ffffff;
  --text-primary: #111827;
  --text-secondary: #374151;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --success: #059669;
  --success-bg: #ecfdf5;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --info: #2563eb;
  --info-bg: #eff6ff;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --transition: 150ms ease;
}

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

body {
  font-family: var(--font);
  background-color: var(--bg);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

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

/* --- Sidebar --- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 250px;
  height: 100vh;
  background-color: var(--navy);
  color: #fff;
  padding-top: 60px;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 0 20px;
  height: 60px;
  display: flex;
  align-items: center;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar ul { list-style: none; }

.sidebar li {
  padding: 10px 20px;
  cursor: pointer;
  transition: background-color var(--transition);
  font-size: 14px;
  color: rgba(255, 255, 255, 0.7);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar li:hover {
  background-color: var(--navy-light);
  color: #fff;
}

.sidebar li.active {
  background-color: var(--navy-hover);
  color: #fff;
  font-weight: 500;
}

.sidebar li i,
.sidebar li .icon {
  width: 18px;
  text-align: center;
  opacity: 0.7;
}

/* ── Nav content section label (Bob fix: must be <li>, not <div>) ── */
.sidebar li.nav-content-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #64748b;
  padding: 8px 10px 4px 20px;
  cursor: default;
  background: none;
}

.sidebar li.nav-content-label:hover {
  background: none;
  color: #64748b;
}

/* ── Nav group labels (sub-sections within a category) ── */
.sidebar li.nav-group-label {
  font-size: 9.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #94a3b8;
  padding: 10px 10px 3px 20px;
  cursor: default;
  background: none;
  border-top: 1px solid rgba(255,255,255,0.06);
  margin-top: 4px;
}
.sidebar li.nav-group-label:first-of-type {
  border-top: none;
  margin-top: 0;
}
.sidebar li.nav-group-label:hover {
  background: none;
  color: #94a3b8;
}

/* ── Nav sub-items (Content section) ── */
.sidebar li.nav-sub {
  padding-left: 32px;
  font-size: 0.88rem;
}

.sidebar li.nav-sub.active {
  background: var(--navy-hover);
}

/* --- Header --- */
.header {
  position: fixed;
  top: 0;
  left: 250px;
  right: 0;
  height: 60px;
  background-color: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 99;
}

.brand-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-selector label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.brand-selector select {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--white);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-secondary);
}

.logout-btn {
  background-color: transparent;
  color: var(--danger);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  transition: all var(--transition);
}

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

/* --- Main Content --- */
.main {
  margin-left: 250px;
  margin-top: 60px;
  padding: 24px;
  min-height: calc(100vh - 60px);
  background-color: var(--bg);
}

/* --- Login --- */
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: var(--bg);
}

.login-form {
  background: var(--white);
  padding: 40px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 360px;
  max-width: 90vw;
}

.login-form h2 {
  text-align: center;
  margin-bottom: 24px;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

.login-form input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
}

.login-form button {
  width: 100%;
  padding: 10px;
  background-color: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background-color var(--transition);
}

.login-form button:hover {
  background-color: var(--accent-hover);
}

#forgotRequestPanel,
#forgotConfirmPanel {
  background: var(--white);
  padding: 40px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 360px;
  max-width: 90vw;
}
#forgotRequestPanel h2,
#forgotConfirmPanel h2 {
  text-align: center;
  margin-bottom: 16px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}
#forgotRequestPanel input,
#forgotConfirmPanel input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
}
#forgotRequestPanel button,
#forgotConfirmPanel button {
  width: 100%;
  padding: 10px;
  background-color: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}
#forgotRequestPanel button:hover,
#forgotConfirmPanel button:hover {
  background-color: var(--accent-hover);
}
.forgot-link {
  display: block;
  text-align: center;
  margin-top: 12px;
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
}
.forgot-link:hover { text-decoration: underline; }
.login-success-banner {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #86efac;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 16px;
  font-size: 13px;
  text-align: center;
}

/* Auth visibility */
.authenticated .login-container { display: none; }
.not-authenticated .sidebar,
.not-authenticated .header,
.not-authenticated .main { display: none; }

/* --- Buttons --- */
button, .btn {
  font-family: var(--font);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  transition: all var(--transition);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-weight: 500;
  border: 1px solid transparent;
  text-decoration: none;
}

.btn-primary {
  background-color: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover {
  background-color: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background-color: var(--white);
  color: var(--text-secondary);
  border-color: var(--border);
}

.btn-secondary:hover {
  background-color: var(--border-light);
  border-color: #d1d5db;
}

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

.btn-danger:hover {
  background-color: #b91c1c;
  border-color: #b91c1c;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

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

/* --- Forms --- */
label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

input, select, textarea {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  margin-bottom: 6px;
}

.form-row {
  display: flex;
  gap: 16px;
}

.form-row .form-group {
  flex: 1;
}

/* --- Tables --- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  text-align: left;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--border);
  background: var(--bg);
}

td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
}

tr:hover td {
  background-color: var(--border-light);
}

.table-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.table-actions .btn-sm {
  padding: 4px 8px;
  font-size: 12px;
}

/* --- Cards --- */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-light);
}

.card-header h3 {
  font-size: 16px;
  font-weight: 600;
}

/* --- Content Sections --- */
.content-section {
  margin-bottom: 24px;
}

.section-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1,
.page-header h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 9999px;
  line-height: 1.6;
  background: var(--border-light);
  color: var(--text-secondary);
}

.badge-success {
  background-color: var(--success-bg);
  color: var(--success);
}

.badge-warning {
  background-color: var(--warning-bg);
  color: var(--warning);
}

.badge-danger {
  background-color: var(--danger-bg);
  color: var(--danger);
}

.badge-info {
  background-color: var(--info-bg);
  color: var(--info);
}

/* --- Search & Filters --- */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.search-input {
  max-width: 320px;
  padding: 8px 12px 8px 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%239ca3af' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242.156a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
}

.filters {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.filters select,
.filters input {
  width: auto;
  min-width: 140px;
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state p {
  font-size: 15px;
  margin-bottom: 16px;
}

/* --- Loading & Error States --- */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 14px;
}

.loading::before {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 10px;
}

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

.error {
  background-color: var(--danger-bg);
  color: var(--danger);
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid #fecaca;
  font-size: 14px;
}

/* --- Notifications (toast) --- */
.notification {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  min-width: 300px;
  max-width: 420px;
  padding: 14px 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  color: var(--white);
  background: var(--text-primary);
  animation: slideIn 0.25s ease-out;
}

.notification-success {
  background-color: var(--success);
}

.notification-error {
  background-color: var(--danger);
}

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

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.15s ease;
}

.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 520px;
  max-width: 90vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: modalIn 0.2s ease-out;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 16px;
  font-weight: 600;
}

.modal-header .close-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.modal-header .close-btn:hover {
  background: var(--border-light);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes modalIn {
  from { transform: scale(0.95); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

/* --- Stats Grid (Dashboard) --- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* --- Tabs --- */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}

.tab {
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color var(--transition), border-color var(--transition);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}

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

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

/* --- Utility --- */
.text-muted  { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-sm     { font-size: 12px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.hidden { display: none !important; }

/* --- CodeMirror wrapper --- */
.editor-wrapper {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.CodeMirror {
  height: auto;
  min-height: 200px;
  font-size: 13px;
}

/* --- Mobile: hamburger button hidden by default --- */
.menu-toggle { display: none; }

/* --- Mobile: sidebar overlay --- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99;
}
.sidebar-overlay.active { display: block; }

/* --- Global: table horizontal scroll (prevents overflow on mobile) --- */
.main table {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

/* --- Global: chart/canvas containers --- */
canvas { max-width: 100%; height: auto !important; }

/* --- Responsive --- */
@media (max-width: 768px) {
  .sidebar { width: 200px; }
  .header  { left: 200px; }
  .main    { margin-left: 200px; padding: 16px; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s;
    width: 250px;
  }
  .sidebar.open { transform: translateX(0); }
  .header { left: 0; }
  .main   { margin-left: 0; }

  .menu-toggle {
    display: block;
    position: fixed;
    top: 15px;
    left: 15px;
    background: var(--navy);
    color: #fff;
    border: none;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    z-index: 101;
    cursor: pointer;
  }

  .modal { width: 95vw; }
  .stats-grid { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; }

  /* Touch targets — minimum 44px height */
  .sidebar li {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}
