/* ══════════════════════════════════════════════════
   SBG Client Portal — Premium SaaS Theme v2
   Inspired by Stripe, Linear, Notion dashboards
   ══════════════════════════════════════════════════ */

:root {
  /* Surface system — subtle, layered depth */
  --bg-0: #09090b;
  --bg-1: #0c0d10;
  --bg-2: #111215;
  --bg-3: #18191d;
  --bg-4: #1e2025;
  --bg-hover: #22242a;
  --bg-active: #27292f;

  /* Border system */
  --border-subtle: rgba(255,255,255,0.06);
  --border: rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.12);
  --border-focus: rgba(99,102,241,0.5);

  /* Text system */
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-tertiary: #71717a;
  --text-quaternary: #52525b;

  /* Accent palette */
  --blue: #6366f1;
  --blue-subtle: rgba(99,102,241,0.12);
  --blue-text: #818cf8;
  --green: #10b981;
  --green-subtle: rgba(16,185,129,0.12);
  --green-text: #34d399;
  --orange: #f59e0b;
  --orange-subtle: rgba(245,158,11,0.12);
  --orange-text: #fbbf24;
  --red: #ef4444;
  --red-subtle: rgba(239,68,68,0.10);
  --red-text: #f87171;
  --purple: #a855f7;
  --purple-subtle: rgba(168,85,247,0.12);
  --cyan: #06b6d4;
  --cyan-subtle: rgba(6,182,212,0.12);

  /* Layout */
  --sidebar-w: 240px;
  --header-h: 52px;
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius: 10px;
  --radius-lg: 14px;

  /* Motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --duration: 150ms;
  --duration-md: 250ms;

  /* Typography */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* ─── Reset ──────────────────────────────────────── */

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

[hidden] {
  display: none !important;
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg-0);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  overflow-x: hidden;
}

/* ═══════════════════════════════════════════════════
   AUTH PAGES
   ═══════════════════════════════════════════════════ */

.auth-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-0);
  padding: 1.5rem;
  position: relative;
}

.auth-page::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 50% 50% at 30% 20%, rgba(99,102,241,0.08), transparent),
    radial-gradient(ellipse 50% 50% at 70% 80%, rgba(168,85,247,0.05), transparent);
  pointer-events: none;
}

.auth-container { width: 100%; max-width: 400px; position: relative; z-index: 1; }

.auth-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: 0 0 0 1px var(--border-subtle), 0 16px 48px rgba(0,0,0,0.4);
}

.auth-brand { text-align: center; margin-bottom: 2rem; }

.auth-logo {
  filter: drop-shadow(0 2px 12px rgba(99,102,241,0.15));
  margin-bottom: 1rem;
  object-fit: contain;
}

.auth-brand h1 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.auth-brand p {
  color: var(--text-tertiary);
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

.auth-form { display: flex; flex-direction: column; gap: 1.25rem; }

.form-group { display: flex; flex-direction: column; gap: 0.375rem; }
.form-group label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}
.form-group input, .form-group textarea, .form-group select {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.75rem;
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: var(--font);
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
  outline: none;
}
.form-group input::placeholder, .form-group textarea::placeholder {
  color: var(--text-quaternary);
}
.form-group input:focus, .form-group textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
}

.form-error {
  background: var(--red-subtle);
  color: var(--red-text);
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  border: 1px solid rgba(239,68,68,0.15);
}

.auth-footer {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.8125rem;
  color: var(--text-tertiary);
}
.auth-footer a { color: var(--blue-text); text-decoration: none; font-weight: 500; }
.auth-footer a:hover { text-decoration: underline; }

.back-link {
  display: inline-block;
  margin-top: 0.75rem;
  font-size: 0.8125rem;
  color: var(--text-quaternary) !important;
  font-weight: 400 !important;
}

.auth-demo {
  margin-top: 1.5rem;
  padding: 0.875rem;
  background: var(--bg-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-tertiary);
}
.auth-demo code {
  color: var(--blue-text);
  font-size: 0.8125rem;
  font-family: 'SF Mono', 'Cascadia Code', monospace;
}
.auth-demo p { margin-bottom: 0.25rem; }

/* ═══════════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════════ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  white-space: nowrap;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.1);
}
.btn-primary:hover {
  background: #5558e6;
  box-shadow: 0 2px 6px rgba(99,102,241,0.3), inset 0 1px 0 rgba(255,255,255,0.1);
}
.btn-primary:active { transform: scale(0.98); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-strong); }

.btn-sm { padding: 0.375rem 0.625rem; font-size: 0.75rem; }

.btn-full { width: 100%; }

.btn-loader {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════ */

.dashboard-page {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-1);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: transform 0.3s var(--ease);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 1rem 1rem;
  font-weight: 600;
  font-size: 0.875rem;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.brand-mark {
  width: 28px; height: 28px;
  border-radius: var(--radius-xs);
  background: linear-gradient(135deg, var(--blue), #8b5cf6);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.625rem;
  color: #fff;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.sidebar-section-label {
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--text-quaternary);
  padding: 1.25rem 1rem 0.375rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sidebar-nav {
  padding: 0 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 450;
  transition: all var(--duration) var(--ease);
  position: relative;
}
.nav-item svg {
  width: 18px; height: 18px;
  flex-shrink: 0;
  opacity: 0.65;
  transition: opacity var(--duration) var(--ease);
}
.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}
.nav-item:hover svg { opacity: 0.9; }

.nav-item.active {
  background: var(--bg-active);
  color: var(--text-primary);
  font-weight: 500;
}
.nav-item.active svg { opacity: 1; }

.badge {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  font-size: 0.625rem;
  font-weight: 600;
  padding: 0.1em 0.45em;
  border-radius: 99px;
  min-width: 16px;
  text-align: center;
  line-height: 1.4;
}

.sidebar-footer {
  margin-top: auto;
  padding: 0.75rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.user-avatar {
  width: 30px; height: 30px;
  border-radius: var(--radius-xs);
  background: linear-gradient(135deg, var(--blue), var(--purple));
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 0.75rem;
  color: #fff;
  flex-shrink: 0;
}

.user-details { min-width: 0; line-height: 1.3; }
.user-details strong {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}
.user-details small {
  color: var(--text-quaternary);
  font-size: 0.6875rem;
}

.btn-logout, .btn-logout-mobile {
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  padding: 0.3125rem;
  color: var(--text-quaternary);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  display: flex;
  align-items: center;
}
.btn-logout svg, .btn-logout-mobile svg { width: 16px; height: 16px; }
.btn-logout:hover, .btn-logout-mobile:hover {
  border-color: rgba(239,68,68,0.3);
  color: var(--red-text);
  background: var(--red-subtle);
}

/* ═══════════════════════════════════════════════════
   MOBILE
   ═══════════════════════════════════════════════════ */

.dash-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--bg-1);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 1rem;
  align-items: center;
  justify-content: space-between;
  z-index: 90;
  backdrop-filter: blur(12px);
}
.dash-header-title { font-weight: 600; font-size: 0.875rem; }

.menu-toggle {
  background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px;
  padding: 0.5rem;
}
.menu-toggle span {
  display: block;
  width: 18px; height: 1.5px;
  background: var(--text-secondary);
  border-radius: 2px;
  transition: var(--duration) var(--ease);
}

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

/* ═══════════════════════════════════════════════════
   MAIN CONTENT
   ═══════════════════════════════════════════════════ */

.dash-main {
  margin-left: var(--sidebar-w);
  padding: 1.5rem 2rem 3rem;
  flex: 1;
  min-height: 100vh;
  max-width: 1200px;
}

.panel h2 {
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--text-primary);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.panel-subtitle {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  margin-top: 0.25rem;
  font-weight: 400;
}

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

.date-display {
  font-size: 0.8125rem;
  color: var(--text-quaternary);
  font-weight: 400;
  padding: 0.375rem 0.75rem;
  background: var(--bg-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

/* ═══════════════════════════════════════════════════
   KPI CARDS
   ═══════════════════════════════════════════════════ */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.kpi-grid-3 { grid-template-columns: repeat(3, 1fr); }
.kpi-grid-2 { grid-template-columns: repeat(2, 1fr); }

.kpi-card {
  padding: 1.125rem 1.25rem;
  background: var(--bg-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  transition: border-color var(--duration-md) var(--ease), box-shadow var(--duration-md) var(--ease);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: relative;
  overflow: hidden;
}

.kpi-card::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  opacity: 0;
  transition: opacity var(--duration-md) var(--ease);
}

.kpi-card[data-accent="blue"]::after { background: var(--blue); }
.kpi-card[data-accent="orange"]::after { background: var(--orange); }
.kpi-card[data-accent="green"]::after { background: var(--green); }
.kpi-card[data-accent="red"]::after { background: var(--red); }

.kpi-card:hover {
  border-color: var(--border-strong);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.kpi-card:hover::after { opacity: 1; }

.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kpi-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-tertiary);
}

.kpi-icon {
  width: 32px; height: 32px;
  border-radius: var(--radius-xs);
  display: grid;
  place-items: center;
}
.kpi-icon svg { width: 16px; height: 16px; }

.kpi-card[data-accent="blue"] .kpi-icon { background: var(--blue-subtle); color: var(--blue-text); }
.kpi-card[data-accent="orange"] .kpi-icon { background: var(--orange-subtle); color: var(--orange-text); }
.kpi-card[data-accent="green"] .kpi-icon { background: var(--green-subtle); color: var(--green-text); }
.kpi-card[data-accent="red"] .kpi-icon { background: var(--red-subtle); color: var(--red-text); }

.kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--text-primary);
}

.kpi-compact .kpi-value { font-size: 1.375rem; }

.kpi-trend {
  font-size: 0.6875rem;
  color: var(--text-quaternary);
  font-weight: 400;
}
.kpi-trend.up { color: var(--green-text); }

/* ═══════════════════════════════════════════════════
   CHARTS
   ═══════════════════════════════════════════════════ */

.charts-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.chart-card {
  background: var(--bg-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 1.25rem;
}

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

.chart-header h3 {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.chart-badge {
  font-size: 0.6875rem;
  color: var(--text-quaternary);
  background: var(--bg-4);
  padding: 0.2em 0.5em;
  border-radius: var(--radius-xs);
  font-weight: 500;
}

/* ═══════════════════════════════════════════════════
   DATA TABLES — Stripe-inspired clean layout
   ═══════════════════════════════════════════════════ */

.table-container {
  background: var(--bg-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1rem;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
}
.table-header h3 {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}
.data-table th {
  text-align: left;
  padding: 0.75rem 1.25rem;
  color: var(--text-quaternary);
  font-weight: 500;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
  background: var(--bg-3);
}
.data-table td {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}
.data-table td strong {
  color: var(--text-primary);
  font-weight: 500;
}
.data-table tbody tr {
  transition: background var(--duration) var(--ease);
}
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table tbody tr.selected { background: var(--blue-subtle); }

/* ═══════════════════════════════════════════════════
   STATUS BADGES — pill-style with dot indicator
   ═══════════════════════════════════════════════════ */

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25em 0.625em;
  border-radius: 99px;
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: capitalize;
  letter-spacing: 0.01em;
}
.status::before {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.status-delivered, .status-paid { background: var(--green-subtle); color: var(--green-text); }
.status-shipped, .status-in_transit, .status-out_for_delivery { background: var(--blue-subtle); color: var(--blue-text); }
.status-processing, .status-customs, .status-picked_up { background: var(--purple-subtle); color: #c084fc; }
.status-confirmed { background: var(--cyan-subtle); color: #22d3ee; }
.status-pending { background: var(--orange-subtle); color: var(--orange-text); }
.status-unpaid, .status-overdue { background: var(--red-subtle); color: var(--red-text); }
.status-cancelled, .status-refunded { background: rgba(113,113,122,0.12); color: #a1a1aa; }

/* ═══════════════════════════════════════════════════
   TRACKING TIMELINE
   ═══════════════════════════════════════════════════ */

.detail-panel {
  background: var(--bg-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-top: 1rem;
  animation: slideUp 0.25s var(--ease);
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.detail-header h3 {
  font-size: 0.9375rem;
  font-weight: 600;
}

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

.timeline {
  position: relative;
  padding-left: 1.75rem;
}
.timeline::before {
  content: '';
  position: absolute;
  left: 7px; top: 4px; bottom: 4px;
  width: 1.5px;
  background: var(--border-strong);
}

.timeline-event {
  position: relative;
  padding-bottom: 1.5rem;
}
.timeline-event::before {
  content: '';
  position: absolute;
  left: -21px; top: 5px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 0 0 3px var(--bg-2);
}
.timeline-event:first-child::before {
  background: var(--green);
  box-shadow: 0 0 0 3px var(--bg-2), 0 0 8px rgba(16,185,129,0.3);
}
.timeline-event:last-child { padding-bottom: 0; }
.timeline-event .event-date {
  font-size: 0.6875rem;
  color: var(--text-quaternary);
  margin-bottom: 0.125rem;
  font-weight: 500;
}
.timeline-event .event-status {
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--text-primary);
}
.timeline-event .event-detail {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  margin-top: 0.125rem;
}
.timeline-event .event-location {
  font-size: 0.75rem;
  color: var(--text-quaternary);
}

/* ═══════════════════════════════════════════════════
   MESSAGES
   ═══════════════════════════════════════════════════ */

.compose-form {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  animation: slideUp 0.2s var(--ease);
}
.compose-actions { display: flex; gap: 0.5rem; }

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.message-item {
  background: var(--bg-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  transition: border-color var(--duration) var(--ease);
  cursor: pointer;
}
.message-item:hover { border-color: var(--border-strong); }
.message-item.unread {
  border-left: 2px solid var(--blue);
  background: rgba(99,102,241,0.03);
}

.message-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.375rem;
  gap: 0.5rem;
}
.message-subject {
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text-primary);
}
.message-meta {
  font-size: 0.6875rem;
  color: var(--text-quaternary);
}
.message-direction {
  font-size: 0.625rem;
  font-weight: 500;
  padding: 0.15em 0.5em;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.dir-inbound { background: var(--blue-subtle); color: var(--blue-text); }
.dir-outbound { background: var(--green-subtle); color: var(--green-text); }

.message-body {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  white-space: pre-line;
  line-height: 1.6;
  display: none;
}
.message-item.expanded .message-body { display: block; margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px solid var(--border-subtle); }

/* ═══════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════ */

@media (max-width: 1024px) {
  .dash-main { padding: 1.25rem 1.5rem 3rem; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
}

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

  .dash-header { display: flex; }

  .dash-main {
    margin-left: 0;
    padding: 0.75rem;
    padding-top: calc(var(--header-h) + 0.75rem);
  }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
  .kpi-grid-3 { grid-template-columns: repeat(3, 1fr); }
  .kpi-card { padding: 0.875rem 1rem; }
  .kpi-value { font-size: 1.25rem; }
  .panel-header { flex-direction: column; gap: 0.75rem; }
}

@media (max-width: 480px) {
  .kpi-grid, .kpi-grid-2, .kpi-grid-3 { grid-template-columns: 1fr; }
  .auth-card { padding: 1.5rem; }
}

/* ═══════════════════════════════════════════════════
   ANIMATIONS & SKELETON
   ═══════════════════════════════════════════════════ */

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

.panel { animation: fadeIn 0.3s var(--ease); }

.skeleton {
  background: linear-gradient(90deg, var(--bg-3) 25%, var(--bg-4) 50%, var(--bg-3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

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

/* ═══════════════════════════════════════════════════
   AI CHAT DRAWER
   ═══════════════════════════════════════════════════ */

/* Floating Action Button */
.ai-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  z-index: 300;
  box-shadow: 0 4px 16px rgba(99,102,241,0.35), 0 0 0 0 rgba(99,102,241,0.3);
  transition: all var(--duration-md) var(--ease);
}
.ai-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(99,102,241,0.45);
}
.ai-fab:active { transform: scale(0.96); }
.ai-fab svg { width: 24px; height: 24px; color: #fff; }

.ai-fab-pulse {
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 2px solid rgba(99,102,241,0.4);
  animation: fabPulse 2s ease infinite;
}
@keyframes fabPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0; }
}

.ai-fab.active .ai-fab-icon { display: none; }
.ai-fab.active .ai-fab-close { display: block; }
.ai-fab.active .ai-fab-pulse { display: none; }

/* Drawer */
.ai-drawer {
  position: fixed;
  bottom: 5.5rem;
  right: 1.5rem;
  width: 420px;
  height: min(580px, calc(100vh - 8rem));
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 16px 64px rgba(0,0,0,0.5), 0 0 0 1px var(--border-subtle);
  z-index: 290;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  pointer-events: none;
  transition: all 0.25s var(--ease);
}
.ai-drawer.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

.ai-drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 280;
}

/* Drawer Header */
.ai-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-2);
  flex-shrink: 0;
}
.ai-drawer-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.ai-drawer-title strong {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary);
}
.ai-avatar-sm {
  width: 26px; height: 26px;
  border-radius: var(--radius-xs);
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.ai-avatar-sm svg { color: #fff; }
.ai-status {
  display: block;
  font-size: 0.625rem;
  color: var(--green-text);
  font-weight: 500;
}
.ai-drawer-actions { display: flex; gap: 0.25rem; }

.ai-btn-icon {
  width: 30px; height: 30px;
  border-radius: var(--radius-xs);
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-tertiary);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all var(--duration) var(--ease);
}
.ai-btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border);
}

/* History Panel */
.ai-history-panel {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 200px;
  background: var(--bg-0);
  border-right: 1px solid var(--border-subtle);
  z-index: 10;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.2s var(--ease);
}
.ai-history-panel.open {
  transform: translateX(0);
}
.ai-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.ai-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.375rem;
}
.ai-history-item {
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius-xs);
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
}
.ai-history-item:hover { background: var(--bg-hover); color: var(--text-secondary); }
.ai-history-item.active { background: var(--bg-active); color: var(--text-primary); }

.ai-history-delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-quaternary);
  cursor: pointer;
  padding: 2px;
  flex-shrink: 0;
  transition: all var(--duration) var(--ease);
}
.ai-history-item:hover .ai-history-delete { opacity: 1; }
.ai-history-delete:hover { color: var(--red-text); }

/* Messages Area */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Welcome Screen */
.ai-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex: 1;
  gap: 0.75rem;
  padding: 1rem;
}
.ai-welcome-icon {
  width: 56px; height: 56px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(99,102,241,0.15), rgba(139,92,246,0.15));
  display: grid;
  place-items: center;
  color: var(--blue-text);
}
.ai-welcome h4 {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
}
.ai-welcome p {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  max-width: 280px;
}

.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  justify-content: center;
  margin-top: 0.5rem;
}
.ai-suggestion {
  padding: 0.375rem 0.625rem;
  background: var(--bg-3);
  border: 1px solid var(--border-subtle);
  border-radius: 99px;
  font-size: 0.6875rem;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font);
  transition: all var(--duration) var(--ease);
}
.ai-suggestion:hover {
  background: var(--bg-hover);
  border-color: var(--border);
  color: var(--text-primary);
}

/* Message Bubbles */
.ai-msg {
  display: flex;
  gap: 0.5rem;
  max-width: 100%;
  animation: msgIn 0.2s var(--ease);
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-msg-avatar {
  width: 24px; height: 24px;
  border-radius: var(--radius-xs);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  margin-top: 2px;
}
.ai-msg-avatar.ai {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
}
.ai-msg-avatar.ai svg { width: 12px; height: 12px; color: #fff; }
.ai-msg-avatar.user {
  background: linear-gradient(135deg, var(--green), #059669);
  font-size: 0.625rem;
  font-weight: 600;
  color: #fff;
}

.ai-msg-content {
  flex: 1;
  min-width: 0;
}
.ai-msg-name {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.ai-msg-body {
  font-size: 0.8125rem;
  line-height: 1.6;
  color: var(--text-secondary);
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.ai-msg-body strong { color: var(--text-primary); font-weight: 600; }
.ai-msg-body em { color: var(--text-tertiary); font-style: italic; }
.ai-msg-body ul, .ai-msg-body ol { padding-left: 1.25rem; margin: 0.375rem 0; }
.ai-msg-body li { margin-bottom: 0.25rem; }
.ai-msg-body code {
  background: var(--bg-4);
  padding: 0.15em 0.35em;
  border-radius: 3px;
  font-size: 0.75rem;
  font-family: 'SF Mono', 'Cascadia Code', monospace;
}

.ai-msg.user-msg { flex-direction: row-reverse; }
.ai-msg.user-msg .ai-msg-body {
  background: var(--blue);
  color: #fff;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm) 4px var(--radius-sm) var(--radius-sm);
}
.ai-msg.user-msg .ai-msg-name { text-align: right; }

/* Typing Indicator */
.ai-typing {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.ai-typing-dots {
  display: flex;
  gap: 3px;
  padding: 0.625rem 0.75rem;
  background: var(--bg-3);
  border-radius: var(--radius-sm);
}
.ai-typing-dots span {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--text-quaternary);
  animation: typingBounce 1.4s ease infinite;
}
.ai-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* Input Area */
.ai-input-area {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-2);
  flex-shrink: 0;
}
.ai-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 0.375rem;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.375rem 0.5rem;
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}
.ai-input-wrap:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

#ai-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 0.8125rem;
  font-family: var(--font);
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.5;
  padding: 0.25rem 0;
}
#ai-input::placeholder { color: var(--text-quaternary); }

.ai-send-btn {
  width: 30px; height: 30px;
  border-radius: var(--radius-xs);
  background: var(--blue);
  border: none;
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: all var(--duration) var(--ease);
  opacity: 0.5;
}
.ai-send-btn:not(:disabled) { opacity: 1; }
.ai-send-btn:not(:disabled):hover { background: #5558e6; }
.ai-send-btn:disabled { cursor: default; }

.ai-input-hint {
  display: block;
  font-size: 0.5625rem;
  color: var(--text-quaternary);
  text-align: center;
  margin-top: 0.375rem;
}

/* Mobile AI Drawer */
@media (max-width: 768px) {
  .ai-drawer {
    bottom: 0;
    right: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
  }
  .ai-fab { bottom: 1rem; right: 1rem; }
}

/* ═══════════════════════════════════════════════════
   SaaS CONVERSION & PREMIUM UI
   ═══════════════════════════════════════════════════ */

/* Plan Badges */
.user-sub-status { margin-top: 4px; }
.plan-badge { display: inline-block; padding: 2px 6px; border-radius: 4px; font-size: 0.65rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.plan-starter { background: var(--bg-3); color: var(--text-tertiary); border: 1px solid var(--border); }
.plan-pro { background: var(--blue-subtle); color: var(--blue-text); border: 1px solid rgba(99,102,241,0.2); }
.plan-enterprise { background: var(--purple-subtle); color: var(--purple); border: 1px solid rgba(168,85,247,0.2); }

/* Sidebar Upgrade CTA */
.btn-sidebar-cta {
  width: 100%;
  margin-top: 12px;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  color: #fff;
  border: none;
  padding: 8px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.75rem;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}
.btn-sidebar-cta:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(168,85,247,0.3); }

/* Welcome Modal */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.modal-content {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem; width: 100%; max-width: 440px;
  text-align: center;
  box-shadow: 0 24px 48px rgba(0,0,0,0.5);
  animation: modalIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes modalIn {
  0% { opacity: 0; transform: translateY(20px) scale(0.95); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-icon { font-size: 3rem; margin-bottom: 1rem; }
.modal-content h2 { font-size: 1.5rem; margin-bottom: 0.75rem; }
.modal-content p { color: var(--text-secondary); margin-bottom: 1.5rem; font-size: 0.9rem; }
.modal-tips { background: var(--bg-2); padding: 1rem; border-radius: var(--radius-sm); border: 1px dashed var(--border-strong); margin-bottom: 1.5rem;text-align: left; }
.modal-tips p { margin: 0; font-size: 0.85rem; color: var(--text-primary); }

/* Premium Gated Content (Blurred Analytics) */
.premium-lock {
  position: absolute;
  top: 80px; left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(8px);
  background: rgba(9,9,11,0.4);
  border-radius: var(--radius);
}
.premium-lock-content {
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  padding: 2rem; border-radius: var(--radius-lg);
  text-align: center; max-width: 380px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
}
.premium-lock-content svg { margin-bottom: 1rem; color: var(--orange); }
.premium-lock-content h3 { font-size: 1.25rem; margin-bottom: 0.5rem; }
.premium-lock-content p { color: var(--text-secondary); font-size: 0.875rem; margin-bottom: 1.5rem; line-height: 1.5; }
.premium-gated-content.is-locked { user-select: none; filter: grayscale(100%) opacity(0.3); pointer-events: none; }
#panel-analytics { position: relative; }

