/*
 * Console layer.
 *
 * Builds on site.css rather than replacing it, so the console and the public site share one palette
 * and re-theme together when a franchise's branding loads. What changes here is density and
 * intent: the marketing site is read, the console is operated.
 *
 * That means smaller type, tighter spacing, tabular figures wherever numbers align, and colour used
 * to encode state rather than to decorate.
 */

:root {
  --console-nav: 232px;
  --console-gutter: 1.75rem;

  /* Semantic colours, separate from the brand accent. State must not read as branding. */
  --good: #1f7a4d;
  --good-bg: #e6f2ec;
  --warn: #8a6a2a;
  --warn-bg: #f7efdd;
  --bad: #b3261e;
  --bad-bg: #fbeae9;
  --info: #2f6e75;
  --info-bg: #e4eff0;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --good: #5fbf8e;
    --good-bg: #12261d;
    --warn: #d4a94f;
    --warn-bg: #2a2314;
    --bad: #e2756c;
    --bad-bg: #2c1614;
    --info: #6fb3ba;
    --info-bg: #12262a;
  }
}

/* ---------- Shell ---------- */

.console {
  display: grid;
  grid-template-columns: var(--console-nav) 1fr;
  min-height: 100vh;
  background: var(--surface-alt);
}

.console-nav {
  background: var(--brand-primary);
  color: #c3d0da;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.console-brand {
  padding: 1.25rem 1.25rem 1rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: #f3f6f8;
  border-bottom: 1px solid rgb(255 255 255 / 10%);
}

.console-brand span { color: var(--brand-accent); }

.console-nav-group {
  padding: 1rem 0.75rem 0.25rem;
}

.console-nav-label {
  padding: 0 0.5rem 0.4rem;
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #7d94a4;
}

.console-nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  color: #c3d0da;
  text-decoration: none;
  font-size: 0.9rem;
  transition: background var(--transition), color var(--transition);
}

.console-nav a:hover { background: rgb(255 255 255 / 7%); color: #fff; }

/* A left rail rather than a filled block: the active item should be unambiguous without
   competing with the accent used for actions. */
.console-nav a[aria-current="page"] {
  background: rgb(255 255 255 / 10%);
  color: #fff;
  box-shadow: inset 2px 0 0 var(--brand-accent);
}

.console-nav .count {
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  background: var(--brand-accent);
  color: #14202b;
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
  font-weight: 600;
}

.console-user {
  margin-top: auto;
  padding: 1rem 1.25rem;
  border-top: 1px solid rgb(255 255 255 / 10%);
  font-size: 0.82rem;
}

.console-user .name { color: #f3f6f8; display: block; }
.console-user .role { color: #7d94a4; font-size: 0.74rem; }

.console-main {
  padding: 1.5rem var(--console-gutter) 4rem;
  max-width: 1400px;
}

/* ---------- Page furniture ---------- */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.page-header h1 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  margin: 0;
}

.page-sub {
  margin: 0.25rem 0 0;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.page-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.card-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  margin: 0 0 1rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
  align-items: start;
}

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th {
  text-align: start;
  padding: 0.5rem 0.75rem;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
}

.data-table td {
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid var(--hairline);
  vertical-align: middle;
}

.data-table [data-align="end"] {
  text-align: end;

  /* Money and counts line up in their columns. Without this a list of totals is unreadable. */
  font-variant-numeric: tabular-nums;
}

.data-table [data-align="center"] { text-align: center; }

.data-table tbody tr:last-child td { border-bottom: 0; }

.data-table tr.is-clickable { cursor: pointer; }
.data-table tr.is-clickable:hover td { background: var(--surface-alt); }
.data-table tr.is-clickable:focus-visible { outline: 2px solid var(--brand-accent); outline-offset: -2px; }

.data-table .primary { font-weight: 600; }
.data-table .muted { color: var(--ink-muted); font-size: 0.82rem; }

/* ---------- Pills ---------- */

.pill {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
  background: var(--surface-alt);
  color: var(--ink-muted);
  border: 1px solid var(--hairline);
}

.pill[data-tone="good"] { background: var(--good-bg); color: var(--good); border-color: transparent; }
.pill[data-tone="warn"] { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.pill[data-tone="bad"]  { background: var(--bad-bg);  color: var(--bad);  border-color: transparent; }
.pill[data-tone="info"] { background: var(--info-bg); color: var(--info); border-color: transparent; }

/* ---------- Fields ---------- */

.field-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem 1.5rem;
  margin: 0;
}

.field dt {
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 0.15rem;
}

.field dd { margin: 0; font-size: 0.92rem; }

/* ---------- Stats ---------- */

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px;
  background: var(--hairline);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1.25rem;
}

.stat {
  background: var(--surface);
  padding: 1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.stat-label {
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.stat-value {
  font-family: var(--font-display);
  font-size: 1.6rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat-note { font-size: 0.76rem; color: var(--ink-muted); }

/* ---------- Empty and error states ---------- */

.empty {
  border: 1px dashed var(--hairline);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--ink-muted);
  background: var(--surface);
}

.empty p { margin: 0 0 0.75rem; }
.empty p:last-child { margin-bottom: 0; }
.empty.is-error { border-color: var(--bad); border-style: solid; }
.empty-detail { font-size: 0.82rem; font-family: ui-monospace, monospace; }

/* ---------- Calendar ---------- */

.calendar {
  display: grid;
  grid-template-columns: 3.5rem repeat(7, minmax(0, 1fr));
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.calendar-head {
  padding: 0.6rem 0.5rem;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  text-align: center;
  border-bottom: 1px solid var(--hairline);
  background: var(--surface-alt);
}

.calendar-head[data-today="true"] { color: var(--brand-accent); font-weight: 700; }

.calendar-hour {
  font-size: 0.68rem;
  color: var(--ink-muted);
  text-align: end;
  padding: 0 0.4rem;
  border-right: 1px solid var(--hairline);

  /* Aligned with the top gridline rather than centred in the row: an event at 09:00 should sit
     level with the 09 label, which is how anyone reads a diary. */
  transform: translateY(-0.5em);
}

.calendar-cell {
  border-right: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
  min-height: 2.75rem;
  padding: 2px;
}

.calendar-cell:nth-child(8n + 1) { border-right: 0; }

.calendar-event {
  display: block;
  width: 100%;
  text-align: start;
  background: var(--info-bg);
  color: var(--info);
  border-left: 3px solid var(--info);
  border-radius: 2px;
  padding: 0.2rem 0.35rem;
  font-size: 0.72rem;
  line-height: 1.25;
  margin-bottom: 2px;
  cursor: pointer;
  border-top: 0;
  border-right: 0;
  border-bottom: 0;
}

.calendar-event[data-kind="Consult"] {
  background: var(--warn-bg);
  color: var(--warn);
  border-left-color: var(--warn);
}

.calendar-event strong { display: block; font-weight: 600; }

/* ---------- Quote builder ---------- */

.builder {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1.25rem;
  align-items: start;
}

.builder-total {
  position: sticky;
  top: 1.5rem;
}

.total-row {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.total-row.is-grand {
  border-top: 1px solid var(--hairline);
  margin-top: 0.4rem;
  padding-top: 0.7rem;
  font-family: var(--font-display);
  font-size: 1.3rem;
}

/* ---------- Message thread ---------- */

.thread {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.message {
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  background: var(--surface);
  max-width: 42rem;
}

.message.is-mine { align-self: flex-end; background: var(--info-bg); border-color: transparent; }

/* Internal notes look different on purpose. Staff must be able to tell at a glance what the
   client can see, because the cost of getting that wrong is a client reading a margin discussion. */
.message.is-internal {
  background: var(--warn-bg);
  border-color: var(--warn);
  border-style: dashed;
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.72rem;
  color: var(--ink-muted);
  margin-bottom: 0.3rem;
}

.message-body { font-size: 0.9rem; white-space: pre-wrap; margin: 0; }

/* ---------- Forms ---------- */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.console label.form-label {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 0.25rem;
}

.console .form-control,
.console .form-select {
  background: var(--surface);
  border: 1px solid var(--hairline);
  color: var(--ink);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.console .form-control:focus,
.console .form-select:focus {
  border-color: var(--brand-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-accent) 22%, transparent);
}

/* ---------- Toast ---------- */

.toast-stack {
  position: fixed;
  bottom: 1.25rem;
  inset-inline-end: 1.25rem;
  z-index: 1080;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 24rem;
}

.toast-item {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--info);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.88rem;
  box-shadow: 0 6px 24px rgb(0 0 0 / 12%);
}

.toast-item[data-tone="good"] { border-left-color: var(--good); }
.toast-item[data-tone="bad"] { border-left-color: var(--bad); }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .console { grid-template-columns: 1fr; }

  .console-nav {
    position: static;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    align-items: center;
  }

  .console-nav-group { display: flex; gap: 0.25rem; padding: 0.5rem; }
  .console-nav-label, .console-user { display: none; }
  .console-main { padding: 1rem; }
  .builder { grid-template-columns: 1fr; }
  .builder-total { position: static; }
}

@media (prefers-reduced-motion: reduce) {
  .console-nav a { transition: none; }
}

/*
 * The console's top strip.
 *
 * A class rather than an inline style override on .shell: the Content-Security-Policy has no
 * unsafe-inline, so a style attribute here is dropped by the browser and the header silently keeps
 * the marketing site's reading width.
 */
.console-header {
  padding-inline: 1.5rem;
}

/* ---------- Onboarding wizard ---------- */

/*
 * The step indicator. Shared shape with the portal's job tracker on purpose: both answer "where in
 * this are we", and a reader who has seen one recognises the other.
 */
.tracker {
  display: flex;
  gap: 0.25rem;
  margin: 0 0 1.5rem;
  padding: 0;
  list-style: none;
}

.tracker li {
  flex: 1;
  font-size: 0.74rem;
  color: var(--ink-muted);
  text-align: center;
  padding-top: 0.55rem;
  border-top: 3px solid var(--hairline);
}

.tracker li[data-state="done"] {
  color: var(--ink);
  border-top-color: var(--good);
}

.tracker li[data-state="current"] {
  color: var(--ink);
  font-weight: 700;
  border-top-color: var(--brand-accent);
}

/*
 * The hand-over blocks: a Stripe link and a temporary password, each shown exactly once. Marked
 * out from the surrounding form so an operator scanning the page cannot miss the thing they will
 * not be shown again.
 */
.handover {
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--brand-accent);
  border-radius: var(--radius);
  background: var(--surface-alt);
  padding: 1rem;
  margin-bottom: 1.25rem;
}

.handover h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  margin: 0 0 0.5rem;
}

.handover p { font-size: 0.88rem; }

.handover input {
  font-family: ui-monospace, "SFMono-Regular", "Consolas", monospace;
  font-size: 0.9rem;
}

.handover-list {
  margin: 0;
  padding-left: 1.15rem;
  display: grid;
  gap: 0.4rem;
  font-size: 0.92rem;
}
