/* === CSS VARIABLES === */
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --text: #111827;
  --text-2: #374151;
  --text-3: #6b7280;
  --text-4: #9ca3af;
  --border: #e5e7eb;
  --border-2: #f3f4f6;
  --success: #10b981;
  --success-bg: #ecfdf5;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.04);
  --shadow: 0 1px 3px rgba(17, 24, 39, 0.06), 0 4px 12px rgba(17, 24, 39, 0.04);
  --shadow-md: 0 4px 16px rgba(17, 24, 39, 0.08);
  --shadow-lg: 0 12px 32px rgba(17, 24, 39, 0.12);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
}

/* === RESET === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
  padding-top: env(safe-area-inset-top);
  /* Prevent iOS double-tap zoom (the side-panel blank zoom issue) */
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; touch-action: manipulation; }
input, select, textarea { font: inherit; color: inherit; outline: none; }
a { color: var(--primary); text-decoration: none; }
::selection { background: #c7d2fe; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* === LAYOUT (mobile first) === */
#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
}

.topbar {
  padding: 14px 18px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 800; font-size: 15px;
  letter-spacing: -0.02em; box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}
.topbar h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; color: var(--text); white-space: nowrap; }
.topbar .meta { font-size: 11px; color: var(--text-3); margin-top: 1px; }
.topbar-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3); background: transparent;
  transition: background 0.15s; font-size: 16px;
}
.icon-btn:hover { background: var(--surface); }

/* Person toggle */
.person-toggle {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 1px;
  box-shadow: var(--shadow-sm);
}
.person-toggle button {
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-3);
  transition: all 0.15s;
  white-space: nowrap;
}
.person-toggle button:hover { color: var(--text); }
.person-toggle button.active {
  background: var(--primary);
  color: white;
}

/* Top nav (desktop only) */
.topnav { display: none; }
.topnav button {
  padding: 8px 14px;
  border-radius: 10px;
  color: var(--text-3);
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}
.topnav button:hover { background: var(--primary-light); color: var(--primary-hover); }
.topnav button.active { background: var(--primary-light); color: var(--primary-hover); }

.content {
  flex: 1;
  padding: 4px 16px 96px;
  overflow-x: hidden;
}

/* Bottom tabbar (mobile) */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 560px;
  margin: 0 auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 12px rgba(17,24,39,0.06);
}
.tabbar button {
  flex: 1;
  padding: 9px 2px 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--text-4);
  font-size: 10px;
  font-weight: 500;
  transition: color 0.15s;
}
.tabbar button.active { color: var(--primary); }
.tabbar button .icon {
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
}

/* === COMMON === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}
.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  padding: 14px 4px 8px;
}
.empty {
  color: var(--text-3);
  text-align: center;
  padding: 36px 16px;
  font-size: 14px;
}
.empty .big { font-size: 30px; margin-bottom: 8px; opacity: 0.5; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 14px;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: white; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--primary-light); color: var(--primary-hover); }
.btn-secondary:hover { background: #e0e7ff; }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { background: #fee2e2; }
.btn-ghost { background: transparent; color: var(--text-3); }
.btn-ghost:hover { background: var(--surface); }
.btn-block { width: 100%; }

.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary-hover);
  line-height: 1.4;
}
.pill-red { background: var(--danger-bg); color: #dc2626; }
.pill-green { background: var(--success-bg); color: var(--success); }
.pill-orange { background: var(--warning-bg); color: #d97706; }
.pill-gray { background: #f3f4f6; color: var(--text-3); }
.pill-blue { background: #dbeafe; color: #2563eb; }
.pill-purple { background: #ede9fe; color: #7c3aed; }
.pill-cyan { background: #cffafe; color: #0891b2; }
.pill-yellow { background: #fef9c3; color: #ca8a04; }

/* Stage colors (lead tracker) */
.stage-new_lead       { background: #dbeafe; color: #2563eb; }
.stage-filtered       { background: #fef3c7; color: #d97706; }
.stage-napisana_poruka { background: #ede9fe; color: #7c3aed; }
.stage-warmup_1       { background: #ede9fe; color: #7c3aed; }
.stage-warmup_2       { background: #ddd6fe; color: #6d28d9; }
.stage-warmup_3       { background: #c7d2fe; color: #4338ca; }
.stage-warmup_4       { background: #c7d2fe; color: #4338ca; }
.stage-poslan_dm      { background: #cffafe; color: #0891b2; }
.stage-follow_up      { background: #cffafe; color: #0891b2; }
.stage-fu_waiting     { background: #f3f4f6; color: #6b7280; }
.stage-dobiven_odgovor{ background: #d1fae5; color: #059669; }
.stage-audit          { background: #fef9c3; color: #ca8a04; }
.stage-poziv_1        { background: #ffedd5; color: #ea580c; }
.stage-poziv_2        { background: #fde68a; color: #d97706; }
.stage-won            { background: #dcfce7; color: #16a34a; }
.stage-lost           { background: #fee2e2; color: #dc2626; }
.stage-firmetina      { background: #f1f5f9; color: #64748b; }
.stage-mail_new       { background: #dbeafe; color: #2563eb; }
.stage-mail_napisana  { background: #ede9fe; color: #7c3aed; }
.stage-mail_poslan    { background: #c7d2fe; color: #4338ca; }
.stage-mail_fu1       { background: #cffafe; color: #0891b2; }
.stage-mail_fu2       { background: #ccfbf1; color: #0d9488; }
.stage-mail_fu3       { background: #e0f2fe; color: #0284c7; }
.stage-mail_audit     { background: #fef9c3; color: #ca8a04; }
.stage-mail_poziv1    { background: #ffedd5; color: #ea580c; }
.stage-mail_poziv2    { background: #fde68a; color: #d97706; }
.stage-mail_won       { background: #dcfce7; color: #16a34a; }
.stage-mail_lost      { background: #fee2e2; color: #dc2626; }

/* === DATE NAVIGATOR === */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 6px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  gap: 6px;
}
.date-nav .arrow {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3); font-size: 18px; font-weight: 600;
  background: transparent; transition: background 0.15s;
}
.date-nav .arrow:hover { background: var(--primary-light); color: var(--primary-hover); }
.date-nav .center {
  flex: 1; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.date-nav .date-label {
  font-weight: 700; font-size: 15px;
  color: var(--text); letter-spacing: -0.01em;
}
.date-nav .today-pill {
  font-size: 10px; font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: var(--primary-light);
  padding: 2px 8px;
  border-radius: 999px;
}
.date-nav .today-jump {
  font-size: 11px; font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  padding: 3px 10px;
  border-radius: 999px;
  cursor: pointer;
}

/* === TASK ITEM === */
.task-list { display: flex; flex-direction: column; gap: 10px; }
.task {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  cursor: pointer;
}
.task:hover { background: #fafbfc; }
.task.overdue { background: var(--danger-bg); border-color: #fecaca; }
.task.selected { background: var(--primary-light); border-color: #c7d2fe; }
.task.completed { opacity: 0.55; background: var(--surface-2); }
.task-checkbox {
  width: 22px; height: 22px;
  border: 2px solid #d1d5db;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 2px;
  background: white; transition: all 0.15s;
}
.task-checkbox:hover { border-color: var(--primary); }
.task-checkbox.checked {
  background: var(--primary); border-color: var(--primary); color: white;
  box-shadow: 0 0 0 4px var(--primary-light);
}
.task-checkbox.checked::after { content: "✓"; font-size: 14px; font-weight: 700; }
.task-body { flex: 1; min-width: 0; }
.task-title {
  font-weight: 600; font-size: 15px; line-height: 1.4;
  word-wrap: break-word; color: var(--text);
}
.task-sub {
  font-size: 12px; color: var(--text-3); margin-top: 5px;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.task-detail {
  font-size: 12.5px; color: var(--text-2); margin-top: 8px;
  line-height: 1.5; padding-top: 8px;
  border-top: 1px solid var(--border-2);
}

/* === SELECTION BAR === */
.select-bar {
  position: sticky; top: 0;
  background: var(--primary-hover);
  color: white;
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  margin-bottom: 12px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; z-index: 10;
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.3);
}
.select-bar .left { font-weight: 600; font-size: 14px; }
.select-bar .actions { display: flex; gap: 8px; }
.select-bar button {
  background: rgba(255,255,255,0.18);
  color: white;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13px; font-weight: 600;
  transition: background 0.15s;
}
.select-bar button:hover { background: rgba(255,255,255,0.28); }
.select-bar button.danger { background: rgba(239, 68, 68, 0.85); }
.select-bar button.danger:hover { background: rgba(220, 38, 38, 1); }

/* === PIPELINE === */
.pipeline-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 10px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.pipeline-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  cursor: pointer; user-select: none;
  transition: background 0.15s;
}
.pipeline-header:hover { background: var(--surface-2); }
.pipeline-header.empty { opacity: 0.55; cursor: default; }
.pipeline-header.empty:hover { background: transparent; }
.pipeline-header .label {
  font-weight: 600; font-size: 14px;
  display: flex; align-items: center; gap: 10px;
  color: var(--text);
}
.pipeline-header .count {
  background: var(--primary-light);
  color: var(--primary-hover);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px; font-weight: 700;
}
.pipeline-stage-dot { width: 10px; height: 10px; border-radius: 50%; background: #d1d5db; }
.pipeline-stage-dot.active { background: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.pipeline-body {
  padding: 0 16px 14px;
  display: none;
}
.pipeline-section.open .pipeline-body { display: block; }
.pipeline-account {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0;
  border-top: 1px solid var(--border-2);
  gap: 10px;
}
.pipeline-account:first-child { border-top: 0; }
.pipeline-account .name { font-weight: 600; font-size: 14px; color: var(--text); }
.pipeline-account .next { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #c7d2fe, #a5b4fc);
  color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px;
  flex-shrink: 0; letter-spacing: 0.02em;
}
.avatar.tin { background: linear-gradient(135deg, #fbcfe8, #f9a8d4); color: #be185d; }
.avatar.rene { background: linear-gradient(135deg, #bbf7d0, #86efac); color: #15803d; }
.avatar-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.progress-track {
  background: var(--border-2);
  height: 6px;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 10px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #8b5cf6);
  border-radius: 999px;
  transition: width 0.4s;
}

/* === DASHBOARD === */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s;
}
.stat:hover { box-shadow: var(--shadow); }
.stat .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  font-weight: 600;
}
.stat .value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 6px;
  letter-spacing: -0.025em;
  color: var(--text);
  line-height: 1.1;
}
.stat .sub { font-size: 12px; color: var(--text-3); margin-top: 6px; }
.stat-progress { margin-top: 10px; }
.stat-wide { grid-column: span 2; }
/* Red-bordered tile state — used when drafted-message inventory is below target */
.stat.stat-alert {
  border: 1px solid #fecaca;
  background: #fef2f2;
}

/* === LEAD TRACKER === */
.subtab-bar {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}
.subtab-bar button {
  flex: 1;
  padding: 8px 4px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-3);
  transition: all 0.15s;
}
.subtab-bar button:hover { color: var(--text-2); }
.subtab-bar button.active { background: var(--primary-light); color: var(--primary-hover); }
.channel-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.channel-bar button {
  flex: 1;
  padding: 9px 8px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-3);
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: all 0.15s;
}
.channel-bar button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.lead-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 12px;
  margin-bottom: 7px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex; align-items: center; gap: 10px;
}
.lead-card:hover { background: var(--surface-2); border-color: #c7d2fe; }
.lead-card .uname {
  font-weight: 600; font-size: 14px; color: var(--text);
}
.lead-card .meta {
  font-size: 11.5px; color: var(--text-3); margin-top: 2px;
  display: flex; flex-wrap: wrap; gap: 5px; align-items: center;
}
.lead-card .right {
  font-size: 11px; color: var(--text-3);
  white-space: nowrap;
}
.lead-card.active-task { background: var(--primary-light); border-color: #c7d2fe; }
.lead-checkbox {
  width: 22px; height: 22px;
  border: 2px solid #d1d5db;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  background: white;
  transition: all 0.15s;
}
.lead-checkbox.checked {
  background: var(--success); border-color: var(--success); color: white;
}
.lead-checkbox.checked::after { content: "✓"; font-size: 13px; font-weight: 700; }

.acct-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 10px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.acct-group .header {
  padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-2);
}
.acct-group .header .name { font-weight: 700; font-size: 14px; color: var(--text); }
.acct-group .body { padding: 8px; }

.lead-detail-section {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-2);
}
.message-bubble {
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 13px;
  margin-bottom: 6px;
  max-width: 88%;
  line-height: 1.45;
  word-wrap: break-word;
}
.message-bubble.me {
  background: var(--primary);
  color: white;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}
.message-bubble.them {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-2);
  border-bottom-left-radius: 4px;
}
.message-meta {
  font-size: 10px;
  color: var(--text-3);
  margin-bottom: 4px;
  padding: 0 4px;
}
.message-meta.me { text-align: right; }

/* === MODAL === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.5);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  padding: 14px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.modal-overlay.open { display: flex; animation: fadeIn 0.2s; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 22px;
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal h2 { font-size: 19px; font-weight: 700; margin-bottom: 8px; letter-spacing: -0.01em; }
.modal h3 { font-size: 14px; font-weight: 700; margin-bottom: 8px; color: var(--text-2); }
.modal p { color: var(--text-3); font-size: 14px; margin-bottom: 14px; line-height: 1.5; }
.modal .actions { display: flex; gap: 8px; flex-direction: column; }
.modal label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.modal input[type="text"], .modal input[type="number"], .modal input[type="url"], .modal textarea, .modal select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 12px;
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}
.modal textarea { min-height: 80px; resize: vertical; }
.modal input:focus, .modal textarea:focus, .modal select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.modal .close-x {
  position: absolute;
  top: 14px; right: 14px;
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  color: var(--text-3);
  background: transparent;
}
.modal .close-x:hover { background: var(--surface-2); color: var(--text); }
.modal-positioned { position: relative; }

/* === SETTINGS === */
.acc-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0;
  border-top: 1px solid var(--border-2);
  gap: 12px;
}
.acc-row:first-child { border-top: 0; }
.switch {
  width: 44px; height: 26px;
  background: #e5e7eb;
  border-radius: 999px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
  cursor: pointer;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.switch.on { background: var(--primary); }
.switch.on::after { transform: translateX(18px); }

.accounts-info {
  background: var(--primary-light);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
  color: var(--primary-dark);
  margin-bottom: 12px;
  line-height: 1.55;
}
.link-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.link-row input {
  flex: 1;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  background: var(--surface-2);
  transition: background 0.15s, border-color 0.15s;
}
.link-row input:focus { background: var(--surface); border-color: var(--primary); }

.counter { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.counter button {
  width: 32px; height: 32px;
  border-radius: 9px;
  background: var(--primary-light);
  color: var(--primary-hover);
  font-size: 18px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.counter button:hover { background: #e0e7ff; }
.counter input {
  flex: 1; text-align: center;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 700;
  background: var(--surface);
}

.info-panel {
  background: var(--primary-light);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
  color: var(--primary-dark);
  font-size: 13px;
  line-height: 1.6;
}
.info-panel h3 { font-size: 13px; font-weight: 700; margin-bottom: 6px; color: #312e81; }
.info-panel ul { padding-left: 18px; }
.info-panel li { margin-bottom: 4px; }
.info-warn { background: var(--warning-bg); color: #92400e; }
.info-warn h3 { color: #78350f; }

/* === HELPERS === */
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.col { display: flex; flex-direction: column; gap: 6px; }
.grow { flex: 1; min-width: 0; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nowrap { white-space: nowrap; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; }
.text-muted { color: var(--text-3); }
.text-sm { font-size: 12.5px; }
.text-xs { font-size: 11px; }
.center { text-align: center; }

/* === INSTALL BANNER === */
.install-banner {
  position: fixed;
  bottom: calc(78px + env(safe-area-inset-bottom));
  left: 12px; right: 12px;
  max-width: 540px;
  margin: 0 auto;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: white;
  padding: 13px 14px;
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.35);
  display: flex; align-items: center; gap: 11px;
  z-index: 150;
  animation: slideUp 0.3s;
}
.install-banner.hide { display: none; }
.install-banner .install-icon {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: rgba(255,255,255,0.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}
.install-banner .install-body { flex: 1; min-width: 0; }
.install-banner .install-title { font-weight: 700; font-size: 13.5px; }
.install-banner .install-sub { font-size: 11.5px; opacity: 0.92; margin-top: 2px; line-height: 1.4; }
.install-banner .install-btn {
  background: white;
  color: var(--primary-hover);
  padding: 7px 11px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}
.install-banner .install-close {
  background: transparent;
  color: rgba(255,255,255,0.7);
  width: 26px; height: 26px;
  border-radius: 8px;
  font-size: 17px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.install-banner .install-close:hover { background: rgba(255,255,255,0.15); color: white; }

/* === LEAD MESSAGE PREVIEW + COPY BUTTON (Tasks tab per-lead rows) === */
.lead-msg-preview {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.lead-msg-text {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.45;
  max-height: 80px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.btn-copy-msg {
  align-self: flex-start;
  background: var(--primary);
  color: white;
  padding: 7px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 12.5px;
  transition: background 0.15s;
}
.btn-copy-msg:hover { background: var(--primary-hover); }
.btn-copy-msg:active { transform: scale(0.97); }

/* "Write message" variant — used when lead has no drafted cold DM yet.
   Same shape as copy, different color to signal it opens an editor instead of copying. */
.btn-copy-msg.btn-draft-msg {
  background: #f59e0b;
}
.btn-copy-msg.btn-draft-msg:hover { background: #d97706; }

/* === Open IG (mobile deep link + web fallback) === */
.btn-open-ig {
  align-self: flex-start;
  background: #1f1f1f;
  color: white;
  padding: 7px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 12.5px;
  transition: background 0.15s;
}
.btn-open-ig:hover { background: #333; }
.btn-open-ig:active { transform: scale(0.97); }

/* Row that wraps copy + open-IG buttons */
.task-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

/* Audit watch toggles in the lead detail modal */
.audit-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 14px;
}
.audit-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}
.audit-toggle:hover { background: var(--surface); }

/* === FORECAST TAB — 30-day grid === */
.forecast-table-wrap {
  overflow-x: auto;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.forecast-table {
  border-collapse: collapse;
  min-width: 100%;
  font-size: 12px;
}
.forecast-table th, .forecast-table td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 6px 4px;
  text-align: center;
  vertical-align: middle;
  min-width: 44px;
}
.forecast-table th { background: var(--surface-2); font-weight: 600; }
.forecast-table th.day-col.today { background: #fef3c7; color: #92400e; }
.forecast-table td.acct-col, .forecast-table th.acct-col {
  text-align: left;
  padding-left: 10px;
  min-width: 140px;
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 2;
}
.forecast-table tbody tr:hover td { background: var(--surface-2); cursor: pointer; }
.forecast-table tbody tr:hover td.acct-col { background: var(--surface); }
.forecast-table .acct-name { font-weight: 600; }
.forecast-table .acct-sub { font-size: 10.5px; color: var(--text-3); }
.forecast-table .cell-dms { font-weight: 700; color: var(--primary); font-size: 13px; }
.forecast-table .cell-warmup { font-size: 10.5px; color: var(--text-3); }
.forecast-table .cell-empty { color: var(--text-3); opacity: 0.4; }

/* Follow-up tasks — orange tint, never red overdue. Per user May 14 directive. */
.task.task-followup {
  background: #fff7ed;
  border-left: 3px solid #f59e0b;
}
.task.task-followup:hover { background: #ffedd5; }

/* Lead card flagged "missing message" — at Drafted Message stage or later but no DM/body text */
.lead-card.lead-card-missing-msg {
  border: 1px solid #fecaca;
  background: #fef2f2;
}
.lead-card.lead-card-missing-msg .uname { color: #b91c1c; }
.missing-msg-flag {
  display: inline-block;
  margin-left: 6px;
  font-size: 10.5px;
  font-weight: 700;
  color: #b91c1c;
  background: #fee2e2;
  padding: 2px 6px;
  border-radius: 4px;
  vertical-align: middle;
}

/* Section toggle (collapsible panels in Settings) */
.section-toggle:hover { color: var(--primary); }
.settings-account-pipeline {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* Email thread display in lead detail modal */
.email-entry {
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
}
.email-entry .email-meta {
  font-size: 11.5px;
  color: var(--text-3);
  margin-bottom: 4px;
}
.email-entry .email-subject {
  font-weight: 600;
  font-size: 13.5px;
  margin-bottom: 6px;
}
.email-entry .email-body,
.email-entry .email-body-plain,
.email-entry .email-body-html {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.5;
  word-break: break-word;
  max-width: 100%;
  overflow-x: auto;
}
.email-entry .email-body-plain { white-space: pre-wrap; }
.email-entry .email-body-html p { margin: 0 0 8px 0; }
.email-entry .email-body-html a { color: var(--primary); text-decoration: underline; }
.email-entry .email-body-html img { max-width: 100%; height: auto; }
.email-entry .email-body-html blockquote {
  border-left: 3px solid var(--border);
  padding-left: 10px;
  margin: 6px 0;
  color: var(--text-3);
}

/* === DELETE-ACCOUNT BUTTON (Settings, next to the toggle) === */
.btn-delete-acct {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.btn-delete-acct:hover { background: #fee2e2; }
.btn-delete-acct:active { transform: scale(0.92); }

/* === SYNC STATUS BAR (Leads tab) === */
.sync-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  font-size: 12px;
}
.btn-sync-now {
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--primary-light);
  color: var(--primary-hover);
  font-weight: 600;
  font-size: 12px;
  transition: background 0.15s;
}
.btn-sync-now:hover { background: #e0e7ff; }
.btn-sync-now:active { transform: scale(0.97); }

/* === WARNING BANNERS (engine-set risk/shortage) === */
.warning-banner {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 10px;
  font-size: 13px;
  line-height: 1.45;
  font-weight: 500;
}
.warning-banner.risk { background: #fff1f2; color: #be123c; border-color: #fda4af; }
.warning-banner.shortage { background: var(--warning-bg); color: #92400e; border-color: #fde68a; }

/* === PER-ACCOUNT CHIP FILTER (Tasks + Leads tabs) === */
.chip-filter {
  display: flex;
  gap: 6px;
  margin: 0 0 12px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.chip-filter::-webkit-scrollbar { height: 4px; }
.chip-filter .chip {
  flex-shrink: 0;
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  background: var(--surface);
  border: 1px solid var(--border);
  white-space: nowrap;
  transition: all 0.15s;
}
.chip-filter .chip:hover { color: var(--text); border-color: var(--primary); }
.chip-filter .chip.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* === COMPRESSED-WARMUP TASK (expandable sub-checklist) === */
.task.compressed-task { border-left: 3px solid var(--danger); }
.compressed-steps {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border-2);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.compressed-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: 10px;
  transition: opacity 0.15s;
}
.compressed-step.done { opacity: 0.55; }
.compressed-step .step-checkbox {
  width: 20px; height: 20px;
  border: 2px solid #d1d5db;
  border-radius: 6px;
  flex-shrink: 0;
  margin-top: 2px;
  background: white;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.compressed-step .step-checkbox.checked {
  background: var(--success);
  border-color: var(--success);
  color: white;
}
.compressed-step .step-checkbox.checked::after { content: "✓"; font-size: 12px; font-weight: 700; }
.compressed-step .step-body { flex: 1; min-width: 0; }
.compressed-step .step-label { font-size: 13px; font-weight: 600; color: var(--text); }
.compressed-step .step-meta { font-size: 11px; color: var(--text-3); margin-top: 2px; }

/* === SYNC STATUS === */
.sync-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--success);
  display: inline-block;
  margin-right: 5px;
}
.sync-dot.offline { background: var(--text-4); }
.sync-dot.error { background: var(--danger); }

/* ============================================================
   DESKTOP STYLES — full-screen SaaS layout, Flozy-inspired
   Breakpoints: 768 (tablet) / 1024 (desktop) / 1440 (max)
   ============================================================ */

/* === Tablet (768-1023px): 2-column grids, condensed === */
@media (min-width: 768px) {
  body { font-size: 15px; }
  #app { max-width: 100%; padding: 0 28px; }
  .topbar {
    padding: 18px 4px 12px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 10px;
  }
  .topbar h1 { font-size: 22px; }
  .topnav { display: flex; gap: 4px; align-items: center; margin-left: 20px; }
  .tabbar { display: none; }
  .content { padding: 12px 0 40px; }

  .stat-grid { grid-template-columns: repeat(4, 1fr); gap: 12px; }
  .stat { padding: 16px; }
  .stat .value { font-size: 26px; }
  .stat-wide { grid-column: span 2; }

  .pipeline-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  .desktop-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }
  .desktop-grid > .full { grid-column: span 2; }
  .acc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
  .acc-grid .acc-row {
    padding: 14px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border-2);
    margin-bottom: 8px;
  }
  .install-banner { display: none; }
  .date-nav { padding: 8px; max-width: 480px; margin: 0 auto 16px; }
  .person-toggle button { padding: 7px 14px; font-size: 13px; }
}

/* === Desktop (1024px+): full-width SaaS layout === */
@media (min-width: 1024px) {
  body { font-size: 16px; }
  #app { max-width: 100%; padding: 0 40px; }
  .topbar {
    padding: 22px 4px 16px;
    margin-bottom: 16px;
  }
  .topbar h1 { font-size: 26px; }
  .topbar .meta { font-size: 12px; }
  .topnav button { padding: 9px 16px; font-size: 14px; }
  .content { padding: 16px 0 60px; max-width: 100%; }

  /* === TASKS — dense data-table style on desktop === */
  .task-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 8px;
    box-shadow: var(--shadow-sm);
  }
  .task {
    padding: 14px 18px;
    margin-bottom: 0;
    border-radius: var(--radius);
    border: 1px solid transparent;
    box-shadow: none;
    background: transparent;
  }
  .task:hover { background: var(--surface-2); }
  .task.overdue { background: var(--danger-bg); border: 1px solid #fecaca; }
  .task-title { font-size: 15px; }

  /* === DASHBOARD — 4-col grid w/ comfortable spacing === */
  .stat-grid { grid-template-columns: repeat(4, 1fr); gap: 16px; }
  .stat { padding: 20px; }
  .stat .value { font-size: 30px; }
  .stat .label { font-size: 11.5px; }

  /* Dashboard 2-up wide stats span 2 cols (already styled with .stat-wide) */

  /* === PIPELINE — horizontal kanban (Flozy-style) === */
  .pipeline-grid {
    display: flex;
    grid-template-columns: none;
    overflow-x: auto;
    overflow-y: visible;
    gap: 12px;
    padding-bottom: 16px;
    /* allow horizontal scroll INSIDE this container, not page */
    scroll-snap-type: x mandatory;
  }
  .pipeline-section {
    flex: 0 0 auto;
    width: 300px;
    min-width: 280px;
    max-width: 340px;
    scroll-snap-align: start;
    /* Force open on desktop kanban — sections are columns, not accordions */
    margin-bottom: 0;
  }
  /* Desktop pipeline: sections are columns in a horizontal kanban.
     Default state is EXPANDED on desktop (set by JS in renderPipeline);
     user can click the header to collapse if desired. */
  .pipeline-section .pipeline-body { padding: 0 14px 12px; }
  .pipeline-header { background: var(--surface-2); cursor: pointer; }
  .pipeline-header:hover { background: var(--surface); }
  .pipeline-account { padding: 12px 0; }
  .pipeline-account:first-child { border-top: 0; }

  /* === LEADS — kanban + multi-col Today view === */
  .channel-bar { max-width: 400px; }
  .subtab-bar { max-width: 600px; }

  /* Today view: multi-column per account on desktop */
  .acct-group {
    display: inline-block;
    width: 100%;
  }

  /* Settings — 2 col card grid */
  .acc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .acc-grid .acc-row {
    padding: 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border-2);
    margin-bottom: 0;
  }

  .modal { padding: 30px; max-width: 640px; }
  .modal h2 { font-size: 22px; }

  /* Section titles slightly larger */
  .section-title { padding: 22px 4px 12px; font-size: 12.5px; }

  /* Date nav stays compact / centered */
  .date-nav { max-width: 520px; }
}

/* === Wide desktop (1440px+): max comfort === */
@media (min-width: 1440px) {
  #app { padding: 0 40px; }
  .topbar { padding: 26px 4px 18px; }
  .topbar h1 { font-size: 28px; }
  .stat .value { font-size: 32px; }
  .pipeline-section { width: 320px; }
  .modal { max-width: 720px; }
  .content { padding: 20px 0 80px; }
}

/* === Ultra-wide (1920px+): fill the screen with comfortable padding === */
@media (min-width: 1920px) {
  #app { max-width: 100%; margin: 0; padding: 0 40px; }
}
