/* ============================================================
   SalesCRM — app.css
   Design: Dark sidebar, crisp white content area, DM Sans type
   ============================================================ */

:root {
  --sidebar-w: 220px;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --sidebar-bg: #0f1117;
  --sidebar-text: #a0a8b8;
  --sidebar-active: #ffffff;
  --sidebar-accent: #3b7fff;
  --accent: #3b7fff;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);

  /* Stage colors */
  --stage-lead: #6366f1;
  --stage-prospect: #8b5cf6;
  --stage-proposal: #3b7fff;
  --stage-negotiation: #f59e0b;
  --stage-contract: #10b981;
  --stage-won: #22c55e;
  --stage-lost: #ef4444;
  --stage-route: #06b6d4;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

/* ── Shell ─────────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }

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

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px 20px 20px;
  color: #fff;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: .02em;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.brand-mark {
  font-size: 22px;
  color: var(--accent);
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 7px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 400;
  transition: all .15s;
}

.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(59,127,255,.18); color: var(--sidebar-active); font-weight: 500; }
.nav-item.active .nav-icon { color: var(--accent); }
.nav-icon { font-size: 15px; width: 18px; text-align: center; }

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid rgba(255,255,255,.06);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name { color: #fff; font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { color: var(--sidebar-text); font-size: 11px; text-transform: capitalize; }

.logout-btn {
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 16px;
  padding: 4px;
  border-radius: 5px;
  transition: color .15s;
}
.logout-btn:hover { color: var(--danger); }

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

/* ── Page header ────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.page-title { font-size: 22px; font-weight: 600; }
.page-subtitle { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  border: 1px solid var(--border);
}

.card-sm { padding: 18px 20px; }

/* ── Stat grid ──────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 28px; font-weight: 600; margin-top: 6px; font-family: 'DM Mono', monospace; }
.stat-sub   { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 7px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  border: none;
  transition: all .15s;
  white-space: nowrap;
}

.btn-primary   { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn-ghost { background: none; color: var(--text-muted); border: 1px solid transparent; }
.btn-ghost:hover { background: var(--bg); color: var(--text); border-color: var(--border); }

/* ── Table ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 14px; text-align: left; }
th { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); border-bottom: 2px solid var(--border); }
td { border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }

/* ── Forms ──────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-grid.full { grid-template-columns: 1fr; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.span2 { grid-column: 1 / -1; }

label { font-size: 12.5px; font-weight: 500; color: var(--text-muted); }

input[type=text], input[type=email], input[type=tel], input[type=date],
input[type=number], input[type=password], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border .15s;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,127,255,.12);
}

textarea { resize: vertical; min-height: 80px; }

/* ── Badges / Tags ──────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .02em;
  white-space: nowrap;
}

.badge-lead         { background: #ede9fe; color: #5b21b6; }
.badge-prospect     { background: #f3e8ff; color: #7c3aed; }
.badge-proposal     { background: #dbeafe; color: #1d4ed8; }
.badge-negotiation  { background: #fef3c7; color: #92400e; }
.badge-contract     { background: #d1fae5; color: #065f46; }
.badge-won          { background: #dcfce7; color: #166534; }
.badge-lost         { background: #fee2e2; color: #991b1b; }
.badge-route        { background: #cffafe; color: #155e75; }

/* ── Kanban ─────────────────────────────────────────────── */
.kanban-board {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 16px;
  align-items: flex-start;
}

.kanban-col {
  flex-shrink: 0;
  width: 220px;
  background: #f8f9fb;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
}

.kanban-col-header {
  padding: 12px 14px 10px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kanban-count {
  background: var(--border);
  border-radius: 20px;
  padding: 1px 7px;
  font-size: 11px;
}

.kanban-cards { padding: 10px; display: flex; flex-direction: column; gap: 8px; min-height: 60px; }

.deal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  transition: box-shadow .15s, transform .1s;
  text-decoration: none;
  display: block;
  color: var(--text);
}

.deal-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.deal-card-title { font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.deal-card-company { font-size: 12px; color: var(--text-muted); }
.deal-card-value { font-size: 13px; font-weight: 600; color: var(--accent); margin-top: 6px; font-family: 'DM Mono', monospace; }
.deal-card-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.deal-card-assignee { font-size: 11px; color: var(--text-muted); }
.deal-card-followup { font-size: 11px; color: var(--warning); }

/* ── Modal ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}

.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--surface);
  border-radius: 14px;
  padding: 28px;
  width: 580px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(12px);
  transition: transform .2s;
  box-shadow: 0 20px 60px rgba(0,0,0,.18);
}

.modal-overlay.open .modal { transform: none; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; }
.modal-title { font-size: 17px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

/* ── Flash messages ─────────────────────────────────────── */
.flash {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-weight: 500;
  font-size: 13.5px;
}

.flash-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.flash-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* ── Search & filter bar ────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.filter-bar input, .filter-bar select {
  width: auto;
  min-width: 160px;
}

/* ── Activity timeline ──────────────────────────────────── */
.timeline { display: flex; flex-direction: column; gap: 0; }

.timeline-item {
  display: flex;
  gap: 14px;
  position: relative;
  padding-bottom: 20px;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: 16px;
  top: 32px;
  bottom: 0;
  width: 1px;
  background: var(--border);
}

.timeline-item:last-child::before { display: none; }

.timeline-dot {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}

.timeline-body { flex: 1; padding-top: 4px; }
.timeline-desc { font-size: 13.5px; }
.timeline-meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

/* ── Follow-up overdue ──────────────────────────────────── */
.overdue { color: var(--danger) !important; font-weight: 600; }

/* ── Utility ────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.items-center { align-items: center; }

/* ── Login page ─────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px;
  width: 380px;
  box-shadow: 0 24px 80px rgba(0,0,0,.3);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo .brand-mark { font-size: 36px; color: var(--accent); display: block; }
.login-logo .brand-name { font-size: 20px; font-weight: 600; margin-top: 8px; display: block; }

.login-card .form-group { margin-bottom: 16px; }
.login-card .btn { width: 100%; justify-content: center; padding: 11px; font-size: 15px; margin-top: 6px; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .main-content { margin-left: 0; padding: 20px 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .kanban-col { width: 180px; }
}
