/* AI Rascals HQ - tokens, base, the shared parts and the shell.
   The idea: a plain, simple CRM. White, thin grey lines, one blue for the thing you can do
   or the place you are, red only for late. Every page is tabs, one slim line of numbers,
   filter chips and one list (SPEC-STEP7.md). See docs/DESIGN.md before adding anything. */

@font-face {
  font-family: "Inter";
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  src: url("../fonts/inter-latin-wght-normal.woff2") format("woff2");
}

/* ---------- Tokens ---------- */

:root {
  color-scheme: light dark;

  --bg: #ffffff;
  --panel: #f7f8fa;
  --chip: #eef0f3;
  --line: #e6e8ec;
  --line-soft: #eef0f3;
  --control: #d5d9e0;
  --ink: #18202c;
  --ink-2: #3b4554;
  --ink-3: #5a6472;
  --accent: #2563d9;
  --accent-ink: #1d4fc0;
  --accent-soft: #eaf1fd;
  --accent-line: #b9cff7;
  --on-accent: #ffffff;
  --late: #c2321f;
  --late-soft: #fdecea;
  --warn: #9a5b00;
  --warn-soft: #fff4e0;
  --ok: #1a7f4b;
  --backdrop: rgba(24, 32, 44, 0.4);
  --shadow: 0 8px 28px rgba(24, 32, 44, 0.16);

  /* Text in the accent colour on the page (links, quiet buttons, the current phone tab).
     The accent itself on white; the lighter accent ink on dark. */
  --link: var(--accent);
  /* Behind --ok text in a pill: --ok on it is 4.6:1 (light) and 7.3:1 (dark). */
  --ok-soft: #f1f7f4;
  --hover: color-mix(in srgb, var(--ink) 4%, transparent);

  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --r-control: 8px;
  --r-box: 10px;
  --r-pill: 999px;

  /* Space at the sides of the content: 28px on laptops, 16px on phones. */
  --gutter: 16px;
  --tap: 44px;
  --tabbar-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151c;
    --panel: #161c25;
    --chip: #212936;
    --line: #283140;
    --line-soft: #1f2733;
    --control: #364152;
    --ink: #e9edf2;
    --ink-2: #c5ccd6;
    --ink-3: #9aa5b3;
    --accent: #2f68de;
    --accent-ink: #8ab0ff;
    --accent-soft: #1a2a4a;
    --accent-line: #2d4578;
    --on-accent: #ffffff;
    --late: #ff8f80;
    --late-soft: #3a1c18;
    --warn: #f0b24a;
    --warn-soft: #33270f;
    --ok: #5fcf95;
    --backdrop: rgba(0, 0, 0, 0.55);
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);

    --link: var(--accent-ink);
    --ok-soft: #1b2f2d;
    --hover: color-mix(in srgb, var(--ink) 6%, transparent);
  }
}

@media (min-width: 900px) {
  :root {
    --gutter: 28px;
    --tap: 32px;
    --tabbar-h: 0px;
  }
}

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

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 20px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

@media (min-width: 900px) {
  body {
    font-size: 14px;
  }
}

h1,
h2,
h3,
h4,
p,
ul,
ol,
dl,
dd {
  margin: 0;
}

h1,
h2,
h3,
h4 {
  font-size: inherit;
  font-weight: 600;
}

ul,
ol {
  padding: 0;
  list-style: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

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

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

.no-scroll,
.no-scroll body {
  overflow: hidden;
}

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

.boot {
  padding: 48px 16px;
  text-align: center;
  color: var(--ink-3);
}

.soft {
  color: var(--ink-3);
}

.num,
.fig {
  font-variant-numeric: tabular-nums;
}

.fig {
  font-weight: 600;
}

.icon {
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

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

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--control);
  border-radius: var(--r-control);
  background: var(--bg);
  color: var(--ink);
  font-size: inherit;
  font-weight: 500;
  line-height: 20px;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.btn--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

.btn--quiet {
  border-color: transparent;
  background: transparent;
  color: var(--link);
  padding: 0 8px;
}

.btn--danger {
  border-color: var(--late);
  color: var(--late);
}

.btn--small {
  min-height: 36px;
  padding: 0 12px;
  font-size: 13px;
  line-height: 18px;
}

.btn--quiet.btn--small {
  padding: 0 6px;
}

/* A small button on a phone keeps a 44px tap area around its smaller box. */
.btn--small::after {
  content: "";
  position: absolute;
  inset: -4px 0;
}

.btn--block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

@media (min-width: 900px) {
  .btn {
    min-height: 36px;
  }

  .btn--small {
    min-height: 32px;
  }

  .btn--small::after {
    content: none;
  }
}

.iconbtn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: var(--r-control);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}

@media (min-width: 900px) {
  .iconbtn {
    width: 36px;
    height: 36px;
  }
}

/* A button that reads as a link (old name; pages may use .btn--quiet instead). */
.linkbtn {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--link);
  font-weight: 500;
  cursor: pointer;
}

/* ---------- Fields ---------- */

.form {
  display: grid;
  gap: 16px;
}

.form__row {
  display: grid;
  gap: 16px;
}

@media (min-width: 560px) {
  .form__row {
    grid-template-columns: 1fr 1fr;
  }
}

.form__error {
  padding: 8px 12px;
  border-radius: var(--r-control);
  background: var(--late-soft);
  color: var(--late);
}

.form__note {
  color: var(--ink-3);
  font-size: 13px;
  line-height: 18px;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field__label {
  font-size: 13px;
  line-height: 18px;
  font-weight: 500;
}

.field__req {
  font-weight: 400;
  color: var(--ink-3);
}

.field__hint {
  font-size: 12px;
  line-height: 16px;
  color: var(--ink-3);
}

.field__error {
  font-size: 13px;
  line-height: 18px;
  color: var(--late);
}

/* Inputs are 16px on phones: iOS zooms the page on anything smaller. */
.input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--control);
  border-radius: var(--r-control);
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 22px;
}

textarea.input {
  min-height: 92px;
  padding: 10px 12px;
  resize: vertical;
}

select.input {
  padding-right: 8px;
}

@media (min-width: 900px) {
  .input {
    min-height: 40px;
    font-size: 14px;
    line-height: 20px;
  }
}

.input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: var(--accent);
}

.input[aria-invalid="true"] {
  border-color: var(--late);
}

.input::placeholder {
  color: var(--ink-3);
  opacity: 1;
}

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

.input-wrap__pre {
  position: absolute;
  left: 12px;
  color: var(--ink-3);
  pointer-events: none;
}

.input-wrap__post {
  flex: none;
  color: var(--ink-3);
  font-size: 13px;
  white-space: nowrap;
}

.input--money {
  padding-left: 26px;
  font-variant-numeric: tabular-nums;
}

/* A plain checkbox row. */
.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: 32px;
}

.check input {
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
  flex: none;
  accent-color: var(--accent);
}

/* ---------- Sheets and dialogs (the only raised layer) ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: var(--backdrop);
}

.sheet {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: calc(100vh - 20px);
  max-height: calc(100dvh - 20px - env(safe-area-inset-top));
  background: var(--bg);
  color: var(--ink);
  border-radius: 12px 12px 0 0;
  box-shadow: var(--shadow);
  animation: sheet-rise 0.16s ease-out;
}

.sheet:focus {
  outline: none;
}

.sheet__head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 12px 10px 12px 20px;
  border-bottom: 1px solid var(--line);
}

.sheet__title {
  flex: 1;
  min-width: 0;
  padding-top: 8px;
  font-size: 20px;
  line-height: 28px;
  font-weight: 600;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.sheet__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

.sheet__foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.sheet__body:has(+ .sheet__foot) {
  padding-bottom: 20px;
}

/* Inside a sheet the sample mark shows (it is hidden in every list). */
.sheet .tag--sample {
  display: inline-flex;
}

@keyframes sheet-rise {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

@keyframes sheet-slide {
  from {
    transform: translateX(24px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (min-width: 900px) {
  .overlay {
    align-items: center;
    padding: 24px;
  }

  .sheet {
    max-width: 520px;
    max-height: calc(100vh - 48px);
    max-height: calc(100dvh - 48px);
    border-radius: var(--r-box);
    animation-name: fade-in;
  }

  .sheet--dialog {
    max-width: 420px;
  }

  .overlay--panel {
    align-items: stretch;
    justify-content: flex-end;
    padding: 0;
  }

  .sheet--panel {
    max-width: 480px;
    height: 100%;
    max-height: none;
    border-radius: 0;
    border-left: 1px solid var(--line);
    animation-name: sheet-slide;
  }
}

/* ---------- Small parts ---------- */

/* A status: grey unless a tone says otherwise. */
.pill,
.tag {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 22px;
  padding: 0 8px;
  border-radius: var(--r-pill);
  background: var(--chip);
  color: var(--ink-2);
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

.pill--late,
.tag--late {
  background: var(--late-soft);
  color: var(--late);
}

.pill--warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.pill--ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.pill--accent {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.pill--quiet {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink-3);
}

.tag--today {
  color: var(--ink);
  font-weight: 600;
}

/* "Sample" is not shown in lists; only a sheet shows it (see .sheet .tag--sample). */
.tag--sample {
  display: none;
  font-weight: 400;
}

/* The owner's initials on a grey circle. No owner colours. */
.mark {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 50%;
  background: var(--chip);
  color: var(--ink-2);
  font-size: 11px;
  line-height: 1;
  font-weight: 600;
  font-style: normal;
}

.mark--lg {
  width: 30px;
  height: 30px;
}

.mark--none {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--control);
  color: var(--ink-3);
}

/* Chips: 32px on laptops; on phones a 34px pill inside a 44px tap area. */
.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid var(--control);
  border-radius: var(--r-pill);
  background: var(--bg);
  color: var(--ink-2);
  font-size: 14px;
  line-height: 18px;
  font-weight: 400;
  white-space: nowrap;
  cursor: pointer;
}

.chip::after {
  content: "";
  position: absolute;
  inset: -5px 0;
}

.chip[aria-pressed="true"] {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 600;
}

.chip:disabled {
  opacity: 0.5;
  cursor: default;
}

.chip__n {
  font-variant-numeric: tabular-nums;
}

@media (min-width: 900px) {
  .chip {
    min-height: 32px;
    padding: 0 12px;
    font-size: 13px;
  }

  .chip::after {
    content: none;
  }
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* The small switch: a joined pair or trio of buttons. */
.seg {
  display: inline-flex;
  flex: none;
  border: 1px solid var(--control);
  border-radius: var(--r-control);
  background: var(--bg);
  overflow: hidden;
}

.seg__btn {
  position: relative;
  min-height: 42px;
  padding: 0 14px;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font-size: inherit;
  white-space: nowrap;
  cursor: pointer;
}

.seg__btn + .seg__btn {
  border-left: 1px solid var(--control);
}

.seg__btn[aria-pressed="true"] {
  background: var(--chip);
  color: var(--ink);
  font-weight: 600;
}

.seg__btn:focus-visible {
  outline-offset: -2px;
}

.seg--small .seg__btn {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

@media (min-width: 900px) {
  .seg__btn {
    min-height: 34px;
  }

  .seg--small .seg__btn {
    min-height: 30px;
  }
}

/* An on/off switch (two-step sign-in for everyone, in People). */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  border-radius: var(--r-control);
  background: transparent;
  font-weight: 500;
  cursor: pointer;
}

.switch:disabled {
  opacity: 0.5;
  cursor: default;
}

.switch__track {
  position: relative;
  width: 36px;
  height: 20px;
  flex: none;
  border-radius: var(--r-pill);
  background: var(--control);
  transition: background 0.12s ease;
}

.switch__knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg);
  transition: transform 0.12s ease;
}

.switch[aria-checked="true"] .switch__track {
  background: var(--accent);
}

.switch[aria-checked="true"] .switch__knob {
  background: var(--on-accent);
  transform: translateX(16px);
}

.money {
  font-variant-numeric: tabular-nums;
}

.money__per {
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-3);
}

/* A date in a list: quiet; late is red and bold; today is bold. */
.due {
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.due--late {
  color: var(--late);
  font-weight: 600;
}

.due--today {
  color: var(--ink);
  font-weight: 600;
}

.empty {
  display: grid;
  gap: 6px;
  justify-items: center;
  padding: 40px 16px;
  text-align: center;
}

.empty__title {
  font-size: 15px;
  line-height: 20px;
  font-weight: 600;
}

.empty__body {
  max-width: 46ch;
  color: var(--ink-3);
}

.empty__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}

/* Toasts sit at the top so they never cover the buttons at the bottom of a sheet. */
.toasts {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 0;
  right: 0;
  z-index: 80;
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 0 16px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 480px;
  padding: 10px 16px;
  border-radius: var(--r-control);
  background: var(--ink);
  color: var(--bg);
  font-weight: 500;
  box-shadow: var(--shadow);
}

.toast::before {
  content: "";
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--ok);
}

.toast--error {
  background: var(--late-soft);
  color: var(--late);
  box-shadow: var(--shadow), inset 0 0 0 1px var(--late);
}

.toast--error::before {
  background: var(--late);
}

/* A plain note box (used to be dashed). */
.callout {
  display: grid;
  gap: 8px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-box);
  background: var(--panel);
}

.secret {
  font-size: 18px;
  line-height: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  user-select: all;
  overflow-wrap: anywhere;
}

.stack {
  display: grid;
  gap: 16px;
}

.inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* ---------- The page pattern: Tabs, Figures, FilterRow, one list ---------- */

/* Tabs: plain text tabs on a line that runs the full width of the content. */
.ptabs {
  display: flex;
  gap: 24px;
  margin: 0 calc(-1 * var(--gutter));
  padding: 0 var(--gutter);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}

.ptabs::-webkit-scrollbar {
  display: none;
}

.ptab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink-3);
  font-size: inherit;
  white-space: nowrap;
  cursor: pointer;
}

.ptab[aria-selected="true"] {
  color: var(--ink);
  font-weight: 600;
  box-shadow: inset 0 -2px 0 var(--accent);
}

.ptab__n {
  color: var(--ink-3);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.ptab:focus-visible {
  outline-offset: -2px;
}

/* Figures: one slim line of numbers. */
dl.figures {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 0 calc(-1 * var(--gutter));
  padding: 12px var(--gutter);
  border: 0;
  border-bottom: 1px solid var(--line-soft);
}

dl.figures > .figure {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 0;
  border: 0;
}

dl.figures .figure__label {
  font-size: 11px;
  line-height: 14px;
  color: var(--ink-3);
  overflow-wrap: anywhere;
}

dl.figures .figure__value {
  font-size: 16px;
  line-height: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

dl.figures .figure__unit {
  display: none;
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-3);
}

dl.figures .figure--warn .figure__value {
  color: var(--warn);
}

dl.figures .figure--late .figure__value {
  color: var(--late);
}

@media (min-width: 900px) {
  dl.figures {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 56px;
    padding: 16px var(--gutter);
  }

  dl.figures .figure__label {
    font-size: 12px;
    line-height: 16px;
  }

  dl.figures .figure__value {
    font-size: 18px;
    line-height: 24px;
  }

  dl.figures .figure__unit {
    display: inline;
  }
}

/* FilterRow: chips on the left, actions on the right (they wrap under when there is no room). */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 8px 0;
}

.filters__chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.filters__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-left: auto;
  font-size: 13px;
  line-height: 18px;
}

.filters__actions .btn--quiet {
  padding: 0 4px;
  font-size: 13px;
}

.filters__actions .input {
  width: auto;
  min-height: 36px;
  font-size: 13px;
}

/* Phones: the chips are one line that scrolls sideways inside the row (the page never
   does), from edge to edge; the actions sit on their own line under it. The padding keeps
   each chip's tap area and its focus ring inside the scrolling box. */
@media (max-width: 899.98px) {
  .filters__chips {
    flex: 1 0 100%;
    flex-wrap: nowrap;
    margin: -5px calc(-1 * var(--gutter));
    padding: 5px var(--gutter);
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  .filters__chips::-webkit-scrollbar {
    display: none;
  }

  .filters__chips > * {
    flex: none;
  }
}

@media (min-width: 900px) {
  .filters {
    padding: 14px 0;
  }

  .filters__actions .input {
    min-height: 32px;
  }
}

/* ---------- DataTable (SPEC-STEP7 4.1) ---------- */

/* Phones first: no box, no head row, each row two lines of 65px. */
.dt {
  margin: 0 calc(-1 * var(--gutter));
}

.dt--end,
.dt--value,
.dt--aside {
  font-variant-numeric: tabular-nums;
}

.dt__head {
  display: none;
}

.dt__row {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "title title value"
    "pill text aside";
  align-items: center;
  align-content: center;
  gap: 4px 12px;
  min-height: 65px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line-soft);
}

.dt__row:has(> .dt--full) {
  grid-template-areas:
    "title title value"
    "pill text aside"
    "full full full";
}

.dt__cell {
  min-width: 0;
}

.dt__cell.dt--title {
  grid-area: title;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-weight: 500;
}

.dt__cell.dt--value {
  grid-area: value;
  text-align: right;
  white-space: nowrap;
}

.dt__cell.dt--pill {
  grid-area: pill;
  display: flex;
  font-size: 13px;
  line-height: 18px;
}

.dt__cell.dt--text {
  grid-area: text;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--ink-3);
  font-size: 13px;
  line-height: 18px;
}

/* A row without a pill lets the text start at the left edge. */
.dt__row:not(:has(> .dt--pill)) > .dt--text {
  grid-column: 1 / 3;
}

.dt__cell.dt--aside {
  grid-area: aside;
  text-align: right;
  white-space: nowrap;
  font-size: 13px;
  line-height: 18px;
}

.dt__cell.dt--full {
  grid-area: full;
}

.dt__cell.dt--hide {
  display: none;
}

/* The row's own button: the title, stretched over the whole row. */
.dt__open {
  display: block;
  max-width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: inherit;
  font-weight: 500;
  text-align: left;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
}

.dt__open::after {
  content: "";
  position: absolute;
  inset: 0;
}

.dt__open:focus-visible {
  outline: none;
}

.dt__open:focus-visible::after {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: var(--r-control);
}

/* Anything else clickable in a row stays above the row's button. */
.dt__act {
  position: relative;
  z-index: 1;
}

.dt__row.is-quiet,
.dt__row.is-quiet .dt__open {
  color: var(--ink-3);
}

.dt__panel {
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line-soft);
}

.dt__sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.dt--end .dt__sort {
  flex-direction: row-reverse;
}

@media (min-width: 900px) {
  .dt {
    margin: 0;
    border: 1px solid var(--line);
    border-radius: var(--r-box);
    overflow-x: auto;
  }

  .dt__head,
  .dt__row {
    display: grid;
    grid-template-columns: var(--dt-cols);
    grid-template-areas: none;
    align-items: center;
    column-gap: 16px;
    row-gap: 0;
    min-width: var(--dt-min, 0);
    padding: 0 16px;
  }

  .dt__row:has(> .dt--full) {
    grid-template-areas: none;
  }

  .dt__head {
    min-height: 40px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    color: var(--ink-3);
    font-size: 12px;
    line-height: 16px;
    font-weight: 500;
  }

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

  .dt__row {
    min-height: 48px;
    border-bottom: 0;
    border-top: 1px solid var(--line-soft);
  }

  .dt__body > :first-child {
    border-top: 0;
  }

  .dt__cell,
  .dt__cell.dt--title,
  .dt__cell.dt--value,
  .dt__cell.dt--pill,
  .dt__cell.dt--text,
  .dt__cell.dt--aside,
  .dt__cell.dt--full,
  .dt__cell.dt--hide {
    display: block;
    grid-area: auto;
    grid-column: auto;
    min-width: 0;
    padding: 12px 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: inherit;
    font-size: inherit;
    line-height: 20px;
    font-weight: 400;
    text-align: left;
  }

  .dt__cell.dt--title {
    font-weight: 500;
  }

  .dt__row:not(:has(> .dt--pill)) > .dt--text {
    grid-column: auto;
  }

  .dt__th.dt--end,
  .dt__cell.dt--end {
    text-align: right;
  }

  .dt__panel {
    min-width: var(--dt-min, 0);
    border-bottom: 0;
    border-top: 1px solid var(--line-soft);
  }

  .dt__row.is-quiet,
  .dt__row.is-quiet .dt__open {
    color: var(--ink-3);
  }
}

@media (min-width: 900px) and (hover: hover) {
  .dt__row--open:hover {
    background: var(--panel);
  }
}

/* ---------- Board (SPEC-STEP7 4.2) ---------- */

/* Phones first: the columns stack into one list with a grey heading per stage. */
.board[role="group"] {
  display: block;
  margin: 0 calc(-1 * var(--gutter));
}

.board[role="group"] > .board__col {
  display: block;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.board__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
  padding: 0 16px;
  background: var(--panel);
}

.board__title {
  margin: 0;
  font-size: 13px;
  line-height: 18px;
  font-weight: 600;
}

.board__n {
  margin-left: 6px;
  color: var(--ink-3);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.board__total {
  color: var(--ink-3);
  font-size: 13px;
  line-height: 18px;
  font-variant-numeric: tabular-nums;
}

.board__list {
  display: flex;
  flex-direction: column;
}

.board__empty {
  padding: 12px 16px;
  color: var(--ink-3);
  font-size: 13px;
  line-height: 18px;
}

.bcard {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "open left"
    "sub right";
  align-items: baseline;
  align-content: center;
  gap: 4px 12px;
  min-height: 65px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg);
  color: var(--ink);
}

.bcard__open {
  grid-area: open;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: inherit;
  font-weight: 500;
  text-align: left;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

button.bcard__open {
  cursor: pointer;
}

button.bcard__open::after {
  content: "";
  position: absolute;
  inset: 0;
}

button.bcard__open:focus-visible {
  outline: none;
}

button.bcard__open:focus-visible::after {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: var(--r-control);
}

.bcard__mark {
  display: none;
}

.bcard__sub {
  grid-area: sub;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--ink-3);
  font-size: 13px;
  line-height: 18px;
}

.bcard__left {
  grid-area: left;
  justify-self: end;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.bcard__right {
  grid-area: right;
  justify-self: end;
  white-space: nowrap;
  font-size: 13px;
  line-height: 18px;
}

.bcard .dt__act,
.bcard a,
.bcard button:not(.bcard__open) {
  position: relative;
  z-index: 1;
}

/* A card without an amount: the title takes the whole first line. */
.bcard:not(:has(> .bcard__left)) > .bcard__open {
  grid-column: 1 / -1;
}

.bcard.is-quiet,
.bcard.is-quiet .bcard__open {
  color: var(--ink-3);
}

@media (min-width: 900px) {
  .board[role="group"] {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(230px, 100%), 1fr));
    align-items: start;
    gap: 16px;
    margin: 0;
  }

  .board[role="group"] > .board__col {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border-radius: var(--r-box);
    background: var(--panel);
  }

  .board__head {
    align-items: baseline;
    min-height: 0;
    padding: 0 2px 4px;
    background: transparent;
  }

  .board__title {
    line-height: 20px;
  }

  .board__total {
    font-size: 12px;
    line-height: 16px;
  }

  .board__list {
    gap: 8px;
  }

  .board__empty {
    padding: 4px 2px;
  }

  .bcard {
    grid-template-areas:
      "open mark"
      "sub sub"
      "left right";
    align-items: center;
    gap: 6px 8px;
    min-height: 0;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--r-control);
  }

  .bcard:not(:has(> .bcard__sub)) {
    grid-template-areas:
      "open mark"
      "left right";
  }

  .bcard:not(:has(> .bcard__left)) > .bcard__open {
    grid-column: open;
  }

  .bcard__open {
    align-self: center;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .bcard__mark {
    grid-area: mark;
    display: flex;
    align-self: start;
    justify-self: end;
  }

  .bcard__mark .mark {
    width: 24px;
    height: 24px;
    font-size: 10px;
  }

  .bcard__left {
    justify-self: start;
    font-size: 13px;
    line-height: 18px;
  }
}

@media (min-width: 900px) and (hover: hover) {
  .bcard:has(> button.bcard__open):hover {
    border-color: var(--control);
  }
}

/* ---------- The shell ---------- */

/* Phones: a top bar with the page's name, the page, and a bottom bar with the pages.
   Laptops: a side menu on the left and the page beside it. */
.app {
  min-height: 100vh;
  min-height: 100dvh;
}

.app__main {
  min-width: 0;
}

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: env(safe-area-inset-top) max(6px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: var(--bg);
}

.top__row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 56px;
}

.top__title {
  min-width: 0;
  margin: 0 auto 0 0;
  font-size: 20px;
  line-height: 28px;
  font-weight: 600;
  letter-spacing: -0.01em;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.top__search {
  padding: 0 10px 10px 0;
}

/* Phones: the tool's name is a link for screen readers (the bar shows the page's name).
   It shows when it has keyboard focus, like a skip link. */
.top__home {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.top__home:focus-visible {
  top: calc(4px + env(safe-area-inset-top));
  left: 8px;
  z-index: 1;
  width: auto;
  height: auto;
  padding: 8px 12px;
  border-radius: var(--r-control);
  background: var(--bg);
  box-shadow: var(--shadow);
  clip-path: none;
}

/* The search box: a bordered box with the icon and a borderless input. */
.search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--control);
  border-radius: var(--r-control);
  background: var(--bg);
  color: var(--ink-3);
}

.search:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: var(--accent);
}

.search .search__input {
  flex: 1;
  min-height: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.search .search__input:focus-visible {
  outline: 0;
}

.avatar {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

/* Banners: one quiet line under the header. */
.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin: 0;
  padding: 8px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  background: var(--panel);
  color: var(--ink-3);
  font-size: 13px;
  line-height: 18px;
}

.banner--offline {
  background: var(--warn-soft);
  color: var(--warn);
  font-weight: 500;
}

.banner .btn {
  margin-left: auto;
  min-height: 28px;
}

.page {
  padding: 0 max(var(--gutter), env(safe-area-inset-right)) calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
}

/* The page links. On laptops they are the side menu; on phones the bottom bar. */
.tablabel {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-width: 0;
  white-space: nowrap;
}

/* The mark on a page link: the Library's count of new finds (a small grey pill), or the
   Operations AI budget mark (a small amber dot, its words for screen readers only). */
.tabmark {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-pill);
  background: var(--chip);
  color: var(--ink-2);
  font-size: 12px;
  line-height: 1;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.tabmark--dot {
  min-width: 8px;
  width: 8px;
  height: 8px;
  padding: 0;
  background: var(--warn);
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  align-items: stretch;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--bg);
  border-top: 1px solid var(--line);
}

.tabbar__item {
  position: relative;
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  height: 64px;
  color: var(--ink-3);
  font-size: 11px;
  line-height: 14px;
  text-decoration: none;
}

.tabbar__item .icon {
  width: 22px;
  height: 22px;
}

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

.tabbar__item .tablabel {
  position: static;
}

.tabbar__item .tabmark {
  position: absolute;
  top: 6px;
  left: calc(50% + 6px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 11px;
}

.tabbar__item .tabmark--dot {
  top: 9px;
  left: calc(50% + 9px);
  min-width: 8px;
  height: 8px;
  padding: 0;
}

/* Five slots: two pages, Add, two pages. The slot stays (empty) on a page this person can
   only view, so the pages keep their places. */
.tabbar__slot {
  display: grid;
  place-items: center;
  flex: 1 1 0;
  min-width: 0;
}

.tabbar__add {
  width: 48px;
  height: 48px;
  min-height: 48px;
  padding: 0;
  border-radius: 50%;
}

/* The side menu (laptops). */
.side {
  display: none;
}

@media (min-width: 900px) {
  /* The side menu's grey and its line run the full height of a long page: the column
     behind the sticky menu is painted on the grid itself. */
  .app {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    background: linear-gradient(to right, var(--panel) 219px, var(--line) 219px, var(--line) 220px, var(--bg) 220px);
  }

  .app__main {
    background: var(--bg);
  }

  .side {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    height: 100vh;
    height: 100dvh;
    padding: 16px 12px;
    overflow-y: auto;
    background: var(--panel);
    border-right: 1px solid var(--line);
  }

  .side__brand {
    padding: 6px 12px 18px;
    color: var(--ink);
    font-size: 15px;
    line-height: 20px;
    font-weight: 600;
    letter-spacing: -0.01em;
    text-decoration: none;
  }

  .side .tabs {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .tab {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 36px;
    padding: 0 12px;
    border-radius: var(--r-control);
    color: var(--ink-2);
    text-decoration: none;
  }

  .tab .icon {
    width: 18px;
    height: 18px;
  }

  .tab .tablabel {
    flex: 1;
    justify-content: space-between;
    gap: 8px;
  }

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

  .tab[aria-current="page"] .tabmark:not(.tabmark--dot) {
    background: var(--bg);
  }

  .side__account {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    margin-top: auto;
    padding: 0 12px;
    border: 0;
    border-radius: var(--r-control);
    background: transparent;
    color: var(--ink);
    text-align: left;
    cursor: pointer;
  }

  .side__account .mark {
    width: 28px;
    height: 28px;
    background: var(--line);
  }

  .side__who {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .side__name {
    font-weight: 500;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .side__role {
    color: var(--ink-3);
    font-size: 12px;
    line-height: 16px;
  }

  .top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding: 14px var(--gutter);
    border-bottom: 1px solid var(--line);
  }

  .top__row {
    display: contents;
  }

  .search {
    width: 260px;
    max-width: 100%;
    min-height: 36px;
  }

  .banner {
    padding: 8px var(--gutter);
  }

  .tabbar {
    display: none;
  }
}

/* ---------- Screens outside the app: setup, sign in, password change, load error ---------- */

.auth {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 16px;
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--panel);
}

.auth__name {
  font-size: 15px;
  line-height: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.auth__box {
  width: 100%;
  max-width: 400px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-box);
}

.auth__inner {
  display: grid;
  gap: 16px;
  padding: 24px;
}

.auth__title {
  font-size: 20px;
  line-height: 28px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.auth__lead {
  color: var(--ink-3);
}

/* A plain panel: what someone sees when no page is open to them. */
.panel {
  max-width: 62ch;
  padding: 28px 0;
}

.panel__title {
  font-size: 20px;
  line-height: 28px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.panel__body {
  margin-top: 8px;
  color: var(--ink-3);
}

.panel__list {
  margin-top: 16px;
  border-top: 1px solid var(--line-soft);
}

.panel__list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
}

.panel__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

/* Hover only where a pointer can hover, so taps on phones do not leave it stuck. */
@media (hover: hover) {
  .btn:hover {
    background: var(--panel);
  }

  .btn--primary:hover {
    border-color: var(--accent-ink);
    background: var(--accent-ink);
  }

  .btn--quiet:hover {
    background: transparent;
    color: var(--accent-ink);
    text-decoration: underline;
    text-underline-offset: 3px;
  }

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

  .iconbtn:hover,
  .avatar:hover,
  .side__account:hover {
    background: var(--hover);
  }

  .chip:hover:not([aria-pressed="true"]) {
    border-color: var(--ink-3);
  }

  .seg__btn:hover:not([aria-pressed="true"]) {
    background: var(--panel);
  }

  .ptab:hover:not([aria-selected="true"]) {
    color: var(--ink);
  }

  .tab:hover:not([aria-current="page"]) {
    background: var(--hover);
  }

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

/* Dark: a hovered primary button gets darker, not lighter, so its white text stays above
   4.5:1 (about 6.4:1). */
@media (hover: hover) and (prefers-color-scheme: dark) {
  .btn--primary:hover {
    border-color: color-mix(in srgb, var(--accent) 82%, black);
    background: color-mix(in srgb, var(--accent) 82%, black);
  }
}
