/* Brand It Midlands CRM
   ---------------------------------------------------------------------------
   Palette is four inks: the brand teal off the logo, plus magenta, yellow and
   key. Teal leads because it's the brand colour and digital is the biggest
   revenue line, and every job ticket carries a spine in the ink of its
   discipline so the board reads by colour.

   Type is one family at two widths. Archivo stretched wide for display and set
   normal for body: one voice, different substrates. Refs and money sit in the
   system monospace so figures line up in a column.
   --------------------------------------------------------------------------- */

@font-face {
  font-family: "Archivo";
  src: url("../fonts/archivo.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
}

:root {
  --ink: #12161c;
  --ink-2: #39424e;
  --muted: #6b7683;
  --faint: #99a3af;
  --substrate: #eef1f5;
  --card: #ffffff;
  --rule: #dde3ea;
  --rule-strong: #c6cfd9;

  /* Straight off the logo artwork. --brand is the mark colour; --brand-text is
     a shade down so links and small text clear AA contrast on white. */
  --brand: #008a82;
  --brand-text: #00736c;
  --brand-tint: #7fd0c9;
  --magenta: #b62f74;
  --yellow: #c98a06;
  --key: #2a313b;

  --green: #14764a;
  --green-bg: #e4f3ec;
  --red: #bb3626;
  --red-bg: #fbe9e6;
  --amber-bg: #fdf2dc;

  --sans: "Archivo", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --rail-w: 13.5rem;
  --gap: 1.125rem;
  --radius: 3px;

  --shadow-1: 0 1px 2px rgb(18 22 28 / 0.06), 0 1px 1px rgb(18 22 28 / 0.04);
  --shadow-2: 0 4px 16px rgb(18 22 28 / 0.1);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--substrate);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.9375rem;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-text); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 2px;
}

h1, h2, h3, h4 {
  margin: 0;
  font-stretch: 112%;
  font-weight: 700;
  letter-spacing: -0.012em;
  line-height: 1.15;
}
h1 { font-size: 1.5rem; }
h2 { font-size: 1.0625rem; }
h3 { font-size: 0.9375rem; }

p { margin: 0 0 0.75rem; }
p:last-child { margin-bottom: 0; }

/* Small uppercase label. Used for every field name and column head, so the
   interface has one consistent way of naming a thing. */
.label {
  display: block;
  font-size: 0.6875rem;
  font-stretch: 108%;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 0.8125rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.stack { display: grid; gap: 0.375rem; }
.row-flex { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.spacer { flex: 1 1 auto; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* --- Shell ---------------------------------------------------------------- */

.shell { display: flex; min-height: 100vh; }

.rail {
  position: sticky;
  top: 0;
  flex: 0 0 var(--rail-w);
  width: var(--rail-w);
  height: 100vh;
  background: var(--ink);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 1.125rem 0.75rem;
  gap: 1.25rem;
}

.brand { display: block; padding: 0.125rem 0.375rem 0; }
.brand img { display: block; width: 100%; max-width: 10.5rem; height: auto; }
.brand-sub {
  display: block; margin-top: 0.3125rem;
  font-size: 0.625rem; font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--faint);
}

.rail-nav { display: grid; gap: 1px; }
.rail-nav a {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.625rem;
  color: #c3cbd5;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
}
.rail-nav a:hover { background: rgb(255 255 255 / 0.07); color: #fff; text-decoration: none; }
.rail-nav a[aria-current="page"] { background: rgb(255 255 255 / 0.11); color: #fff; font-weight: 600; }
.rail-nav a[aria-current="page"] .dot { background: var(--brand); }
.rail-nav .dot {
  width: 5px; height: 5px; border-radius: 50%; background: #59636f; flex: none;
}
.rail-nav .count {
  margin-left: auto; font-family: var(--mono); font-size: 0.6875rem; color: var(--faint);
}

.rail-foot { margin-top: auto; display: grid; gap: 0.5rem; padding: 0 0.375rem; }
.rail-user { font-size: 0.75rem; color: var(--faint); line-height: 1.35; }
.rail-user strong { display: block; color: #fff; font-size: 0.8125rem; font-weight: 600; }
.rail-foot button {
  background: none; border: 1px solid rgb(255 255 255 / 0.18); color: #c3cbd5;
  padding: 0.3125rem 0.5rem; border-radius: var(--radius); font: inherit;
  font-size: 0.75rem; cursor: pointer; text-align: left;
}
.rail-foot button:hover { background: rgb(255 255 255 / 0.08); color: #fff; }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: var(--gap);
  padding: 0.75rem var(--gap);
  background: var(--card);
  border-bottom: 1px solid var(--rule);
  position: sticky; top: 0; z-index: 20;
}
.topbar form { flex: 1 1 22rem; max-width: 30rem; }
.topbar input[type="search"] { width: 100%; }

.content { padding: var(--gap); display: grid; gap: var(--gap); align-content: start; }

.page-head { display: flex; align-items: flex-end; gap: var(--gap); flex-wrap: wrap; }
.page-head .label { margin-bottom: 0.25rem; }

/* --- Flash ---------------------------------------------------------------- */

.flash {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.625rem 0.875rem;
  background: var(--ink); color: #fff;
  border-radius: var(--radius);
  font-size: 0.875rem;
  box-shadow: var(--shadow-1);
}
.flash i { width: 4px; align-self: stretch; background: var(--brand); border-radius: 2px; }

/* --- Money band ----------------------------------------------------------- */
/* The headline figures sit in one ruled band rather than separate cards, so
   they read as a single sentence about the business. */

.band {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(11rem, 100%), 1fr));
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}
.band > div {
  padding: 0.875rem 1.125rem;
  border-right: 1px solid var(--rule);
  display: grid;
  gap: 0.125rem;
  align-content: start;
}
.band > div:last-child { border-right: 0; }
.band .figure {
  font-stretch: 118%;
  font-weight: 700;
  font-size: clamp(1.375rem, 2.6vw, 1.875rem);
  letter-spacing: -0.02em;
  line-height: 1.05;
}
.band .sub { font-size: 0.75rem; color: var(--muted); }
.band .figure.is-red { color: var(--red); }
.band .figure.is-green { color: var(--green); }

/* --- Panels --------------------------------------------------------------- */

.grid { display: grid; gap: var(--gap); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(21rem, 100%), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(15rem, 100%), 1fr)); }
.grid-wide { grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); }
@media (max-width: 68rem) { .grid-wide { grid-template-columns: minmax(0, 1fr); } }

.panel {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  min-width: 0;
}
.panel-head {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--rule);
}
.panel-head h2 { flex: 1 1 auto; min-width: 0; }
.panel-body { padding: 1rem; }
.panel-body.flush { padding: 0; }
.panel-foot {
  padding: 0.625rem 1rem; border-top: 1px solid var(--rule); background: #f8fafb;
  font-size: 0.8125rem;
}

.empty {
  padding: 1.5rem 1rem; text-align: center; color: var(--muted); font-size: 0.875rem;
}
.empty strong { display: block; color: var(--ink); font-weight: 600; margin-bottom: 0.25rem; }

/* --- Tables --------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
  text-align: left; padding: 0.5rem 1rem;
  font-size: 0.6875rem; font-stretch: 108%; font-weight: 600;
  letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--rule); white-space: nowrap;
  background: #f8fafb;
}
tbody td { padding: 0.5625rem 1rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fafb; }
td.num, th.num { text-align: right; font-family: var(--mono); white-space: nowrap; }
td .sub { display: block; font-size: 0.75rem; color: var(--muted); }

/* --- Chips ---------------------------------------------------------------- */

.chip {
  display: inline-flex; align-items: center; gap: 0.3125rem;
  padding: 0.125rem 0.4375rem;
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  font-size: 0.6875rem; font-weight: 600; font-stretch: 105%;
  letter-spacing: 0.02em; white-space: nowrap; color: var(--ink-2);
  background: #fff;
}
.chip::before {
  content: ""; width: 6px; height: 6px; border-radius: 1px; background: var(--faint);
}
.chip[data-ink="teal"]::before { background: var(--brand); }
.chip[data-ink="magenta"]::before { background: var(--magenta); }
.chip[data-ink="yellow"]::before { background: #e0a008; }
.chip[data-ink="key"]::before { background: var(--key); }

.chip[data-state="paid"] { background: var(--green-bg); border-color: #b9dfcc; color: var(--green); }
.chip[data-state="paid"]::before { background: var(--green); }
.chip[data-state="sent"] { background: var(--amber-bg); border-color: #eed9a8; color: #8a6410; }
.chip[data-state="sent"]::before { background: #c98a06; }
.chip[data-state="overdue"] { background: var(--red-bg); border-color: #f0c4bd; color: var(--red); }
.chip[data-state="overdue"]::before { background: var(--red); }
.chip[data-state="draft"]::before { background: var(--faint); }
.chip[data-state="void"] { color: var(--muted); text-decoration: line-through; }
.chip[data-state="lost"] { color: var(--muted); }

/* --- Buttons -------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.375rem;
  padding: 0.4375rem 0.8125rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: #fff; color: var(--ink);
  font: inherit; font-size: 0.8125rem; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f3f6f8; text-decoration: none; border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #232b35; border-color: #232b35; }
.btn-danger { color: var(--red); border-color: #e8bdb6; background: #fff; }
.btn-danger:hover { background: var(--red-bg); border-color: var(--red); }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
.btn-link {
  background: none; border: 0; padding: 0; color: var(--brand-text);
  font: inherit; font-size: 0.8125rem; cursor: pointer; text-decoration: underline;
}
.btn-link.danger { color: var(--red); }

/* --- Forms ---------------------------------------------------------------- */

.field { display: grid; gap: 0.25rem; min-width: 0; }
.field-row {
  display: grid; gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(min(11rem, 100%), 1fr));
}

input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="date"], input[type="number"], input[type="url"], input[type="tel"],
select, textarea {
  width: 100%;
  padding: 0.4375rem 0.5625rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 0.875rem;
}
textarea { resize: vertical; min-height: 4.5rem; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgb(0 138 130 / 0.16);
}
input[type="file"] { font-size: 0.8125rem; }
.check { display: flex; align-items: center; gap: 0.4375rem; font-size: 0.875rem; }
.check input { width: auto; margin: 0; }

.money-input { position: relative; }
.money-input input { padding-left: 1.5rem; font-family: var(--mono); }
.money-input::before {
  content: "£"; position: absolute; left: 0.5625rem; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-family: var(--mono); font-size: 0.875rem; pointer-events: none;
}

.form-actions {
  display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap;
  margin-top: 0.875rem;
}

/* Disclosure form that drops out of a panel head */
details.adder { border-top: 1px solid var(--rule); }
details.adder > summary {
  list-style: none; cursor: pointer; padding: 0.625rem 1rem;
  font-size: 0.8125rem; font-weight: 600; color: var(--brand-text);
  display: flex; align-items: center; gap: 0.375rem;
}
details.adder > summary::-webkit-details-marker { display: none; }
details.adder > summary::before { content: "+"; font-size: 1rem; line-height: 1; }
details.adder[open] > summary { border-bottom: 1px solid var(--rule); }
details.adder[open] > summary::before { content: "\2212"; }
details.adder .adder-body { padding: 1rem; background: #f8fafb; }

/* --- Job ticket ----------------------------------------------------------- */
/* The signature element. A ticket carries the docket ref in mono, the client
   in wide type, and a spine in the ink of its discipline. */

.ticket {
  --spine: var(--faint);
  position: relative;
  display: block;
  background: var(--card);
  border: 1px solid var(--rule);
  border-left: 4px solid var(--spine);
  border-radius: 2px;
  padding: 0.625rem 0.75rem;
  color: inherit;
  box-shadow: var(--shadow-1);
}
.ticket:hover { text-decoration: none; border-color: var(--rule-strong); border-left-color: var(--spine); box-shadow: var(--shadow-2); }
.ticket[data-ink="teal"] { --spine: var(--brand); }
.ticket[data-ink="magenta"] { --spine: var(--magenta); }
.ticket[data-ink="yellow"] { --spine: #e0a008; }
.ticket[data-ink="key"] { --spine: var(--key); }

.ticket-top {
  display: flex; align-items: baseline; gap: 0.5rem; margin-bottom: 0.1875rem;
}
.ticket-ref {
  font-family: var(--mono); font-size: 0.6875rem; color: var(--muted); letter-spacing: 0.02em;
}
.ticket-value {
  margin-left: auto; font-family: var(--mono); font-size: 0.8125rem; font-weight: 600;
}
.ticket-client {
  font-stretch: 112%; font-weight: 700; font-size: 0.875rem; line-height: 1.2;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ticket-title {
  font-size: 0.8125rem; color: var(--ink-2); line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.ticket-foot {
  display: flex; align-items: center; gap: 0.375rem; margin-top: 0.4375rem;
  font-size: 0.6875rem; color: var(--muted);
}
.ticket-foot .due.late { color: var(--red); font-weight: 600; }
.ticket.dragging { opacity: 0.4; }

/* --- Board ---------------------------------------------------------------- */

.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(15.5rem, 1fr);
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  align-items: start;
}
.board-col {
  background: #e5e9ef;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  display: flex; flex-direction: column; min-height: 7rem;
}
.board-col-head {
  display: flex; align-items: baseline; gap: 0.5rem;
  padding: 0.5rem 0.625rem;
  border-bottom: 1px solid var(--rule);
}
.board-col-head .label { flex: 1 1 auto; }
.board-col-head .n { font-family: var(--mono); font-size: 0.6875rem; color: var(--muted); }
.board-col-total {
  padding: 0.375rem 0.625rem; border-top: 1px solid var(--rule);
  font-family: var(--mono); font-size: 0.75rem; color: var(--ink-2); text-align: right;
}
.board-drop { padding: 0.5rem; display: grid; gap: 0.5rem; flex: 1 1 auto; min-height: 3rem; }
.board-drop.over { background: rgb(0 138 130 / 0.10); outline: 2px dashed var(--brand); outline-offset: -4px; }
.board-empty { color: var(--muted); font-size: 0.75rem; text-align: center; padding: 0.75rem 0; }

/* --- Week diary ----------------------------------------------------------- */
/* Seven columns on a desk, a single stack on a phone. Deliberately not a
   time-grid: fittings and installs are day-scale work, not 15 minute slots. */

.week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}
.day { background: var(--card); display: flex; flex-direction: column; min-height: 9rem; }
.day.is-today { background: #f4fbfa; }
.day-head {
  display: flex; align-items: baseline; gap: 0.375rem;
  padding: 0.5rem 0.625rem; border-bottom: 1px solid var(--rule);
}
.day-name {
  font-size: 0.6875rem; font-stretch: 108%; font-weight: 600;
  letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted);
}
.day-num { font-family: var(--mono); font-size: 0.875rem; font-weight: 600; }
.day.is-today .day-num { color: var(--brand-text); }
.day-body { padding: 0.5rem; display: grid; gap: 0.5rem; align-content: start; }
.day-empty { color: var(--faint); font-size: 0.75rem; text-align: center; padding: 0.5rem 0; margin: 0; }

.entry {
  display: block; color: inherit;
  border-left: 3px solid var(--key);
  background: #f8fafb;
  border-radius: 2px;
  padding: 0.4375rem 0.5rem;
}
.entry:hover { text-decoration: none; background: #f1f5f6; }
.entry[data-kind="fitting"], .entry[data-kind="install"] { border-left-color: #e0a008; }
.entry[data-kind="site_visit"] { border-left-color: var(--magenta); }
.entry[data-kind="meeting"], .entry[data-kind="call"] { border-left-color: var(--brand); }
.entry[data-kind="deadline"] { border-left-color: var(--red); }
.entry.is-google { border-left-color: var(--faint); border-left-style: dashed; }
.entry.is-due { border-left-color: var(--red); background: var(--red-bg); }
.entry-time { font-family: var(--mono); font-size: 0.6875rem; color: var(--muted); }
.entry-title { font-size: 0.8125rem; font-weight: 600; line-height: 1.25; }
.entry-meta { font-size: 0.6875rem; color: var(--muted); line-height: 1.3; }

/* The spoken brief, shown as it will be read out. */
.script {
  font-size: 1.0625rem; line-height: 1.6; max-width: 60ch;
  border-left: 3px solid var(--brand); padding-left: 0.875rem;
}

@media (max-width: 60rem) {
  .week { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 40rem) {
  .week { grid-template-columns: minmax(0, 1fr); }
  .day { min-height: 0; }
}

/* --- Charts --------------------------------------------------------------- */

.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--rule); stroke-width: 1; }
.chart .zero-line { stroke: var(--rule-strong); stroke-width: 1; }
.chart .bar-income { fill: var(--brand); }
.chart .bar-costs { fill: #b9c3ce; }
.chart .bar-recurring { fill: var(--brand); }
.chart .bar-pipeline { fill: var(--brand-tint); }
.chart .axis-text { font-family: var(--mono); font-size: 9px; fill: var(--muted); }
.chart .profit-line { fill: none; stroke: var(--magenta); stroke-width: 2; }
.chart .profit-dot { fill: var(--magenta); }

.legend { display: flex; gap: 0.875rem; flex-wrap: wrap; font-size: 0.75rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 0.3125rem; }
.legend i { width: 9px; height: 9px; border-radius: 1px; display: block; }

/* Horizontal share bars, used for revenue by discipline */
.share { display: grid; gap: 0.5rem; }
.share-row { display: grid; grid-template-columns: 1fr auto; gap: 0.25rem 0.75rem; align-items: baseline; }
.share-name { font-size: 0.8125rem; }
.share-val { font-family: var(--mono); font-size: 0.8125rem; }
.share-track { grid-column: 1 / -1; height: 6px; background: #e5e9ef; border-radius: 1px; overflow: hidden; }
.share-fill { height: 100%; display: block; background: var(--faint); }
.share-fill[data-ink="teal"] { background: var(--brand); }
.share-fill[data-ink="magenta"] { background: var(--magenta); }
.share-fill[data-ink="yellow"] { background: #e0a008; }
.share-fill[data-ink="key"] { background: var(--key); }

/* --- Login ---------------------------------------------------------------- */

.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background: var(--ink);
  background-image:
    linear-gradient(115deg, rgb(0 138 130 / 0.30), transparent 42%),
    linear-gradient(300deg, rgb(182 47 116 / 0.16), transparent 46%);
}
.login-card {
  width: min(24rem, 100%);
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: 0 18px 48px rgb(0 0 0 / 0.4);
}
.login-card .brand { padding: 0; margin-bottom: 1.5rem; }
.login-card .brand img { max-width: 15rem; }
.login-card .brand-sub { color: var(--muted); margin-top: 0.5rem; }
.login-card h1 { font-size: 1.25rem; margin-bottom: 0.25rem; }
/* The rotating line. It changes on every visit, so give it a fixed two lines of
   room and the card stops jumping about between loads. */
.login-card .lede {
  color: var(--ink-2); font-size: 0.875rem; margin-bottom: 1.25rem;
  min-height: 2.6em;
}
.login-card .field { margin-bottom: 0.875rem; }
.login-card .btn { width: 100%; padding: 0.5625rem; font-size: 0.875rem; }
.login-error {
  background: var(--red-bg); border: 1px solid #f0c4bd; color: var(--red);
  padding: 0.5rem 0.6875rem; border-radius: var(--radius);
  font-size: 0.8125rem; margin-bottom: 0.875rem;
}
.login-foot { margin-top: 1.25rem; font-size: 0.75rem; color: var(--faint); text-align: center; }

/* --- Detail layout -------------------------------------------------------- */

.detail-head {
  background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius);
  border-left: 4px solid var(--spine, var(--brand));
  padding: 1rem 1.125rem;
  display: flex; gap: var(--gap); flex-wrap: wrap; align-items: flex-start;
}
.detail-head[data-ink="teal"] { --spine: var(--brand); }
.detail-head[data-ink="magenta"] { --spine: var(--magenta); }
.detail-head[data-ink="yellow"] { --spine: #e0a008; }
.detail-head[data-ink="key"] { --spine: var(--key); }
.detail-head .headline { flex: 1 1 18rem; min-width: 0; }
.detail-head h1 { font-size: 1.375rem; margin-bottom: 0.25rem; }
.detail-figures { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.detail-figures .figure {
  font-family: var(--mono); font-size: 1.0625rem; font-weight: 600;
}

.stage-bar { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.stage-bar button {
  border: 1px solid var(--rule-strong); background: #fff; color: var(--ink-2);
  padding: 0.3125rem 0.5625rem; border-radius: var(--radius);
  font: inherit; font-size: 0.75rem; font-weight: 600; cursor: pointer;
}
.stage-bar button:hover { border-color: var(--muted); background: #f3f6f8; }
.stage-bar button[aria-pressed="true"] {
  background: var(--ink); border-color: var(--ink); color: #fff;
}

.timeline { display: grid; gap: 0; }
.timeline-item {
  display: grid; grid-template-columns: auto 1fr; gap: 0.75rem;
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--rule);
}
.timeline-item:last-child { border-bottom: 0; }
.timeline-mark {
  width: 6px; border-radius: 3px; background: var(--rule-strong); min-height: 100%;
}
.timeline-item[data-kind="call"] .timeline-mark { background: var(--brand); }
.timeline-item[data-kind="email"] .timeline-mark { background: var(--magenta); }
.timeline-item[data-kind="meeting"] .timeline-mark { background: #e0a008; }
.timeline-item[data-kind="site_visit"] .timeline-mark { background: var(--key); }
.timeline-body p { font-size: 0.875rem; white-space: pre-wrap; }
.timeline-meta { font-size: 0.75rem; color: var(--muted); margin-bottom: 0.1875rem; }

.file-row {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.5625rem 1rem; border-bottom: 1px solid var(--rule);
}
.file-row:last-child { border-bottom: 0; }
.file-ext {
  flex: none; width: 2.25rem; height: 2.25rem; display: grid; place-items: center;
  background: #eef1f5; border: 1px solid var(--rule); border-radius: 2px;
  font-family: var(--mono); font-size: 0.625rem; font-weight: 600; color: var(--ink-2);
  text-transform: uppercase;
}
.file-main { flex: 1 1 auto; min-width: 0; }
.file-name {
  font-size: 0.875rem; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-meta { font-size: 0.75rem; color: var(--muted); }

.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--rule); flex-wrap: wrap; }
.tabs a {
  padding: 0.4375rem 0.75rem; font-size: 0.8125rem; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--brand); }

.inline-form { display: inline; }

/* --- Responsive ----------------------------------------------------------- */

@media (max-width: 60rem) {
  .shell { flex-direction: column; }
  .rail {
    position: static; width: 100%; height: auto; flex: none;
    flex-direction: row; align-items: center; flex-wrap: wrap;
    padding: 0.625rem 0.75rem; gap: 0.75rem;
  }
  .rail-nav {
    grid-auto-flow: column; grid-auto-columns: max-content;
    overflow-x: auto; flex: 1 1 100%; gap: 0.25rem;
  }
  .rail-nav .count { display: none; }
  .rail-foot { margin: 0 0 0 auto; grid-auto-flow: column; align-items: center; gap: 0.75rem; }
  .topbar { position: static; }
  .band > div { border-right: 0; border-bottom: 1px solid var(--rule); }
}

@media (max-width: 40rem) {
  :root { --gap: 0.875rem; }
  .content { padding: 0.875rem; }
  .detail-head { padding: 0.875rem; }
  .panel-body { padding: 0.875rem; }
  thead th, tbody td { padding-left: 0.625rem; padding-right: 0.625rem; }
  .board { grid-auto-columns: minmax(14rem, 85vw); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .btn:active { transform: none; }
}

@media print {
  .rail, .topbar, .form-actions, details.adder { display: none; }
  body { background: #fff; }
  .panel { break-inside: avoid; }
}
