/* =================================================================
   ClientFlow CRM — Stylesheet
   =================================================================
   DESIGN TOKENS
   Every color, font and spacing value the app uses is declared
   once at the top as a CSS "custom property" (a variable, written
   --like-this). Every other rule below reads from these variables
   instead of repeating hex codes everywhere. Change a value here
   and it updates the whole app — that's the entire point of
   having tokens instead of scattering colors through the file.

   Palette:
     --ink       near-black text, cool blue-grey tint
     --paper     the page background (cool light grey, not white)
     --surface   card / panel background
     --primary   brand blue — buttons, links, active nav, focus
     --accent    emerald green — money, conversions, success
     --warn      burnt amber — medium/high priority, warnings
     --danger    red — delete actions, "Lost" status, errors

   Type:
     --font-display  "Space Grotesk" — headings, big numbers
     --font-body     "Inter" — body text, forms, table rows
   ================================================================= */

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

:root {
  --ink: #12141c;
  --ink-soft: #4b5265;
  --paper: #eef0f4;
  --surface: #ffffff;
  --line: #dde1e9;

  --primary: #24408e;
  --primary-soft: #e8edfb;
  --accent: #1f8a5c;
  --accent-soft: #e4f5ec;
  --warn: #c2622c;
  --warn-soft: #fbeee3;
  --danger: #b23b3b;
  --danger-soft: #fbe9e9;

  --shadow: 0 12px 30px rgba(18, 20, 28, 0.08);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;

  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
}

body.dark {
  --ink: #eef0f6;
  --ink-soft: #a7adc0;
  --paper: #0f1119;
  --surface: #171a25;
  --line: #262b3a;

  --primary: #6f8cf0;
  --primary-soft: #1c2440;
  --accent: #3ecf8e;
  --accent-soft: #133226;
  --warn: #e59155;
  --warn-soft: #34241a;
  --danger: #e2726f;
  --danger-soft: #3a1e1e;

  --shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

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

body {
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.5;
  transition: background 0.2s, color 0.2s;
}

h1, h2, h3, .brand, .stat-value, .pipeline-value {
  font-family: var(--font-display);
  letter-spacing: -0.02em;
}

a { color: inherit; }
button { font-family: inherit; }

/* ---- App shell: sidebar + main column ---- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; font-size: 19px; font-weight: 700; padding: 0 8px; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--primary); display: grid; place-items: center; color: #fff; font-size: 15px; font-weight: 700; }

.nav-list { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--ink-soft); font-weight: 600; font-size: 14px;
  cursor: pointer; border: none; background: none; text-align: left; width: 100%;
}
.nav-item .icon { font-size: 16px; width: 18px; text-align: center; }
.nav-item:hover { background: var(--paper); color: var(--ink); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); }

.sidebar-footer { border-top: 1px solid var(--line); padding-top: 16px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.user-chip small { display: block; color: var(--ink-soft); font-size: 11px; }
.logout-btn { margin-top: 10px; width: 100%; padding: 9px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: transparent; color: var(--ink-soft); font-size: 13px; font-weight: 600; cursor: pointer; }
.logout-btn:hover { border-color: var(--danger); color: var(--danger); }

/* ---- Main column ---- */
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 66px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; z-index: 20;
  gap: 16px;
}
.topbar h1 { font-size: 18px; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.icon-btn {
  width: 38px; height: 38px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  display: grid; place-items: center; cursor: pointer; font-size: 16px; position: relative;
}
.icon-btn:hover { background: var(--paper); }
.badge-dot { position: absolute; top: -4px; right: -4px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 99px; display: grid; place-items: center; padding: 0 3px; }

.content { padding: 28px; max-width: 1280px; width: 100%; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; animation: fade-in 0.15s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---- Buttons ---- */
.btn { border: none; border-radius: var(--radius-sm); padding: 10px 16px; font-weight: 600; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--paper); }
.btn-danger-text { background: transparent; border: none; color: var(--danger); font-weight: 600; font-size: 12px; cursor: pointer; }
.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: 7px 12px; font-size: 12px; }

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

/* ---- Dashboard: stat cards ---- */
.stat-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-bottom: 20px; }
.stat-card { padding: 18px; display: flex; flex-direction: column; gap: 6px; }
.stat-label { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.stat-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 11px; color: var(--ink-soft); }

.dash-row { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 16px; }

/* ---- Pipeline funnel ---- */
.pipeline-card { padding: 22px; }
.pipeline-card h2 { font-size: 15px; margin-bottom: 4px; }
.pipeline-card .hint { font-size: 12px; color: var(--ink-soft); margin-bottom: 18px; }
.funnel { display: flex; flex-direction: column; gap: 10px; }
.funnel-row { display: grid; grid-template-columns: 96px 1fr 40px; align-items: center; gap: 12px; }
.funnel-label { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.funnel-track { height: 14px; border-radius: 99px; background: var(--paper); overflow: hidden; }
.funnel-fill { height: 100%; border-radius: 99px; background: var(--primary); transition: width 0.4s ease; }
.funnel-count { font-size: 12px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Activity feed ---- */
.activity-card { padding: 22px; }
.activity-card h2 { font-size: 15px; margin-bottom: 16px; }
.activity-list { display: flex; flex-direction: column; gap: 14px; max-height: 320px; overflow-y: auto; }
.activity-row { display: flex; gap: 10px; font-size: 13px; }
.activity-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); margin-top: 6px; flex-shrink: 0; }
.activity-text b { font-weight: 600; }
.activity-time { color: var(--ink-soft); font-size: 11px; }
.empty-hint { color: var(--ink-soft); font-size: 13px; padding: 8px 0; }

/* ---- Leads page ---- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; justify-content: space-between; }
.toolbar-left { display: flex; flex-wrap: wrap; gap: 10px; flex: 1; align-items: center; }
.quick-filters { display: flex; gap: 5px; }
.quick-filter { border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft); border-radius: 99px; padding: 8px 11px; font-size: 11px; font-weight: 700; cursor: pointer; }
.quick-filter:hover { color: var(--ink); }
.quick-filter.active { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.search-box { position: relative; flex: 1; min-width: 220px; max-width: 320px; }
.search-box input { width: 100%; padding: 10px 12px 10px 34px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); color: var(--ink); outline: none; font-size: 13px; }
.search-box::before { content: "🔍"; position: absolute; left: 11px; top: 50%; transform: translateY(-50%); font-size: 12px; opacity: 0.6; }
select.filter-select { padding: 10px 10px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 13px; }

.table-card { overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th { text-align: left; padding: 13px 18px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; white-space: nowrap; }
th:hover { color: var(--ink); }
td { padding: 15px 18px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.lead-row { cursor: pointer; }
tr.lead-row:hover { background: var(--paper); }
.cell-name strong { display: block; }
.cell-name small { color: var(--ink-soft); font-size: 12px; }
.cell-value { font-variant-numeric: tabular-nums; font-weight: 600; }
.followup-due { color: var(--danger); font-weight: 700; }

.badge { display: inline-block; padding: 4px 10px; border-radius: 99px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge-New { background: var(--primary-soft); color: var(--primary); }
.badge-Contacted { background: var(--warn-soft); color: var(--warn); }
.badge-Qualified { background: var(--accent-soft); color: var(--accent); }
.badge-Proposal { background: var(--accent-soft); color: var(--accent); }
.badge-Converted { background: var(--accent-soft); color: var(--accent); }
.badge-Lost { background: var(--danger-soft); color: var(--danger); }
.priority-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.priority-High .priority-dot { background: var(--danger); }
.priority-Medium .priority-dot { background: var(--warn); }
.priority-Low .priority-dot { background: var(--ink-soft); }

.row-actions { display: flex; gap: 6px; }
.icon-action { border: none; background: transparent; cursor: pointer; font-size: 14px; padding: 4px 6px; border-radius: 6px; color: var(--ink-soft); }
.icon-action:hover { background: var(--paper); color: var(--ink); }

.empty-state { text-align: center; padding: 50px 20px; color: var(--ink-soft); }
.empty-state .big { font-size: 30px; margin-bottom: 8px; }

/* ---- Analytics page ---- */
.analytics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.bar-list { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 34px; align-items: center; gap: 10px; font-size: 12px; }
.bar-track { height: 10px; background: var(--paper); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 99px; }
.revenue-compare { display: flex; gap: 20px; padding: 6px 0; }
.revenue-item { flex: 1; }
.revenue-item .amount { font-family: var(--font-display); font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.revenue-item .label { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }

/* ---- Settings page ---- */
.settings-card { padding: 24px; max-width: 520px; }
.settings-heading { display:flex; justify-content:space-between; align-items:flex-start; margin-bottom:18px; }
.settings-heading .hint { font-size:12px; color:var(--ink-soft); }
.settings-section-title { font-size:13px; padding-top:4px; margin-bottom:2px; }
.settings-row { display: flex; justify-content: space-between; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--line); }
.settings-row:last-child { border-bottom: none; }
.settings-row .label { font-size: 13px; color: var(--ink-soft); }
.settings-row .value { font-size: 13px; font-weight: 600; }
.role-pill { background: var(--primary-soft); color: var(--primary); padding: 2px 9px; border-radius: 99px; font-size: 11px; font-weight: 700; }
.toggle { width: 42px; height: 24px; border-radius: 99px; background: var(--line); border: none; cursor: pointer; position: relative; }
.toggle.on { background: var(--primary); }
.toggle::after { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: left 0.15s; }
.toggle.on::after { left: 21px; }

/* ---- Modal (Add/Edit lead, Lead detail) ---- */
.modal-overlay { position: fixed; inset: 0; background: rgba(10, 12, 20, 0.55); display: flex; align-items: flex-start; justify-content: center; padding: 40px 20px; overflow-y: auto; z-index: 100; }
.modal-overlay.hidden { display: none; }
.modal-box { background: var(--surface); border-radius: var(--radius-lg); width: min(600px, 100%); padding: 26px; position: relative; }
.modal-box.wide { width: min(720px, 100%); }
.modal-close { position: absolute; right: 18px; top: 16px; border: none; background: transparent; font-size: 22px; color: var(--ink-soft); cursor: pointer; }
.modal-box h2 { font-size: 19px; margin-bottom: 4px; }
.modal-sub { font-size: 12px; color: var(--ink-soft); margin-bottom: 18px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 6px; }
.form-grid label { font-size: 12px; font-weight: 600; color: var(--ink-soft); display: block; }
.form-grid label.full { grid-column: 1 / -1; }
input, select, textarea {
  display: block; width: 100%; margin-top: 6px; padding: 10px 11px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--paper); color: var(--ink); font-size: 13px; font-family: inherit; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 70px; }
.form-message { font-size: 12px; margin-top: 12px; text-align: center; min-height: 16px; }
.form-message.error { color: var(--danger); }
.form-message.success { color: var(--accent); }
.form-actions { margin-top: 18px; }

/* ---- Lead detail modal ---- */
.detail-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.detail-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; font-size: 13px; }
.detail-meta div span { display: block; color: var(--ink-soft); font-size: 11px; margin-bottom: 2px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tab-btn { padding: 9px 14px; border: none; background: none; font-size: 13px; font-weight: 600; color: var(--ink-soft); cursor: pointer; border-bottom: 2px solid transparent; }
.tab-btn.active { color: var(--primary); border-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.note-item { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.note-item:last-child { border-bottom: none; }
.note-item .meta { color: var(--ink-soft); font-size: 11px; margin-top: 4px; }
.status-select-row { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; }

/* ---- Notifications dropdown ---- */
.dropdown { position: absolute; top: 52px; right: 28px; width: 320px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); box-shadow: var(--shadow); z-index: 30; max-height: 400px; overflow-y: auto; }
.dropdown.hidden { display: none; }
.dropdown-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 13px; font-weight: 700; }
.dropdown-head button { font-size: 11px; color: var(--primary); background: none; border: none; cursor: pointer; font-weight: 600; }
.notif-item { padding: 12px 16px; font-size: 12.5px; border-bottom: 1px solid var(--line); cursor: pointer; }
.notif-item:last-child { border-bottom: none; }
.notif-item.unread { background: var(--primary-soft); }
.notif-item .time { color: var(--ink-soft); font-size: 11px; margin-top: 3px; }

/* ---- Login page ---- */
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--paper); padding: 20px; }
.login-card { width: min(380px, 100%); padding: 32px; text-align: center; }
.login-card .brand { justify-content: center; margin-bottom: 22px; }
.login-card h1 { font-size: 20px; margin-bottom: 6px; }
.login-card p.sub { font-size: 13px; color: var(--ink-soft); margin-bottom: 22px; }
.login-card form { text-align: left; }
.login-card label { font-size: 12px; font-weight: 600; color: var(--ink-soft); display: block; margin-bottom: 14px; }
.demo-hint { margin-top: 18px; font-size: 11.5px; color: var(--ink-soft); background: var(--paper); border-radius: var(--radius-sm); padding: 10px; text-align: left; line-height: 1.6; }

/* ---- Mobile ---- */
.mobile-toggle { display: none; }

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar { position: fixed; left: -260px; top: 0; height: 100vh; z-index: 50; transition: left 0.2s; width: 240px; }
  .sidebar.open { left: 0; box-shadow: var(--shadow); }
  .mobile-toggle { display: grid; }
  .dash-row, .analytics-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .quick-filters { width: 100%; }
  .content { padding: 18px; }
  .form-grid { grid-template-columns: 1fr; }
  .dropdown { right: 16px; width: calc(100% - 32px); }
}

@media (max-width: 520px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .quick-filters { width: 100%; }
  .topbar { padding: 0 14px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-left { flex-direction: column; }
  .search-box { max-width: none; }
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; }
.show-password { display:flex !important; align-items:center; gap:7px; font-size:11px !important; font-weight:500 !important; margin-top:-7px; }
.show-password input { width:auto; margin:0; }
