:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1c1f24;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #e3262f;      /* Good Gearz red */
  --accent-soft: #fdecec;
  --blue: #2563eb;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --green: #15803d;
  --green-soft: #dcfce7;
  --gray-soft: #eef0f3;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 20px;
  padding: 10px 16px; background: #111; color: #fff;
}
.brand { font-weight: 700; font-size: 16px; }
.brand span { color: var(--accent); }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { text-decoration: none; padding: 6px 12px; border-radius: 6px; color: #cfd3d8; }
.topbar nav a.active { background: #2a2a2a; color: #fff; }

.topbar[hidden] { display: none; }
.usermenu { position: relative; }
.usermenu summary { list-style: none; cursor: pointer; padding: 6px 10px; border-radius: 8px; color: #cfd3d8; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu summary:hover { background: #2a2a2a; }
.usermenu .menu {
  position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; min-width: 160px; padding: 4px; box-shadow: 0 6px 20px rgba(0,0,0,.15);
}
.usermenu .menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; cursor: pointer; font: inherit; }
.usermenu .menu button:hover { background: var(--gray-soft); }

.auth { max-width: 360px; margin: 10vh auto 0; }
.auth .brand { font-size: 22px; margin-bottom: 14px; color: var(--text); }
.auth .err { color: var(--accent); min-height: 18px; margin-top: 8px; font-size: 13px; }
.auth button[type=submit] { width: 100%; margin-top: 16px; padding: 10px; }

.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font: inherit;
}
.btn:hover { border-color: #c5cad1; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--accent); }
.btn.small { padding: 4px 8px; font-size: 12px; }

main { padding: 16px; }

/* ---------- Board ---------- */
.board-summary { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; color: var(--muted); }
.board-summary b { color: var(--text); }
.board-summary .sync { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.board {
  display: grid; grid-template-columns: repeat(5, minmax(220px, 1fr)); gap: 12px;
  overflow-x: auto; padding-bottom: 8px;
}
.col { background: var(--gray-soft); border-radius: var(--radius); padding: 8px; min-height: 60vh; }
.col.drag-over { outline: 2px dashed var(--blue); outline-offset: -2px; }
.col-head { display: flex; justify-content: space-between; align-items: baseline; padding: 4px 6px 10px; }
.col-head h3 { margin: 0; font-size: 14px; }
.col-head small { color: var(--muted); }
.col[data-stage="won"] .col-head h3 { color: var(--green); }
.col[data-stage="lost"] .col-head h3 { color: var(--muted); }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px; margin-bottom: 8px; cursor: grab;
}
.card:hover { border-color: #c5cad1; }
.card.dragging { opacity: .4; }
.card .who { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--gray-soft); object-fit: cover; flex: none; }
.avatar.lg { width: 48px; height: 48px; }
.card .cust { font-weight: 600; }
.card .title { margin-bottom: 6px; }
.card .meta { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 12px; }
.card .value { font-weight: 600; color: var(--text); }
.tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--gray-soft); color: var(--muted); }
.tag.bot { background: #e0e7ff; color: #3730a3; }
.tag.outside { background: var(--amber-soft); color: var(--amber); }
.tag.check { background: var(--accent-soft); color: var(--accent); }

/* ---------- Customers ---------- */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; }
.toolbar input { flex: 1; max-width: 340px; }
table.list { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
table.list th, table.list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
table.list th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; }
table.list tr.row { cursor: pointer; }
table.list tr.row:hover td { background: #fafbfc; }

.customer { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.panel h2 { margin: 0 0 4px; font-size: 18px; }
.panel h3 { margin: 0 0 10px; font-size: 14px; }
.back { display: inline-block; margin-bottom: 10px; color: var(--muted); text-decoration: none; }
.cust-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.muted { color: var(--muted); }
.job-row { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; cursor: pointer; }
.job-row:hover { border-color: #c5cad1; }
.stage-pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--gray-soft); }
.stage-pill.won { background: var(--green-soft); color: var(--green); }
.stage-pill.quoted { background: #dbeafe; color: var(--blue); }
.stage-pill.prototype { background: #ede9fe; color: #6d28d9; }

.chat { max-height: 520px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding-right: 4px; }
.msg { max-width: 75%; padding: 7px 10px; border-radius: 10px; white-space: pre-wrap; line-height: 1.4; }
.msg.in { background: var(--gray-soft); align-self: flex-start; }
.msg.out { background: #dbeafe; align-self: flex-end; }
.msg time { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.msg.file { font-style: italic; }

/* ---------- Forms / modal ---------- */
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
input[type=text], input[type=number], input[type=tel], input[type=search], input[type=password], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff;
}
textarea { min-height: 70px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
.check input { width: auto; }
dialog { border: none; border-radius: 12px; padding: 0; width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.35); }
#modalForm { padding: 18px; }
#modalForm h2 { margin: 0 0 6px; font-size: 17px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.actions .spacer { flex: 1; }
.events { margin-top: 12px; font-size: 12px; color: var(--muted); max-height: 120px; overflow-y: auto; }
.events div { padding: 2px 0; }

#toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: #111; color: #fff; padding: 8px 14px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none;
}
#toast.show { opacity: 1; }

.empty { color: var(--muted); padding: 20px; text-align: center; }

@media (max-width: 800px) {
  .topbar { flex-wrap: wrap; gap: 8px; }
  .board { grid-template-columns: repeat(5, 78vw); }
  .customer { grid-template-columns: 1fr; }
  table.list .hide-sm { display: none; }
}
