:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --border: #e4e8ee;
  --border-soft: #edf0f5;
  --text: #101828;
  --text-muted: #667085;
  --text-faint: #98a2b3;
  --accent: #3457d5;
  --accent-dark: #24409e;
  --accent-light: #ebf0ff;
  --danger: #d92d20;
  --danger-light: #fef0ee;
  --warning: #b54708;
  --warning-light: #fef6e7;
  --success: #067647;
  --success-light: #e9f7ef;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 6px 16px rgba(16, 24, 40, 0.08), 0 2px 4px rgba(16, 24, 40, 0.04);

  --sidebar-bg: #101a30;
  --sidebar-bg-raised: #16233f;
  --sidebar-active: #22335a;
  --sidebar-text: #c9d3ea;
  --sidebar-text-muted: #7c8aac;
  --sidebar-border: #22304e;
}

* { box-sizing: border-box; }

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

button { font-family: inherit; cursor: pointer; }
a { color: var(--accent); }

/* ---------- Auth pages ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 20% 15%, #182541 0%, #0d1526 55%, #0a0f1c 100%);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
  padding: 32px;
}

.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-card p.sub { color: var(--text-muted); margin: 0 0 24px; font-size: 13px; }

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}
.field textarea { resize: vertical; min-height: 70px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  transition: filter 0.15s, background 0.15s, border-color 0.15s;
}
.btn:hover { filter: brightness(1.07); }
.btn.secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn.secondary:hover { border-color: var(--accent); color: var(--accent); filter: none; }
.btn.danger { background: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.6; cursor: default; }

.error-msg { background: var(--danger-light); color: var(--danger); padding: 8px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.success-msg { background: var(--success-light); color: var(--success); padding: 8px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }

/* ---------- App shell ---------- */
.shell { min-height: 100vh; display: flex; }

.sidebar {
  width: 234px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 18px 14px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 18px;
  font-weight: 800;
  font-size: 13.5px;
  letter-spacing: -0.01em;
  color: #fff;
  line-height: 1.2;
}
.sidebar-brand .logo-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #6c8cff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(52, 87, 213, 0.45);
}

.sidebar-section-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--sidebar-text-muted);
  padding: 14px 8px 6px;
}

.sidebar-businesses { display: flex; flex-direction: column; gap: 2px; }

.biz-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  padding: 8px 8px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  transition: background 0.12s;
}
.biz-item:hover { background: var(--sidebar-bg-raised); }
.biz-item.active { background: var(--sidebar-active); color: #fff; }
.biz-item .biz-icon {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}
.biz-item .biz-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.biz-item .biz-badge {
  background: var(--danger);
  color: #fff;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  flex-shrink: 0;
}

.sidebar-add-business {
  border: 1px dashed var(--sidebar-border);
  background: transparent;
  color: var(--sidebar-text-muted);
  border-radius: var(--radius-sm);
  padding: 8px;
  font-size: 12.5px;
  font-weight: 600;
  margin-top: 6px;
  transition: border-color 0.15s, color 0.15s;
}
.sidebar-add-business:hover { border-color: var(--accent); color: #fff; }

.sidebar-views { display: flex; flex-direction: column; gap: 2px; }
.view-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  padding: 8px 8px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  transition: background 0.12s;
}
.view-btn:hover { background: var(--sidebar-bg-raised); }
.view-btn.active { background: linear-gradient(135deg, var(--accent), #4a6bea); color: #fff; }
.view-btn .view-icon { font-size: 14px; width: 18px; text-align: center; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-user {
  font-size: 11.5px;
  color: var(--sidebar-text-muted);
  padding: 0 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }

/* ---------- Notification banner ---------- */
.notif-banner {
  background: #fff9f0;
  border-bottom: 1px solid #fbe3bf;
  padding: 11px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13.5px;
}
.notif-banner .notif-icon { font-size: 16px; flex-shrink: 0; }
.notif-banner.overdue { background: #fef3f2; border-bottom-color: #fecdca; }
.notif-banner.clear { background: #f0fdf6; border-bottom-color: #cdf0dd; }
.notif-banner strong { font-weight: 700; }
.notif-banner .muted-note { color: var(--text-muted); }
.notif-banner .spacer { flex: 1; }
.notif-banner button.link {
  background: none;
  border: 1px solid transparent;
  color: var(--accent);
  font-weight: 700;
  font-size: 12.5px;
  padding: 5px 10px;
  border-radius: 999px;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.notif-banner button.link:hover { background: rgba(52, 87, 213, 0.08); border-color: rgba(52, 87, 213, 0.25); }
.notif-list { border-bottom: 1px solid var(--border); background: #fff; max-height: 280px; overflow-y: auto; }
.notif-item {
  padding: 10px 24px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.1s;
}
.notif-item:hover { background: var(--bg); }
.notif-item .biz-icon { font-size: 16px; }
.notif-item .name { font-weight: 600; }
.notif-item .meta { color: var(--text-muted); }
.notif-item .spacer { flex: 1; }
.notif-item .bucket-tag {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  padding: 2px 7px; border-radius: 999px;
}
.notif-item .bucket-tag.overdue { background: var(--danger-light); color: var(--danger); }
.notif-item .bucket-tag.due { background: var(--warning-light); color: var(--warning); }
.notif-item .bucket-tag.upcoming { background: var(--accent-light); color: var(--accent); }

/* ---------- Topbar / stats ---------- */
.topbar {
  padding: 20px 24px 0;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 15;
}

.stats-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 16px; }
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat-card .stat-value { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); font-weight: 600; margin-top: 3px; }
.stat-card.tone-danger .stat-value { color: var(--danger); }
.stat-card.tone-warning .stat-value { color: var(--warning); }
.stat-card.tone-accent .stat-value { color: var(--accent); }
.stat-card.tone-neutral .stat-value { color: var(--text); }

@media (max-width: 1000px) { .stats-row { grid-template-columns: repeat(2, 1fr); } }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type="search"] { padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; min-width: 220px; background: #fff; }
.toolbar select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; background: #fff; }
.toolbar .spacer { flex: 1; }

/* ---------- Main content ---------- */
main { flex: 1; padding: 0 24px 24px; min-width: 0; }
.view-panel.hidden { display: none; }\n.view-hint { color: var(--text-muted); font-size: 12.5px; margin: 0 0 12px; max-width: 720px; }

.card-table { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-md); }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 960px; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); font-weight: 700; padding: 12px 16px; border-bottom: 1px solid var(--border);
  background: #fafbfc; position: sticky; top: 0;
}
th.col-actions, td.col-actions { text-align: right; }
tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border-soft); font-size: 13.5px; vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.1s; position: relative; }
tbody tr:hover { background: #f8faff; }
tbody tr.row-overdue { box-shadow: inset 3px 0 0 var(--danger); }
tbody tr.row-due { box-shadow: inset 3px 0 0 var(--warning); }

.name-cell { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.avatar-circle {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; display: flex;
  align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: #fff; margin-top: 1px;
}

.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; letter-spacing: 0.01em; }
.pill.status-not { background: #eef0f4; color: #475467; }
.pill.status-contacted { background: var(--accent-light); color: var(--accent); }
.pill.status-followup { background: var(--warning-light); color: var(--warning); }
.pill.status-responded { background: var(--success-light); color: var(--success); }
.pill.status-declined { background: var(--danger-light); color: var(--danger); }
.pill.status-other { background: #f1f0fb; color: #6941c6; }

.date-tag { font-weight: 700; display: inline-flex; align-items: center; gap: 5px; }
.date-tag.overdue { color: var(--danger); }
.date-tag.today { color: var(--warning); }
.date-tag.future { color: var(--text); font-weight: 600; }
.date-tag.none { color: var(--text-faint); font-weight: 400; }
.date-tag .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.review-flag {
  display: inline-flex; align-items: center; gap: 4px; color: var(--warning); background: var(--warning-light);
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; padding: 2px 7px;
  border-radius: 999px; margin-left: 6px;
}

/* Quick action chips */
.quick-actions { display: flex; gap: 4px; justify-content: flex-end; }
.qa-btn {
  width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--border); background: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 13px; color: var(--text-muted);
  transition: transform 0.1s, border-color 0.1s, background 0.1s;
}
.qa-btn:hover { transform: translateY(-1px); }
.qa-btn.qa-whatsapp:hover { background: #e7f9ee; border-color: #067647; color: #067647; }
.qa-btn.qa-email:hover { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.qa-btn.qa-log:hover { background: var(--warning-light); border-color: var(--warning); color: var(--warning); }
.qa-btn:disabled { opacity: 0.35; cursor: default; }
.qa-btn:disabled:hover { transform: none; background: #fff; border-color: var(--border); color: var(--text-muted); }

.empty-state { padding: 60px 20px; text-align: center; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 28px; margin-bottom: 10px; }

/* ---------- Pipeline / kanban ---------- */
.pipeline-board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; align-items: flex-start; }
.pipeline-col {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 268px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 260px);
  box-shadow: var(--shadow);
}
.pipeline-col.drag-over { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-light); }
.pipeline-col-header {
  display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border);
  font-size: 12.5px; font-weight: 700; color: var(--text-muted);
}
.pipeline-col-header .col-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.pipeline-col-header .col-count {
  background: var(--bg); color: var(--text-muted); font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; margin-left: auto;
}
.pipeline-col-body { padding: 10px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; flex: 1; }
.pipeline-col-empty { color: var(--text-faint); font-size: 12px; text-align: center; padding: 18px 6px; }

.pipeline-card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px;
  cursor: grab; transition: box-shadow 0.12s, transform 0.12s; box-shadow: var(--shadow);
}
.pipeline-card:hover { box-shadow: var(--shadow-md); }
.pipeline-card.dragging { opacity: 0.4; }
.pipeline-card.row-overdue { box-shadow: inset 3px 0 0 var(--danger), var(--shadow); }
.pipeline-card.row-due { box-shadow: inset 3px 0 0 var(--warning), var(--shadow); }
.pipeline-card .pc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.pipeline-card .pc-title { font-weight: 700; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pipeline-card .pc-meta { font-size: 11.5px; color: var(--text-muted); margin-bottom: 6px; }
.pipeline-card .pc-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.pipeline-card .pc-date { font-size: 11px; font-weight: 700; }
.pipeline-card .qa-btn { width: 24px; height: 24px; font-size: 11px; }

/* ---------- Calendar ---------- */
.calendar-wrap { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 16px; }
.calendar-header { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.calendar-title { font-size: 15px; font-weight: 800; min-width: 150px; text-align: center; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.calendar-dow { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); text-align: center; padding: 4px 0 8px; }
.calendar-cell {
  min-height: 76px; border: 1px solid var(--border-soft); border-radius: 10px; padding: 6px; background: #fbfcfe;
  display: flex; flex-direction: column; gap: 4px; cursor: pointer; transition: border-color 0.12s, background 0.12s;
}
.calendar-cell:hover { border-color: var(--accent); }
.calendar-cell.outside { background: transparent; border-color: transparent; cursor: default; }
.calendar-cell.today { border-color: var(--accent); background: var(--accent-light); }
.calendar-cell.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-light) inset; }
.calendar-cell .cc-num { font-size: 12px; font-weight: 700; color: var(--text-muted); }
.calendar-cell.today .cc-num { color: var(--accent); }
.calendar-cell .cc-badges { display: flex; flex-wrap: wrap; gap: 3px; }
.cc-badge { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 999px; }
.cc-badge.overdue { background: var(--danger-light); color: var(--danger); }
.cc-badge.due { background: var(--warning-light); color: var(--warning); }
.cc-badge.upcoming { background: var(--accent-light); color: var(--accent); }

.calendar-day-list { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.calendar-day-list h3 { font-size: 13px; margin: 0 0 10px; }
.cdl-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; cursor: pointer;
  transition: background 0.1s;
}
.cdl-item:hover { background: var(--bg); }
.cdl-item .name { font-weight: 600; flex: 1; }
.cdl-item .meta { color: var(--text-muted); font-size: 12px; }
.cdl-empty { color: var(--text-faint); font-size: 13px; padding: 6px 10px; }

/* ---------- Modal / drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); display: flex; justify-content: flex-end; z-index: 50; }
.overlay.center { justify-content: center; align-items: center; }
.drawer { background: #fff; width: 100%; max-width: 520px; height: 100%; overflow-y: auto; padding: 24px; box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
.modal-box { background: #fff; width: 100%; max-width: 460px; border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); max-height: 90vh; overflow-y: auto; }
.drawer-header, .modal-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 16px; }
.drawer-header h2, .modal-header h2 { margin: 0; font-size: 17px; }
.close-x { background: none; border: none; font-size: 18px; color: var(--text-muted); line-height: 1; }

.drawer-quick-actions { display: flex; gap: 8px; margin-bottom: 18px; }
.drawer-quick-actions .btn { flex: 1; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }

.section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); margin: 20px 0 10px; }

.timeline { display: flex; flex-direction: column; gap: 10px; }
.timeline-entry { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; background: #fafbfc; }
.timeline-entry .te-head { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }
.timeline-entry .te-note { font-size: 13px; white-space: pre-wrap; line-height: 1.5; }

.actions-row { display: flex; gap: 8px; margin-top: 16px; }
.hidden { display: none !important; }

.token-box { background: #0f172a; color: #d1fae5; padding: 12px; border-radius: 8px; font-family: ui-monospace, monospace; font-size: 12px; word-break: break-all; margin: 12px 0; }
.helper-text { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; flex-direction: row; flex-wrap: wrap; gap: 10px; align-items: center; }
  .sidebar-businesses, .sidebar-views { flex-direction: row; flex-wrap: wrap; }
  .sidebar-footer { margin-top: 0; border-top: none; flex-direction: row; margin-left: auto; }
  .sidebar-brand { padding-bottom: 0; }
}

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  main { padding: 0 12px 12px; }
  .topbar { padding: 12px 12px 0; }
}
