:root {
  --accent: #4f46e5;
  --accent-contrast: #fff;
  --bg: #f5f6fa;
  --card: #ffffff;
  --border: #e4e6ef;
  --text: #1f2330;
  --muted: #6b7280;
  --danger: #dc2626;
  --success: #059669;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- Auth pages ---------- */

.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  padding: 32px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}

.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 6px; }
.auth-form input,
.modal input, .modal select, .modal textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  width: 100%;
}

.auth-form button, .primary-btn {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.auth-form button:hover, .primary-btn:hover { filter: brightness(1.05); }
.auth-form button:disabled { opacity: 0.6; cursor: not-allowed; }

.secondary-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.secondary-btn:hover { background: var(--bg); }

.auth-error { color: var(--danger); font-size: 13px; margin: 4px 0 0; }
.auth-status { color: var(--success); font-size: 13px; margin: 4px 0 0; font-weight: 600; }
.auth-toggle { margin-top: 12px; font-size: 13px; text-align: center; }
.auth-toggle a { color: var(--accent); text-decoration: none; }
.auth-toggle a:hover { text-decoration: underline; }

/* Back-to-home link shown above the auth card */
.back-home {
  position: fixed;
  top: 16px;
  left: 20px;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  background: var(--card);
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  z-index: 10;
}
.back-home:hover { color: var(--text); }

/* Demo entry panel */
.demo-blurb {
  font-size: 14px;
  color: var(--muted);
  margin: 0 0 16px;
  line-height: 1.5;
}
.demo-full-btn {
  width: 100%;
  padding: 14px;
  font-size: 15px;
  margin-bottom: 12px;
  justify-content: center;
}

/* ---------- App shell ---------- */

.app-body { min-height: 100vh; display: flex; flex-direction: column; }

.app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand img { height: 28px; width: auto; }

.app-nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav-btn {
  background: transparent;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.nav-btn:hover { background: var(--bg); color: var(--text); }
.nav-btn.active { background: var(--accent); color: var(--accent-contrast); }

.user-area { display: flex; gap: 12px; align-items: center; font-size: 14px; color: var(--muted); }
.ghost-btn {
  background: transparent; border: 1px solid var(--border); padding: 6px 12px;
  border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--text);
}
.ghost-btn:hover { background: var(--bg); }
.danger-btn { color: var(--danger); border-color: var(--danger); }
.danger-btn:hover { background: #fef2f2; }

/* ---------- Main content ---------- */

.app-main { padding: 24px; flex: 1; overflow-x: hidden; }

.view { max-width: 1200px; margin: 0 auto; }
.view h1 { margin: 0 0 20px; font-size: 24px; }
.demo-banner {
  max-width: 1200px;
  margin: 0 auto 16px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #fed7aa;
  background: #fff7ed;
  color: #9a3412;
  font-size: 14px;
}
.view-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 12px; }
.view-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.view-actions input[type="search"] {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; min-width: 200px;
}

/* ---------- Stats ---------- */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat { background: var(--card); padding: 16px; border-radius: 10px; border: 1px solid var(--border); }
.stat-label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.stat-value { display: block; font-size: 24px; font-weight: 700; margin-top: 4px; }

/* ---------- Table ---------- */

.table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; background: var(--card); min-width: 600px; }
.data-table th, .data-table td { padding: 12px 14px; text-align: left; font-size: 14px; border-bottom: 1px solid var(--border); }
.data-table th { background: #fafbfc; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #fafbfc; cursor: pointer; }

/* ---------- Pipeline ---------- */

.pipeline-board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; -webkit-overflow-scrolling: touch; }
.pipeline-col {
  background: var(--card); border-radius: 10px; border: 1px solid var(--border);
  min-width: 220px; flex: 1; padding: 12px; display: flex; flex-direction: column; gap: 8px;
}
.pipeline-col h3 { margin: 0 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); display: flex; justify-content: space-between; }
.deal-card { background: var(--bg); padding: 10px 12px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.deal-card:hover { background: #eef0f7; }
.deal-card .deal-title { font-weight: 600; }
.deal-card .deal-meta { color: var(--muted); font-size: 12px; margin-top: 4px; line-height: 1.4; }
.deal-card .deal-amount { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- Timeline ---------- */

.timeline { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.timeline li { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.timeline .t-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.timeline .t-subject { font-weight: 600; }
.timeline .t-meta { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.timeline.compact li { background: #fafbfc; }

/* ---------- Modal ---------- */

.modal-root {
  position: fixed; inset: 0; background: rgba(15, 17, 26, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal {
  background: var(--card); border-radius: 12px; padding: 24px; width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto; display: flex; flex-direction: column; gap: 12px;
}
.modal h2 { margin: 0; font-size: 18px; }
.modal label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.modal-error { color: var(--danger); font-size: 13px; margin: 4px 0 0; }

/* ---------- Status pills ---------- */

.status-pill {
  display: inline-block; padding: 2px 8px; font-size: 11px; border-radius: 999px;
  background: var(--bg); color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px;
}
.status-pill.customer { background: #dcfce7; color: var(--success); }
.status-pill.lead { background: #eef2ff; color: var(--accent); }
.status-pill.prospect { background: #fef3c7; color: #92400e; }
.status-pill.archived { background: #f3f4f6; color: var(--muted); }

.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 24px; }

/* ---------- AI panel ---------- */

.ai-panel {
  margin-top: 8px;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(79, 70, 229, 0.04), rgba(79, 70, 229, 0.01));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-result {
  font-size: 13px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-summary-text { line-height: 1.5; }
.ai-risk { color: var(--muted); font-size: 12px; }
.ai-risk strong { color: var(--accent); font-size: 14px; }
.ai-actions-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); margin-top: 4px; }
.ai-actions { padding-left: 18px; margin: 0; }
.ai-actions li { margin: 4px 0; }
.ai-error { color: var(--danger); }
.ai-stub-warning {
  font-size: 11px;
  padding: 6px 8px;
  background: #fff7ed;
  color: #9a3412;
  border-radius: 6px;
  border: 1px solid #fed7aa;
}

/* ---------- Mobile responsive ---------- */

@media (max-width: 768px) {
  .app-header {
    padding: 10px 16px;
    gap: 10px;
  }

  .app-nav { order: 3; width: 100%; gap: 2px; }
  .nav-btn { padding: 6px 10px; font-size: 13px; }

  .user-area { order: 2; }

  .app-main { padding: 16px; }

  .view h1 { font-size: 20px; }

  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat { padding: 12px; }
  .stat-value { font-size: 20px; }

  .view-actions input[type="search"] { min-width: 100%; }

  .pipeline-col { min-width: 200px; }

  .modal { padding: 20px; max-width: 100%; }
  .modal-actions { flex-direction: column; }
  .modal-actions button { width: 100%; }

  .auth-card { padding: 24px; }
}

@media (max-width: 480px) {
  .app-header { padding: 8px 12px; }
  .app-main { padding: 12px; }

  .stat-grid { grid-template-columns: 1fr; }

  .brand { font-size: 14px; }

  .view-header { flex-direction: column; align-items: stretch; }
  .view-actions { flex-direction: column; }
  .view-actions .primary-btn { width: 100%; }
}
