:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-dim: #1d4ed8;
  --success: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 10px;
  --font: "DM Sans", system-ui, sans-serif;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

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

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: #f1f5f9;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: var(--shadow);
}
.login-brand {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1.25rem;
}
.login-brand h1 { margin: 0; font-size: 1.35rem; font-weight: 700; }
.login-brand p { margin: 0.15rem 0 0; font-size: 0.85rem; color: var(--muted); }
.login-hint { color: var(--muted); font-size: 0.9rem; line-height: 1.55; margin: 0; }

.logo-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.25rem;
  flex-shrink: 0;
}
.logo-mark.sm {
  width: 32px;
  height: 32px;
  font-size: 0.9rem;
  border-radius: 8px;
}

/* App shell */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
  background: var(--bg);
}

.sidebar {
  background: var(--surface2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0.75rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0 0.5rem 0.5rem;
}

.agent-tag {
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0 0.5rem 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  line-height: 1.35;
}

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

/* Manager dual-mode: groups the Team block and My Work block visually so the two
   never read as one merged list. */
.nav-section-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0.6rem 0.75rem 0.2rem;
}
.nav-section-label:first-child { padding-top: 0.1rem; }

.nav-item {
  text-align: left;
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.88rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  width: 100%;
}
.nav-item:hover { background: #fff; color: var(--text); }
.nav-item.active {
  background: #fff;
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow);
}
.nav-item:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.nav-chevron {
  font-size: 0.7rem;
  transition: transform 0.15s;
  color: var(--muted);
}
.nav-group.open .nav-chevron { transform: rotate(90deg); }

.nav-children {
  display: none;
  flex-direction: column;
  gap: 2px;
  padding-left: 0.65rem;
  margin: 0 0 0.15rem;
  border-left: 2px solid var(--border);
  margin-left: 0.75rem;
}
.nav-group.open .nav-children { display: flex; }
.nav-children .nav-item {
  font-size: 0.82rem;
  padding: 0.4rem 0.65rem;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  width: 100%;
  margin-top: auto;
  border: none;
  font: inherit;
  font-weight: 600;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
}
.btn-ghost:hover { color: var(--text); background: #fff; }

.main {
  padding: 1.5rem 2rem 2.5rem;
  overflow-x: auto;
  background: var(--bg);
  min-width: 0;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.topbar-left { display: flex; align-items: flex-start; gap: 0.75rem; }
.topbar-titles h2 { margin: 0; font-size: 1.5rem; }
.muted { color: var(--muted); font-size: 0.85rem; margin: 0.2rem 0 0; }
.topbar-actions { display: flex; align-items: center; gap: 0.75rem; }

.nav-toggle {
  display: none;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.nav-toggle-icon,
.nav-toggle-icon::before,
.nav-toggle-icon::after {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  position: relative;
}
.nav-toggle-icon::before,
.nav-toggle-icon::after {
  content: "";
  position: absolute;
  left: 0;
}
.nav-toggle-icon::before { top: -6px; }
.nav-toggle-icon::after { top: 6px; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 40;
}

.badge {
  background: var(--danger);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  min-width: 1.4rem;
  text-align: center;
  cursor: pointer;
}

.badge-sprint {
  background: var(--success);
  cursor: default;
  white-space: nowrap;
}
.badge-pending {
  background: var(--warn);
  cursor: default;
  white-space: nowrap;
  border-radius: 999px;
}

.next-lead-fab {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1.25rem, env(safe-area-inset-bottom));
  z-index: 35;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
  border-radius: 999px;
  padding: 0.7rem 1.15rem;
  font-weight: 600;
}

.loading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Cards / tables */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 0.75rem; font-size: 1.05rem; font-weight: 600; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.kpi .value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.kpi .label { font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }
.kpi.clickable { cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s; }
.kpi.clickable:hover { border-color: var(--accent); }
.kpi.danger .value { color: var(--danger); }
.kpi-hint { font-size: 0.72rem; color: var(--muted); margin-top: 0.2rem; line-height: 1.3; }
.kpi-tap-hint { font-size: 0.7rem; color: var(--accent); margin-top: 0.4rem; font-weight: 600; }
.kpi.kpi-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
}

/* Team Report per-agent drill cells */
.report-drill-cell {
  font: inherit;
  font-weight: 600;
  color: var(--accent);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.report-drill-cell:hover { color: var(--accent-dim); }

.call-report-card { margin-bottom: 1.25rem; }
.call-report-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.65rem;
}
.call-report-head h3 { margin: 0; }
.call-report-period { font-size: 0.85rem; }
.call-report-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.65rem;
  margin-bottom: 0.85rem;
}
.call-report-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}
.call-report-field input {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  min-width: 7.5rem;
}
.call-report-kpis { margin-bottom: 0; }

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
}
.chip {
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
}
.chip:hover { color: var(--text); border-color: #cbd5e1; }
.chip.active {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: var(--accent);
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.85rem 1.25rem;
}
.info-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.92rem;
  word-break: break-word;
}
.info-item .label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.timeline-table td.notes-cell {
  max-width: 28rem;
  white-space: normal;
  word-break: break-word;
}

.timeline-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.timeline-line {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 0.75rem;
  padding: 0.55rem 0.65rem;
  background: var(--surface2, #f8fafc);
  border-radius: 8px;
  font-size: 0.9rem;
  line-height: 1.35;
}
.timeline-when {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}
.timeline-body {
  word-break: break-word;
}
.lead-notes {
  grid-column: 1 / -1;
}
.note-edited-tag,
.note-edit-btn {
  display: inline-block;
  border: none;
  background: none;
  padding: 0;
  margin-left: 0.35rem;
  font: inherit;
  font-size: 0.78rem;
  color: var(--accent, #2563eb);
  text-decoration: underline;
  cursor: pointer;
}
.note-original {
  display: block;
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-style: italic;
}
.lead-notes .label { display: block; margin-bottom: 0.2rem; }
.leads-table .notes-cell {
  max-width: 22rem;
  white-space: normal;
  word-break: break-word;
  font-size: 0.86rem;
  color: #334155;
}

@media (max-width: 720px) {
  .timeline-line {
    grid-template-columns: 1fr;
    gap: 0.2rem;
  }
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 0.65rem 0.5rem; border-bottom: 1px solid var(--border); text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.02em; }
tr.lead-row { cursor: pointer; }
tr.lead-row:hover td { background: var(--surface2); }

.status-pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  background: #eff6ff;
  color: var(--accent);
}
.status-pill.fu { background: #fff7ed; color: var(--warn); }
.status-pill.mtg { background: #f0fdf4; color: var(--success); }
.status-pill.new { background: #eff6ff; color: var(--accent); }
.status-pill.pool { background: #f5f3ff; color: #6d28d9; }
.status-pill.ok { background: #ecfdf5; color: #047857; }
.status-pill.bad { background: #fef2f2; color: var(--danger); }

.btn, .btn-primary, .btn-secondary {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0.6rem 1.1rem;
  transition: background 0.15s, opacity 0.15s;
}
.btn:disabled, .btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dim); }
.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface2); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-wa {
  background: #25d366;
  color: #fff;
  border: none;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0.6rem 1.1rem;
}
.btn-wa:hover { background: #1ebe57; color: #fff; }
/* Incoming call — a call the CLIENT made to the agent. Deliberately distinct from the
   blue Call Start button so the two are never tapped by mistake. */
.btn-incoming {
  background: #fff;
  color: #0f766e;
  border: 1px solid #5eead4;
}
.btn-incoming:hover { background: #f0fdfa; }

.datetime-fields {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 0.15rem;
}
.datetime-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.datetime-row .dt-label {
  flex: 0 0 3.25rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
}
/* Incoming-call times: "Started" / "Ended" need more room than "Date" / "Time". */
.time-fields .dt-label { flex: 0 0 4.25rem; }
.datetime-row input[type="date"],
.datetime-row input[type="time"] {
  flex: 1;
  min-height: 48px;
  font-size: 16px;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  color-scheme: light;
}
.datetime-row input[type="date"]::-webkit-calendar-picker-indicator,
.datetime-row input[type="time"]::-webkit-calendar-picker-indicator {
  opacity: 1;
  cursor: pointer;
  width: 1.35rem;
  height: 1.35rem;
  padding: 0.15rem;
}

.lead-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }
.lead-meta { display: grid; gap: 0.65rem; }
.lead-meta p { margin: 0; font-size: 0.95rem; }
.lead-meta .label { color: var(--muted); font-size: 0.78rem; display: block; margin-bottom: 0.1rem; }

.task-list { list-style: none; margin: 0; padding: 0; }
.task-list li {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}
.task-list li:last-child { border-bottom: none; }
.task-list li:hover { color: var(--accent); }
.task-list li.is-overdue .task-due { color: var(--danger); font-weight: 600; }
.task-main { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }
.task-meta { font-size: 0.8rem; color: var(--muted); }
.task-due { font-size: 0.8rem; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.overdue-tag {
  display: inline-block;
  margin-left: 0.35rem;
  font-size: 0.68rem;
  font-weight: 700;
  color: #fff;
  background: var(--danger);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  vertical-align: middle;
}

.auto-hint {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
  font-size: 0.82rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  margin: 0.75rem 0 0;
  line-height: 1.4;
}

.outcome-choices {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.35rem;
}
.outcome-choice {
  font: inherit;
  text-align: left;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  min-height: 44px;
}
.outcome-choice:hover { border-color: #93c5fd; background: #f8fafc; }
.outcome-choice.selected {
  border-color: var(--accent);
  background: #eff6ff;
  color: var(--accent);
  font-weight: 600;
}
.outcome-choice.sub { font-size: 0.9rem; min-height: 40px; padding: 0.55rem 0.85rem; }

.modal-inner {
  display: flex;
  flex-direction: column;
  max-height: min(92vh, 640px);
  padding: 0;
  overflow: hidden;
}
.modal-scroll {
  padding: 1.35rem 1.35rem 0.5rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-height: 0;
}
.modal-inner h2 { margin: 0 0 0.75rem; font-size: 1.15rem; }
.modal-inner .modal-actions {
  padding: 0.85rem 1.35rem 1.25rem;
  margin-top: 0;
  border-top: 1px solid var(--border);
  background: #fff;
  flex-shrink: 0;
}

.phone-reveal {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
  align-items: center;
}
.toolbar input[type="search"] {
  flex: 1;
  min-width: 160px;
  max-width: 320px;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
}

/* Request leads wizard */
.wizard-steps { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.wizard-step {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--surface2);
}
.wizard-step.active { background: #dbeafe; color: var(--accent); }
.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.65rem;
}
.choice-btn {
  text-align: left;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  font: inherit;
}
.choice-btn:hover, .choice-btn.selected {
  border-color: var(--accent);
  background: #eff6ff;
}
.choice-btn .cnt { display: block; font-size: 0.75rem; color: var(--muted); margin-top: 0.2rem; }

/* Wizard step labels (Add Lead, call outcome) — plain <label> tags with no other class */
.card > label,
.ul-dyn-field label {
  display: block;
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

/* Add Lead wizard — status's own dynamic fields (follow-up date, meeting date, notes, ...),
   rendered inline below the status picker the instant a status is chosen */
.ul-dyn-field { margin-top: 0.85rem; }

/* Add Lead wizard — plain text/phone/number/date fields */
.ul-input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 16px; /* prevent iOS zoom */
}
.ul-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Add Lead wizard — project/status searchable dropdown */
.ul-combo { position: relative; }
.ul-combo-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
}
.ul-combo-trigger:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.ul-combo.open .ul-combo-trigger { border-color: var(--accent); }
.ul-combo-label.placeholder { color: var(--muted); }
.ul-combo-chevron { color: var(--muted); flex-shrink: 0; transition: transform 0.15s; }
.ul-combo.open .ul-combo-chevron { transform: rotate(180deg); }
.ul-combo-panel {
  position: absolute;
  z-index: 60;
  top: calc(100% + 0.35rem);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.14);
  padding: 0.5rem;
}
.ul-combo-search {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 16px;
  margin-bottom: 0.4rem;
}
.ul-combo-search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.ul-combo-list { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.ul-combo-option {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.ul-combo-option:hover { background: var(--surface2); }
.ul-combo-option.selected { background: #eff6ff; color: var(--accent); font-weight: 600; }

@media (max-width: 720px) {
  .ul-combo-panel { max-height: min(60vh, 360px); overflow-y: auto; }
  .ul-combo-list { max-height: none; }
}

.banner {
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.banner-warn { background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; }
.banner-ok { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.banner-error { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}
.modal-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 10px 40px rgba(15, 23, 42, 0.12);
}
.modal-inner label {
  display: block;
  margin: 0.85rem 0 0.35rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
}
.modal-inner input,
.modal-inner select,
.modal-inner textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 16px; /* prevent iOS zoom */
}
.modal-inner input:focus,
.modal-inner select:focus,
.modal-inner textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.field-error { color: var(--danger); font-size: 0.8rem; margin: 0.35rem 0 0; }
.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.15rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.modal-actions .btn,
.modal-actions .btn-primary,
.modal-actions .btn-secondary {
  min-height: 44px;
  min-width: 100px;
}

.toast {
  position: fixed;
  bottom: max(1.5rem, env(safe-area-inset-bottom));
  left: 1rem;
  right: 1rem;
  margin: 0 auto;
  max-width: 360px;
  background: #0f172a;
  color: #fff;
  padding: 0.75rem 1.15rem;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.2);
  text-align: center;
}
.toast.error { background: var(--danger); }
.toast.ok { background: var(--success); }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(300px, 88vw);
    z-index: 50;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    height: 100%;
    padding-top: max(1.25rem, env(safe-area-inset-top));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
  .app.nav-open .sidebar { transform: translateX(0); }
  .app.nav-open .sidebar-backdrop { display: block; }
  .nav-toggle { display: inline-flex; min-width: 44px; min-height: 44px; }
  .nav-item { min-height: 44px; padding: 0.7rem 0.85rem; font-size: 0.95rem; }
  .main {
    padding: 0.85rem 0.85rem max(2rem, env(safe-area-inset-bottom));
    padding-top: max(0.85rem, env(safe-area-inset-top));
  }
  .topbar { margin-bottom: 0.85rem; gap: 0.65rem; }
  .topbar-titles h2 { font-size: 1.25rem; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 0.65rem; }
  .kpi { padding: 0.85rem; }
  .kpi .value { font-size: 1.45rem; }
  .lead-actions { flex-direction: column; align-items: stretch; }
  .lead-actions .btn,
  .lead-actions .btn-primary,
  .lead-actions .btn-secondary,
  .lead-actions .btn-wa,
  .lead-actions a.btn-primary,
  .lead-actions a.btn-secondary,
  .lead-actions a.btn-wa {
    width: 100%;
    text-align: center;
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
  }
  .info-grid { grid-template-columns: 1fr; }
  .choice-grid { grid-template-columns: 1fr; }
  .toolbar input[type="search"] { max-width: none; width: 100%; font-size: 16px; }
  .filter-chips { gap: 0.35rem; }
  .chip { min-height: 36px; padding: 0.4rem 0.85rem; }
  .modal { padding: 0.5rem; align-items: flex-end; }
  .modal-inner {
    max-width: none;
    width: 100%;
    max-height: min(92vh, 100%);
    border-radius: 16px 16px 0 0;
  }
  .modal-scroll {
    padding: 1.15rem 1.15rem 0.5rem;
    padding-bottom: 0.75rem;
  }
  .modal-inner .modal-actions {
    padding: 0.75rem 1.15rem max(1rem, env(safe-area-inset-bottom));
    flex-direction: column-reverse;
  }
  .modal-actions .btn,
  .modal-actions .btn-primary,
  .modal-actions .btn-secondary { width: 100%; }

  /* Card-style lead rows on phone */
  .leads-table thead { display: none; }
  .leads-table,
  .leads-table tbody,
  .leads-table tr,
  .leads-table td {
    display: block;
    width: 100%;
  }
  .leads-table tr.lead-row {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.85rem 1rem;
    margin-bottom: 0.65rem;
    background: #fff;
    box-shadow: var(--shadow);
  }
  .leads-table tr.lead-row:active { background: #f8fafc; }
  .leads-table td {
    border: none;
    padding: 0.2rem 0;
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    align-items: baseline;
  }
  .leads-table td::before {
    content: attr(data-label);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
  }
  .leads-table td:first-child {
    font-weight: 600;
    font-size: 1.02rem;
    padding-bottom: 0.45rem;
    margin-bottom: 0.35rem;
    border-bottom: 1px solid var(--border);
  }
  .leads-table td:first-child::before { display: none; }
  .task-list li { flex-direction: column; gap: 0.35rem; padding: 0.85rem 0; min-height: 52px; }
  .task-due { align-self: flex-start; }
  .login-screen { padding: 1rem; padding-top: max(1.5rem, env(safe-area-inset-top)); }
  .login-card { padding: 1.5rem 1.25rem; }
}

@media (max-width: 380px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi .value { font-size: 1.3rem; }
}

.leads-table .notes-cell {
  max-width: 220px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.85rem;
  color: var(--muted);
}
