:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --blue: #1d4ed8;
  --blue-soft: #eff4ff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 4px 14px rgba(15, 23, 42, 0.05);
  --lead: #64748b;
  --qualified: #0891b2;
  --proposal: #7c3aed;
  --negotiation: #d97706;
  --won: #16a34a;
  --lost: #dc2626;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

button, input, select { font: inherit; color: inherit; }

/* ---- header ---- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: -0.01em; }
.brand p { margin: 0; color: var(--muted); font-size: 13px; }

.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.button {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
}
.button:hover { border-color: #cbd5e1; }
.button.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.button.primary:hover { background: #1e40af; }
.button.quiet { color: var(--muted); }
.button:disabled { opacity: 0.6; cursor: default; }

:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; }
.live[data-state="live"] { background: #ecfdf3; color: #15803d; }
.live[data-state="live"] .dot { background: #16a34a; animation: pulse 1.8s infinite; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.5); }
  70% { box-shadow: 0 0 0 8px rgba(22, 163, 74, 0); }
  100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}

/* ---- numbers ---- */

main { padding: 22px 28px 40px; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat .label { color: var(--muted); font-size: 13px; font-weight: 600; }
.stat strong { font-size: 30px; letter-spacing: -0.02em; line-height: 1.2; }
.stat .hint { color: var(--muted); font-size: 12.5px; }
.stat.accent { background: var(--blue); border-color: var(--blue); color: #fff; }
.stat.accent .label, .stat.accent .hint { color: #dbeafe; }

/* ---- board ---- */

.board {
  display: grid;
  grid-template-columns: repeat(6, minmax(230px, 1fr));
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 12px;
  align-items: start;
}

.column {
  background: #eaeef6;
  border-radius: var(--radius);
  padding: 10px;
  min-height: 220px;
  border: 2px solid transparent;
  transition: border-color 0.12s, background 0.12s;
}
.column.drop { border-color: var(--stage); background: #e2e8f5; }

.column[data-stage="lead"] { --stage: var(--lead); }
.column[data-stage="qualified"] { --stage: var(--qualified); }
.column[data-stage="proposal"] { --stage: var(--proposal); }
.column[data-stage="negotiation"] { --stage: var(--negotiation); }
.column[data-stage="won"] { --stage: var(--won); }
.column[data-stage="lost"] { --stage: var(--lost); }

.column-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 10px;
}
.column-head .swatch { width: 10px; height: 10px; border-radius: 3px; background: var(--stage); }
.column-head h2 { margin: 0; font-size: 14px; }
.column-head .count {
  background: #fff;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.column-head .total { margin-left: auto; font-size: 13px; font-weight: 700; color: var(--muted); }

.cards { display: flex; flex-direction: column; gap: 8px; }

.empty {
  border: 1.5px dashed #cbd5e1;
  border-radius: 10px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 18px 8px;
}

.card {
  background: var(--panel);
  border-radius: 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--stage);
  box-shadow: var(--shadow);
  padding: 11px 12px 9px;
  cursor: grab;
}
.card.dragging { opacity: 0.45; }
.card.fresh { animation: fresh 1.4s ease-out; }

@keyframes fresh {
  0% { box-shadow: 0 0 0 3px var(--stage); transform: scale(1.02); }
  100% { box-shadow: var(--shadow); transform: scale(1); }
}

.card h3 { margin: 0; font-size: 14.5px; line-height: 1.3; }
.card .title { margin: 2px 0 8px; color: var(--muted); font-size: 13px; }

.card .meta { display: flex; align-items: center; gap: 8px; }
.card .value { font-weight: 700; font-size: 15px; white-space: nowrap; }
.card .age { color: var(--muted); font-size: 12px; white-space: nowrap; }
.card .owner {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  min-width: 0;
  white-space: nowrap;
}
.card .avatar {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.card .tools {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid #f1f5f9;
}
.tool {
  border: 0;
  background: #f1f5f9;
  border-radius: 7px;
  min-width: 30px;
  height: 26px;
  padding: 0 8px;
  font-size: 13px;
  font-weight: 700;
  color: #334155;
  cursor: pointer;
}
.tool:hover { background: #e2e8f0; color: var(--ink); }
.tool.spacer { margin-left: auto; }
.tool.danger:hover { background: #fee2e2; color: #b91c1c; }
.tool:disabled { opacity: 0.35; cursor: default; }

/* ---- dialog ---- */

dialog {
  border: 0;
  border-radius: 16px;
  padding: 0;
  width: min(440px, calc(100vw - 32px));
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.3);
}
dialog::backdrop { background: rgba(15, 23, 42, 0.45); }

#deal-form { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
#deal-form h2 { margin: 0 0 4px; font-size: 18px; }
#deal-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: #334155; }
#deal-form input, #deal-form select {
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  padding: 9px 10px;
  font-weight: 400;
  background: #fff;
  width: 100%;
}
#deal-form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error { margin: 0; color: #b91c1c; font-size: 13px; font-weight: 600; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* ---- toast and confetti ---- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.3);
  z-index: 20;
}

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 30; }
.confetti i {
  position: absolute;
  top: -20px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  animation: fall linear forwards;
}

@keyframes fall {
  to { transform: translate3d(var(--drift), 105vh, 0) rotate(var(--spin)); opacity: 0.9; }
}

@media (max-width: 900px) {
  .top, main { padding-left: 16px; padding-right: 16px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat strong { font-size: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .card.fresh, .live .dot { animation: none; }
  .confetti { display: none; }
}
