/* ============================================================
   Montar CRM — sidebar, dashboard, contacts, clients
   Board and lead panel live in pipeline.css
   ============================================================ */

.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

/* ---------------------------------------------------------- sidebar */
.sidebar {
  flex: none;
  width: 186px;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--card);
  border-right: 1px solid var(--hair);
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 11px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--ink-soft);
  font-size: var(--text-sm);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background var(--duration) var(--ease), color var(--duration) var(--ease);
}
.nav-item:hover { background: var(--paper-2); color: var(--ink); }

/* The active item is carried by weight and a tinted ground, not colour
   alone — it still reads in greyscale and forced-colors. */
.nav-item.is-active {
  background: var(--accent-tint);
  color: var(--accent-ink);
  font-weight: 700;
}

.nav-icon { flex: none; }

/* min-height matters as much as min-width: on mobile the workspace is
   column-reverse, and without it this grows to content height and
   overflows upward behind the app bar. */
.view-host {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.view { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

/* Dashboard, contacts and clients scroll as ordinary pages. */
.view-scroll {
  overflow-y: auto;
  padding: clamp(1rem, 0.5rem + 1.6vw, 1.9rem);
  gap: 16px;
}

.view-loading { color: var(--ink-faint); font-size: var(--text-sm); padding: 20px 2px; }

/* -------------------------------------------------------------- KPIs */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.kpi {
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--hair);
  border-radius: var(--radius);
}

.kpi-value {
  display: block;
  font-size: clamp(1.5rem, 1.1rem + 1.4vw, 2.1rem);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.kpi-label {
  display: block;
  margin-top: 7px;
  font-size: var(--text-micro);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.kpi-note { display: block; margin-top: 3px; font-size: var(--text-sm); color: var(--ink-faint); }

/* ------------------------------------------------------------ panels */
.panel-card {
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--hair);
  border-radius: var(--radius);
}

.panel-card-head { margin-bottom: 14px; }
.panel-card-head h2 { font-size: var(--text-lede); letter-spacing: -0.02em; }
.panel-card-head p { margin-top: 2px; font-size: var(--text-sm); color: var(--ink-faint); }

.panel-pair {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

/* ------------------------------------------------------------ charts */
.chart-frame { position: relative; }
.chart-svg { width: 100%; height: 168px; display: block; overflow: visible; }

.chart-tip {
  position: absolute;
  top: -4px;
  translate: -50% -100%;
  padding: 6px 10px;
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius-sm);
  font-size: var(--text-micro);
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.chart-tip strong { font-size: var(--text-sm); font-variant-numeric: tabular-nums; }

.chart-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: var(--text-micro);
  color: var(--ink-faint);
}

/* The numbers, always reachable — no colour, no pointer required. */
.chart-data { margin-top: 12px; }
.chart-data summary {
  font-size: var(--text-micro);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  cursor: pointer;
}
.chart-data summary:hover { color: var(--ink); }
.chart-table-wrap { overflow-x: auto; margin-top: 8px; }
.chart-table { border-collapse: collapse; font-size: var(--text-sm); width: 100%; }
.chart-table th, .chart-table td {
  padding: 5px 12px 5px 0;
  text-align: left;
  border-bottom: 1px solid var(--hair);
  white-space: nowrap;
}
.chart-table th { color: var(--ink-faint); font-weight: 600; font-size: var(--text-micro);
  text-transform: uppercase; letter-spacing: 0.06em; }
.chart-table td { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------- ranked bars */
.bar-rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }

.bar-row { display: grid; grid-template-columns: 96px 1fr auto; align-items: center; gap: 10px; }
.bar-label { font-size: var(--text-sm); color: var(--ink-soft); }
.bar-track { height: 9px; background: var(--paper-2); border-radius: 999px; overflow: hidden; }
.bar-fill {
  display: block;
  height: 100%;
  background: var(--chart-1);
  border-radius: 999px;
  transition: width var(--duration) var(--ease);
}
.bar-value { font-size: var(--text-sm); font-weight: 700; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------- column bars */
.col-bars {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  gap: 8px; align-items: end; height: 168px;
}
.col-bar { display: flex; flex-direction: column; height: 100%; gap: 7px; }
.col-track { position: relative; flex: 1 1 auto; display: flex; align-items: flex-end; }
.col-fill {
  width: 100%;
  background: var(--chart-1);
  /* Rounded data-end, square where it meets the baseline. */
  border-radius: 4px 4px 0 0;
  transition: height var(--duration) var(--ease);
}
.col-tip {
  position: absolute; inset-inline: 0; bottom: 100%;
  margin-bottom: 5px; text-align: center;
  font-size: var(--text-micro); font-variant-numeric: tabular-nums;
  color: var(--ink-soft); opacity: 0;
  transition: opacity var(--duration) var(--ease);
}
.col-bar:hover .col-tip { opacity: 1; }
.col-label { text-align: center; font-size: var(--text-micro); color: var(--ink-faint); }

/* ---------------------------------------------------------- contacts */
.list-toolbar { display: flex; align-items: center; gap: 12px; }
.list-toolbar select {
  padding: 6px 10px; background: var(--card);
  border: 1px solid var(--hair); border-radius: var(--radius-sm); font-size: var(--text-sm);
}
.list-count { font-size: var(--text-sm); color: var(--ink-faint); }

.contact-list {
  list-style: none; margin: 0; padding: 0;
  background: var(--card); border: 1px solid var(--hair); border-radius: var(--radius);
  overflow: hidden;
}

.contact-row {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--hair);
}
.contact-row:last-child { border-bottom: none; }
.contact-row:hover { background: var(--card-2); }

.contact-main { flex: 1 1 auto; min-width: 0; }
.contact-name { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.contact-sub {
  display: block; margin-top: 2px;
  font-size: var(--text-sm); color: var(--ink-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.contact-figures { flex: none; text-align: right; }
.contact-value { display: block; font-weight: 700; font-variant-numeric: tabular-nums; }
.contact-when { display: block; font-size: var(--text-micro); color: var(--ink-faint); }
.contact-call { flex: none; }

.tag.is-repeat { background: var(--go-tint); color: color-mix(in oklab, var(--go) 74%, var(--ink)); }

/* ----------------------------------------------------------- clients */
.admin-layout { display: grid; grid-template-columns: 232px minmax(0, 1fr); gap: 16px; }

.client-rail {
  background: var(--card); border: 1px solid var(--hair);
  border-radius: var(--radius); padding: 12px; align-self: start;
}
.rail-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.rail-head h2 { font-size: var(--text-sm); text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--ink-faint); }
.rail-head .btn { margin-left: auto; padding: 5px 8px; }

.client-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.client-item {
  display: block; width: 100%; padding: 9px 11px;
  border: none; border-radius: var(--radius-sm); background: none;
  text-align: left; cursor: pointer;
  transition: background var(--duration) var(--ease);
}
.client-item:hover { background: var(--paper-2); }
.client-item.is-active { background: var(--accent-tint); }
.client-name { display: block; font-weight: 700; font-size: var(--text-sm); }
.client-slug { display: block; font-size: var(--text-micro); color: var(--ink-faint); font-family: var(--mono); }

.admin-editor { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.field-hint { display: block; margin-top: 4px; font-size: var(--text-micro); color: var(--ink-faint); }
.field-hint.code { font-family: var(--mono); overflow-wrap: anywhere; }
.field input[type="color"] { height: 38px; padding: 3px; cursor: pointer; }
.admin-actions { display: flex; justify-content: flex-end; }

.people-list { list-style: none; margin: 0 0 12px; padding: 0; }
.person-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--hair);
}
.person-row:last-child { border-bottom: none; }
.person-main { flex: 1 1 auto; min-width: 0; }
.person-email { display: block; font-weight: 600; font-size: var(--text-sm); overflow-wrap: anywhere; }
.person-meta { display: block; font-size: var(--text-micro); color: var(--ink-faint); }
.invite-row { display: flex; align-items: flex-end; gap: 10px; }
.invite-row .field { flex: 1 1 auto; margin-top: 0; }

/* -------------------------------------------------------- responsive */
@media (max-width: 900px) {
  .admin-layout { grid-template-columns: 1fr; }
  .client-rail { position: static; }
  .client-list { flex-direction: row; flex-wrap: wrap; }
  .client-item { width: auto; }
}

/* Below this the sidebar becomes a row of icons at the bottom — thumb
   reach on a phone, and it stops eating a third of a narrow screen. */
@media (max-width: 760px) {
  .workspace { flex-direction: column-reverse; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    justify-content: space-around;
    padding: 6px 8px;
    border-right: none;
    border-top: 1px solid var(--hair);
  }
  .nav-item { flex-direction: column; gap: 3px; padding: 6px 8px; }
  .nav-label { font-size: var(--text-micro); }
  .contact-figures { display: none; }
}

/* ----------------------------------------------------- agency level
   Montar's own screen. Sits above the clients rather than inside one,
   so it is the only view that does not wear a client's branding. */
.agency-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}
.agency-head h1 {
  font-size: var(--text-h2);
  letter-spacing: -0.035em;
}
.agency-head p {
  margin-top: 3px;
  font-size: var(--text-sm);
  color: var(--ink-faint);
}
.agency-head .btn { margin-left: auto; }

.client-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.client-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration) var(--ease),
              box-shadow var(--duration) var(--ease),
              border-color var(--duration) var(--ease);
}
.client-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
  border-color: var(--hair-2);
}

/* The one client-specific colour on this screen: a left edge in their
   own accent, so a card is recognisable before you read the name. */
.client-card { border-left: 3px solid var(--accent); }
.client-card.needs-attention { border-left-color: var(--action); }

.client-card-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.client-card-logo { height: 24px; width: auto; max-width: 116px; object-fit: contain; flex: none; }
.client-card-dot {
  width: 22px; height: 22px; flex: none;
  border-radius: var(--radius-xs);
  background: var(--accent-tint);
  border: 1px solid var(--accent);
}
.client-card-name { min-width: 0; }
.client-card-title {
  display: block; font-weight: 700; letter-spacing: -0.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.client-card-when { display: block; font-size: var(--text-micro); color: var(--ink-faint); }

.client-card .alert-pill { align-self: flex-start; margin-top: 0; }

.client-card-figures {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--hair);
}
.mini-value {
  display: block; font-size: var(--text-lede); font-weight: 700;
  letter-spacing: -0.02em; font-variant-numeric: tabular-nums;
}
.mini-label {
  display: block; margin-top: 1px;
  font-size: var(--text-micro); letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--ink-faint);
}


/* ------------------------------------------------- client list rows */
.client-line { display: flex; align-items: center; gap: 7px; margin-top: 3px; }

.client-mrr {
  font-size: var(--text-micro);
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

/* Subscription state. Colour is doubled by the label text, so it never
   carries the meaning on its own. */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: var(--text-micro);
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--paper-2);
  color: var(--ink-soft);
}
.pill-active   { background: var(--go-tint);   color: color-mix(in oklab, var(--go) 76%, var(--ink)); }
.pill-trial    { background: var(--accent-tint); color: var(--accent-ink); }
.pill-past_due { background: var(--action-tint); color: color-mix(in oklab, var(--action) 78%, var(--ink)); }
.pill-paused   { background: var(--gold-tint); color: color-mix(in oklab, var(--gold) 76%, var(--ink)); }

/* ------------------------------------------------------ client panel */
.client-summary-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.client-summary-head h2 { font-size: var(--text-lede); letter-spacing: -0.02em; }
.client-summary-head .btn { margin-left: auto; }
.client-summary .client-card-figures { border-top: 1px solid var(--hair); }

/* The way back out of a client's CRM. */
.back-btn { flex: none; margin-right: 2px; }

@media (max-width: 560px) {
  .client-summary-head .btn { margin-left: 0; width: 100%; justify-content: center; }
}

/* ------------------------------------------------------ logo upload */
.logo-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--paper);
  border: 1px dashed var(--hair-2);
  border-radius: var(--radius-sm);
}
.logo-preview-img { max-height: 32px; max-width: 180px; width: auto; object-fit: contain; }
.logo-empty { font-size: var(--text-sm); color: var(--ink-faint); }
.logo-preview .btn { margin-left: auto; }

input[type="file"] { font-size: var(--text-sm); }

/* ---------------------------------------------------- stage editor */
.stage-head,
.stage-row {
  display: grid;
  grid-template-columns: 14px minmax(0, 1.4fr) minmax(0, 1.2fr) minmax(0, 0.7fr) auto;
  align-items: center;
  gap: 8px;
}

.stage-head {
  padding: 0 0 6px 0;
  font-size: var(--text-micro);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.stage-head span:first-child { grid-column: 1 / 3; }

.stage-list { list-style: none; margin: 0; padding: 0; }

.stage-row {
  padding: 6px 0;
  border-bottom: 1px solid var(--hair);
}
.stage-row:last-child { border-bottom: none; }

.stage-row input,
.stage-row select {
  padding: 6px 9px;
  background: var(--paper);
  border: 1px solid var(--hair);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  min-width: 0;
}
.stage-row input:focus, .stage-row select:focus {
  background: var(--card);
  border-color: var(--accent);
}

.stage-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-faint); }
.tone-action .stage-dot  { background: var(--action); }
.tone-trust  .stage-dot  { background: var(--accent); }
.tone-gold   .stage-dot  { background: var(--gold); }
.tone-go     .stage-dot  { background: var(--go); }
.tone-muted  .stage-dot  { background: var(--hair-2); }

.stage-moves { display: flex; gap: 2px; }
.stage-moves .btn { padding: 5px 7px; }
.stage-moves .btn[disabled] { opacity: 0.3; }

@media (max-width: 720px) {
  .stage-head { display: none; }
  .stage-row {
    grid-template-columns: 14px minmax(0, 1fr) auto;
    grid-template-areas: 'dot name moves' '. type type' '. tone tone';
    row-gap: 6px;
    padding: 10px 0;
  }
  .stage-row .stage-dot { grid-area: dot; }
  .stage-row input { grid-area: name; }
  .stage-row select:nth-of-type(1) { grid-area: type; }
  .stage-row select:nth-of-type(2) { grid-area: tone; }
  .stage-moves { grid-area: moves; }
}

/* ==================================================== the deal list
   A sales pipeline of twenty prospects is read down columns — who is
   overdue, what the month is worth, who has gone quiet. So it is a
   table, dense and scannable, not a board. */
.dl-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  padding: 5px 12px;
  border: 1px solid var(--hair);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink-soft);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--duration) var(--ease),
              border-color var(--duration) var(--ease),
              color var(--duration) var(--ease);
}
.chip:hover { border-color: var(--hair-2); color: var(--ink); }
.chip.is-on {
  background: var(--accent-tint);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.chip-alert { color: var(--action); border-color: color-mix(in oklab, var(--action) 35%, transparent); }
.chip-alert.is-on { background: var(--action-tint); border-color: var(--action);
  color: color-mix(in oklab, var(--action) 78%, var(--ink)); }

.dl-search {
  flex: 1 1 220px;
  min-width: 160px;
  padding: 7px 12px;
  background: var(--card);
  border: 1px solid var(--hair);
  border-radius: 999px;
  font-size: var(--text-sm);
}
.dl-search:focus { border-color: var(--accent); }

.deal-list {
  background: var(--card);
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  overflow: hidden;
}

/* One grid definition drives the header and every row, so columns can
   never drift out of alignment with their labels. */
.dl-head,
.dl-row {
  display: grid;
  grid-template-columns: 2fr 1.2fr 1fr 0.8fr 1fr 0.8fr;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
}

.dl-head {
  border-bottom: 1px solid var(--hair);
  background: var(--card-2);
}

.dl-th {
  padding: 10px 0;
  border: none;
  background: none;
  text-align: left;
  font-size: var(--text-micro);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}
.dl-th:hover { color: var(--ink); }
.dl-th.is-sorted { color: var(--ink); }
.dl-th.is-right { justify-content: flex-end; }
.dl-caret { font-size: 0.9em; }

.dl-row {
  width: 100%;
  padding-block: 11px;
  border: none;
  border-bottom: 1px solid var(--hair);
  background: none;
  text-align: left;
  cursor: pointer;
  transition: background var(--duration) var(--ease);
}
.dl-row:last-child { border-bottom: none; }
.dl-row:hover { background: var(--card-2); }

/* An overdue follow-up is the one thing on this screen that should
   catch the eye before you have read anything. */
.dl-row.is-overdue { box-shadow: inset 3px 0 0 var(--action); }

.dl-cell { min-width: 0; font-size: var(--text-sm); overflow: hidden; text-overflow: ellipsis; }
.dl-cell.is-right { text-align: right; }
.dl-muted { color: var(--ink-soft); }
.dl-money { font-weight: 700; font-variant-numeric: tabular-nums; }
.dl-overdue { color: var(--action); font-weight: 600; }

.dl-primary { display: flex; flex-direction: column; gap: 1px; }
.dl-name {
  font-weight: 700;
  letter-spacing: -0.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dl-sub {
  font-size: var(--text-micro);
  color: var(--ink-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.pill-open { background: var(--accent-tint); color: var(--accent-ink); }
.pill-won  { background: var(--go-tint); color: color-mix(in oklab, var(--go) 76%, var(--ink)); }
.pill-lost { background: var(--paper-2); color: var(--ink-faint); }

/* A prospect carries more fields than a lead, so its panel is wider. */
.panel-wide { width: min(520px, 100%); }

/* Below the desktop breakpoint the table becomes stacked cards — a
   six-column grid at 375px is unreadable however it is styled. */
@media (max-width: 860px) {
  .dl-head { display: none; }
  .dl-row {
    grid-template-columns: 1fr auto;
    grid-template-areas: 'name status' 'industry mrr' 'follow days';
    row-gap: 4px;
    padding-block: 14px;
  }
  .dl-row .dl-cell:nth-child(1) { grid-area: name; }
  .dl-row .dl-cell:nth-child(2) { grid-area: industry; }
  .dl-row .dl-cell:nth-child(3) { grid-area: status; justify-self: end; }
  .dl-row .dl-cell:nth-child(4) { grid-area: mrr; }
  .dl-row .dl-cell:nth-child(5) { grid-area: follow; }
  .dl-row .dl-cell:nth-child(6) { grid-area: days; }
}
