/* The Console's stylesheet — one file, served same-origin (`style-src
   'self'`, security.py), mobile-first because the audience is sole traders
   on phones in carparks (spec §3.1). Issue 27 dressed it in the owner's
   visual language: the navy (#101828 — already the theme colour), light
   cards on a pale ground, status chips, and the app navigation that is a
   bottom tab bar on a phone and the same markup as a sidebar on a wide
   viewport. The design study ("TorqueDesk Restyle", 2026-08-23) is the
   reference for layout and palette — not a pixel contract. */

:root {
  --navy: #101828;
  --ink: #101828;
  --paper: #ffffff;
  --ground: #f4f6fa;
  --edge: #e2e7ef;
  --body: #4a5468;
  --muted: #6a7386;
  --accent: #2b59c3;
  --accent-soft: #eef2fa;
  --good: #137a4c;
  --good-soft: #e3f2ea;
  --good-deep: #116a43;
  --warn: #a05a08;
  --bad: #b02a34;
  --bad-soft: #fdf1f2;
  --bad-edge: #f0cdd0;
  --bad-chip: #fbe4e6;
  --bad-deep: #a12630;
  --mute-chip: #eceff4;
  --mute-deep: #5b6472;
  --bar-other: #93a0b4;
  --rule: #edf0f5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--ground);
  line-height: 1.5;
}

main {
  max-width: 40rem;
  margin: 0 auto;
  padding: 1.5rem 1rem 2rem;
}

/* The signed-in app leaves room for the fixed tab bar. */
body.app main {
  padding-bottom: 5.5rem;
}

h1 {
  font-size: 1.4rem;
  margin: 0 0 0.75rem;
  letter-spacing: -0.01em;
}

p {
  margin: 0 0 1rem;
  color: var(--body);
}

h2 {
  font-size: 1.1rem;
  margin: 2rem 0 0.5rem;
}

a {
  color: var(--accent);
}

/* ---- The app navigation (issue 27): one markup, two compositions ---- */

.tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--navy);
  padding: 0.5rem 0.4rem 0.65rem;
}

.tabs .brand {
  display: none;
}

.tabs a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.68rem;
  color: #8b94a8;
  text-decoration: none;
}

.tabs a[aria-current="page"] {
  color: var(--paper);
  font-weight: 600;
}

.tabs svg {
  width: 1.2rem;
  height: 1.2rem;
}

@media (min-width: 56rem) {
  body.app {
    display: grid;
    grid-template-columns: 13.5rem minmax(0, 1fr);
    min-height: 100vh;
  }

  body.app main {
    padding: 1.75rem 1.5rem 2rem;
    width: 100%;
  }

  .tabs {
    position: sticky;
    top: 0;
    align-self: start;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 1.25rem 0.8rem;
  }

  .tabs .brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--paper);
    font-weight: 700;
    font-size: 1rem;
    padding: 0 0.5rem 1rem;
  }

  .tabs .brand img {
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 0.6rem;
    display: block;
  }

  .tabs a {
    flex-direction: row;
    justify-content: flex-start;
    gap: 0.6rem;
    font-size: 0.85rem;
    padding: 0.5rem 0.6rem;
    border-radius: 0.5rem;
  }

  .tabs a[aria-current="page"] {
    background: var(--accent);
    color: var(--paper);
  }

  .tabs svg {
    width: 1rem;
    height: 1rem;
  }
}

/* ---- Screen head: title + the windows pill on one line ---- */

.screen-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.9rem;
}

.screen-head h1 {
  margin: 0;
}

/* ---- The windows menu (issue 27 §4): a details dropdown, no JS ---- */

details.windows {
  position: relative;
}

details.windows summary {
  list-style: none;
  cursor: pointer;
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: 0.5rem;
  padding: 0.25rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--body);
  white-space: nowrap;
}

details.windows summary::-webkit-details-marker {
  display: none;
}

details.windows summary::after {
  content: " ▾";
  color: var(--muted);
  font-size: 0.7rem;
}

.window-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  z-index: 20;
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: 0.65rem;
  box-shadow: 0 12px 26px rgba(16, 24, 40, 0.16);
  padding: 0.4rem;
  min-width: 10.5rem;
  max-height: 60vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.window-menu-title {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0.1rem 0.5rem 0.3rem;
}

.window-menu a {
  font-size: 0.85rem;
  padding: 0.35rem 0.6rem;
  border-radius: 0.4rem;
  color: var(--body);
  text-decoration: none;
  white-space: nowrap;
}

.window-menu a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--ink);
  font-weight: 600;
}

.window-menu hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 0.25rem 0.2rem;
}

/* ---- The three counts ---- */

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin: 0 0 0.9rem;
}

.stat {
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: 0.65rem;
  padding: 0.6rem 0.4rem 0.55rem;
  text-align: center;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
}

.stat-n {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.stat-l {
  font-size: 0.66rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat.stat-bad .stat-n {
  color: var(--bad);
}

/* ---- Cards ---- */

.card {
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: 0.75rem;
  padding: 0.85rem 1rem;
  margin: 0 0 0.9rem;
}

/* The chase card: the loudest treatment on the screen belongs to the
   jobs worth chasing — the near-miss list is the money screen. */
.card.hero {
  background: var(--bad-soft);
  border-color: var(--bad-edge);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0 0 0.5rem;
}

.card-head h2 {
  margin: 0;
  font-size: 0.95rem;
}

.card.hero .card-head h2 {
  color: var(--bad);
}

.card-link {
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
}

.card.hero .card-link {
  color: var(--bad-deep);
}

.card-cap {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}

.card-empty {
  margin: 0;
  font-size: 0.85rem;
}

/* ---- The chase card's entry ---- */

.miss-who {
  margin: 0 0 0.1rem;
  color: var(--ink);
}

.miss-why {
  margin: 0 0 0.3rem;
  font-size: 0.85rem;
  color: #55404a;
}

.miss-call {
  display: inline-block;
  background: var(--bad);
  color: var(--paper);
  border-radius: 0.5rem;
  padding: 0.4rem 0.8rem;
  font-weight: 600;
  font-size: 0.8rem;
  text-decoration: none;
  margin: 0.1rem 0 0.2rem;
}

/* ---- Recent bookings rows ---- */

.brow {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.5rem 0;
  border-top: 1px solid var(--rule);
}

.brow:first-child {
  border-top: 0;
  padding-top: 0.1rem;
}

.brow-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0;
  color: var(--ink);
}

.brow-when {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.brow-job {
  font-size: 0.8rem;
  color: var(--body);
  margin: 0;
}

/* ---- The services tally: SVG rects, widths precomputed server-side
   (the CSP refuses inline styles) ---- */

.svc {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.svc-row {
  display: grid;
  grid-template-columns: minmax(0, 8.5rem) 1fr 2rem;
  align-items: center;
  gap: 0.6rem;
}

.svc-name {
  font-size: 0.78rem;
  color: var(--body);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.svc-barwrap {
  border-left: 1px solid #d6dce7;
  display: flex;
  align-items: center;
}

.svc-bar {
  display: block;
  width: 100%;
  height: 0.6rem;
}

.svc-bar rect {
  fill: var(--accent);
}

.svc-bar.other rect {
  fill: var(--bar-other);
}

.svc-num {
  font-size: 0.78rem;
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

/* ---- Status chips: story.py's outcome vocabulary, verbatim ---- */

.chip {
  display: inline-block;
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.72rem;
  font-weight: 600;
}

.chip-good {
  background: var(--good-soft);
  color: var(--good-deep);
}

.chip-bad {
  background: var(--bad-chip);
  color: var(--bad-deep);
}

.chip-mute {
  background: var(--mute-chip);
  color: var(--mute-deep);
}

.call-chip {
  margin: 0 0 0.35rem;
}

/* ---- Forms (issue 07's vocabulary, recoloured) ---- */

fieldset {
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: 0.65rem;
  margin: 0 0 1.25rem;
  padding: 1rem;
}

legend {
  font-weight: 600;
  padding: 0 0.35rem;
}

label {
  display: block;
  margin: 0.75rem 0 0.25rem;
  font-weight: 500;
}

label.check {
  font-weight: 500;
}

input,
textarea,
select {
  width: 100%;
  font: inherit;
  color: var(--ink);
  border: 1px solid var(--edge);
  border-radius: 0.375rem;
  padding: 0.5rem 0.65rem;
  background: var(--paper);
}

input[type="checkbox"] {
  width: auto;
  margin-right: 0.5rem;
}

button {
  font: inherit;
  font-weight: 600;
  color: var(--paper);
  background: var(--navy);
  border: 0;
  border-radius: 0.375rem;
  padding: 0.65rem 1.25rem;
  margin: 0.25rem 0 1rem;
}

.hint {
  font-size: 0.875rem;
  color: var(--muted);
  margin: 0.35rem 0 0.75rem;
}

.field-error {
  color: var(--bad);
  font-size: 0.9rem;
  margin: 0.5rem 0 0.25rem;
}

.notice {
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: 0.65rem;
  padding: 0.7rem 0.9rem;
}

.notice.saved {
  color: var(--good);
}

table.history {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: 0.65rem;
}

table.history th,
table.history td {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--rule);
}

/* ---- History (issue 08), restyled ---- */

nav.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0 0 1rem;
}

nav.filters a {
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: 999px;
  padding: 0.25rem 0.8rem;
  font-size: 0.8rem;
  color: var(--body);
  text-decoration: none;
}

nav.filters a[aria-current="page"] {
  background: var(--navy);
  border-color: var(--navy);
  color: var(--paper);
  font-weight: 600;
}

ul.calls,
ul.bookings,
ul.devices {
  list-style: none;
  margin: 0;
  padding: 0;
}

ul.calls li,
ul.bookings li,
ul.devices li {
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: 0.75rem;
  padding: 0.75rem 1rem 0.25rem;
  margin: 0 0 0.75rem;
}

/* A near-miss card carries the serious tint — the same treatment as the
   Overview's chase card, because it is the same money. */
li.near-miss {
  border-color: var(--bad-edge);
  background: var(--bad-soft);
}

.call-head {
  margin: 0 0 0.35rem;
}

.call-head strong {
  color: var(--ink);
  display: block;
}

.when {
  font-size: 0.78rem;
  color: var(--muted);
}

.reason {
  color: var(--ink);
  font-size: 0.9rem;
}

.status-line {
  font-size: 0.85rem;
}

.urgent {
  color: var(--bad);
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.call-actions {
  font-size: 0.9rem;
}

.transcript .turn {
  margin: 0 0 0.5rem;
}

.transcript .turn strong {
  color: var(--ink);
}

nav.pages a {
  margin-right: 0.75rem;
}

.message {
  background: var(--paper);
  border: 1px solid var(--edge);
  border-left: 3px solid var(--edge);
  border-radius: 0.5rem;
  padding: 0.6rem 0.75rem;
  margin: 0 0 1rem;
}
