/* ── Reset & base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --accent: #238636;
  --accent-hover: #2ea043;
  --accent2: #1f6feb;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --danger: #da3633;
  --warn: #e3b341;
  --success: #3fb950;
  --sidebar-w: 220px;
  --radius: 8px;
  --shadow: 0 2px 12px rgba(0,0,0,.4);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  padding: 20px 16px;
  font-size: 18px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}
.brand-icon { font-size: 22px; }

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  transition: background .15s, color .15s;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--surface2); color: var(--text); font-weight: 600; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.api-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}
.api-status.online .status-dot { background: var(--success); }
.api-status.offline .status-dot { background: var(--danger); }
.api-status.connecting .status-dot { background: var(--warn); animation: pulse 1.2s infinite; }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ── Main ────────────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 32px;
  max-width: 1100px;
}

/* ── Views ───────────────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; }

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 12px;
}
.view-header h1 { font-size: 22px; font-weight: 700; }
.view-header .subtitle { color: var(--text-muted); font-size: 13px; margin-left: 4px; }

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

/* ── Card ────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
}

/* ── Funnel chart ────────────────────────────────────────────── */
.funnel-chart { display: flex; flex-direction: column; gap: 10px; }
.funnel-stage {
  display: flex;
  align-items: center;
  gap: 12px;
}
.funnel-label { width: 160px; font-size: 13px; color: var(--text-muted); flex-shrink: 0; }
.funnel-bar-wrap { flex: 1; background: var(--surface2); border-radius: 4px; height: 26px; overflow: hidden; }
.funnel-bar { height: 100%; border-radius: 4px; transition: width .5s ease; min-width: 2px; }
.funnel-count { width: 32px; text-align: right; font-size: 13px; font-weight: 600; color: var(--text); }

/* ── Company badges ──────────────────────────────────────────── */
.company-badges { display: flex; flex-wrap: wrap; gap: 8px; }
.badge {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 14px;
  font-size: 12px;
  color: var(--text);
}

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  min-height: 40px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s;
}
.btn svg { width: 14px; height: 14px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 6px; border-radius: 6px; background: transparent; border: none; cursor: pointer; color: var(--text-muted); }
.btn-icon:hover { background: var(--surface2); color: var(--text); }
.btn-icon svg { width: 14px; height: 14px; }

/* ── Filter bar ───────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* ── Forms ───────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .4px; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--accent2); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-select { appearance: none; cursor: pointer; }

/* ── Table ───────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 10px 12px;
  background: var(--surface2);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface2); }

/* ── Stage pill ──────────────────────────────────────────────── */
.stage-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.stage-Identified      { background: #21262d; color: #8b949e; }
.stage-Contacted       { background: #1c2d3f; color: #58a6ff; }
.stage-Meeting-Scheduled { background: #1e2d1f; color: #3fb950; }
.stage-Proposal-Sent   { background: #2d2213; color: #e3b341; }
.stage-Closed-Won      { background: #1b3a25; color: #56d364; }
.stage-Closed-Lost     { background: #3a1414; color: #f85149; }

/* ── Card list (emails / meetings / orders / feedback) ───────── */
.card-list { display: flex; flex-direction: column; gap: 12px; }
.list-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.list-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
  gap: 12px;
}
.list-card-title { font-weight: 600; font-size: 14px; }
.list-card-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.list-card-body { font-size: 13px; color: var(--text-muted); white-space: pre-wrap; line-height: 1.5; }
.list-card-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ── Status pill ─────────────────────────────────────────────── */
.status-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.status-Draft    { background:#21262d; color:#8b949e; }
.status-Sent     { background:#1c2d3f; color:#58a6ff; }
.status-Scheduled{ background:#1e2d1f; color:#3fb950; }
.status-Completed{ background:#1b3a25; color:#56d364; }
.status-Pending  { background:#21262d; color:#8b949e; }
.status-Confirmed{ background:#1c2d3f; color:#58a6ff; }
.status-Shipped  { background:#2d2213; color:#e3b341; }
.status-Delivered{ background:#1b3a25; color:#56d364; }
.status-Cancelled{ background:#3a1414; color:#f85149; }
.status-Positive { background:#1b3a25; color:#56d364; }
.status-Neutral  { background:#21262d; color:#8b949e; }
.status-Negative { background:#3a1414; color:#f85149; }

/* ── Agent chat ──────────────────────────────────────────────── */
.agent-card { display: flex; flex-direction: column; gap: 12px; }
.agent-messages {
  min-height: 280px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.agent-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.agent-msg.user { align-self: flex-end; background: var(--accent2); color: #fff; border-bottom-right-radius: 2px; }
.agent-msg.agent { align-self: flex-start; background: var(--surface2); color: var(--text); border-bottom-left-radius: 2px; }
.agent-input-row { display: flex; gap: 8px; align-items: stretch; }
.agent-contact { width: 220px; flex-shrink: 0; }
.agent-input { flex: 1; }
.agent-examples { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); }
.chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 12px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  transition: background .15s;
}
.chip:hover { background: var(--border); }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 520px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow);
}
.modal-close {
  position: absolute; top: 14px; right: 16px;
  background: none; border: none;
  color: var(--text-muted);
  font-size: 20px; cursor: pointer; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal h2 { font-size: 17px; font-weight: 700; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ── Toast ───────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 13px;
  color: var(--text);
  z-index: 300;
  box-shadow: var(--shadow);
  transition: opacity .3s;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.hidden  { display: none; }

/* ── Loader ──────────────────────────────────────────────────── */
.loader { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent2); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Approval pill ───────────────────────────────────────────── */
.approval-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.approval-pending  { background: #2d2213; color: #e3b341; }
.approval-approved { background: #1b3a25; color: #56d364; }
.approval-rejected { background: #3a1414; color: #f85149; }

/* ── Nav badge ───────────────────────────────────────────────── */
.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
  line-height: 16px;
}

/* ── Stat card warning variant ───────────────────────────────── */
.stat-card-warn .stat-value { color: var(--warn); }

/* ── Mobile nav toggle (hidden on desktop) ───────────────────── */
.nav-toggle,
.nav-close {
  display: none;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.nav-toggle svg,
.nav-close svg { width: 20px; height: 20px; }
.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 150;
}

/* Larger touch targets on nav */
.nav-item {
  min-height: 44px;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 700px) {
  :root { --sidebar-w: 0px; }

  .nav-toggle {
    display: inline-flex;
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    z-index: 140;
  }

  .nav-close {
    display: inline-flex;
    margin-left: auto;
    border: none;
    background: transparent;
    color: var(--text-muted);
  }

  .sidebar {
    display: flex;
    width: min(280px, 86vw);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    z-index: 160;
    box-shadow: var(--shadow);
  }
  body.nav-open .sidebar {
    transform: translateX(0);
  }
  body.nav-open .nav-backdrop {
    display: block;
  }
  body.nav-open .nav-toggle {
    visibility: hidden;
  }

  .main {
    padding: 16px;
    padding-top: 64px; /* room for fixed menu button */
  }

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

  .filter-bar {
    flex-wrap: wrap;
  }
  .form-select,
  .form-input {
    min-height: 44px;
    font-size: 16px; /* avoid iOS zoom on focus */
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
  }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 22px; }

  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .agent-input-row {
    flex-wrap: wrap;
  }
}

/* ── Catalog Monitor ─────────────────────────────────────────── */
.header-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.view-header { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.catalog-status-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  text-transform: capitalize;
}
.cat-not_started { background: #21262d; color: #8b949e; }
.cat-applied { background: #1c2d41; color: #58a6ff; }
.cat-in_review { background: #2d2213; color: #e3b341; }
.cat-approved { background: #1b3a25; color: #56d364; }
.cat-listed { background: #0d3b2e; color: #3fb950; }
.cat-on_hold { background: #3a2e14; color: #d29922; }
.cat-rejected { background: #3a1414; color: #f85149; }
.catalog-price-input {
  width: 96px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
}
.catalog-sku-chip {
  display: inline-block;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 10px;
  margin: 1px;
  font-family: ui-monospace, monospace;
}
