/* ----- Theme ----- */
:root {
  --primary: #1E3A8A;
  --primary-dark: #162969;
  --accent: #F59E0B;
  --accent-dark: #B45309;
  --success: #10B981;
  --danger: #DC2626;
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --border: #E2E8F0;
  --text: #0F172A;
  --muted: #64748B;
  --coaching: #8B5CF6;
  --corporate: #0EA5E9;
  --school: #10B981;
  --other: #64748B;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}

h1 { font-size: 1.5rem; margin: 0 0 0.5rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.5rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }

/* ----- Topbar ----- */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
  padding-top: calc(0.75rem + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 0.5rem; text-decoration: none; color: var(--text); font-weight: 700; }
.brand-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
}
.brand-text { font-size: 0.95rem; }
.nav { display: flex; gap: 0.5rem; margin-left: auto; }
.nav a {
  padding: 0.4rem 0.7rem; border-radius: 6px; text-decoration: none; color: var(--muted); font-weight: 500;
}
.nav a.active, .nav a:hover { background: var(--bg); color: var(--text); }

.sync-indicator { display: flex; align-items: center; gap: 0.4rem; font-size: 0.75rem; color: var(--muted); }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: #9CA3AF; }
.sync-indicator.online  .sync-dot { background: var(--success); }
.sync-indicator.offline .sync-dot { background: var(--accent); }
.sync-indicator.syncing .sync-dot { background: var(--primary); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }

@media (max-width: 480px) {
  .brand-text { display: none; }
  .sync-text  { display: none; }
}

/* ----- Layout ----- */
.page { max-width: 980px; margin: 0 auto; padding: 1rem; }
.flash-wrap { max-width: 980px; margin: 0.5rem auto 0; padding: 0 1rem; }
.flash { padding: 0.6rem 0.8rem; border-radius: 6px; margin-bottom: 0.5rem; }
.flash-success { background: #ECFDF5; color: #065F46; border: 1px solid #A7F3D0; }
.flash-error   { background: #FEF2F2; color: #7F1D1D; border: 1px solid #FECACA; }

.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
@media (max-width: 560px) { .row-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 1rem; margin-bottom: 1rem;
}
.card h2 { margin-bottom: 0.25rem; }
.card.danger { border-color: #FECACA; background: #FFFAFA; }

.center-card {
  max-width: 360px; margin: 3rem auto 0;
  background: var(--surface); padding: 1.5rem; border-radius: 12px; border: 1px solid var(--border);
}

/* ----- Buttons ----- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.65rem 1rem; min-height: 44px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 0.95rem; font-weight: 600; cursor: pointer;
  text-decoration: none; transition: background 0.1s, transform 0.05s;
}
.btn:hover { background: var(--bg); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 0.4rem 0.7rem; min-height: 36px; font-size: 0.85rem; }
.btn-lg { min-height: 54px; font-size: 1.05rem; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-accent:hover { background: var(--accent-dark); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ----- Forms ----- */
.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.85rem; }
.field .label { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
input[type="text"], input[type="email"], input[type="tel"], input[type="search"],
input[type="password"], textarea, select {
  width: 100%; padding: 0.7rem 0.8rem; min-height: 46px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 1rem; font-family: inherit; background: var(--surface); color: var(--text);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.15);
}
.input-lg { font-size: 1.25rem; text-align: center; letter-spacing: 0.3em; min-height: 56px; }

/* ----- Chip picker ----- */
.chip-group { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip {
  padding: 0.65rem 1rem; min-height: 44px;
  border: 1.5px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text); font-weight: 600; font-size: 0.95rem;
  cursor: pointer; transition: all 0.1s;
}
.chip:active { transform: scale(0.97); }
.chip.selected { background: var(--primary); color: #fff; border-color: var(--primary); }
.chip-hot.selected  { background: #DC2626; border-color: #DC2626; }
.chip-warm.selected { background: var(--accent); border-color: var(--accent); }
.chip-cold.selected { background: #0EA5E9; border-color: #0EA5E9; }

/* ----- Capture ----- */
.capture-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.queue-badge {
  background: var(--accent); color: #fff; padding: 0.25rem 0.6rem;
  border-radius: 999px; font-size: 0.8rem; font-weight: 600;
}
.actions { display: flex; gap: 0.75rem; margin-top: 1rem; }
.actions .btn-primary { flex: 1; }

/* ----- Toast ----- */
.toast {
  position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #0F172A; color: #fff;
  padding: 0.75rem 1.2rem; border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.15);
  z-index: 20; max-width: 90vw;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }

/* ----- Dashboard ----- */
.stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0.6rem; margin-bottom: 1rem; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem;
  text-align: center;
}
.stat-label { font-size: 0.75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-value { font-size: 1.6rem; font-weight: 700; margin-top: 0.25rem; }
@media (max-width: 720px) { .stats { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 420px) { .stats { grid-template-columns: repeat(2, 1fr); } }

.toolbar { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: center; }
.filters { display: flex; gap: 0.5rem; flex-wrap: wrap; flex: 1; }
.filters input, .filters select { min-height: 40px; }
.filters input[type="search"] { min-width: 200px; flex: 1; }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow-x: auto; }
.leads { width: 100%; border-collapse: collapse; }
.leads th, .leads td { padding: 0.6rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.leads th { background: var(--bg); font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.leads tr:last-child td { border-bottom: none; }
.leads tr:hover td { background: #FAFBFC; }

.pill {
  display: inline-block; padding: 0.2rem 0.6rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  color: #fff;
}
.pill-coaching  { background: var(--coaching); }
.pill-corporate { background: var(--corporate); }
.pill-school    { background: var(--school); }
.pill-other     { background: var(--other); }

.pri { font-size: 1.2rem; text-align: center; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }

/* ----- Detail ----- */
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; }
.followup-row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; }
.followup-row form { display: flex; gap: 0.6rem; align-items: center; }
