/* ===== BI-Tool Layout Styles ===== */

:root {
  --sidebar-w: 80px;
  --sidebar-bg: #ffffff;
  --sidebar-hover: #f0f4ff;
  --sidebar-active-bg: #eff6ff;
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #2563eb;
  --sidebar-border: #e5e7eb;
  --bg: #F8FAFC;
  --card-bg: #fff;
  --border: #E2E8F0;
  --text: #0F172A;
  --text-secondary: #64748B;
  --text-muted: #94A3B8;
  --accent: #0EA5E9;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; }

body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  overflow-x: hidden;
}

/* ========== Sidebar ========== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  box-shadow: 1px 0 0 0 var(--sidebar-border);
}

.sidebar-brand {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-brand a {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #3366FF 0%, #4F46E5 100%);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-shadow: 0 6px 14px -6px rgba(51,102,255,0.55);
  transition: transform 0.15s;
}
.sidebar-brand a:hover { transform: scale(1.06); }
.sidebar-brand a i {
  color: #fff;
  font-size: 1.15rem;
  margin: 0;
}

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

.sidebar-bottom {
  border-top: 1px solid var(--sidebar-border);
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 0;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.2px;
  transition: background 0.15s, color 0.15s;
  position: relative;
  margin: 0 6px;
  border-radius: 8px;
}

.sidebar-link i {
  font-size: 1.2rem;
  margin-bottom: 3px;
}

.sidebar-link:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-active);
}

.sidebar-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-text-active);
}

.sidebar-link.active i { color: var(--sidebar-text-active); }

.sidebar-link.active::before {
  content: '';
  position: absolute;
  left: -6px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: var(--sidebar-text-active);
  border-radius: 0 3px 3px 0;
}

/* ========== Main Content ========== */
.main-wrapper {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  width: calc(100% - var(--sidebar-w));
}

/* Guest pages (no sidebar): full-width main-wrapper */
body.is-guest .main-wrapper {
  margin-left: 0;
  width: 100%;
}

/* Canvas sparkle animation */
@keyframes aiPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.6; }
}

.main-content {
  flex: 1;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow-x: auto;
  overflow-y: auto;
  width: 100%;
}

/* ===== Unified authenticated app layout =====
   All authenticated pages share this content frame so spacing,
   max-width, and alignment are identical across:
   /dashboard, /dashboard/history, /sources, /templates, /ai-builder. */
body.is-authed .main-content {
  padding: 24px 10px 32px 10px;
  gap: 24px;
}
body.is-authed .main-content > * {
  width: 100%;
  margin-left: 0;
  margin-right: 0;
}
@media (max-width: 768px) {
  body.is-authed .main-content { padding: 16px 16px 24px 10px; gap: 16px; }
}

/* Reusable page container — opt-in for pages rendered as standalone
   shells (e.g. home.ejs with layout: false). Same spec as above. */
.app-page {
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
@media (max-width: 768px) {
  .app-page { padding: 16px 16px 24px; gap: 16px; }
}

/* Mode cards - fill available space when displayed */
#aiModeCard,
#manualModeCard {
  min-height: 0;
  min-width: 0;
}

#aiModeCard {
  display: flex !important;
}

#manualModeCard:not([style*="display:none"]) {
  display: flex !important;
}

/* ========== Page Header ========== */
.page-header {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0;
  color: var(--text);
  letter-spacing: -0.01em;
}

.page-header p {
  font-size: 13.5px;
  color: var(--text-secondary);
  margin: 4px 0 0;
}

/* ========== Prompt Panel (Home) ========== */
.prompt-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  height: 100%;
}

.prompt-panel h6 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.prompt-panel textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8125rem;
  resize: vertical;
  min-height: 80px;
}

.prompt-panel textarea:focus {
  border-color: var(--accent);
  box-shadow: none;
}

.prompt-panel .form-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.prompt-panel .form-select,
.prompt-panel .form-control {
  font-size: 0.8125rem;
  border-radius: var(--radius);
}

/* ========== Cards ========== */
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: none;
  background: var(--card-bg);
}

.card:hover {
  box-shadow: none;
}

.card-header {
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-secondary);
  padding: 10px 14px;
  background: var(--card-bg);
}

.card-body {
  padding: 14px;
}

.card-footer {
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  padding: 10px 14px;
}

/* ========== KPI Cards ========== */
.kpi-card {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card-bg);
}

.kpi-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
  line-height: 1.2;
}

.kpi-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ========== Tables ========== */
.table {
  font-size: 0.8125rem;
  margin-bottom: 0;
}

.table thead th {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.65rem;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  background: #faf9f8;
}

.table td {
  vertical-align: middle;
  padding: 8px 12px;
  border-bottom: 1px solid #f0efee;
}

.table-hover tbody tr:hover {
  background-color: #faf9f8;
}

.table-dark {
  --bs-table-bg: #323130;
  --bs-table-color: #fff;
}

.table-dark th {
  color: #fff;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ========== Badges ========== */
.badge {
  font-weight: 500;
  padding: 3px 8px;
  font-size: 0.65rem;
  border-radius: 2px;
  letter-spacing: 0.2px;
}

/* ========== Buttons ========== */
.btn {
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: var(--radius);
  padding: 6px 14px;
}

.btn-sm {
  font-size: 0.75rem;
  padding: 4px 10px;
}

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

.btn-primary:hover {
  background: #444;
  border-color: #444;
}

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

.btn-outline-secondary:hover {
  background: #f5f4f3;
  color: var(--text);
  border-color: var(--border);
}

/* ========== Sample Prompts ========== */
.sample-prompt-btn {
  font-size: 0.7rem;
  border-radius: 2px;
  border-color: var(--border);
  color: var(--text-secondary);
  padding: 3px 10px;
  background: #faf9f8;
}

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

/* ========== Chart ========== */
.chart-container {
  min-height: 300px;
}

/* ========== List Groups ========== */
.list-group-item {
  border: none;
  border-bottom: 1px solid #f0efee;
  padding: 10px 14px;
  font-size: 0.8125rem;
}

.list-group-item:last-child {
  border-bottom: none;
}

/* ========== Alerts ========== */
.alert {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8125rem;
  margin: 12px 24px 0;
}

/* ========== Pre/Code ========== */
pre {
  border-radius: var(--radius);
  font-size: 0.75rem;
  background: #faf9f8;
  border: 1px solid var(--border);
}

/* ========== Forms ========== */
.form-control, .form-select {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8125rem;
}

.form-control:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: none;
}

.form-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-secondary);
}

/* ========== Section Labels ========== */
.section-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* ========== Page Title ========== */
h2 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.2px;
}

/* ========== Content Panel (for left/right split) ========== */
.content-left {
  position: sticky;
  top: 20px;
  align-self: flex-start;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    flex-direction: row;
  }

  .sidebar-brand {
    height: auto;
    border-bottom: none;
    border-right: 1px solid #333;
    padding: 8px 12px;
  }

  .sidebar-nav {
    flex-direction: row;
    padding-top: 0;
    overflow-x: auto;
  }

  .sidebar-bottom {
    border-top: none;
    border-left: 1px solid #333;
    display: flex;
  }

  .sidebar-link {
    padding: 8px 12px;
    flex-direction: row;
    gap: 4px;
  }

  .sidebar-link i {
    margin-bottom: 0;
    font-size: 1rem;
  }

  .sidebar-link.active::before {
    left: 8px;
    right: 8px;
    top: auto;
    bottom: 0;
    width: auto;
    height: 3px;
    border-radius: 2px 2px 0 0;
  }

  .main-wrapper {
    margin-left: 0;
  }

  .main-content {
    padding: 16px;
  }

  .content-left {
    position: static;
  }

  .kpi-value {
    font-size: 1.25rem;
  }

  .chart-container {
    min-height: 250px;
  }
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #d2d0ce;
  border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
  background: #a19f9d;
}

/* ========== Template Cards ========== */
.template-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  overflow: hidden;
  transition: box-shadow 0.12s, border-color 0.12s;
  cursor: default;
}

.template-card:hover {
  border-color: #aaa;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.template-color-bar {
  display: flex;
  height: 8px;
  width: 100%;
}

.template-color-bar > div {
  flex: 1;
}

.template-card .card-body {
  padding: 14px 16px;
}

.template-card .template-name {
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 2px;
}

.template-card .template-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.template-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 12px;
}

.template-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.08);
  flex-shrink: 0;
}

.color-picker-cell {
  background: #fff;
}

.color-picker-cell input[type="color"] {
  width: 36px;
  height: 36px;
  padding: 2px;
  cursor: pointer;
  border-radius: var(--radius);
}

/* ========== Site Footer (public marketing) ========== */
.site-footer {
  margin-top: 80px;
  background: #0F172A;
  color: #CBD5E1;
  padding: 56px 0 24px;
}
.site-footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 32px;
}
.site-footer-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 48px;
  margin-bottom: 40px;
}
.site-footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  margin-bottom: 14px;
}
.site-footer-brand-icon {
  width: 38px; height: 38px;
  background: #2563EB;
  color: #fff;
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 20px;
  box-shadow: 0 8px 24px rgba(37,99,235,.25);
  flex-shrink: 0;
}
.site-footer-brand-icon i { color: #fff; font-size: 20px; }
.site-footer-brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.site-footer-brand-name { font-weight: 800; font-size: 17px; color: #fff; letter-spacing: -.01em; }
.site-footer-brand-name .ai { color: #60A5FA; }
.site-footer-brand-tag { font-size: 11px; color: #94A3B8; font-weight: 500; margin-top: 2px; }
.site-footer-tagline {
  font-size: 0.92rem;
  line-height: 1.6;
  color: #94A3B8;
  max-width: 380px;
  margin: 0;
}
.site-footer-heading {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #fff;
  font-weight: 600;
  margin: 0 0 16px;
}
.site-footer-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.site-footer-list li { margin-bottom: 10px; }
.site-footer-list a {
  color: #94A3B8;
  text-decoration: none;
  font-size: 0.92rem;
  transition: color 0.15s ease;
}
.site-footer-list a:hover { color: #fff; }
.site-footer-bottom {
  border-top: 1px solid #1E293B;
  padding-top: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: #64748B;
  flex-wrap: wrap;
  gap: 12px;
}
.site-footer-poweredby a {
  color: #93C5FD;
  text-decoration: none;
  font-weight: 500;
}
.site-footer-poweredby a:hover { color: #fff; }
@media (max-width: 768px) {
  .site-footer-grid { grid-template-columns: 1fr 1fr; gap: 32px; }
  .site-footer-brand-col { grid-column: 1 / -1; }
  .site-footer-bottom { flex-direction: column; align-items: flex-start; }
}

/* Mini footer (authenticated app pages) */
.site-footer-mini {
  background: transparent;
  color: #64748B;
  padding: 18px 24px;
  border-top: 1px solid #ECEEF2;
  margin-top: 24px;
}
.site-footer-mini-inner {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  flex-wrap: wrap;
  gap: 8px;
}
.site-footer-mini .site-footer-poweredby a { color: #3366FF; text-decoration: none; font-weight: 500; }
.site-footer-mini .site-footer-poweredby a:hover { color: #2952E6; text-decoration: underline; }

/* ========== Marketing / SEO landing sections ========== */
.marketing-section {
  max-width: 1100px;
  margin: 80px auto 0;
  padding: 0 64px;
}
.marketing-eyebrow {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #2563EB;
  background: #EFF6FF;
  padding: 6px 12px;
  border-radius: 999px;
  margin-bottom: 14px;
}
.marketing-h2 {
  font-size: 2rem;
  font-weight: 800;
  color: #0F172A;
  letter-spacing: -0.4px;
  margin: 0 0 12px;
}
.marketing-lead {
  font-size: 1.05rem;
  color: #64748B;
  max-width: 720px;
  margin-bottom: 36px;
  line-height: 1.6;
}
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
}
.feature-card {
  background: #fff;
  border: 1px solid #E2E8F0;
  border-radius: 14px;
  padding: 24px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.feature-card:hover {
  border-color: #C7D2FE;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.08);
  transform: translateY(-2px);
}
.feature-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: #EFF6FF;
  color: #2563EB;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  margin-bottom: 16px;
}
.feature-card h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #0F172A;
  margin: 0 0 8px;
}
.feature-card p {
  font-size: 0.92rem;
  color: #64748B;
  line-height: 1.55;
  margin: 0;
}
.steps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  counter-reset: stepcount;
}
.step-card {
  background: #fff;
  border: 1px solid #E2E8F0;
  border-radius: 14px;
  padding: 24px;
  position: relative;
}
.step-card::before {
  counter-increment: stepcount;
  content: counter(stepcount);
  position: absolute;
  top: -14px;
  left: 20px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #2563EB;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
}
.step-card h3 {
  font-size: 1rem;
  font-weight: 700;
  color: #0F172A;
  margin: 8px 0 6px;
}
.step-card p {
  font-size: 0.9rem;
  color: #64748B;
  line-height: 1.55;
  margin: 0;
}
.usecase-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}
.usecase-pill {
  background: #fff;
  border: 1px solid #E2E8F0;
  border-radius: 12px;
  padding: 18px 20px;
}
.usecase-pill h3 {
  font-size: 0.98rem;
  font-weight: 700;
  color: #0F172A;
  margin: 0 0 6px;
}
.usecase-pill p {
  font-size: 0.88rem;
  color: #64748B;
  margin: 0;
  line-height: 1.5;
}
.faq-list { display: flex; flex-direction: column; gap: 12px; }
.faq-item {
  background: #fff;
  border: 1px solid #E2E8F0;
  border-radius: 12px;
  padding: 18px 22px;
}
.faq-item h3 {
  font-size: 1rem;
  font-weight: 700;
  color: #0F172A;
  margin: 0 0 8px;
}
.faq-item p {
  font-size: 0.93rem;
  color: #475569;
  line-height: 1.6;
  margin: 0;
}
.cta-banner {
  margin: 96px auto 0;
  max-width: 1100px;
  padding: 48px 32px;
  background: linear-gradient(135deg, #2563EB 0%, #4F46E5 100%);
  border-radius: 20px;
  color: #fff;
  text-align: center;
}
.cta-banner h2 {
  font-size: 1.8rem;
  font-weight: 800;
  margin: 0 0 12px;
  letter-spacing: -0.3px;
}
.cta-banner p {
  font-size: 1.02rem;
  opacity: 0.92;
  margin: 0 0 24px;
}
.cta-banner-btn {
  display: inline-block;
  background: #fff;
  color: #2563EB;
  font-weight: 600;
  padding: 12px 28px;
  border-radius: 10px;
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.cta-banner-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.18);
  color: #1D4ED8;
}

/* ========== Public marketing pages (about/features/faq) ========== */
.public-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 64px 32px;
}
.public-page .lead-hero {
  text-align: center;
  max-width: 760px;
  margin: 0 auto 56px;
}
.public-page .lead-hero h1 {
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: -0.6px;
  color: #0F172A;
  margin: 0 0 16px;
}
.public-page .lead-hero p {
  font-size: 1.1rem;
  color: #64748B;
  line-height: 1.65;
  margin: 0;
}
.public-page h2 {
  font-size: 1.6rem;
  font-weight: 800;
  color: #0F172A;
  margin: 56px 0 16px;
  letter-spacing: -0.3px;
}
.public-page p { color: #475569; line-height: 1.7; margin: 0 0 14px; }
