/* Layout + components, built on static/css/tokens.css (loaded first).
   Mobile-first: base rules target phones; min-width media queries add
   tablet (768px) and desktop (1024px) behavior. No inline styles
   anywhere — the production CSP forbids them. */

/* ---------- Base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}

h1, h2, h3, h4 {
  line-height: 1.25;
  margin: 0 0 var(--space-3);
}

h1 { font-size: var(--text-2xl); font-weight: var(--weight-bold); letter-spacing: -0.01em; }
h2 { font-size: var(--text-xl); margin-top: var(--space-6); }
h3 { font-size: var(--text-lg); }

p { margin: 0 0 var(--space-3); }

a {
  color: var(--color-link);
  text-underline-offset: 2px;
}

a:hover {
  color: var(--color-link-hover);
}

:focus-visible {
  outline: 2px solid var(--color-link);
  outline-offset: 2px;
}

img, svg {
  max-width: 100%;
}

hr {
  border: 0;
  border-top: 1px solid var(--color-border);
  margin: var(--space-5) 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--space-2);
  top: -3rem;
  z-index: 100;
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.skip-link:focus {
  top: var(--space-2);
}

.icon {
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-sprite {
  display: none;
}

@media (min-width: 1024px) {
  h1 { font-size: var(--text-3xl); }
}

/* Multi-color icons (nav, hub cards) carry their own fills. */
.icon.icon-color {
  stroke: none;
}

/* ---------- App shell (Phase 17.5, ADR 0010) ----------
   Desktop (≥1024px): a floating rounded sidebar beside a transparent
   top bar and the content. Below that: a top bar with a menu button
   and the sidebar as an off-canvas drawer (static/js/nav.js); phones
   add the bottom bar. Flyouts and dropdowns are <details>, so they
   work without JS; the script adds close-on-outside-click/Escape. */

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "topbar"
    "main";
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  font-weight: var(--weight-bold);
  color: var(--color-text);
  text-decoration: none;
}

.brand-mark {
  width: 2rem;
  height: 2rem;
  flex: none;
  border-radius: var(--radius-sm);
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}

.brand-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.brand-sub {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
}

/* ----- Top bar ----- */

.topbar {
  grid-area: topbar;
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--topbar-height);
  padding: var(--space-2) var(--space-3);
  padding-left: max(var(--space-3), env(safe-area-inset-left));
  padding-right: max(var(--space-3), env(safe-area-inset-right));
  background: var(--color-bg);
}

.topbar-brand {
  font-size: var(--text-base);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

.topbar-icon {
  width: 2.5rem;
  min-width: 2.5rem;
  height: 2.5rem;
  min-height: 2.5rem;
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}

.topbar-icon:hover {
  background: var(--color-surface-2);
}

.topbar-search {
  position: relative;
  display: none;
  align-items: center;
}

.topbar-search .icon {
  position: absolute;
  left: var(--space-4);
  width: 1.125rem;
  height: 1.125rem;
  color: var(--color-text-muted);
  pointer-events: none;
}

.topbar-search input[type="search"] {
  width: 18rem;
  max-width: none;
  min-height: 2.5rem;
  padding-left: 2.75rem;
  padding-right: 3.25rem;
  border-color: var(--color-border);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

.topbar-search .kbd {
  position: absolute;
  right: var(--space-3);
}

.kbd {
  display: inline-flex;
  align-items: center;
  min-height: 1.4rem;
  padding: 0 0.4rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font: inherit;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}

.btn-create {
  min-height: 2.5rem;
  padding: 0 var(--space-3);
}

.create-label {
  display: none;
}

.topbar .hide-phone {
  display: none;
}

/* Theme button: a moon in light mode, a sun in dark mode. */
.theme-icon-sun {
  display: none;
}

:root[data-theme="dark"] .theme-icon-sun {
  display: block;
}

:root[data-theme="dark"] .theme-icon-moon {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-icon-sun {
    display: block;
  }

  :root:not([data-theme="light"]) .theme-icon-moon {
    display: none;
  }
}

.theme-form {
  display: contents;
}

@media (min-width: 768px) {
  .topbar {
    padding: var(--space-3) var(--space-5);
  }

  .topbar-search {
    display: flex;
  }

  .create-label {
    display: inline;
  }

  .btn-create {
    padding: 0 var(--space-4);
  }

  .topbar .hide-phone {
    display: inline-flex;
  }
}

/* ----- Dropdowns (Create, settings gear, help) ----- */

.dropdown {
  position: relative;
}

.dropdown > summary {
  list-style: none;
  cursor: pointer;
}

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

.dropdown-menu {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  z-index: 60;
  min-width: 15rem;
  padding: var(--space-2);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-lg);
}

.dropdown-menu hr {
  margin: var(--space-2) 0;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 2.5rem;
  padding: 0 var(--space-3);
  border: none;
  border-radius: var(--radius);
  background: none;
  box-shadow: none;
  color: var(--color-text);
  font: inherit;
  font-weight: var(--weight-medium);
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
}

.dropdown-item:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.dropdown-item .icon {
  color: var(--color-text-muted);
}

.dropdown-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
}

.dropdown-name {
  font-weight: var(--weight-bold);
}

.dropdown-label {
  margin: var(--space-1) var(--space-3) var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

/* The Dark Mode row draws a small switch that follows the theme. */
.dropdown-toggle-row .switch-visual {
  position: relative;
  width: 2.25rem;
  height: 1.25rem;
  margin-left: auto;
  border-radius: var(--radius-full);
  background: var(--color-border-strong);
}

.dropdown-toggle-row .switch-visual::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1rem;
  height: 1rem;
  border-radius: var(--radius-full);
  background: #ffffff;
}

:root[data-theme="dark"] .dropdown-toggle-row .switch-visual {
  background: var(--switch-track-on);
}

:root[data-theme="dark"] .dropdown-toggle-row .switch-visual::before {
  background: var(--switch-thumb-on);
  transform: translateX(1rem);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .dropdown-toggle-row .switch-visual {
    background: var(--switch-track-on);
  }

  :root:not([data-theme="light"]) .dropdown-toggle-row .switch-visual::before {
    background: var(--switch-thumb-on);
    transform: translateX(1rem);
  }
}

/* ----- Sidebar ----- */

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  width: min(18rem, 85vw);
  display: flex;
  flex-direction: column;
  padding: var(--space-4) var(--space-3);
  padding-bottom: max(var(--space-4), env(safe-area-inset-bottom));
  background: var(--color-sidebar);
  overflow-y: auto;
  transform: translateX(-100%);
  visibility: hidden;
  transition: transform 0.2s ease, visibility 0.2s;
}

.nav-open .sidebar {
  transform: none;
  visibility: visible;
  box-shadow: var(--shadow-lg);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-1) var(--space-4);
}

.sidebar-header .brand {
  flex: 1;
}

.sidebar .sidebar-toggle {
  display: none;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}

.nav-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--color-overlay);
}

.nav-backdrop[hidden] {
  display: none;
}

.nav-label {
  margin: 0 var(--space-3) var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--tap-target);
  padding: 0 var(--space-3);
  border-radius: var(--radius-full);
  color: var(--color-text);
  font-weight: var(--weight-medium);
  text-decoration: none;
  cursor: pointer;
}

.nav-link .icon {
  width: 1.375rem;
  height: 1.375rem;
}

.nav-link:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.nav-link[aria-current="page"],
.nav-group.is-active > .nav-link {
  background: var(--color-primary-soft);
  color: var(--color-primary-soft-text);
  font-weight: var(--weight-bold);
}

.nav-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.nav-arrow {
  color: var(--color-text-muted);
  transition: transform 0.15s;
}

.nav-group.is-active .nav-arrow {
  color: var(--color-primary-soft-text);
}

.nav-group > summary {
  list-style: none;
}

.nav-group > summary::-webkit-details-marker {
  display: none;
}

/* The arrow turns into a down-chevron while the flyout is open. */
.nav-group[open] .nav-arrow {
  transform: rotate(90deg);
}

/* The logout control must be a POST <button>, styled as a nav link. */
.nav-button {
  width: 100%;
  justify-content: flex-start;
  border: none;
  background: none;
  box-shadow: none;
  text-align: left;
  font-weight: var(--weight-medium);
  line-height: 1.5;
}

.nav-button:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

/* Flyout: inline inside the phone/tablet drawer, floating beside the
   sidebar on desktop. */
.flyout {
  margin: var(--space-1) 0 var(--space-2) var(--space-6);
}

.flyout-label {
  display: none;
  margin: 0 var(--space-3) var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

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

.flyout-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 2.5rem;
  padding: 0 var(--space-3);
  border-radius: var(--radius-full);
  color: var(--color-text);
  font-weight: var(--weight-medium);
  text-decoration: none;
}

.flyout-link .icon {
  color: var(--color-text-muted);
}

.flyout-link:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.flyout-link[aria-current="page"] {
  background: var(--color-primary-soft);
  color: var(--color-primary-soft-text);
  font-weight: var(--weight-bold);
}

.flyout-link[aria-current="page"] .icon {
  color: var(--color-primary-soft-text);
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: auto;
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
}

.app-main {
  grid-area: main;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-3) var(--space-4) var(--space-4);
  padding-bottom: calc(var(--bottombar-height) + var(--space-8) + env(safe-area-inset-bottom));
  min-width: 0;
}

/* ----- Phone bottom bar ----- */

.bottom-bar {
  position: fixed;
  inset: auto var(--space-2) var(--space-2);
  z-index: 30;
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  padding-bottom: env(safe-area-inset-bottom);
  border-radius: var(--radius-xl);
  background: var(--color-surface);
  box-shadow: var(--shadow-lg);
}

.bottom-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--bottombar-height);
  padding: var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  text-decoration: none;
}

.bottom-link:hover {
  color: var(--color-text);
}

.bottom-link[aria-current="page"] {
  color: var(--color-link);
  font-weight: var(--weight-bold);
}

/* ----- Floating help button ----- */

.help-fab {
  position: fixed;
  right: var(--space-4);
  bottom: calc(var(--bottombar-height) + var(--space-5) + env(safe-area-inset-bottom));
  z-index: 35;
}

.help-fab-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-on-primary);
  box-shadow: 0 8px 20px rgb(37 99 235 / 35%);
}

.help-fab-button .icon {
  width: 1.5rem;
  height: 1.5rem;
}

.help-menu {
  top: auto;
  bottom: calc(100% + var(--space-2));
  min-width: 18rem;
}

.shortcut-list {
  grid-template-columns: max-content minmax(0, 1fr);
  gap: var(--space-2) var(--space-3);
  margin: 0 var(--space-3) var(--space-2);
  font-size: var(--text-sm);
}

.shortcut-list dt {
  font-weight: var(--weight-medium);
  color: var(--color-text);
}

.shortcut-list dd {
  margin: 0;
  color: var(--color-text-muted);
}

/* ----- Command palette (⌘K) ----- */

.palette {
  width: min(40rem, calc(100vw - 2rem));
  max-height: min(32rem, 80vh);
  margin: 12vh auto auto;
  padding: 0;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.palette[open] {
  display: flex;
  flex-direction: column;
}

.palette::backdrop {
  background: var(--color-overlay);
}

.palette-input {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.palette-input .icon {
  color: var(--color-text-muted);
}

.palette-input input[type="text"] {
  flex: 1;
  max-width: none;
  min-height: 2.5rem;
  padding: 0;
  border: none;
  background: transparent;
  font-size: var(--text-lg);
}

.palette-input input[type="text"]:focus-visible {
  box-shadow: none;
}

.palette-list {
  list-style: none;
  margin: 0;
  padding: var(--space-2);
  overflow-y: auto;
}

.palette-list:empty {
  display: none;
}

.palette-list + .palette-list {
  border-top: 1px solid var(--color-border);
}

.palette-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 2.75rem;
  padding: 0 var(--space-3);
  border-radius: var(--radius);
  color: var(--color-text);
  text-decoration: none;
}

.palette-item .icon {
  color: var(--color-text-muted);
}

.palette-item:hover,
.palette-item.is-selected {
  background: var(--color-primary-soft);
  color: var(--color-primary-soft-text);
}

.palette-item > span:nth-of-type(1) {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.palette-kind,
.palette-detail {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.palette-item[hidden] {
  display: none;
}

/* ----- Wider screens ----- */

@media (min-width: 768px) {
  .bottom-bar {
    display: none;
  }

  .app-main {
    padding: var(--space-4) var(--space-5) var(--space-7);
  }

  .help-fab {
    bottom: var(--space-5);
    right: var(--space-5);
  }
}

@media (min-width: 1024px) {
  .app-shell {
    grid-template-columns: calc(var(--sidebar-width) + 2 * var(--sidebar-inset)) minmax(0, 1fr);
    grid-template-areas:
      "sidebar topbar"
      "sidebar main";
  }

  .sidebar {
    grid-area: sidebar;
    position: sticky;
    top: var(--sidebar-inset);
    width: auto;
    height: calc(100vh - 2 * var(--sidebar-inset));
    height: calc(100dvh - 2 * var(--sidebar-inset));
    margin: var(--sidebar-inset);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
    /* Visible so a flyout can float beside the sidebar. */
    overflow: visible;
    transform: none;
    visibility: visible;
    transition: none;
  }

  .nav-open .sidebar {
    box-shadow: var(--shadow);
  }

  .sidebar .sidebar-toggle {
    display: inline-flex;
  }

  .topbar {
    position: static;
    background: transparent;
  }

  .topbar .topbar-brand,
  .topbar .menu-toggle,
  .sidebar .sidebar-close,
  .nav-backdrop {
    display: none;
  }

  .nav-group {
    position: relative;
  }

  .flyout {
    position: absolute;
    top: calc(-1 * var(--space-2));
    left: calc(100% + var(--space-4));
    z-index: 60;
    min-width: 15rem;
    margin: 0;
    padding: var(--space-3) var(--space-2);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    box-shadow: var(--shadow-lg);
  }

  .flyout-label {
    display: block;
  }

  .app-main {
    padding: var(--space-2) var(--space-6) var(--space-7);
  }

  /* Collapsed: icons only. */
  .sidebar-collapsed .app-shell {
    grid-template-columns: calc(4.75rem + 2 * var(--sidebar-inset)) minmax(0, 1fr);
  }

  .sidebar-collapsed .sidebar {
    padding-left: var(--space-2);
    padding-right: var(--space-2);
  }

  .sidebar-collapsed .brand,
  .sidebar-collapsed .nav-label,
  .sidebar-collapsed .nav-text,
  .sidebar-collapsed .nav-arrow {
    display: none;
  }

  .sidebar-collapsed .sidebar-header {
    justify-content: center;
  }

  .sidebar-collapsed .nav-link {
    justify-content: center;
    padding: 0;
  }

  .sidebar-collapsed .nav-badge {
    position: absolute;
    top: 0;
    right: 0;
  }

  .sidebar-collapsed .nav-list > li {
    position: relative;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .nav-arrow {
    transition: none;
  }
}

/* Logged-out pages (login, password reset) */
.auth-layout {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--space-4);
}

.auth-card {
  width: min(26rem, 100%);
}

.auth-brand {
  display: flex;
  justify-content: center;
  margin-bottom: var(--space-5);
}

/* ---------- Page structure ---------- */

/* One page heading, two names. `dash-hero` arrived with the restyled
   pages and `page-header` was already on the rest; they had drifted a
   couple of pixels apart, which is exactly the sort of difference
   nobody can name but everybody sees. Same rule for both. */
.page-header,
.dash-hero {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.page-header h1,
.dash-hero h1 {
  margin: 0;
}

.page-subtitle {
  margin: var(--space-1) 0 0;
  color: var(--color-text-muted);
}

.card {
  background: var(--color-surface);
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow);
}

.card + .card {
  margin-top: var(--space-4);
}

/* Side-by-side cards are spaced by the grid gap, not stacking margin. */
.grid-2 > .card + .card {
  margin-top: 0;
}

/* Cards in a pair normally stretch to the same height. `is-top` lets
   each one end where its content does — for a short card beside a long
   one, the stretch leaves a lot of empty card. */
.grid-2.is-top {
  align-items: start;
}

.card-title {
  margin: 0 0 var(--space-3);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.stat-card {
  display: block;
  position: relative;
  background: var(--color-surface);
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow);
  color: var(--color-text);
  text-decoration: none;
}

a.stat-card:hover {
  border-color: var(--accent, var(--color-link));
  color: var(--color-text);
}

/* Tinted: the card takes its accent's soft color; the value its text. */
.stat-card.is-tinted {
  background: linear-gradient(135deg, var(--accent-soft), var(--color-surface) 140%);
}

.stat-card.is-tinted .stat-value,
.stat-card.is-arc .stat-value {
  color: var(--accent-text);
}

.stat-card.is-outlined {
  border-color: var(--accent);
}

/* Curved accent border: a colored arc on the left edge. */
.stat-card.is-arc {
  border-left: 5px solid var(--accent);
}

.stat-card.is-pill {
  border-radius: var(--radius-2xl);
  padding: var(--space-5) var(--space-6);
}

.stat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.stat-label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.stat-value {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  line-height: 1.2;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Values shrink to fit narrow cards instead of breaking mid-number. */
.stat-card {
  container-type: inline-size;
}

.stat-card .stat-value {
  font-size: clamp(1.125rem, 17cqi, var(--text-2xl));
}

.stat-meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.grid-2 {
  display: grid;
  gap: var(--space-4);
}

@media (min-width: 768px) {
  .grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.stack > * + * {
  margin-top: var(--space-3);
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.muted {
  color: var(--color-text-muted);
}

.text-right {
  text-align: right;
}

/* ---------- Buttons ---------- */

.btn,
button,
input[type="submit"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-target);
  padding: 0 var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  font: inherit;
  font-weight: var(--weight-semibold);
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  background: var(--color-primary);
  color: var(--color-on-primary);
  box-shadow: 0 2px 6px rgb(37 99 235 / 25%);
}

.btn:hover,
button:hover,
input[type="submit"]:hover {
  background: var(--color-primary-hover);
  color: var(--color-on-primary);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-link);
  border-color: var(--color-border-strong);
  box-shadow: none;
}

.btn-secondary:hover {
  background: var(--color-primary-soft);
  color: var(--color-primary-soft-text);
}

/* Secondary with a blue outline (e.g. "Revenue" on Scheduling). */
.btn-outline {
  border-color: var(--color-link);
}

.btn-text {
  min-height: 0;
  padding: 0;
  background: none;
  color: var(--color-link);
  box-shadow: none;
}

.btn-text:hover {
  background: none;
  color: var(--color-link-hover);
  text-decoration: underline;
}

.btn-lg {
  min-height: 3.5rem;
  padding: 0 var(--space-7);
  font-size: var(--text-lg);
  box-shadow: 0 8px 24px rgb(37 99 235 / 30%);
}

.btn .icon,
button .icon {
  width: 1.125rem;
  height: 1.125rem;
}

.btn-danger {
  background: var(--color-danger);
  color: #ffffff;
  box-shadow: none;
}

.btn-danger-text {
  background: var(--color-surface);
  color: var(--color-danger);
  border-color: var(--color-danger);
  box-shadow: none;
}

.btn-danger-text:hover {
  background: var(--color-danger-soft);
  color: var(--color-danger-soft-text);
}

.btn-danger:hover {
  background: var(--color-danger-soft-text);
  color: #ffffff;
}

.btn-sm {
  min-height: 2.25rem;
  padding: 0 var(--space-4);
  font-size: var(--text-sm);
}

.btn-block {
  width: 100%;
}

button:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.6;
  cursor: not-allowed;
}

/* The New / In progress / Complete buttons on a schedule row and a
   job page. A flex row so they sit beside the status badge rather than
   stacking, and wrapping on a phone instead of overflowing. */
.status-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* Before and after photos on a job or estimate (Phase 18 unit 2).
   A grid that fits whatever width it is given, so it is one column on
   a phone without a media query. */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
  gap: var(--space-4);
  list-style: none;
  margin: var(--space-3) 0 0;
  padding: 0;
}

.photo-tile img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius-lg);
  background: var(--color-border);
}

.photo-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
  font-size: var(--text-sm);
}

.photo-form {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

/* A form that exists only to be submitted by a script — never shown,
   never focusable. Used by the calendar's drag-to-move, which has to
   post a rendered CSRF field because no script here can read the
   cookie. */
.is-hidden {
  display: none;
}

/* Moving a job from the day schedule (Phase 18 unit 4). Two small
   forms side by side where there is room, stacked on a phone. */
.move-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.move-nudges,
.move-exact {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.move-exact input {
  margin: 0;
}

/* A chip being dragged on the week or month view. Only ever set by
   static/js/reschedule.js, so it never shows without it. */
.event.is-dragging {
  opacity: 0.5;
}

/* The drag target is whatever carries data-day, which is .cal-day on
   the week view and .cal-cell on the month view. This rule named
   .calendar-day, a class no template has ever rendered, so the
   outline has never once shown. */
.cal-day.is-drop-target,
.cal-cell.is-drop-target {
  outline: 2px dashed var(--color-primary);
  outline-offset: -2px;
}

.link-button {
  display: inline;
  min-height: 0;
  padding: 0;
  border: none;
  background: none;
  box-shadow: none;
  color: var(--color-link);
  font: inherit;
  font-weight: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.link-button:hover {
  background: none;
  color: var(--color-link-hover);
}

.logout-form {
  display: inline;
}

/* ---------- Forms ---------- */

form p {
  margin: 0 0 var(--space-5);
}

label {
  display: block;
  margin-bottom: var(--space-1);
  font-weight: var(--weight-semibold);
}

/* Floating label: in a form row holding a text-like field, the label
   sits on the field's top border (Material "outlined" look). Checkbox
   rows and grouped widgets keep a normal label. Browsers without :has()
   just show the label above the field. */
form p:has(> input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), > select, > textarea) {
  position: relative;
  max-width: 32rem;
}

form p:has(> input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), > select, > textarea) > label {
  position: absolute;
  top: -0.6rem;
  left: var(--space-4);
  z-index: 1;
  max-width: calc(100% - 2 * var(--space-4));
  margin: 0;
  padding: 0 var(--space-1);
  overflow: hidden;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-muted);
  white-space: nowrap;
  text-overflow: ellipsis;
  background: linear-gradient(to bottom, transparent 55%, var(--color-surface-3) 55%);
  border-radius: var(--radius-sm);
}

form p:has(> :focus-visible) > label {
  color: var(--color-link);
}

.helptext {
  padding-left: var(--space-4);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="search"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
select,
textarea {
  width: 100%;
  max-width: 32rem;
  min-height: 3rem;
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface-3);
  color: var(--color-text);
  font: inherit;
}

textarea {
  min-height: 6rem;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  resize: vertical;
}

input[readonly],
input:disabled,
select:disabled,
textarea[readonly] {
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  cursor: not-allowed;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--color-link);
  box-shadow: var(--focus-ring);
}

input[type="checkbox"],
input[type="radio"] {
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--color-primary);
}

.helptext {
  display: block;
  margin-top: var(--space-1);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.errorlist {
  list-style: none;
  margin: 0 0 var(--space-2);
  padding: 0;
  color: var(--color-danger);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

/* The bulk action bar (Phase 22), above a list's rows. Same shape as
   the filter form above it, so the two read as one band of controls. */
.bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
}

.bulk-bar select {
  width: auto;
  flex: 0 1 auto;
  background-color: var(--color-surface);
}

/* Narrow enough not to steal room from the name, wide enough to hit. */
.col-select {
  width: 2.5rem;
  text-align: center;
}

/* A search box above a long dropdown (Phase 22). Rendered `hidden` and
   unhidden by static/js/picker.js, so it never appears without the
   script that makes it do something. */
.field-filter {
  margin: 0 0 var(--space-2);
}

.field-filter input[type="search"] {
  width: 100%;
}

/* Whose addresses are listed, announced as well as drawn. Empty until
   a customer is chosen, so it takes no room on a blank form. */
.address-note {
  /* `.field-row` is a grid (auto-fit columns above 768px), so the note
     spans every column rather than becoming a column of its own and
     squeezing the two fields. */
  grid-column: 1 / -1;
  font-size: var(--text-sm);
}

/* How many matched, announced as well as drawn. Empty until something
   is typed, so it takes no room on a form nobody has searched. */
.field-filter .filter-count {
  display: block;
  font-size: var(--text-sm);
  margin-top: var(--space-1);
}

.filter-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-4);
}

.filter-form input[type="text"],
.filter-form input[type="search"] {
  flex: 1 1 12rem;
  max-width: 20rem;
  background: var(--color-surface);
}

.filter-form select {
  background-color: var(--color-surface);
}

.filter-form select {
  width: auto;
  flex: 0 1 auto;
}

/* ---------- Badges, alerts, avatars ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.125rem var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  line-height: 1.5;
  white-space: nowrap;
  background: var(--tone-bg, var(--color-surface-2));
  color: var(--tone-fg, var(--color-text));
}

.badge-info { background: var(--color-primary-soft); color: var(--color-primary-soft-text); }
.badge-success { background: var(--color-success-soft); color: var(--color-success-soft-text); }
.badge-warning { background: var(--color-warning-soft); color: var(--color-warning-soft-text); }
.badge-danger { background: var(--color-danger-soft); color: var(--color-danger-soft-text); }
.badge-solid { background: var(--color-primary); color: var(--color-on-primary); }
.badge-solid-green { background: var(--color-success); color: #ffffff; }
.badge-outline { background: transparent; color: var(--color-text); border: 1px solid var(--color-border-strong); }
.badge-cyan { background: var(--color-sky-soft); color: var(--color-sky); }

.messages {
  list-style: none;
  margin: 0 0 var(--space-4);
  padding: 0;
}

.message {
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}

.message + .message {
  margin-top: var(--space-2);
}

.message.success { background: var(--color-success-soft); color: var(--color-success-soft-text); border-color: transparent; }
.message.error { background: var(--color-danger-soft); color: var(--color-danger-soft-text); border-color: transparent; }
.message.warning { background: var(--color-warning-soft); color: var(--color-warning-soft-text); border-color: transparent; }
.message.info { background: var(--color-primary-soft); color: var(--color-primary-soft-text); border-color: transparent; }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  flex: none;
  border-radius: var(--radius-full);
  background: var(--avatar-2);
  color: #ffffff;
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
}

.avatar-c1 { background: var(--avatar-1); }
.avatar-c2 { background: var(--avatar-2); }
.avatar-c3 { background: var(--avatar-3); }
.avatar-c4 { background: var(--avatar-4); }
.avatar-c5 { background: var(--avatar-5); }

.avatar-sm {
  width: 1.75rem;
  height: 1.75rem;
  font-size: var(--text-xs);
}

.avatar-stack {
  display: inline-flex;
}

.avatar-stack .avatar + .avatar {
  margin-left: -0.5rem;
  box-shadow: 0 0 0 2px var(--color-surface);
}

/* ---------- Empty & loading states ---------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-7) var(--space-4);
  text-align: center;
  color: var(--color-text-muted);
}

.empty-state-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 4rem;
  height: 4rem;
  margin-bottom: var(--space-3);
  border-radius: var(--radius-full);
  background: var(--color-primary-soft);
  color: var(--color-link);
}

.empty-state .icon {
  width: 1.75rem;
  height: 1.75rem;
}

.empty-state-title {
  margin: 0 0 var(--space-1);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  color: var(--color-text);
}

.empty-state-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  margin-top: var(--space-3);
}

.skeleton {
  display: block;
  height: 1em;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--color-surface-2), var(--color-border), var(--color-surface-2));
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.2s ease-in-out infinite;
}

@keyframes skeleton-shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
  }
}

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: var(--space-1);
  width: fit-content;
  max-width: 100%;
  margin-bottom: var(--space-4);
  padding: 0 var(--space-3);
  overflow-x: auto;
  background: var(--color-surface);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  scrollbar-width: thin;
}

.tab {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-target);
  padding: 0 var(--space-3);
  border-bottom: 3px solid transparent;
  color: var(--color-text-muted);
  font-weight: var(--weight-semibold);
  text-decoration: none;
  white-space: nowrap;
}

.tab:hover {
  color: var(--color-text);
}

.tab[aria-current="page"] {
  color: var(--color-link);
  border-bottom-color: var(--color-link);
}

/* ---------- Tables & lists ---------- */

.table-responsive {
  overflow-x: auto;
  padding: var(--space-3);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow);
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--text-sm);
}

.data-table th,
.data-table td {
  text-align: left;
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.data-table th {
  padding-top: var(--space-3);
  padding-bottom: var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  background: var(--color-surface-2);
  border-bottom: none;
  white-space: nowrap;
}

/* The header row reads as one soft pill. */
.data-table thead th:first-child {
  border-radius: var(--radius-full) 0 0 var(--radius-full);
}

.data-table thead th:last-child {
  border-radius: 0 var(--radius-full) var(--radius-full) 0;
}

.data-table th.text-right,
.data-table td.text-right,
.data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table tr.total-row td {
  font-weight: var(--weight-bold);
  background: var(--color-surface-2);
  border-bottom: none;
}

.data-table td.table-empty {
  padding: var(--space-7) var(--space-4);
  text-align: center;
  color: var(--color-text-muted);
}

.row-actions {
  display: inline-flex;
  gap: var(--space-1);
}

/* `tbody:last-child` only matches a table with no footer. With one, the
   last body row keeps its rule — otherwise it runs straight into the
   Total row with nothing between them — and the footer drops the
   trailing line instead. The mobile rule inside the media query below
   does the same thing; this one was missed first time round, so the
   separator was still absent above 767px. Raised by Sourcery on #219. */
.data-table tbody:last-child tr:last-child td,
.data-table tfoot tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover td {
  background: var(--color-surface-3);
}

/* "Showing 1–10 of N entries" · ‹ 1 2 3 › · per-page select */
.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3) var(--space-4);
  align-items: center;
  justify-content: space-between;
  margin: var(--space-4) 0;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.pagination-pages {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
}

.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.25rem;
  height: 2.25rem;
  padding: 0 var(--space-2);
  border-radius: var(--radius-full);
  color: var(--color-text);
  font-weight: var(--weight-semibold);
  text-decoration: none;
}

.page-link:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.page-link[aria-current="page"] {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

.page-link.is-disabled {
  color: var(--color-border-strong);
  pointer-events: none;
}

.pagination select {
  width: auto;
  min-height: 2.25rem;
  padding: 0 var(--space-3);
  background-color: var(--color-surface);
}

dl {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-1) var(--space-4);
  margin: 0 0 var(--space-4);
}

dt {
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

dd {
  margin: 0 0 var(--space-2);
  overflow-wrap: anywhere;
}

@media (min-width: 768px) {
  dl {
    grid-template-columns: max-content minmax(0, 1fr);
  }

  dd {
    margin: 0;
  }
}

.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  gap: var(--space-3);
  list-style: none;
  margin: 0 0 var(--space-5);
  padding: 0;
}

.dashboard-stats a {
  display: block;
  height: 100%;
  padding: var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  color: var(--color-text);
  font-weight: var(--weight-semibold);
  text-decoration: none;
}

.dashboard-stats a:hover {
  border-color: var(--color-link);
}

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

.timeline-entry {
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
}

.timeline-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-3);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.timeline-subject {
  font-weight: var(--weight-semibold);
}

.timeline-description {
  color: var(--color-text-muted);
}

/* ---------- Error pages ---------- */

.error-page {
  max-width: 32rem;
  margin: var(--space-8) auto;
  padding: 0 var(--space-4);
  text-align: center;
}

/* ---------- Agenda lists (dashboard, day view) ---------- */

.section-gap {
  margin-top: var(--space-4);
}

.list-plain {
  list-style: none;
  margin: 0 0 var(--space-3);
  padding: 0;
}

.list-plain > li {
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
}

.list-plain > li:last-child {
  border-bottom: none;
}

.agenda {
  list-style: none;
  margin: 0 0 var(--space-3);
  padding: 0;
}

/* Phones: time | details, with the status badge under the time.
   Wider: the badge gets its own column on the right. */
.agenda-item {
  display: grid;
  grid-template-columns: 4.75rem minmax(0, 1fr);
  align-items: start;
  gap: var(--space-1) var(--space-3);
  padding: var(--space-3);
  border-left: 4px solid var(--tone-accent, var(--color-border-strong));
  border-bottom: 1px solid var(--color-border);
}

.agenda-item:last-child {
  border-bottom: none;
}

.agenda-item > .badge {
  grid-column: 1;
  justify-self: start;
}

@media (min-width: 768px) {
  .agenda-item {
    grid-template-columns: 5.5rem minmax(0, 1fr) auto;
  }

  .agenda-item > .badge {
    grid-column: 3;
    grid-row: 1;
  }
}

.agenda-time {
  display: flex;
  flex-direction: column;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.agenda-body {
  min-width: 0;
}

.agenda-title {
  font-weight: var(--weight-semibold);
  overflow-wrap: anywhere;
}

.agenda-meta {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.tone-swatch {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  margin-right: var(--space-2);
  border-radius: var(--radius-full);
  background: var(--tone-accent);
  vertical-align: middle;
}

/* ---------- Calendar ---------- */

.cal-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.cal-toolbar .tabs {
  margin-bottom: 0;
}

.cal-filter {
  margin: 0;
}

/* Site visits: dashed, neutral — appointments, not crew work. */
.event-visit {
  --tone-bg: var(--color-surface-2);
  --tone-fg: var(--color-text);
  --tone-accent: var(--color-text-muted);
}

.event {
  display: block;
  margin-top: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border-left: 3px solid var(--tone-accent);
  border-radius: var(--radius-sm);
  background: var(--tone-bg);
  color: var(--tone-fg);
  font-size: var(--text-xs);
  line-height: 1.35;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.event:hover {
  color: var(--tone-fg);
  text-decoration: underline;
}

.event.event-visit {
  border-left-style: dashed;
}

.event.is-done {
  opacity: 0.75;
}

.event-time,
.event-title {
  font-weight: var(--weight-semibold);
}

.event-time {
  margin-right: var(--space-1);
}

.event-sub {
  display: block;
}

/* Times to click on the day schedule. A fixed column count would
   leave a ragged last row on a phone; auto-fill keeps the slots the
   same width at every size. */
.slot-picker {
  margin-top: var(--space-5);
}

.slot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr));
  gap: var(--space-2);
  margin: var(--space-3) 0 0;
  padding: 0;
  list-style: none;
}

.slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  text-decoration: none;
}

.slot:hover,
.slot:focus-visible {
  border-color: var(--color-link);
  color: var(--color-link);
}

/* Marked, not disabled: still a link, because two crews can be out
   at the same time. */
.slot.is-busy {
  background: var(--color-surface-2);
  color: var(--color-text-muted);
}

/* Outside business hours (7am-7pm, apps/jobs/calendar.py). Unlike
   `is-busy` this one really is not a link: the grid only reaches these
   hours when an existing early or late job widens it, and they are
   shown so that job stays visible rather than offered as somewhere to
   book. Dimmed further than busy and with no hover, so it does not
   invite the click it would not answer. */
.slot.is-closed {
  background: var(--color-surface-2);
  border-style: dashed;
  color: var(--color-text-muted);
  cursor: default;
  opacity: 0.7;
}

.slot.is-closed:hover,
.slot.is-closed:focus-visible {
  border-color: var(--color-border);
  color: var(--color-text-muted);
}

.slot-note {
  font-size: var(--text-xs);
  font-weight: 400; /* there is no --weight-normal token; 400 is the base */
  color: var(--color-text-muted);
}

.cal-none {
  margin: var(--space-1) 0 0;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* Week: stacked days on phones, seven columns from tablet width up. */
.cal-week {
  display: grid;
  gap: var(--space-2);
}

.cal-day {
  position: relative; /* for the stretched day link below */
  min-width: 0;
  padding: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.cal-day.is-today {
  border-color: var(--color-link);
  box-shadow: inset 0 3px 0 var(--color-link);
}

.cal-day-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text-muted);
  text-decoration: none;
}

/* Clicking anywhere in a day cell opens that day's schedule.

   The anchor that is already there is stretched across the cell with
   a pseudo-element, rather than wrapping the cell in a second anchor:
   the cell holds event chips which are anchors themselves, and
   nesting anchors is invalid HTML. A pseudo-element is never an event
   target, so reschedule.js's closest("[data-day]") still resolves to
   the cell and dragging is untouched. No extra tab stops either — on
   the month view a filler anchor per cell would have added 42.

   Every role gets this: it only navigates to a day everyone can
   already open. */
.cal-day-head::after,
.cal-date::after {
  content: "";
  position: absolute;
  inset: 0;
}

/* Above the stretched layer, so the chips keep their own clicks and
   their own drags.

   The indicator dots and "No jobs" are deliberately **not** in this
   list. They are not links, so lifting them above the stretched layer
   only created a dead patch in the middle of a cell that is supposed
   to open the day — Sourcery caught that on PR #166. Below the layer
   they lose their `title` tooltips on hover, which is the right way
   round: the dots are decorative (the count beside them carries the
   meaning for a screen reader), a `title` tooltip does not exist on a
   touch screen at all, and this app is used on a phone in somebody's
   driveway. */
.cal-day > .event,
.cal-cell > .event,
.cal-cell > .cal-more {
  position: relative;
}

.cal-day-num {
  font-size: var(--text-lg);
  color: var(--color-text);
}

@media (min-width: 768px) {
  .cal-week {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }

  .cal-day {
    min-height: 12rem;
  }

  .cal-day-head {
    flex-direction: column;
    gap: 0;
  }
}

/* Month: a 7-column grid. On phones each cell shows its date and a
   count; the day view (one tap) has the details. */
.cal-month {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--color-surface);
}

.cal-row {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.cal-weekdays {
  background: var(--color-surface-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-muted);
  text-align: center;
}

.cal-weekdays > div {
  padding: var(--space-2) 0;
}

.cal-weekdays abbr {
  text-decoration: none;
}

.cal-cell {
  position: relative;
  min-width: 0;
  min-height: 3.5rem;
  padding: var(--space-1);
  border-top: 1px solid var(--color-border);
  border-left: 1px solid var(--color-border);
}

.cal-cell:first-child {
  border-left: none;
}

.cal-cell.is-outside {
  background: var(--color-surface-2);
}

.cal-cell.is-outside .cal-date {
  color: var(--color-text-muted);
}

.cal-date {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.75rem;
  min-height: 1.75rem;
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  text-decoration: none;
}

.cal-cell.is-today .cal-date {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

.cal-more {
  display: block;
  margin-top: var(--space-1);
  font-size: var(--text-xs);
}

.cal-count {
  position: absolute;
  right: var(--space-1);
  bottom: var(--space-1);
  min-width: 1.25rem;
  padding: 0 var(--space-1);
  border-radius: var(--radius-full);
  background: var(--color-primary-soft);
  color: var(--color-primary-soft-text);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-align: center;
}

.cal-month .event,
.cal-more {
  display: none;
}

@media (min-width: 768px) {
  .cal-cell {
    min-height: 7rem;
  }

  .cal-month .event,
  .cal-more {
    display: block;
  }

  .cal-month .event-sub {
    display: none;
  }

  .cal-count {
    display: none;
  }
}

/* ---------- Lists that become cards on phones ---------- */

.card-flush {
  padding: 0;
  overflow: hidden;
}

/* The bug this fixes: `.card-flush` and `.table-responsive` are both
   single classes, so they have equal specificity, and `.card-flush` is
   further down the file — its `overflow` shorthand was silently
   overwriting the wrapper's `overflow-x: auto` (line ~1777). Every wide
   table sharing the two classes was therefore clipped with no
   scrollbar, which is how the owner met the payroll table: eleven
   columns, cut off, no way to reach the rest. Reported 2026-11-09.

   This rule wins on **specificity**, not position: two classes beats
   one wherever it sits in the file. Said the other way round first
   time, and corrected after review — the distinction matters, because
   a rule that depended on its position would break the next time
   somebody tidied the stylesheet.

   `overflow-y` stays hidden so the card still clips the table's square
   corners to its own radius, which is what `.card-flush` is for.
   `visible` would not do: paired with a non-visible x value the
   browser computes it back to `auto` and adds a vertical scrollbar. */
.table-responsive.card-flush {
  overflow-x: auto;
  overflow-y: hidden;
}

@media (max-width: 767px) {
  .data-table.stack-mobile thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .data-table.stack-mobile,
  .data-table.stack-mobile tbody,
  .data-table.stack-mobile tfoot,
  .data-table.stack-mobile tr,
  .data-table.stack-mobile td {
    display: block;
    width: 100%;
  }

  .data-table.stack-mobile tr {
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--color-border);
  }

  /* `tbody:last-child` only matches a table with no footer. With one,
     the last person's row keeps its rule — otherwise it runs straight
     into the totals with nothing between them — and the footer drops
     the trailing line instead. */
  .data-table.stack-mobile tbody:last-child tr:last-child,
  .data-table.stack-mobile tfoot tr:last-child {
    border-bottom: none;
  }

  .data-table.stack-mobile td {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-1) var(--space-3);
    border-bottom: none;
    text-align: left;
  }

  .data-table.stack-mobile td::before {
    content: attr(data-label);
    flex: 0 0 6.5rem;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }

  .data-table.stack-mobile td:first-child {
    display: block;
    font-size: var(--text-base);
  }

  .data-table.stack-mobile td:first-child::before {
    content: none;
  }

  /* With a select column the first cell is a checkbox, so the rules
     above would make the checkbox the card's heading and leave the
     name as just another labelled row. Hand the heading to the cell
     after the checkbox, and let the checkbox keep its own label. */
  .data-table.stack-mobile td.col-select {
    display: flex;
    width: 100%;
    text-align: left;
  }

  .data-table.stack-mobile td.col-select::before {
    content: attr(data-label);
  }

  .data-table.stack-mobile td.col-select + td {
    display: block;
    font-size: var(--text-base);
  }

  .data-table.stack-mobile td.col-select + td::before {
    content: none;
  }
}

/* ---------- Contacts & Tasks hub ---------- */

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-top: var(--space-1);
}

.stat-value-sm {
  font-size: var(--text-lg);
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--weight-medium);
}

.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: var(--space-4);
}

.plan-grid > .card + .card {
  margin-top: 0;
}

.plan-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  color: var(--color-text);
  text-decoration: none;
}

.plan-card:hover {
  border-color: var(--color-link);
  color: var(--color-text);
}

/* Styled explicitly: with only accent-color, browsers pick the track
   color themselves and a pale tone can get a dark, "full"-looking track. */
progress {
  --bar-color: var(--tone-accent, var(--color-primary));
  width: 100%;
  height: 0.5rem;
  border: none;
  border-radius: var(--radius-full);
  background: var(--color-surface-2);
  appearance: none;
  overflow: hidden;
}

progress::-webkit-progress-bar {
  background: var(--color-surface-2);
}

progress::-webkit-progress-value {
  background: var(--bar-color);
}

progress::-moz-progress-bar {
  background: var(--bar-color);
}

.checklist {
  list-style: none;
  margin: 0 0 var(--space-3);
  padding: 0;
}

.checklist li {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
}

/* Was `li.is-done > span:nth-child(2)`. The step's text moved inside a
   button when ticking became a real control (Phase 19 unit 2), so a
   direct-child selector stopped matching it and the strike-through
   quietly disappeared. A class says what it means and survives the
   next change of markup. */
.checklist li.is-done .checklist-text {
  color: var(--color-text-muted);
  text-decoration: line-through;
}

/* One form per step, so each is a flex item of `.checklist li`. The
   toggle takes the row and the remove button sits at the end; without
   this the two forms are block-level and stack. */
.checklist-toggle {
  flex: 1;
  min-width: 0;
}

.checklist-toggle button {
  display: inline-flex;
  gap: var(--space-2);
  align-items: baseline;
  text-align: left;
  text-decoration: none;
}

.checklist-toggle button:hover .checklist-text {
  text-decoration: underline;
}

.checklist-remove {
  flex: 0 0 auto;
}

.checklist-remove button {
  color: var(--color-text-muted);
}

.checklist-remove button:hover {
  color: var(--color-danger);
}

.note-body {
  color: var(--color-text);
}

/* ---------- Financials ---------- */

.stat-value.is-negative {
  color: var(--color-danger);
}

.chart {
  display: block;
  width: 100%;
  height: 14rem;
}

.chart-axis {
  stroke: var(--color-border-strong);
  stroke-width: 1;
}

.bar-revenue {
  fill: var(--color-primary);
}

.bar-expenses {
  fill: var(--color-warning);
}

.chart-axis-labels {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
}

.legend-swatch {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  margin-right: var(--space-1);
  border-radius: var(--radius-sm);
  vertical-align: middle;
}

.legend-revenue {
  background: var(--color-primary);
}

.legend-expenses {
  background: var(--color-warning);
}

.chart-table {
  margin-top: var(--space-3);
}

.chart-table summary {
  cursor: pointer;
  color: var(--color-link);
}

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

.share-list > li {
  padding: var(--space-2) 0;
}

.share-row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--text-sm);
}

.share-expense progress {
  --bar-color: var(--color-warning);
}

.aging {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-1) var(--space-3);
}

.aging dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.aging dd.is-late {
  color: var(--color-danger);
  font-weight: var(--weight-semibold);
}

/* ---------- Unread badge, profile, messages ---------- */

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  margin-left: auto;
  padding: 0 var(--space-1);
  border-radius: var(--radius-full);
  background: var(--color-danger);
  color: #ffffff;
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  line-height: 1;
}

.bottom-link {
  position: relative;
}

/* On the phone bar the badge sits on the icon's corner. */
.bottom-link .nav-badge {
  position: absolute;
  top: var(--space-1);
  left: 50%;
  margin-left: 0.5rem;
}

.avatar.avatar-lg {
  width: 3.5rem;
  height: 3.5rem;
  font-size: var(--text-lg);
}

.avatar[class*="tone-"] {
  background: var(--tone-bg);
  color: var(--tone-fg);
}

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

.channel-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0 var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  text-decoration: none;
}

.channel-list > li:last-child .channel-row {
  border-bottom: none;
}

.channel-row:hover .channel-name {
  text-decoration: underline;
}

.channel-name {
  font-weight: var(--weight-semibold);
  color: var(--color-link);
}

.channel-row.has-unread .channel-name {
  font-weight: var(--weight-bold);
}

.channel-topic {
  grid-column: 1;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.channel-meta {
  grid-column: 2;
  grid-row: 1 / span 2;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-1);
  font-size: var(--text-xs);
}

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

.chat-message {
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
}

.chat-message:last-child {
  border-bottom: none;
}

.chat-message.is-mine .timeline-meta strong {
  color: var(--color-link);
}

.chat-body {
  overflow-wrap: anywhere;
}

.chat-refs {
  margin-top: var(--space-1);
}

.chat-refs a.badge {
  text-decoration: none;
}

.chat-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-2);
}

.chat-form textarea {
  flex: 1 1 16rem;
  margin: 0;
}

.chat-form .errorlist {
  flex-basis: 100%;
}

/* ======================================================================
   Shared components (Phase 17.5 restyle — docs/decisions/0010).
   Shown together on /styleguide/ (Owner only).
   ====================================================================== */

/* ---------- Page headers ---------- */

/* Tinted banner behind a blue title (Assignments, Payroll, Reports). */
.page-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  background: linear-gradient(90deg, var(--color-primary-soft), var(--color-purple-soft));
}

.page-banner h1 {
  margin: 0;
  font-size: var(--text-2xl);
  color: var(--color-link);
}

/* "Dashboard › Page" above the title, on a white band. */
.breadcrumb-header {
  margin: calc(-1 * var(--space-2)) 0 var(--space-5);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0 0 var(--space-2);
  padding: 0;
  list-style: none;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.breadcrumb li + li::before {
  content: "›";
  margin-right: var(--space-2);
}

.breadcrumb a {
  color: var(--color-text-muted);
  text-decoration: none;
}

.breadcrumb a:hover {
  color: var(--color-link);
}

.breadcrumb-header h1 {
  margin: 0;
}

/* ---------- Icon circles & icon buttons ---------- */

.icon-circle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  flex: none;
  border-radius: var(--radius-full);
  background: var(--accent-soft, var(--color-primary-soft));
  color: var(--accent-text, var(--color-link));
}

.icon-circle.is-solid {
  background: var(--accent, var(--color-primary));
  color: #ffffff;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  min-width: 2.25rem;
  height: 2.25rem;
  min-height: 2.25rem;
  padding: 0;
  border: none;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--color-text-muted);
  box-shadow: none;
  text-decoration: none;
}

.icon-btn:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.icon-btn.is-active {
  color: var(--color-link);
}

.icon-btn.is-danger {
  color: var(--color-danger);
}

.icon-btn.is-danger:hover {
  background: var(--color-danger-soft);
  color: var(--color-danger-soft-text);
}

/* ---------- Segmented toggle ---------- */

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface);
}

.segmented a,
.segmented button {
  display: inline-flex;
  align-items: center;
  min-height: 2.25rem;
  padding: 0 var(--space-4);
  border: none;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--color-text-muted);
  box-shadow: none;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  text-decoration: none;
}

.segmented a:hover,
.segmented button:hover {
  background: var(--color-surface-3);
  color: var(--color-text);
}

.segmented [aria-current="page"],
.segmented [aria-pressed="true"] {
  background: var(--color-surface-2);
  color: var(--color-text);
}

/* ---------- Date-range chip ---------- */

.date-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 2.5rem;
  padding: 0 var(--space-4);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-decoration: none;
  white-space: nowrap;
}

.date-chip .icon {
  width: 1rem;
  height: 1rem;
  color: var(--color-text-muted);
}

/* ---------- Info banner ---------- */

.info-banner {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--color-info-banner);
  color: var(--color-text);
  font-size: var(--text-sm);
}

.info-banner .icon {
  color: var(--color-link);
}

/* ---------- Toggle row & switch ---------- */

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  background: var(--color-surface-3);
}

.toggle-row + .toggle-row {
  margin-top: var(--space-3);
}

.toggle-row-title {
  font-weight: var(--weight-bold);
}

.toggle-row-text {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* A checkbox drawn as a switch: <input type="checkbox" class="switch">. */
input[type="checkbox"].switch {
  appearance: none;
  position: relative;
  width: 2.75rem;
  height: 1.5rem;
  flex: none;
  margin: 0;
  border-radius: var(--radius-full);
  background: var(--color-border-strong);
  cursor: pointer;
  transition: background 0.15s;
}

input[type="checkbox"].switch::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 1.125rem;
  height: 1.125rem;
  border-radius: var(--radius-full);
  background: #ffffff;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s;
}

input[type="checkbox"].switch:checked {
  background: var(--switch-track-on);
}

input[type="checkbox"].switch:checked::before {
  background: var(--switch-thumb-on);
  transform: translateX(1.25rem);
}

@media (prefers-reduced-motion: reduce) {
  input[type="checkbox"].switch,
  input[type="checkbox"].switch::before {
    transition: none;
  }
}

/* ---------- Settings shell & section cards ---------- */

.settings-shell {
  max-width: 65rem;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5);
  border-radius: var(--radius-2xl);
  background: var(--color-surface);
  box-shadow: var(--shadow);
}

.settings-shell > h1 {
  margin-bottom: var(--space-1);
}

.settings-shell > .page-subtitle {
  margin-bottom: var(--space-6);
}

.section-card {
  padding: var(--space-5) var(--space-5) var(--space-5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  background: var(--color-surface);
}

.section-card + .section-card {
  margin-top: var(--space-5);
}

.section-card-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0 0 var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border);
}

.section-card-head h2 {
  margin: 0;
  font-size: var(--text-lg);
}

.section-card-head .icon {
  color: var(--color-link);
}

.section-card-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

.section-card.is-danger {
  border-color: var(--color-danger);
}

.section-card.is-danger .section-card-head h2,
.section-card.is-danger .section-card-head .icon {
  color: var(--color-danger);
}

.subhead {
  margin: var(--space-5) 0 var(--space-4);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

@media (min-width: 768px) {
  .settings-shell {
    padding: var(--space-7) var(--space-7);
    border-radius: var(--radius-3xl);
  }

  .section-card {
    padding: var(--space-5) var(--space-6);
    border-radius: var(--radius-2xl);
  }
}

/* Side-by-side fields inside a form or section card. */
.field-row {
  display: grid;
  gap: 0 var(--space-4);
}

.field-row > p {
  max-width: none;
}

@media (min-width: 768px) {
  .field-row {
    grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  }
}

/* ---------- Hub cards (Customize) ---------- */

.hub-group {
  margin: var(--space-6) 0 var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.hub-grid {
  display: grid;
  gap: var(--space-3);
}

@media (min-width: 768px) {
  .hub-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.hub-card {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  color: var(--color-text);
  text-decoration: none;
}

a.hub-card:hover {
  border-color: var(--accent, var(--color-link));
  color: var(--color-text);
}

.hub-card.is-unavailable {
  opacity: 0.7;
}

.hub-card-title {
  font-weight: var(--weight-bold);
}

.hub-card-text {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* ---------- Password requirements ---------- */

.password-rules {
  list-style: none;
  margin: 0 0 var(--space-5);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--color-surface-3);
  font-size: var(--text-sm);
}

.password-rules li {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 2px 0;
  color: var(--color-text-muted);
}

.password-rules li::before {
  content: "";
  width: 0.875rem;
  height: 0.875rem;
  flex: none;
  border: 2px solid var(--color-border-strong);
  border-radius: var(--radius-full);
}

.password-rules li.is-met {
  color: var(--color-success);
}

.password-rules li.is-met::before {
  border-color: var(--accent-green);
  background: var(--accent-green);
  box-shadow: inset 0 0 0 2px var(--color-surface-3);
}

/* ---------- Collapsible release entry ---------- */

.release-card {
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

.release-card + .release-card {
  margin-top: var(--space-3);
}

.release-card > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  font-weight: var(--weight-bold);
  cursor: pointer;
  list-style: none;
}

.release-card > summary::-webkit-details-marker {
  display: none;
}

.release-card > summary::after {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.15s;
}

.release-card[open] > summary::after {
  transform: rotate(-135deg);
}

.release-card-body {
  padding: 0 var(--space-5) var(--space-5);
}

.release-card-body ul {
  padding-left: var(--space-5);
}

.release-card-body li::marker {
  color: var(--color-link);
}

/* ---------- Style guide page ---------- */

.swatch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
  gap: var(--space-3);
}

.swatch {
  height: 3rem;
  border-radius: var(--radius);
  background: var(--accent);
}

.sg-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

/* ---------- Business Settings (Phase 17.5 step 3) ---------- */

.brand-mark.is-logo {
  border-radius: var(--radius-full);
  object-fit: cover;
}

.section-note {
  font-size: var(--text-sm);
}

.upload-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  padding: var(--space-4) var(--space-5);
  border: 2px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  background: var(--color-surface-3);
}

.upload-preview {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 4.5rem;
  height: 4.5rem;
  flex: none;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: var(--color-primary-soft);
  color: var(--color-link);
}

.upload-preview img,
.upload-preview canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.upload-preview .icon {
  width: 1.75rem;
  height: 1.75rem;
}

.upload-body {
  flex: 1;
  min-width: 14rem;
}

.upload-title {
  margin: 0 0 var(--space-2);
  font-weight: var(--weight-bold);
}

.upload-body .helptext {
  padding-left: 0;
}

.upload-filename:empty {
  display: none;
}

/* The real file input stays focusable for keyboards; its label is the
   visible button, which shows the focus ring. */
.sr-only-file {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.upload-body:has(.sr-only-file:focus-visible) .upload-button {
  box-shadow: var(--focus-ring);
}

.link-rows {
  display: grid;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.link-row {
  display: grid;
  gap: 0 var(--space-3);
  padding-top: var(--space-3);
}

.link-row > p {
  max-width: none;
  margin-bottom: var(--space-4);
}

.link-remove {
  margin-bottom: var(--space-4);
}

.link-errors {
  grid-column: 1 / -1;
}

@media (min-width: 768px) {
  .link-row {
    grid-template-columns: 12rem 10rem minmax(0, 1fr) auto;
    align-items: start;
  }

  .link-remove {
    align-self: center;
  }
}

.export-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.export-text {
  margin: 0;
}

.export-row select {
  width: auto;
  background-color: var(--color-surface);
}

.crop-dialog {
  width: min(24rem, calc(100vw - 2rem));
  padding: var(--space-5);
  border: none;
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-lg);
}

.crop-dialog::backdrop {
  background: var(--color-overlay);
}

.crop-dialog canvas {
  display: block;
  width: 100%;
  max-width: 20rem;
  margin: 0 auto var(--space-4);
  border-radius: var(--radius);
  background: var(--color-surface-2);
  cursor: move;
  touch-action: none;
}

.crop-dialog input[type="range"] {
  width: 100%;
}

/* ---------- Dashboard (Phase 17.5 step 4) ---------- */

.page-actions,
.dash-hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* A heading with an action on the right, inside a card. */
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}

.card-head .card-title {
  margin-bottom: var(--space-3);
}

.stat-change {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-success);
}

.stat-change .icon {
  width: 1em;
  height: 1em;
}

.stat-change.is-down {
  color: var(--color-danger);
}

/* The down arrow is the up arrow flipped — one icon, both directions. */
.stat-change.is-down .icon {
  transform: scaleY(-1);
}

.spark {
  display: block;
  width: 100%;
  height: 2rem;
  margin-top: var(--space-3);
  overflow: visible;
}

.spark-bar {
  fill: var(--accent, var(--color-primary));
  opacity: 0.55;
}

/* ---------- Progress bar (SVG — the CSP forbids inline widths) ---------- */

.progress {
  display: block;
  width: 100%;
  height: 0.375rem;
  margin: var(--space-2) 0;
}

.progress-track {
  fill: var(--color-surface-3);
}

.progress-fill {
  fill: var(--accent, var(--color-primary));
}

/* ---------- Setup checklist ---------- */

.onboarding {
  margin-bottom: var(--space-5);
}

.onboarding-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.onboarding-head .card-title {
  margin-bottom: var(--space-1);
}

.onboarding-list {
  list-style: none;
  margin: var(--space-4) 0 0;
  padding: 0;
  display: grid;
  gap: var(--space-2);
}

.onboarding-step {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius);
  background: var(--color-surface-2);
}

.onboarding-mark {
  flex: none;
  margin-top: 0.125rem;
  color: var(--color-text-muted);
}

.onboarding-step.is-done .onboarding-mark {
  color: var(--color-success);
}

.onboarding-text {
  display: grid;
  gap: 0.125rem;
  flex: 1;
}

.onboarding-label {
  font-weight: var(--weight-medium);
}

.onboarding-step.is-done .onboarding-label {
  color: var(--color-text-muted);
}

.onboarding-hint {
  font-size: var(--text-xs);
}

/* ---------- Goals ---------- */

.goal-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-4);
}

.goal.is-met {
  --accent: var(--accent-green);
}

.goal-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}

.goal-label {
  font-weight: var(--weight-medium);
}

.goal-numbers {
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.goal-meta {
  margin: 0;
  font-size: var(--text-xs);
}

/* ---------- Quick action tiles ---------- */

.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: var(--space-3);
}

.action-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface-2);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-align: center;
  text-decoration: none;
}

.action-tile:hover {
  border-color: var(--color-link);
  color: var(--color-link);
}

.action-tile .icon {
  width: 1.5rem;
  height: 1.5rem;
  color: var(--color-link);
}

/* ---------- Notification bell ---------- */

.bell-button {
  position: relative;
}

.bell-dot {
  position: absolute;
  top: -0.125rem;
  right: -0.125rem;
  min-width: 1.125rem;
  padding: 0 0.25rem;
  border-radius: var(--radius-full);
  background: var(--color-danger);
  color: #fff;
  font-size: 0.625rem;
  font-weight: var(--weight-bold);
  line-height: 1.125rem;
  text-align: center;
}

.bell-menu {
  width: min(22rem, calc(100vw - 2rem));
  padding: 0;
}

.bell-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.bell-item {
  border-top: 1px solid var(--color-border);
}

.bell-item.is-unread {
  background: var(--color-primary-soft);
}

.bell-link {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  color: var(--color-text);
  font: inherit;
  text-align: left;
}

.bell-link:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.bell-link .icon {
  flex: none;
  margin-top: 0.125rem;
  color: var(--color-link);
}

.bell-text {
  display: grid;
  gap: 0.125rem;
}

.bell-title {
  font-weight: var(--weight-medium);
}

.bell-body,
.bell-when {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.bell-empty {
  margin: 0;
  padding: var(--space-4);
  border-top: 1px solid var(--color-border);
  font-size: var(--text-sm);
}

.bell-all {
  border-top: 1px solid var(--color-border);
  justify-content: center;
  font-weight: var(--weight-medium);
}

/* ---------- Notifications page ---------- */

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

.notice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--color-border);
}

.notice:last-child {
  border-bottom: 0;
}

.notice-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-full);
  background: var(--color-surface-3);
  color: var(--color-link);
}

.notice.is-unread .notice-icon {
  background: var(--color-primary-soft);
}

.notice-body {
  flex: 1;
}

.notice-title {
  margin: 0;
  font-weight: var(--weight-medium);
}

.notice.is-unread .notice-title::after {
  content: "";
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  margin-left: var(--space-2);
  border-radius: var(--radius-full);
  background: var(--color-danger);
  vertical-align: middle;
}

.notice-body p {
  margin: 0;
}

.notice-when {
  font-size: var(--text-xs);
}

/* An empty state inside a card beside cards that do have content. */
.empty-state.is-compact {
  padding: var(--space-5) var(--space-4);
}

.empty-state.is-compact .empty-state-icon {
  width: 2.5rem;
  height: 2.5rem;
}

@media (max-width: 36rem) {
  .page-actions,
  .dash-hero-actions {
    width: 100%;
  }

  .page-actions .btn,
  .dash-hero-actions .btn {
    flex: 1;
    justify-content: center;
  }
}

/* ---------- Scheduling: day indicators (Phase 17.5 step 5) ---------- */

.day-dots {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px;
  margin: 0 0 var(--space-1);
}

.day-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  /* Each dot carries its service's tone class, the same colors the
     chips below use, so the two read as one thing. */
  background: var(--tone-accent, var(--color-primary));
}

.day-dot-more {
  font-size: 0.625rem;
  color: var(--color-text-muted);
}

.day-summary {
  margin: 0 0 var(--space-3);
  font-size: var(--text-sm);
}

/* ---------- Line items on a job or estimate ---------- */

.line-rows {
  display: grid;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.line-row {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-2);
}

.line-row p {
  margin: 0;
}

.line-row input,
.line-row select {
  width: 100%;
}

.line-errors {
  grid-column: 1 / -1;
}

@media (min-width: 48rem) {
  .line-row {
    grid-template-columns: 14rem 1fr 6rem 8rem auto;
    align-items: end;
  }

  /* The column is labelled once by the field above it; repeating the
     label on every row would be noise for a sighted reader. */
  .line-row:not(:first-child) label:not(.checkbox-label) {
    display: none;
  }
}

.crew-picker {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  border: 0;
  margin: 0;
  padding: 0;
}

.crew-choice {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface-2);
  cursor: pointer;
}

.crew-choice:has(input:checked) {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
  color: var(--color-primary-soft-text);
}

.crew-choice:has(input:focus-visible) {
  outline: 2px solid var(--color-link);
  outline-offset: 2px;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

/* ---------- Crew (Phase 17.5 step 7) ---------- */

.crew-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
  gap: var(--space-4);
  align-items: start;
}

.crew-picker legend {
  padding: 0;
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* ---------- Map (Phase 17.5 step 8) ---------- */

.map-card {
  overflow: hidden;
}

.map-canvas {
  height: min(60vh, 32rem);
  width: 100%;
  background: var(--color-surface-2);
}

/* Leaflet draws its own chrome; keep it in the app's palette. */
.leaflet-container {
  font: inherit;
  background: var(--color-surface-2);
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-lg);
}

.leaflet-popup-content a {
  font-weight: var(--weight-medium);
}

.leaflet-bar a {
  background: var(--color-surface);
  color: var(--color-text);
  border-bottom-color: var(--color-border);
}

.leaflet-bar a:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.leaflet-control-attribution {
  background: var(--color-surface);
  color: var(--color-text-muted);
}

.leaflet-control-attribution a {
  color: var(--color-link);
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin: 0;
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.map-key {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.map-dot {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--color-slate);
}

.map-dot.is-scheduled {
  background: var(--color-primary);
}

.map-dot.is-done {
  background: var(--color-success);
}

.map-fallback {
  margin: 0;
  padding: var(--space-5);
}

/* The two ways to place an address: look it up, or type the point.
   A column on a phone so the coordinate boxes don't squeeze the
   buttons, a row once there's space. */
.locate-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.pin-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.pin-form input {
  width: 7rem;
  margin: 0;
}

/* Which address a click on the map will fill in. Only ever set by
   static/js/map.js, so it never shows without the map. */
.pin-form.is-active input {
  border-color: var(--color-primary);
}

.locate-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

/* ---------- Activity log (Phase 17.5 step 10) ---------- */

.change-list {
  list-style: none;
  margin: var(--space-1) 0;
  padding: 0;
  font-size: var(--text-sm);
}

.undo-blocked {
  display: block;
  max-width: 16rem;
  font-size: var(--text-xs);
  text-align: right;
}

.release-group {
  margin: var(--space-4) 0 var(--space-2);
  font-size: var(--text-base);
}
