/* Growth OS — Base styles */

:root {
  --bg: #0c0d12;
  --surface: #14161e;
  --surface-2: #1c1f2a;
  --border: #262a36;
  --text: #e7e9ee;
  --text-muted: #8a90a3;
  --accent: #6366f1;
  --accent-hover: #7c7ef5;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #38bdf8;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

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

button, .btn {
  display: inline-block;
  padding: 8px 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s ease;
  text-decoration: none;
}
button:hover, .btn:hover { background: var(--accent-hover); color: white; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-danger { background: var(--danger); }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 16px 8px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border-radius: 8px;
  display: grid; place-items: center;
  font-weight: 700; color: white;
}
.brand-name { font-weight: 600; }
.brand-tag { font-size: 11px; color: var(--text-muted); }

.nav { display: flex; flex-direction: column; gap: 2px; padding: 12px 0; flex: 1; }
.nav-group {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 14px 8px 4px 8px;
}
.nav-item {
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--accent); border-left: 2px solid var(--accent); padding-left: 8px; }

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}
.org-name { font-weight: 600; }
.org-plan { color: var(--text-muted); margin-bottom: 8px; }
.sandbox-pill {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: 100px;
  font-size: 11px;
  font-weight: 500;
}

.main {
  padding: 28px 36px;
  max-width: 1400px;
  width: 100%;
}

/* Page header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  gap: 16px;
}
.page-header h1 { margin: 0 0 4px 0; font-size: 24px; }
.page-header .subtitle { color: var(--text-muted); font-size: 14px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.card h2, .card h3 { margin-top: 0; }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 28px; font-weight: 600; margin-top: 6px; }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
th, td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }

/* Status pills */
.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.pill-new { background: rgba(56, 189, 248, 0.12); color: var(--info); border-color: rgba(56, 189, 248, 0.3); }
.pill-warm { background: rgba(245, 158, 11, 0.12); color: var(--warning); border-color: rgba(245, 158, 11, 0.3); }
.pill-success { background: rgba(16, 185, 129, 0.12); color: var(--success); border-color: rgba(16, 185, 129, 0.3); }
.pill-danger { background: rgba(239, 68, 68, 0.12); color: var(--danger); border-color: rgba(239, 68, 68, 0.3); }
.pill-accent { background: rgba(99, 102, 241, 0.12); color: var(--accent); border-color: rgba(99, 102, 241, 0.3); }

/* Forms */
form .row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
form .field { flex: 1 1 220px; display: flex; flex-direction: column; gap: 4px; }
label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
input[type="text"], input[type="email"], input[type="url"], input[type="number"],
textarea, select {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }

.form-actions { display: flex; gap: 8px; margin-top: 16px; }

/* Two-column layout for detail pages */
.split {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}
/* ─────────────────────────────────────────────────────────────────
   Mobile responsive — phone + small tablet
   ───────────────────────────────────────────────────────────────── */

/* Hamburger-knapp + topbar — visas BARA på mobil (CSS-toggle nedan) */
.mobile-topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 90;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  align-items: center;
  gap: 10px;
}
.mobile-topbar .brand-mark {
  width: 28px;
  height: 28px;
  font-size: 14px;
}
.mobile-topbar .brand-name {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
}
.hamburger {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 38px;
  height: 38px;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--text);
  font-size: 20px;
  padding: 0;
}
.hamburger:hover { background: var(--surface-2); }

/* Backdrop när sidebar öppen på mobil */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 95;
}

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
  .layout { grid-template-columns: 1fr; }

  /* Mobil-topbar visas */
  .mobile-topbar { display: flex; }

  /* Sidebar blir off-canvas drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 80vw;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    overflow-y: auto;
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.4);
  }
  body.menu-open .sidebar { transform: translateX(0); }
  body.menu-open .sidebar-backdrop { display: block; }

  /* Main-padding minskar på mobil */
  .main { padding: 16px 14px; }

  /* Page header wrappar + tighter spacing */
  .page-header {
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
  }
  .page-header h1 { font-size: 20px; }
  .page-actions { width: 100%; }

  /* Cards: padding tighter */
  .card { padding: 16px; }

  /* Tables: scroll-x när de är för breda */
  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  /* Pipeline: 2 kolumner istället för 8 */
  .pipeline { grid-template-columns: repeat(2, 1fr); }

  /* Form-grids: alla blir 1 kolumn på mobil */
  .form-grid, .calc-grid { grid-template-columns: 1fr !important; gap: 10px; }

  /* Cards-grid (stats) → 2 kolumner på mobil */
  .cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }

  /* Buttons: full bredd på primary, ghost/sm wrappar */
  .btn-lg { width: 100%; text-align: center; }

  /* Login-vyn: max-width 92vw redan i HTML, OK */
}

@media (max-width: 480px) {
  /* Riktigt små phone-screens */
  .main { padding: 12px 10px; }
  .card { padding: 12px; }
  .cards { grid-template-columns: 1fr; }
  .pipeline { grid-template-columns: 1fr; }
  .page-header h1 { font-size: 18px; }
  .btn { font-size: 13px; padding: 8px 14px; }
  .btn-sm { font-size: 11px; padding: 4px 8px; }
}

/* Activity timeline */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline-item {
  border-left: 2px solid var(--border);
  padding: 0 0 18px 16px;
  margin-left: 6px;
  position: relative;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -7px; top: 4px;
  width: 12px; height: 12px;
  background: var(--accent);
  border: 2px solid var(--bg);
  border-radius: 50%;
}
.timeline-time { font-size: 11px; color: var(--text-muted); }
.timeline-title { font-weight: 500; margin: 2px 0; }
.timeline-body { color: var(--text-muted); font-size: 13px; }

/* AI output blocks */
.ai-output {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 14px 16px;
  border-radius: 6px;
  margin: 8px 0;
  white-space: pre-wrap;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", sans-serif;
  font-size: 13px;
  line-height: 1.6;
}
.ai-output-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Pipeline */
.pipeline { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; }
.pipeline-stage {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  min-height: 100px;
}
.pipeline-stage h4 { margin: 0 0 8px 0; font-size: 11px; text-transform: uppercase; color: var(--text-muted); }
.pipeline-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 8px;
  border-radius: 6px;
  font-size: 12px;
  margin-bottom: 6px;
}
.pipeline-card .deal-title { font-weight: 500; }
.pipeline-card .deal-value { color: var(--success); font-size: 11px; }

.empty {
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.flash {
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: var(--success);
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 16px;
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.5;
}

/* Website preview */
.website-preview {
  background: white;
  color: #1a1a1a;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.website-preview .hero {
  padding: 60px 40px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: white;
  text-align: center;
}
.website-preview .hero h1 { font-size: 36px; margin: 0 0 12px 0; }
.website-preview .hero p { font-size: 18px; opacity: 0.9; }
.website-preview .section { padding: 40px; border-bottom: 1px solid #eee; }
.website-preview .section h2 { margin-top: 0; }

/* ═══════════════════════════════════════════════════════════════════════
   PRINT STYLESHEET (Tier 7 #5) — utskriftsvänlig output
   Operator skriver ut leads-list eller lead-detail för möten/dokumentation.
   ═══════════════════════════════════════════════════════════════════════ */
@media print {
  /* White background, black text */
  html, body {
    background: white !important;
    color: black !important;
    font-size: 11pt;
  }
  body * {
    background: white !important;
    color: black !important;
    box-shadow: none !important;
  }

  /* Göm hela sidebar, mobile-topbar, nav, search-palette, modals */
  .sidebar,
  .mobile-topbar,
  .sidebar-backdrop,
  #search-palette,
  #help-overlay,
  #snooze-dialog,
  #quick-tag-dialog {
    display: none !important;
  }

  /* Layout: ta bort grid + använd full bredd */
  .layout {
    display: block !important;
  }
  .main {
    margin: 0 !important;
    padding: 0 !important;
    max-width: none !important;
  }

  /* Göm interactive elements */
  .btn, button, form, input, select, textarea,
  .page-actions,
  [data-snooze-lead-id],
  [data-quick-tag-lead],
  [data-tl-filter],
  details summary {
    display: none !important;
  }

  /* Behåll länk-text men ta bort under-line */
  a {
    color: black !important;
    text-decoration: none !important;
  }
  a[href]::after {
    content: " [" attr(href) "]";
    font-size: 8pt;
    color: #666 !important;
  }
  /* Ta bort URL för interna länkar (för många) */
  a[href^="/"]::after { content: ""; }

  /* Cards: enkla rama in */
  .card {
    border: 1px solid #ccc !important;
    border-radius: 0 !important;
    margin-bottom: 10px !important;
    padding: 12px !important;
    page-break-inside: avoid;
  }

  /* Tables: tydliga rams */
  table {
    width: 100% !important;
    border-collapse: collapse !important;
  }
  th, td {
    border: 1px solid #999 !important;
    padding: 6px 8px !important;
    font-size: 10pt !important;
    color: black !important;
  }
  thead { display: table-header-group; } /* upprepa header på varje sida */
  tr { page-break-inside: avoid; }

  /* Pills: rendera som ramad-text */
  .pill {
    border: 1px solid #999 !important;
    background: white !important;
    padding: 2px 6px !important;
    color: black !important;
    border-radius: 0 !important;
  }

  /* Dölj sparklines, modaler, ikoner som inte fungerar i print */
  svg {
    max-width: 100% !important;
    max-height: 30px !important;
  }

  /* Page break på h1 */
  h1 {
    page-break-before: auto;
    page-break-after: avoid;
  }
  h2, h3 {
    page-break-after: avoid;
  }

  /* Lägg till print-only header (visas bara i utskrift) */
  body::before {
    content: "Growth OS — utskrift " attr(data-print-date);
    display: block;
    font-size: 9pt;
    color: #666 !important;
    text-align: right;
    margin-bottom: 6px;
    border-bottom: 1px solid #ddd;
    padding-bottom: 4px;
  }
}
