@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root {
  --color-primary: #0f172a;
  --color-secondary: #334155;
  --color-accent: #0369a1;
  --color-accent-hover: #075985;
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-text: #020617;
  --color-muted: #475569;
  --color-border: #e2e8f0;
  --color-danger: #dc2626;
  --color-success: #15803d;
  --radius: 10px;
  --z-header: 20;
  --z-panel: 10;
  /* Categorical channel palette (validated: scripts/validate_palette.js, ALL CHECKS PASS) — fixed
     hue order, one per channel, never reused for anything else. */
  --chart-widget: #0369a1;
  --chart-whatsapp: #15803d;
  --chart-telegram: #7c3aed;
  --chart-instagram: #db2777;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-primary: #e2e8f0;
    --color-secondary: #cbd5e1;
    --color-accent: #38bdf8;
    --color-accent-hover: #7dd3fc;
    --color-bg: #0b1120;
    --color-surface: #111827;
    --color-text: #f1f5f9;
    --color-muted: #94a3b8;
    --color-border: #263041;
    --color-danger: #f87171;
    --color-success: #4ade80;
    /* Re-stepped against the dark surface, not an automatic flip — separately validated. */
    --chart-widget: #0284c7;
    --chart-whatsapp: #16a34a;
    --chart-telegram: #8b5cf6;
    --chart-instagram: #ec4899;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 16px;
  line-height: 1.5;
}

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

button {
  font-family: inherit;
  cursor: pointer;
}
button:disabled {
  cursor: default;
  opacity: 0.6;
}

input,
textarea,
select {
  font-family: inherit;
  font-size: 15px;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
}
input:focus,
textarea:focus,
select:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-secondary);
  margin-bottom: 6px;
}

.field {
  margin-bottom: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 14px;
  transition: background-color 200ms, border-color 200ms, color 200ms;
}
.btn-primary {
  background: var(--color-accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--color-accent-hover);
}
.btn-secondary {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-text);
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--color-accent);
  color: var(--color-accent);
}
.btn-danger {
  background: transparent;
  border-color: var(--color-danger);
  color: var(--color-danger);
}
.btn-danger:hover:not(:disabled) {
  background: var(--color-danger);
  color: #fff;
}
.btn-block {
  width: 100%;
}

/* Auth pages — split screen: form panel + brand panel, not a lone centered box */
.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
@media (max-width: 860px) {
  .auth-page {
    grid-template-columns: 1fr;
  }
  .auth-brand-panel {
    display: none;
  }
}

.auth-form-panel {
  background: var(--color-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-form-panel .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 18px;
  margin-bottom: 36px;
}
.auth-form-panel .brand .icon {
  width: 24px;
  height: 24px;
  color: var(--color-accent);
}

.auth-card {
  width: 100%;
  max-width: 380px;
}
.auth-card h1 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0 0 8px;
}
.auth-card p.subtitle {
  color: var(--color-muted);
  margin: 0 0 28px;
  font-size: 14.5px;
}
.auth-footer {
  margin-top: 22px;
  font-size: 14px;
  color: var(--color-muted);
  text-align: center;
}
.auth-footer a {
  font-weight: 600;
}

/* Brand panel — gradient, texture, and a small product mockup for continuity with the landing page */
.auth-brand-panel {
  position: relative;
  overflow: hidden;
  background: linear-gradient(160deg, var(--color-primary), color-mix(in srgb, var(--color-primary) 55%, var(--chart-telegram) 45%));
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 64px;
}
.auth-brand-panel::before,
.auth-brand-panel::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
}
.auth-brand-panel::before {
  width: 380px;
  height: 380px;
  top: -140px;
  right: -100px;
  background: var(--color-accent);
  opacity: 0.35;
}
.auth-brand-panel::after {
  width: 320px;
  height: 320px;
  bottom: -120px;
  left: -80px;
  background: var(--chart-telegram);
  opacity: 0.25;
}
.auth-brand-panel .brand-quote {
  position: relative;
  z-index: 1;
  max-width: 420px;
}
.auth-brand-panel .brand-quote h2 {
  font-size: 28px;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin: 0 0 16px;
}
.auth-brand-panel .brand-quote p {
  color: rgba(255, 255, 255, 0.75);
  font-size: 15px;
  margin: 0 0 28px;
}
.auth-brand-panel .brand-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  padding: 6px 12px;
  border-radius: 20px;
  margin-bottom: 20px;
}
.brand-benefits {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.brand-benefits li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 14.5px;
  color: rgba(255, 255, 255, 0.9);
  line-height: 1.4;
}
.brand-benefits li .check {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(74, 222, 128, 0.18);
  color: #4ade80;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}
.brand-benefits li .check svg {
  width: 12px;
  height: 12px;
}
.brand-benefits li strong {
  color: #fff;
}
.auth-mock {
  position: relative;
  z-index: 1;
  margin-top: 40px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 16px;
  max-width: 340px;
  backdrop-filter: blur(6px);
}
.auth-mock .auth-mock-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.auth-mock .auth-mock-row:last-child {
  border-bottom: none;
}
.auth-mock .auth-mock-row .stage-pill {
  background: rgba(74, 222, 128, 0.2);
  color: #4ade80;
  padding: 2px 10px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 11px;
}
.form-error {
  background: color-mix(in srgb, var(--color-danger) 12%, transparent);
  border: 1px solid var(--color-danger);
  color: var(--color-danger);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  margin-bottom: 16px;
  display: none;
}
.form-error.visible {
  display: block;
}

/* App shell (inbox + settings) */
.app-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--color-primary);
  color: #fff;
}
.app-header .brand {
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.app-header nav {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 14px;
}
.app-header nav a {
  color: rgba(255, 255, 255, 0.75);
}
.app-header nav a.active,
.app-header nav a:hover {
  color: #fff;
}
.app-header .icon-btn {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  border-radius: 8px;
  min-height: 36px;
  padding: 0 14px;
  font-size: 13px;
}
.app-header .icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.app-body {
  height: calc(100vh - 60px);
  display: flex;
}

.icon {
  width: 16px;
  height: 16px;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Inbox layout */
.inbox-list {
  width: 340px;
  min-width: 280px;
  border-right: 1px solid var(--color-border);
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
}
.inbox-tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border);
}
.inbox-tabs button {
  flex: 1;
  background: none;
  border: none;
  padding: 12px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-muted);
  border-bottom: 2px solid transparent;
}
.inbox-tabs button.active {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}
.conversation-items {
  overflow-y: auto;
  flex: 1;
}
.conversation-item {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--color-border);
  padding: 14px 16px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.conversation-item:hover {
  background: var(--color-bg);
}
.conversation-item.selected {
  background: color-mix(in srgb, var(--color-accent) 8%, transparent);
}
.conversation-item .channel-icon {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  color: var(--color-secondary);
}
.conversation-item .meta {
  min-width: 0;
  flex: 1;
}
.conversation-item .meta .top-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
}
.conversation-item .meta .top-row time {
  font-weight: 400;
  color: var(--color-muted);
  font-size: 12px;
  flex: none;
}
.conversation-item .meta .preview {
  color: var(--color-muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--color-accent) 15%, transparent);
  color: var(--color-accent);
}
.unread-badge {
  flex: none;
  align-self: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--color-accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--color-muted);
  font-size: 14px;
}

.thread-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.thread-header {
  height: 56px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}
.thread-header .who {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.thread-header .actions {
  display: flex;
  gap: 8px;
}
.thread-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.bubble {
  max-width: 65%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.bubble.customer {
  align-self: flex-start;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
}
.bubble.bot {
  align-self: flex-start;
  background: color-mix(in srgb, var(--color-secondary) 10%, transparent);
  border: 1px solid var(--color-border);
}
.bubble.agent {
  align-self: flex-end;
  background: var(--color-accent);
  color: #fff;
}
.bubble .role-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  opacity: 0.65;
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.thread-reply {
  flex: none;
  border-top: 1px solid var(--color-border);
  padding: 14px 20px;
  display: flex;
  gap: 10px;
  background: var(--color-surface);
}
.thread-reply textarea {
  resize: none;
  min-height: 44px;
  max-height: 120px;
}
.thread-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-muted);
  font-size: 14px;
}

/* Settings page */
.settings-shell {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}
.settings-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}
.settings-section h2 {
  font-size: 16px;
  margin: 0 0 4px;
}
.settings-section p.section-desc {
  color: var(--color-muted);
  font-size: 13px;
  margin: 0 0 20px;
}
.snippet {
  background: var(--color-primary);
  color: #e2e8f0;
  border-radius: 8px;
  padding: 14px 16px;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 12.5px;
  overflow-x: auto;
  white-space: pre;
}
.settings-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}
.settings-row .field {
  flex: 1;
}
.team-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 14px;
}
.team-row:last-child {
  border-bottom: none;
}
.team-row .role-badge {
  font-size: 11px;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--color-primary);
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 50;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 200ms, transform 200ms;
  pointer-events: none;
}
.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 768px) {
  .app-body {
    flex-direction: column;
    height: auto;
  }
  .inbox-list {
    width: 100%;
    max-height: 40vh;
  }
  .thread-panel {
    min-height: 60vh;
  }
}

/* Leads / CRM board */
.board {
  height: calc(100vh - 60px);
  overflow-x: auto;
  display: flex;
  gap: 16px;
  padding: 20px;
  align-items: flex-start;
}
.board-column {
  flex: none;
  width: 260px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  max-height: 100%;
}
.board-column-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-secondary);
}
.board-column-header .count {
  background: var(--color-bg);
  border-radius: 20px;
  padding: 1px 8px;
  font-size: 12px;
  font-weight: 600;
}
.board-column-cards {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 40px;
}
.lead-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
}
.lead-card:hover {
  border-color: var(--color-accent);
}
.lead-card .name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}
.lead-card .name-row .icon {
  color: var(--color-muted);
}
.lead-card time {
  display: block;
  font-size: 12px;
  color: var(--color-muted);
  margin-bottom: 8px;
}
.lead-card select {
  width: 100%;
  font-size: 12px;
  padding: 6px 8px;
}

/* Slide-in lead detail panel */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.4);
  z-index: 40;
  display: none;
}
.overlay.open {
  display: block;
}
.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 380px;
  max-width: calc(100vw - 40px);
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  z-index: 41;
  padding: 24px;
  overflow-y: auto;
}
.side-panel h2 {
  margin: 0 0 16px;
  font-size: 18px;
}
.side-panel .close-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  background: none;
  border: none;
  font-size: 20px;
  color: var(--color-muted);
  cursor: pointer;
}
.linked-conversation-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 13px;
}
.linked-conversation-row:last-child {
  border-bottom: none;
}

/* Analytics */
.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}
.stat-tile {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}
.stat-tile-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.2;
}
.stat-tile-label {
  font-size: 12px;
  color: var(--color-muted);
  margin-top: 4px;
}
.stat-tile-success .stat-tile-value {
  color: var(--color-success);
}
.stat-tile-danger .stat-tile-value {
  color: var(--color-danger);
}

.funnel-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}
.funnel-label {
  flex: none;
  width: 110px;
  font-size: 13px;
  color: var(--color-text);
}
.funnel-track {
  flex: 1;
  background: var(--color-bg);
  border-radius: 6px;
  height: 20px;
  overflow: hidden;
}
.funnel-bar {
  height: 100%;
  border-radius: 6px;
  background: var(--color-accent);
  min-width: 4px;
  transition: width 300ms;
}
.funnel-bar-success {
  background: var(--color-success);
}
.funnel-bar-danger {
  background: var(--color-danger);
}
.funnel-value {
  flex: none;
  width: 32px;
  text-align: right;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
}

.analytics-shell {
  max-width: 980px;
}
.chart-header h2 {
  margin: 0 0 4px;
  font-size: 16px;
}
.analytics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
@media (max-width: 760px) {
  .analytics-grid {
    grid-template-columns: 1fr;
  }
}

.line-chart-wrap {
  position: relative;
}
#line-chart {
  width: 100%;
  height: 200px;
  overflow: visible;
}
.chart-tooltip {
  position: absolute;
  transform: translate(-50%, -100%);
  background: var(--color-primary);
  color: var(--color-surface);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms;
}
.chart-tooltip.visible {
  opacity: 1;
}

.donut-wrap {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}
.donut {
  flex: none;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  position: relative;
}
.donut::before {
  content: "";
  position: absolute;
  inset: 26px;
  border-radius: 50%;
  background: var(--color-surface);
}
.donut-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 13px;
  color: var(--color-text);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.legend-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
}
