/* ROTOCON CRM — the pipeline board.

   Sits on cockpit.css (shell) and cockpit-tokens.css (tokens), beside crm.css.
   Deal statuses and the stage-progress accent are domain state, which
   cockpit-tokens.css explicitly keeps out of the shared layer — so they live
   here. No raw colour values: every one resolves to an existing token. */

/* --- Board: a horizontal rail of stage columns -------------------------- */
.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(248px, 1fr);
  gap: var(--sp-3);
  align-items: start;
  overflow-x: auto;
  padding-bottom: var(--sp-3);
  /* The rail scrolls; the page should not also scroll sideways underneath it. */
  overscroll-behavior-x: contain;
}

.board__col {
  background: var(--ink-900);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  min-height: 160px;
  display: flex;
  flex-direction: column;
  transition: border-color 120ms ease, background 120ms ease;
}
.board__col.is-over {
  border-color: var(--rot-bright);
  background: var(--ink-800);
}

.board__head {
  padding: var(--sp-3) var(--sp-3) var(--sp-2);
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 var(--sp-2);
}
.board__stage {
  font-size: var(--fs-label);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0;
}
.board__count {
  font-size: var(--fs-micro);
  color: var(--text-muted);
  background: var(--ink-800);
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
  align-self: start;
}
.board__sum {
  grid-column: 1 / -1;
  font-size: var(--fs-body);
  font-variant-numeric: tabular-nums;
}
.board__weighted {
  color: var(--text-muted);
  font-size: var(--fs-micro);
  margin-left: var(--sp-1);
}

/* Stage probability, drawn rather than written: the column reads as a position
   in the funnel at a glance. */
.board__meter {
  grid-column: 1 / -1;
  height: 2px;
  background: var(--line);
  border-radius: 999px;
  margin-top: var(--sp-2);
  overflow: hidden;
}
.board__meter > span {
  display: block;
  height: 100%;
  background: var(--rot);
}

.board__drop {
  padding: var(--sp-2);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  flex: 1;
}
.board__empty {
  color: var(--text-muted);
  text-align: center;
  margin: var(--sp-3) 0;
}

.board__switch select {
  background: var(--ink-800);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.5rem;
  font-size: var(--fs-label);
}

.board__error {
  margin-top: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--warn);
  border-radius: var(--radius-sm);
  color: var(--warn);
  font-size: var(--fs-label);
}

/* --- Deal card ---------------------------------------------------------- */
.dealcard {
  background: var(--ink-800);
  border: 1px solid var(--line);
  border-left: 3px solid var(--mute);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
  display: grid;
  gap: 0.15rem;
  cursor: grab;
}
.dealcard:active { cursor: grabbing; }
.dealcard.is-dragging { opacity: 0.4; }
.dealcard.is-saving { opacity: 0.6; pointer-events: none; }

.dealcard__title {
  font-size: var(--fs-body);
  color: var(--text);
  text-decoration: none;
  line-height: 1.3;
}
.dealcard__title:hover { color: var(--rot-bright); }

.dealcard__value {
  font-size: var(--fs-body);
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.dealcard__org { font-size: var(--fs-micro); color: var(--text-muted); }

.dealcard__foot {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-1);
}
.dealcard__owner {
  margin-left: auto;
  font-size: var(--fs-micro);
  color: var(--text-muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.05rem 0.35rem;
}
.dealcard__rot {
  font-size: var(--fs-micro);
  color: var(--warn);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* --- Deal status: the left edge carries it ------------------------------ */
.dealcard--open { border-left-color: var(--info); }
.dealcard--won  { border-left-color: var(--ok); }
.dealcard--lost { border-left-color: var(--mute); opacity: 0.75; }
.dealcard.is-rotten { border-left-color: var(--warn); }

.status-pill--deal-won  { --c: var(--ok); }
.status-pill--deal-lost { --c: var(--mute); }
.status-pill--deal-open { --c: var(--info); }

/* A dragged card must stay legible on a narrow screen; the rail keeps its
   column width and scrolls instead of crushing the cards. */
@media (max-width: 860px) {
  .board { grid-auto-columns: minmax(220px, 80vw); }
}

/* --- Deal detail ---------------------------------------------------------
   The stage picker is the page's spine: where the deal stands, and the only
   control that moves it. Everything else is reference. */
.detail { display: grid; gap: var(--sp-3); }
.detail__cols {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--sp-3);
  align-items: start;
}
@media (max-width: 920px) { .detail__cols { grid-template-columns: 1fr; } }
.detail__sub { margin-top: var(--sp-4); }

.stagepicker { display: flex; flex-wrap: wrap; gap: var(--sp-1); }
.stagepicker__step {
  flex: 1 1 0;
  min-width: 110px;
  background: var(--ink-900);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--sp-2);
  color: var(--text-muted);
  font: inherit;
  text-align: left;
  cursor: pointer;
  display: grid;
  gap: 0.1rem;
}
.stagepicker__step:hover { border-color: var(--line-strong); color: var(--text); }
.stagepicker__step.is-current {
  background: var(--ink-800);
  border-color: var(--rot);
  color: var(--text);
}
.stagepicker__name { font-size: var(--fs-label); }
.stagepicker__pct { font-size: var(--fs-micro); color: var(--text-muted); }

.deflist { display: grid; grid-template-columns: auto 1fr; gap: var(--sp-2) var(--sp-3); margin: 0; }
.deflist dt { color: var(--text-muted); font-size: var(--fs-label); }
.deflist dd { margin: 0; font-size: var(--fs-body); }
/* A value whose field definition has gone missing: shown, not silently dropped. */
.deflist dt.is-orphan { color: var(--warn); font-style: italic; }

/* --- Activity timeline --------------------------------------------------- */
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-2); }
.timeline__item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--sp-2);
  align-items: start;
  padding: var(--sp-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.timeline__item.is-done { opacity: 0.55; }
.timeline__item.is-done .timeline__subject { text-decoration: line-through; }
.timeline__item.is-overdue { border-color: var(--warn); }

.timeline__tick {
  width: 20px; height: 20px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--ink-900);
  color: var(--ok);
  font: inherit; line-height: 1;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.timeline__tick[disabled] { opacity: 0.5; cursor: wait; }
.timeline__body { display: grid; gap: 0.1rem; }
.timeline__subject { font-size: var(--fs-body); }
.timeline__meta { font-size: var(--fs-micro); color: var(--text-muted); }
.timeline__note { font-size: var(--fs-label); color: var(--text-muted); margin: var(--sp-1) 0 0; }

.note {
  border-left: 2px solid var(--line-strong);
  padding: 0 0 0 var(--sp-3);
  margin: var(--sp-2) 0;
}
.note p { margin: 0; font-size: var(--fs-body); }
.note__foot { font-size: var(--fs-micro); color: var(--text-muted); margin-top: var(--sp-1); }

/* --- Convert lead -------------------------------------------------------- */
.convert { display: grid; gap: var(--sp-3); }
.convert__row { display: grid; gap: var(--sp-1); }
.convert__row label { font-size: var(--fs-label); color: var(--text-muted); }
.convert__row input, .convert__row select {
  background: var(--ink-900);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.6rem;
  font: inherit;
  width: 100%;
}
.convert__row input:focus, .convert__row select:focus { border-color: var(--rot); outline: none; }
.convert__hint { font-size: var(--fs-micro); color: var(--text-muted); }
.convert__error { font-size: var(--fs-micro); color: var(--warn); }
.convert__effects { font-size: var(--fs-label); color: var(--text-muted); padding-left: var(--sp-4); }
.convert__effects li { margin: var(--sp-1) 0; }

/* --- Closing a deal ------------------------------------------------------ */
.closer { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--sp-3); }
.closer__won { display: flex; align-items: center; gap: var(--sp-3); }
.closer__lost summary { cursor: pointer; list-style: none; display: inline-flex; }
.closer__lost summary::-webkit-details-marker { display: none; }
.closer__lost form {
  display: grid;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
  padding: var(--sp-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--ink-900);
  min-width: 280px;
}
.closer__lost label { font-size: var(--fs-label); color: var(--text-muted); }
.closer__lost input[type="text"] {
  background: var(--ink-800);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.6rem;
  font: inherit;
}
.closer__lost input[type="text"]:focus { border-color: var(--rot); outline: none; }
.closer__sweep {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-label);
  color: var(--text-muted);
}
.closer__state { margin: 0; font-size: var(--fs-body); }

/* --- Insights ------------------------------------------------------------
   Two chart forms, both single-series. The colour is passed per chart and
   identifies the measure, so there is no categorical palette here and no
   legend: each title names its own series. Grid and axes stay recessive. */
.insights {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: var(--sp-3);
  align-items: start;
}

/* Horizontal bars — identity plus magnitude. */
.bars { display: grid; gap: var(--sp-2); }
.bars__row {
  display: grid;
  grid-template-columns: minmax(90px, 150px) 1fr auto;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-label);
}
.bars__label {
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bars__track {
  height: 10px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
.bars__fill {
  display: block;
  height: 100%;
  /* Rounded data-end, square against the baseline: the bar reads as anchored
     rather than floating. */
  border-radius: 0 4px 4px 0;
  min-width: 2px;
}
/* Values wear text tokens, never the series colour — the mark carries identity. */
.bars__val { color: var(--text); font-variant-numeric: tabular-nums; text-align: right; }

/* Vertical columns — change across evenly spaced periods. */
.cols {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  align-items: end;
  gap: var(--sp-2);
  height: 140px;
  padding-top: var(--sp-4);
  border-bottom: 1px solid var(--line);
}
.cols__slot {
  display: grid;
  grid-template-rows: 1fr auto;
  align-items: end;
  justify-items: center;
  height: 100%;
  position: relative;
}
.cols__bar {
  width: 70%;
  max-width: 34px;
  border-radius: 4px 4px 0 0;
  align-self: end;
  min-height: 2px;
}
.cols__peak {
  position: absolute;
  top: calc(-1 * var(--sp-4));
  font-size: var(--fs-micro);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cols__tick {
  font-size: var(--fs-micro);
  color: var(--text-muted);
  padding-top: var(--sp-1);
}

.chart-table { margin-top: var(--sp-3); }
.chart-table summary {
  font-size: var(--fs-micro);
  color: var(--text-muted);
  cursor: pointer;
}
.chart-table table { margin-top: var(--sp-2); }

/* Money runs to seven digits here, where the dashboard's KPI strip counts leads.
   The number shrinks to fit rather than wrapping and clipping its own currency. */
.insights-kpis .kpi__n,
/* cockpit.css enlarges the lead tile 1.6x for lead counts; euros at seven digits
   do not fit that, so the override has to reach the same selector depth. */
.insights-kpis .kpi--lead .kpi__n {
  font-size: clamp(17px, 2.1vw, 26px);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.chart-note {
  margin-top: var(--sp-2);
  font-size: var(--fs-micro);
  color: var(--warn);
}

/* --- Inline add/edit forms on the deal page ------------------------------ */
.lineform { margin-top: var(--sp-3); }
.lineform summary { cursor: pointer; list-style: none; display: inline-flex; }
.lineform summary::-webkit-details-marker { display: none; }
.lineform form {
  display: grid;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
  padding: var(--sp-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--ink-900);
}
.lineform select, .lineform input, .lineform textarea {
  background: var(--ink-800);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.55rem;
  font: inherit;
  width: 100%;
}
.lineform input:focus, .lineform select:focus, .lineform textarea:focus {
  border-color: var(--rot); outline: none;
}
.lineform ul { list-style: none; margin: 0; padding: 0; }  /* checkbox sets */
.lineform ul label { display: inline-flex; gap: var(--sp-1); align-items: center; }

/* Row-level destructive action: quiet until hovered, never a primary button. */
.linebtn {
  background: none;
  border: 0;
  color: var(--text-muted);
  font: inherit;
  cursor: pointer;
  padding: 0 0.3rem;
  line-height: 1;
}
.linebtn:hover { color: var(--rot-bright); }

/* The products table has five columns in a half-width card; without this it
   overflows its own border rather than wrapping. Fixed layout keeps the numeric
   columns narrow and lets the product name wrap, which is the one that can. */
.detail__cols .btable { table-layout: fixed; width: 100%; }
.detail__cols .btable td:first-child,
.detail__cols .btable th:first-child { word-break: break-word; }
.detail__cols .btable td:last-child,
.detail__cols .btable th:last-child { width: 2.2rem; }

/* --- Agenda --------------------------------------------------------------
   Buckets, not one sorted list: "what is late" and "what is today" are two
   different questions and should not sit two rows apart. */
.agenda {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: var(--sp-3);
  align-items: start;
}
.agenda__group h3 { display: flex; align-items: center; gap: var(--sp-2); }
/* Only overdue is coloured. If every bucket had an accent, none would read as
   urgent — which is the one thing this screen exists to show. */
.agenda__group--overdue { border-color: var(--warn); }
.agenda__group--overdue h3 { color: var(--warn); }
.agenda__group--done { opacity: 0.7; }
.agenda .timeline__meta a { color: var(--text-muted); }
.agenda .timeline__meta a:hover { color: var(--rot-bright); }
