/* BBS CRM — visual family shared with LocalDeliveryOS / NEMT Logic:
   cool-white canvas, deep-navy headings, crisp 1px-bordered white cards,
   blue for actions and active work, green for completed/financial outcomes.
   Light theme only, matching those products. */

@font-face { font-family: 'Geist Sans'; src: url('/fonts/geist-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Geist Sans'; src: url('/fonts/geist-latin-500-normal.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Geist Sans'; src: url('/fonts/geist-latin-600-normal.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Geist Sans'; src: url('/fonts/geist-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Geist Mono'; src: url('/fonts/geist-mono-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Geist Mono'; src: url('/fonts/geist-mono-latin-500-normal.woff2') format('woff2'); font-weight: 500; font-display: swap; }

:root {
  --brand-navy: #0b1f33;
  --brand-ink: #071827;
  --brand-blue: #0d63e8;
  --brand-blue-hover: #0a52c4;
  --brand-blue-bright: #1677ff;
  --brand-blue-soft: #d9eaff;
  --brand-green: #17a673;
  --brand-green-soft: #ddf7ec;
  --brand-white: #ffffff;
  --brand-neutral: #f5f8fb;
  --brand-neutral-strong: #edf2f7;
  --brand-border: #d8e1ea;
  --brand-muted: #607083;
  --brand-focus: #0f6bff;
  --status-danger: #b42318;
  --status-danger-soft: #fde7e5;
  --status-neutral: #64748b;
  --status-neutral-soft: #eef2f6;
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(7, 24, 39, 0.06);
  --shadow-md: 0 16px 44px rgba(7, 24, 39, 0.12);
  --font-sans: 'Geist Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--brand-neutral);
  color: var(--brand-ink);
  font: 15px/1.6 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0; color: var(--brand-navy); font-weight: 600; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.05rem; }
::selection { background: var(--brand-blue); color: #fff; }
:focus-visible { outline: 3px solid var(--brand-focus); outline-offset: 3px; border-radius: var(--radius-sm); }
main:focus { outline: none; }
.num { font-family: var(--font-mono); font-feature-settings: 'tnum'; font-size: 0.93em; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--brand-white); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }

/* ---------- top bar ---------- */
.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 28px;
  min-height: 64px; padding: 8px 24px;
  background: rgba(255, 255, 255, 0.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--brand-border);
  position: sticky; top: 0; z-index: 5;
}
.brand {
  display: inline-flex; align-items: center; gap: 0; text-decoration: none;
  font-weight: 600; font-size: 1.1rem; color: var(--brand-navy);
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 50%; margin-right: 10px;
  background: linear-gradient(135deg, var(--brand-blue-bright), var(--brand-green));
  box-shadow: inset 0 0 0 6px rgba(255, 255, 255, 0.92), inset 0 0 0 9px var(--brand-blue);
}
.brand-suffix { color: var(--brand-green); margin-left: 5px; }
nav { display: flex; gap: 4px; }
nav a {
  text-decoration: none; padding: 8px 12px; border-radius: var(--radius-sm);
  color: var(--brand-muted); font-weight: 500; font-size: 0.93rem;
}
nav a:hover { color: var(--brand-navy); background: var(--brand-neutral); }
nav a[aria-current="page"] { background: var(--brand-blue-soft); color: var(--brand-blue); font-weight: 600; }

main { max-width: 1040px; margin: 0 auto; padding: 32px 24px 96px; }

/* ---------- page header ---------- */
.eyebrow {
  margin: 0 0 6px; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.14em; color: var(--brand-blue);
}
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-head .sub { color: var(--brand-muted); margin: 6px 0 0; }
.back { display: inline-block; margin-bottom: 16px; color: var(--brand-muted); text-decoration: none; font-size: 0.9rem; font-weight: 500; }
.back:hover { color: var(--brand-blue); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- buttons ---------- */
button, .btn {
  font: inherit; font-weight: 600; font-size: 0.9rem; cursor: pointer; white-space: nowrap;
  min-height: 40px; padding: 8px 16px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); border: 1px solid var(--brand-border);
  background: var(--brand-white); color: var(--brand-navy); text-decoration: none;
  box-shadow: var(--shadow-sm); transition: background 0.15s, border-color 0.15s;
}
button:hover, .btn:hover { background: var(--brand-neutral); border-color: #c3cfdb; }
button.primary { background: var(--brand-blue); border-color: var(--brand-blue); color: #fff; }
button.primary:hover { background: var(--brand-blue-hover); border-color: var(--brand-blue-hover); }
button.danger { color: var(--status-danger); }
button.danger:hover { background: var(--status-danger-soft); border-color: #f3c2bd; }
button[disabled] { opacity: 0.6; cursor: progress; }

/* ---------- cards and lists ---------- */
.card {
  background: var(--brand-white); border: 1px solid var(--brand-border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-sm); overflow: hidden;
}
.section { margin-top: 28px; }
.section > .section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }

.filter { margin-bottom: 12px; }
input, select, textarea {
  font: inherit; color: var(--brand-ink); background: var(--brand-white); width: 100%;
  border: 1px solid var(--brand-border); border-radius: var(--radius-sm); padding: 9px 12px; min-height: 40px;
}
input::placeholder { color: var(--brand-muted); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 1px; border-color: var(--brand-blue); }
textarea { min-height: 96px; resize: vertical; }
[aria-invalid="true"] { border-color: var(--status-danger); }

.rows { list-style: none; margin: 0; padding: 0; }
.rows li + li { border-top: 1px solid var(--brand-border); }
.row {
  display: grid; grid-template-columns: 1.3fr 1fr 1.4fr 0.9fr; gap: 2px 16px; align-items: center;
  padding: 12px 18px; text-decoration: none; font-size: 0.93rem;
}
.row:hover { background: var(--brand-neutral); }
.row:hover .name { color: var(--brand-blue); }
.row .name { font-weight: 600; color: var(--brand-navy); }
.row .dim { color: var(--brand-muted); overflow-wrap: anywhere; }
.tag {
  display: inline-block; font-size: 10px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--status-neutral); background: var(--status-neutral-soft);
  border-radius: 999px; padding: 2px 8px; margin-left: 8px; vertical-align: middle;
}
.empty { padding: 32px 16px; text-align: center; color: var(--brand-muted); margin: 0; }

.details { margin: 0; padding: 6px 18px; display: grid; grid-template-columns: 150px 1fr; font-size: 0.93rem; }
.details dt, .details dd { padding: 11px 0; margin: 0; border-top: 1px solid var(--brand-border); overflow-wrap: anywhere; }
.details dt:first-of-type, .details dd:first-of-type { border-top: 0; }
.details dt { color: var(--brand-muted); }
.details dd { color: var(--brand-navy); font-weight: 500; }
.details dd a { color: var(--brand-blue); text-decoration: none; }
.details dd a:hover { text-decoration: underline; }
.details .notes { white-space: pre-wrap; font-weight: 400; color: var(--brand-ink); }

.page-error { padding: 24px; border-color: #f3c2bd; background: var(--status-danger-soft); }
.page-error h1 { font-size: 1.2rem; margin-bottom: 8px; }
.page-error p { margin: 0 0 14px; }

/* ---------- dialogs ---------- */
dialog {
  border: 1px solid var(--brand-border); border-radius: var(--radius-lg);
  background: var(--brand-white); color: var(--brand-ink); box-shadow: var(--shadow-md);
  padding: 24px; width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
}
dialog::backdrop { background: rgba(7, 24, 39, 0.45); }
dialog h2 { margin-bottom: 16px; font-size: 1.2rem; }
dialog p { margin: 0 0 16px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: 0.87rem; color: var(--brand-navy); margin-bottom: 5px; }
.field .req { color: var(--brand-muted); font-weight: 400; }
.field-error, .form-error { color: var(--status-danger); margin: 5px 0 0; font-size: 0.87rem; }
.form-error { background: var(--status-danger-soft); padding: 10px 12px; border-radius: var(--radius-sm); margin: 0 0 16px; font-weight: 500; }
dialog .actions { justify-content: flex-end; margin-top: 20px; }

/* ---------- confirmation toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--brand-ink); color: #fff; padding: 11px 18px 11px 14px; border-radius: 999px;
  font-weight: 600; font-size: 0.9rem; box-shadow: var(--shadow-md);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; max-width: calc(100vw - 32px); z-index: 20;
}
#toast::before {
  content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--brand-green); margin-right: 10px; vertical-align: 1px;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { #toast, button, .btn { transition: none; } }

/* ---------- chips, tasks, timeline, overview ---------- */
.icon { width: 13px; height: 13px; flex: none; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  font-size: 11.5px; font-weight: 600; border-radius: 999px; padding: 2px 9px 2px 7px;
}
.chip.blue { background: var(--brand-blue-soft); color: #0a4fbb; }
.chip.green { background: var(--brand-green-soft); color: #0e6b49; }
.chip.danger { background: var(--status-danger-soft); color: var(--status-danger); }
.chip.neutral { background: var(--status-neutral-soft); color: #475569; }

.item { display: flex; align-items: flex-start; gap: 12px; padding: 13px 18px; }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 600; color: var(--brand-navy); cursor: pointer; overflow-wrap: anywhere; }
.item-body { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.meta { margin: 4px 0 0; color: var(--brand-muted); font-size: 0.85rem; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.meta a { color: var(--brand-blue); text-decoration: none; font-weight: 500; }
.meta a:hover { text-decoration: underline; }
.task input[type="checkbox"] {
  flex: none; width: 20px; height: 20px; min-height: 0; padding: 0; margin: 1px 0 0;
  accent-color: var(--brand-green); cursor: pointer;
}
.task.is-done .item-title { color: var(--brand-muted); text-decoration: line-through; font-weight: 500; }
.activity .chip { margin-top: 1px; min-width: 112px; justify-content: center; }
.item-actions { display: flex; gap: 2px; flex: none; }
button.quiet {
  min-height: 32px; padding: 4px 10px; font-size: 0.82rem; font-weight: 500;
  border-color: transparent; background: transparent; box-shadow: none; color: var(--brand-muted);
}
button.quiet:hover { background: var(--brand-neutral-strong); border-color: transparent; color: var(--brand-navy); }
button.quiet.danger:hover { background: var(--status-danger-soft); color: var(--status-danger); }
.count { color: var(--brand-muted); font-weight: 500; margin-left: 4px; }
.more { color: var(--brand-blue); text-decoration: none; font-weight: 600; font-size: 0.87rem; }
.more:hover { text-decoration: underline; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.tile { display: flex; flex-direction: column; gap: 2px; padding: 16px 18px; text-decoration: none; }
.tile:hover { border-color: var(--brand-blue); }
.tile-num { font-size: 1.7rem; font-weight: 500; color: var(--brand-navy); line-height: 1.1; }
.tile-label { color: var(--brand-muted); font-size: 0.85rem; font-weight: 500; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; align-items: start; }
.two-col > .section { min-width: 0; }

/* ---------- SPIN deals board ---------- */
main.wide { max-width: 1320px; }
button.small { min-height: 32px; padding: 4px 10px; font-size: 0.8rem; }
button.next { color: var(--brand-blue); border-color: #b7d7ff; }
button.next:hover { background: var(--brand-blue-soft); border-color: var(--brand-blue); }
button.success { background: var(--brand-green); border-color: var(--brand-green); color: #fff; }
button.success:hover { background: #12835b; border-color: #12835b; }
.hint { margin: 2px 0 0; color: var(--brand-muted); font-size: 0.82rem; }
.board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; align-items: start; }
.board.closed { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.closed-title { margin: 32px 0 12px; }
.column { background: var(--brand-neutral-strong); border-radius: var(--radius-md); padding: 12px; border-top: 3px solid var(--brand-blue); }
.column.won { border-top-color: var(--brand-green); }
.column.lost { border-top-color: var(--status-neutral); }
.column-head { padding: 2px 4px 10px; }
.column-total { margin: 6px 0 0; font-size: 0.85rem; font-weight: 500; color: var(--brand-navy); }
.column-empty { margin: 0; padding: 18px 8px; text-align: center; color: var(--brand-muted); font-size: 0.87rem; border: 1px dashed var(--brand-border); border-radius: var(--radius-md); }
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.deal-card { padding: 12px 14px; overflow: visible; }
.deal-name { font-weight: 600; color: var(--brand-navy); text-decoration: none; overflow-wrap: anywhere; }
.deal-name:hover { color: var(--brand-blue); text-decoration: underline; }
.deal-foot { margin: 8px 0 10px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 10px; font-size: 0.82rem; }
.deal-foot .dim { color: var(--brand-muted); }
.deal-value { font-weight: 500; color: var(--brand-navy); }
.deal-value.won { color: #0e6b49; }
.deal-card .actions { gap: 6px; }
.deal-row { grid-template-columns: 1.6fr 1fr 0.6fr; }
.page-head .sub .chip { vertical-align: middle; margin-right: 6px; }

.stage-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; padding: 14px 18px; margin-bottom: 14px; }
.stepper { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; }
.stepper li { display: flex; align-items: center; gap: 8px; color: var(--brand-muted); font-weight: 500; font-size: 0.9rem; }
.step-num { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 0.78rem; background: var(--status-neutral-soft); color: var(--status-neutral); }
.stepper .is-past { color: var(--brand-navy); }
.stepper .is-past .step-num { background: var(--brand-blue-soft); color: #0a4fbb; }
.stepper .is-current { color: var(--brand-blue); font-weight: 600; }
.stepper .is-current .step-num { background: var(--brand-blue); color: #fff; }
.spin-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.spin-card { padding: 14px 18px 16px; }
.spin-card.is-current { border-color: #b7d7ff; box-shadow: 0 0 0 1px #b7d7ff, var(--shadow-sm); }
.spin-card header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.spin-card .eyebrow { margin: 0; }
.spin-text { margin: 10px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.spin-text.is-empty { color: var(--brand-muted); }

.pipeline { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); text-decoration: none; }
.pipeline:hover { border-color: var(--brand-blue); }
.pipe { padding: 12px 16px; display: flex; flex-direction: column; border-left: 1px solid var(--brand-border); border-top: 3px solid var(--brand-blue); }
.pipe:first-child { border-left: 0; }
.pipe.won { border-top-color: var(--brand-green); }
.pipe.lost { border-top-color: var(--status-neutral); }
.pipe-name { font-size: 0.8rem; font-weight: 600; color: var(--brand-muted); }
.pipe-count { font-size: 1.35rem; font-weight: 500; color: var(--brand-navy); line-height: 1.3; }
.pipe-value { font-size: 0.8rem; color: var(--brand-muted); }

@media (max-width: 1000px) { .board { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) {
  .board, .board.closed, .spin-grid { grid-template-columns: 1fr; }
  .pipeline { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .pipe:nth-child(4) { border-left: 0; }
  .pipe { padding: 10px 12px; }
  button.small { min-height: 40px; }
  .deal-row { grid-template-columns: 1fr; }
}

@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }
@media (max-width: 640px) {
  .item { flex-wrap: wrap; padding: 13px 16px; }
  .item-main { flex-basis: calc(100% - 40px); }
  .activity .item-main { flex-basis: 100%; }
  .item-actions { margin-left: auto; }
  button.quiet { min-height: 40px; }
  .tile { padding: 12px 14px; }
  .tile-num { font-size: 1.35rem; }
  /* Six sections do not fit across a phone header, so they become a bottom tab bar. */
  /* The blur must go: it would pin the fixed tab bar to the header instead of the screen. */
  .top { min-height: 52px; position: static; backdrop-filter: none; background: var(--brand-white); }
  nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; gap: 0;
    display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
    background: var(--brand-white); border-top: 1px solid var(--brand-border);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  nav a { padding: 12px 0; font-size: 11px; text-align: center; overflow: hidden; text-overflow: ellipsis; }
  #toast { bottom: calc(68px + env(safe-area-inset-bottom)); }
  main { padding-bottom: 120px !important; }
}

@media (max-width: 640px) {
  .top { padding: 8px 16px; }
  main { padding: 24px 16px 96px; }
  h1 { font-size: 1.4rem; }
  button, .btn, input, select { min-height: 44px; }
  .row { grid-template-columns: 1fr; padding: 12px 16px; }
  .row .dim:empty { display: none; }
  .details { grid-template-columns: 1fr; padding: 6px 16px; }
  .details dd { border-top: 0; padding-top: 0; }
  .details dt { padding-bottom: 0; font-size: 0.8rem; }
  .page-head .actions { width: 100%; }
  .page-head .actions button { flex: 1; }
}

/* ---------- projects ---------- */
.chip.warn { background: #fff3d6; color: #8a5200; }
.help { margin: 4px 0 0; color: var(--brand-muted); font-size: 0.82rem; }
.project-row { grid-template-columns: 1.5fr 1fr 1.3fr 0.9fr; }
.chips { display: flex; flex-wrap: wrap; gap: 4px 6px; }
.progress-wrap { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.progress { display: block; width: 90px; height: 6px; border-radius: 999px; background: var(--brand-neutral-strong); overflow: hidden; flex: none; }
.progress > span { display: block; height: 100%; background: var(--brand-green); border-radius: 999px; }
.dim { color: var(--brand-muted); }
.status-set { display: flex; flex-wrap: wrap; gap: 6px; }
.status-set .is-on { background: var(--brand-blue); border-color: var(--brand-blue); color: #fff; }
.path { font-family: var(--font-mono); font-size: 0.88em; background: var(--brand-neutral-strong); padding: 2px 6px; border-radius: 4px; font-weight: 400; overflow-wrap: anywhere; }
.spin-grid + .section { margin-top: 28px; }
.stage-bar + .spin-grid { margin-top: 0; }
.tiles { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 640px) {
  .project-row { grid-template-columns: 1fr; gap: 6px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
}
.health { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 0 0 4px; font-size: 0.9rem; color: var(--brand-muted); }
.health.danger span { color: var(--status-danger); font-weight: 500; }

/* ---------- sign-in, locked and account ---------- */
body.gated nav { display: none; }
.gate { max-width: 420px; margin: 8vh auto 0; text-align: center; }
.gate .sub { color: var(--brand-muted); margin: 8px 0 24px; }
.gate #sign-in { display: flex; justify-content: center; }
.gate-card { max-width: 520px; margin: 8vh auto 0; }
#account { margin-left: auto; display: flex; align-items: center; gap: 4px; font-size: 0.85rem; color: var(--brand-muted); }
.account-email { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.footnote { margin: 28px 0 0; color: var(--brand-muted); font-size: 0.87rem; }
.footnote button { color: var(--brand-blue); font-weight: 600; }

.new-company { margin-top: 8px; }
