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

:root {
  --bg:          #eef2f7;
  --bg2:         #ffffff;
  --bg3:         #f4f7fb;
  --border:      #dde3ed;
  --border-lt:   #eaeff7;
  --text:        #1a2332;
  --text2:       #64748b;
  --primary:     #4f6ef5;
  --primary-d:   #3451d1;
  --primary-bg:  rgba(79,110,245,.08);
  --rubber:      #ea580c;
  --hunter:      #0891b2;
  --new:         #6366f1;
  --inprog:      #d97706;
  --appoint:     #0891b2;
  --arrived:     #7c3aed;
  --purchased:   #16a34a;
  --rejected:    #dc2626;
  --radius:      10px;
  --shadow:      0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.07);
  --shadow-sm:   0 1px 2px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

/* ── Topbar ───────────────────────────────────────────────────────────────── */
#topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 52px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  gap: 8px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
}

.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-right { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.logo { font-weight: 800; font-size: 15px; color: var(--primary); letter-spacing: -.3px; }

.badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg3);
  color: var(--text2);
  border: 1px solid var(--border);
}
.badge.rubber { background: #fff4ee; color: var(--rubber); border-color: #fcd7ba; }
.badge.hunter { background: #ecfbfe; color: var(--hunter); border-color: #bae6fd; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  padding: 7px 14px;
  border-radius: 8px;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s, box-shadow .15s;
  box-shadow: var(--shadow-sm);
}
.btn:hover { opacity: .88; }
.btn:active { transform: scale(.97); }

.btn-primary   { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--bg2); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.btn-danger    { background: #fff; color: var(--rejected); border: 1px solid #fca5a5; }
.btn-sm        { padding: 5px 10px; font-size: 12px; }
.btn-rubber    { background: #fff4ee; color: var(--rubber); border: 1px solid #fcd7ba; }
.btn-hunter    { background: #ecfbfe; color: var(--hunter); border: 1px solid #bae6fd; }

.tab-btn {
  padding: 6px 12px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.tab-btn.active {
  background: var(--bg3);
  color: var(--text);
  border-color: var(--border);
}

/* ── Overlay / Role picker ────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(100,116,139,.4);
  backdrop-filter: blur(3px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}
.overlay.hidden { display: none; }

.role-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: min(380px, 92vw);
  text-align: center;
  box-shadow: var(--shadow);
}
.role-card h2 { margin-bottom: 8px; color: var(--text); }
.role-card p  { color: var(--text2); margin-bottom: 20px; font-size: 13px; }
.role-buttons { display: flex; flex-direction: column; gap: 8px; }
.role-buttons hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ── Stats bar ────────────────────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.stat-pill {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 13px;
  color: var(--text2);
  display: flex;
  align-items: center;
  gap: 5px;
}
.stat-pill strong { color: var(--text); }

/* ── Stage dots ───────────────────────────────────────────────────────────── */
.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-new       { background: var(--new); }
.dot-inprog    { background: var(--inprog); }
.dot-appoint   { background: var(--appoint); }
.dot-arrived   { background: var(--arrived); }
.dot-purchased { background: var(--purchased); }
.dot-rejected  { background: var(--rejected); }

/* ── Kanban ───────────────────────────────────────────────────────────────── */
.kanban {
  display: flex;
  gap: 10px;
  padding: 14px;
  overflow-x: auto;
  min-height: calc(100vh - 120px);
  align-items: flex-start;
}

.kanban-col {
  flex: 0 0 240px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 140px);
}

.col-header {
  padding: 10px 12px;
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
  position: sticky;
  top: 0;
  background: var(--bg3);
  border-radius: var(--radius) var(--radius) 0 0;
}

.col-body {
  padding: 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Lead card ────────────────────────────────────────────────────────────── */
.lead-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .1s;
  box-shadow: var(--shadow-sm);
}
.lead-card:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(79,110,245,.15); transform: translateY(-1px); }

.lead-card .lc-name  { font-weight: 600; margin-bottom: 3px; font-size: 13px; }
.lead-card .lc-phone { color: var(--text2); font-size: 12px; margin-bottom: 3px; }
.lead-card .lc-meta  { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 5px; }
.lead-card .tag {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 500;
}
.tag-instagram { background: #f5f0ff; color: #7c3aed; border: 1px solid #ddd6fe; }
.tag-target    { background: #fff7ed; color: var(--rubber); border: 1px solid #fed7aa; }
.tag-other     { background: var(--bg3); color: var(--text2); border: 1px solid var(--border); }
.tag-assigned  { background: #ecfbfe; color: var(--hunter); border: 1px solid #bae6fd; }

.lc-time { font-size: 11px; color: var(--text2); margin-top: 5px; }

.btn-take {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 5px;
  background: var(--primary-bg);
  color: var(--primary);
  border: 1px dashed var(--primary);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-take:hover { background: rgba(79,110,245,.15); }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 400; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-overlay { position: absolute; inset: 0; background: rgba(100,116,139,.35); backdrop-filter: blur(2px); }
.modal-box {
  position: relative;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: min(480px, 94vw);
  max-height: 90vh;
  overflow-y: auto;
  z-index: 1;
  box-shadow: var(--shadow);
}
.modal-close {
  position: absolute;
  top: 12px; right: 14px;
  background: none;
  border: none;
  color: var(--text2);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.modal-phone { color: var(--text2); margin-bottom: 12px; font-size: 14px; }
.modal-section { margin-top: 16px; }
.modal-section label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .6px;
}

.stage-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.stage-btn {
  padding: 5px 12px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text2);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.stage-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.stage-btn:hover:not(.active) { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }

.notes-area {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px;
  font-size: 13px;
  resize: vertical;
  min-height: 80px;
  font-family: inherit;
}
.notes-area:focus { outline: none; border-color: var(--primary); }

.history-list { display: flex; flex-direction: column; gap: 6px; }
.history-item {
  font-size: 12px;
  color: var(--text2);
  display: flex;
  gap: 8px;
  align-items: baseline;
}
.history-item .arrow { color: var(--primary); font-weight: 700; }
.history-time { flex-shrink: 0; }

/* ── Calendar ─────────────────────────────────────────────────────────────── */
.cal-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.cal-week-title { font-weight: 700; font-size: 14px; flex: 1; text-align: center; color: var(--text); }
.cal-hint { font-size: 12px; color: var(--text2); margin-left: auto; font-style: italic; }

.cal-legend {
  display: flex;
  gap: 14px;
  padding: 8px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  align-items: center;
  font-size: 12px;
}
.legend-item { display: flex; align-items: center; gap: 5px; color: var(--text2); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ── Calendar scroll wrapper ──────────────────────────────────────────────── */
.cal-scroll {
  overflow: auto;
  height: calc(100vh - 52px - 46px - 36px); /* topbar + toolbar + legend */
  background: var(--bg);
}

/* ── Calendar inner wrapper ───────────────────────────────────────────────── */
.cal-wrapper {
  min-width: 580px;
  user-select: none;
}

/* ── Sticky header row ────────────────────────────────────────────────────── */
.cal-header-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  background: var(--bg2);
  border-bottom: 2px solid var(--border);
  box-shadow: 0 2px 6px rgba(0,0,0,.05);
}

.cal-gutter-corner {
  width: 60px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
}

.cal-day-head {
  flex: 1;
  text-align: center;
  padding: 10px 4px 8px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 0;
}
.cal-day-head.today-head { background: rgba(79,110,245,.04); }

.cal-day-name {
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.cal-day-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}
.cal-day-num.today-num { background: var(--primary); color: #fff; }

/* ── Calendar body ────────────────────────────────────────────────────────── */
.cal-body { display: flex; }

.cal-time-gutter {
  position: sticky;
  left: 0;
  z-index: 20;
  width: 60px;
  flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
}
.cal-tick {
  position: absolute;
  right: 8px;
  font-size: 11px;
  color: var(--text2);
  transform: translateY(-50%);
  white-space: nowrap;
  font-weight: 500;
}

.cal-days { flex: 1; display: flex; }

.cal-day-col {
  flex: 1;
  position: relative;
  border-right: 1px solid var(--border);
  min-width: 0;
  background: var(--bg2);
}
.cal-day-col.today-col { background: rgba(79,110,245,.022); }
.cal-day-col.is-past-day { background: var(--bg3); }
.cal-day-col.hunter-mode { cursor: crosshair; }
.cal-day-col.hunter-mode:hover { background-color: rgba(79,110,245,.015); }

/* Grid lines inside day col */
.cal-hline {
  position: absolute;
  left: 0; right: 0;
  pointer-events: none;
}
.cal-hline.half { border-top: 1px solid var(--border-lt); }
.cal-hline.hour { border-top: 1px solid var(--border); }

/* ── Slot blocks ──────────────────────────────────────────────────────────── */
.cal-slot {
  position: absolute;
  left: 3px;
  right: 3px;
  border-radius: 7px;
  padding: 5px 8px 4px;
  overflow: hidden;
  cursor: pointer;
  transition: filter .1s, box-shadow .1s;
  z-index: 5;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.cal-slot:hover { filter: brightness(.93); }

.cal-slot-time {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.3;
  color: inherit;
}
.cal-slot-label {
  font-size: 11px;
  opacity: .75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-slot-phone {
  font-size: 10px;
  opacity: .6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.cal-slot-del {
  position: absolute;
  top: 4px;
  right: 5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,.12);
  border: none;
  color: inherit;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cal-slot:hover .cal-slot-del { opacity: 1; }
.cal-slot-del:hover { background: rgba(0,0,0,.25); }

/* ── Ghost hover preview ──────────────────────────────────────────────────── */
.cal-ghost {
  position: absolute;
  left: 3px;
  right: 3px;
  border-radius: 7px;
  pointer-events: none;
  z-index: 4;
  display: none;
  flex-direction: column;
  justify-content: center;
  padding: 5px 8px 4px;
  border: 2px dashed;
  transition: top .05s;
}
.cal-ghost.show { display: flex; }
.cal-ghost-time { font-size: 12px; font-weight: 700; }
.cal-ghost.conflict {
  border-color: var(--rejected);
  background: rgba(220,38,38,.08);
  color: var(--rejected);
}

/* ── Field group (appointment modals) ────────────────────────────────────── */
.field-group { margin-bottom: 12px; }
.field-group label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.field-group input,
.field-group select {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  padding: 7px 10px;
  font-size: 13px;
}
.field-group input:focus,
.field-group select:focus { outline: none; border-color: var(--primary); }

/* ── Stats ────────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  padding: 16px;
}
.stats-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.stats-card h3 { font-size: 13px; font-weight: 700; margin-bottom: 14px; color: var(--text2); text-transform: uppercase; letter-spacing: .4px; }

.bar-chart { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-label { width: 80px; font-size: 12px; color: var(--text2); }
.bar-track { flex: 1; background: var(--bg3); border-radius: 4px; height: 20px; overflow: hidden; border: 1px solid var(--border); }
.bar-fill { height: 100%; border-radius: 3px; display: flex; align-items: center; padding-left: 6px; font-size: 11px; font-weight: 600; color: #fff; min-width: 24px; transition: width .4s; }

.funnel-chart { display: flex; flex-direction: column; gap: 6px; }
.funnel-row { display: flex; align-items: center; gap: 8px; }
.funnel-label { width: 80px; font-size: 12px; color: var(--text2); }
.funnel-bar { height: 22px; border-radius: 4px; display: flex; align-items: center; padding: 0 8px; font-size: 12px; font-weight: 600; color: #fff; min-width: 30px; transition: width .4s; }
.funnel-pct { font-size: 11px; color: var(--text2); }

.stats-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stats-table th { color: var(--text2); font-weight: 600; text-align: left; padding: 4px 8px; font-size: 12px; border-bottom: 1px solid var(--border); }
.stats-table td { padding: 6px 8px; }
.stats-table tr:hover td { background: var(--bg3); }

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 13px;
  z-index: 9999;
  box-shadow: var(--shadow);
}
.toast.hidden { display: none; }
.toast.success { border-color: #86efac; color: var(--purchased); background: #f0fdf4; }
.toast.error   { border-color: #fca5a5; color: var(--rejected); background: #fff1f1; }

/* ── Rubber: compact time chips ──────────────────────────────────────────── */
.cal-time-chip {
  position: absolute;
  left: 4px;
  right: 4px;
  height: 26px;
  border-radius: 6px;
  background: var(--primary, #6366f1);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 5;
  transition: filter .1s, transform .1s;
  box-shadow: 0 1px 4px rgba(99,102,241,.25);
}
.cal-time-chip:hover { filter: brightness(1.12); transform: scaleY(1.05); }

/* ── Hunter picker modal list ─────────────────────────────────────────────── */
.hunter-picker-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.hunter-pick-btn {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
}

/* ── Utilities ────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .kanban-col { flex: 0 0 200px; }
  .logo { font-size: 13px; }
  .stats-grid { grid-template-columns: 1fr; }
  .cal-hint { display: none; }
}
