/* Portal and admin: a dark top bar, a side menu on wide screens (a details menu on phones), and white work areas. */
body { background: var(--surface); }
.skip-link { position: absolute; left: -10000px; }
.skip-link:focus { left: var(--s4); top: var(--s4); z-index: 20; background: var(--white); padding: var(--s2) var(--s4); border-radius: var(--radius-control); }

.topbar { background: var(--graphite); color: var(--white); position: sticky; top: 0; z-index: 10; }
.topbar-row { display: flex; align-items: center; gap: var(--s4); min-height: 60px; padding: 0 var(--gutter); }
.topbar .brand { display: flex; align-items: center; gap: var(--s2); color: var(--white); text-decoration: none; font-family: var(--font-display); font-weight: var(--weight-strong); margin-right: auto; }
.topbar .brand img { height: 28px; width: auto; }
.topbar .brand small { color: var(--on-dark); font-family: var(--font); font-weight: var(--weight-strong); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.08em; }
.topbar a, .topbar summary { color: var(--white); }
.topbar .who { font-size: var(--text-sm); color: var(--on-dark); }
.topbar form { margin: 0; }
.preserve { white-space: pre-wrap; overflow-wrap: break-word; }
tr.unread td { font-weight: var(--weight-strong); }
.link-button { white-space: nowrap; background: none; border: 0; padding: 0; font: inherit; font-weight: var(--weight-strong); color: inherit; cursor: pointer; text-decoration: underline; }

.shell { display: grid; grid-template-columns: 1fr; min-height: calc(100vh - 60px); }
@media (min-width: 960px) { .shell { grid-template-columns: 240px 1fr; } }
.sidenav { background: var(--white); border-right: 1px solid var(--line); padding: var(--s5) var(--s4); }
.sidenav ul { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s1); }
.sidenav a { display: flex; align-items: center; gap: var(--s2); padding: var(--s3) var(--s3); border-radius: var(--radius-control); color: var(--graphite); text-decoration: none; font-weight: var(--weight-body); font-size: var(--text-sm); }
.sidenav a:hover { background: var(--surface-sunken); }
.sidenav a[aria-current="page"] { background: var(--graphite); color: var(--white); }
.sidenav .group { margin: var(--s4) 0 var(--s2); padding: 0 var(--s3); font-size: var(--text-xs); font-weight: var(--weight-strong); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.sidenav .count { margin-left: auto; background: var(--terracotta); color: var(--white); border-radius: var(--radius-tag); padding: 0 var(--s2); font-size: var(--text-xs); }
/* The same links twice: a plain list on wide screens, a collapsible menu on phones (no script needed). */
.sidenav .menu-phone { display: none; }
@media (max-width: 959px) {
    .sidenav { border-right: 0; border-bottom: 1px solid var(--line); padding: var(--s2) var(--gutter); }
    .sidenav .menu-wide { display: none; }
    .sidenav .menu-phone { display: block; }
    .sidenav details summary { cursor: pointer; font-weight: var(--weight-strong); padding: var(--s2) 0; }
}

.work { padding: var(--s6) var(--gutter) var(--s8); min-width: 0; }
.work-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s5); }
.work-head h1 { font-size: var(--text-xl); margin: 0; }
.work-head p { margin: var(--s1) 0 0; color: var(--muted); }
.crumbs { font-size: var(--text-sm); margin: 0 0 var(--s2); }
.crumbs a { color: var(--muted); }

/* A group inside a card is a row with a hairline above it, never a card inside a card. */
.item { border-top: 1px solid var(--line); padding-top: var(--s4); margin-top: var(--s4); }
.panel { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius-card); padding: var(--s5); margin-bottom: var(--s5); }
.panel > h2 { font-size: var(--text-lg); margin: 0 0 var(--s4); }
.panel > :last-child { margin-bottom: 0; }
.panels { display: grid; gap: var(--s5); grid-template-columns: 1fr; align-items: start; }
@media (min-width: 1100px) { .panels { grid-template-columns: 2fr 1fr; } .panels.even { grid-template-columns: 1fr 1fr; } }
.stats { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: var(--s5); }
/* Two key numbers to a row on a phone, never one full-width card each (DESIGN.md, Dashboard). */
@media (max-width: 599px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); } .stat { padding: var(--s3) var(--s4); } }
.stat { color: inherit; text-decoration: none; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius-card); padding: var(--s4) var(--s5); }
a.stat:hover { border-color: var(--graphite); }
.stat { container-type: inline-size; }
.stat strong { display: block; color: var(--terracotta); font-family: var(--font-display); font-size: var(--text-xl); font-size: clamp(0.8125rem, 10cqi, var(--text-xl)); white-space: nowrap; }
.stat span { color: var(--muted); font-size: var(--text-sm); }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.data th { text-align: left; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line); white-space: nowrap; }
.data td { padding: var(--s3); border-bottom: 1px solid var(--line-light); vertical-align: top; }
.data td.num, .data th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.data tr:last-child td { border-bottom: 0; }
.data tfoot td { font-weight: var(--weight-strong); border-top: 1px solid var(--line); }
.empty { color: var(--muted); padding: var(--s4) 0; margin: 0; }

.pill { display: inline-block; padding: 0 var(--s2); line-height: 1.5; border-radius: var(--radius-tag); font-size: var(--text-xs); font-weight: var(--weight-body); background: var(--surface-sunken); color: var(--text-soft); white-space: nowrap; }
.pill.good { background: var(--success-bg); color: var(--success); }
.pill.warn { background: var(--warning-bg); color: var(--warning); }
.pill.bad { background: var(--error-bg); color: var(--error); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill.draft { background: var(--warning-bg); color: var(--warning); border: 1px dashed var(--warning-line); }

.button { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: var(--control); padding: 0 var(--s5); border-radius: var(--radius-control);
    border: 1px solid var(--terracotta); background: var(--terracotta); color: var(--white); font: inherit; font-weight: var(--weight-strong); text-decoration: none; cursor: pointer; }
.button:hover { background: var(--terracotta-dark); border-color: var(--terracotta-dark); }
.button.secondary { background: var(--white); color: var(--graphite); border-color: var(--graphite); }
.button.secondary:hover { background: var(--graphite); color: var(--white); }
.button.danger { background: var(--white); color: var(--error); border-color: var(--error); }
.button.small { min-height: var(--control-small); padding: 0 var(--s4); font-size: var(--text-sm); }
.form .button, .panel > form > .button { justify-self: start; }
.actions { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; }
.inline-form { display: inline; margin: 0; }

.notice { border-radius: var(--radius-control); padding: var(--s3) var(--s4); margin: 0 0 var(--s5); background: var(--info-bg); color: var(--info); }
.notice.warn { background: var(--warning-bg); color: var(--warning); }
.notice.good { background: var(--success-bg); color: var(--success); }
.notice.bad { background: var(--error-bg); color: var(--error); }

dl.facts { display: grid; grid-template-columns: minmax(0, 40%) minmax(0, 1fr); gap: var(--s2) var(--s5); margin: 0; }
@media (max-width: 600px) { dl.facts { grid-template-columns: minmax(0, 1fr); gap: 0; } dl.facts dd { margin-bottom: var(--s3); } }
dl.facts dt { color: var(--muted); font-size: var(--text-sm); }
dl.facts dd { margin: 0; font-weight: var(--weight-strong); overflow-wrap: break-word; }
.muted { color: var(--muted); }
.small { font-size: var(--text-sm); }
.mono, code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: var(--text-sm); }
.prose { max-width: 72ch; line-height: 1.6; }
.contract { max-height: 420px; overflow: auto; box-shadow: inset 0 -14px 12px -14px rgba(0, 0, 0, 0.35); border: 1px solid var(--line); border-radius: var(--radius-control); padding: var(--s4); background: var(--surface-quiet); font-size: var(--text-sm); line-height: 1.55; }
.contract h1 { font-size: var(--text-base); margin: 0 0 var(--s3); }
.contract h2 { font-size: var(--text-base); margin: var(--s4) 0 var(--s2); }
.contract h3 { font-size: var(--text-sm); margin: var(--s3) 0 var(--s2); }
.contract p, .contract ul { margin: 0 0 var(--s3); }
.contract ul { padding-left: var(--s5); }
.contract table { border-collapse: collapse; margin: 0 0 var(--s3); width: 100%; }
.contract th, .contract td { border: 1px solid var(--line); padding: var(--s2); text-align: left; vertical-align: top; }

.steps { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s3); }
.steps li { display: flex; gap: var(--s3); align-items: flex-start; }
.steps .dot { flex: none; width: 28px; height: 28px; border-radius: var(--radius-control); display: grid; place-items: center; font-weight: var(--weight-strong); font-size: var(--text-sm); background: var(--surface-sunken); }
.steps .done .dot { background: var(--success); color: var(--white); }
.steps .now .dot { background: var(--terracotta); color: var(--white); }

.week { display: grid; gap: var(--s2); }
.week-row { display: grid; grid-template-columns: 7rem 6rem 1fr; gap: var(--s3); align-items: center; }
@media (max-width: 600px) { .week-row { grid-template-columns: 1fr 5rem; } .week-row input[type="text"] { grid-column: 1 / -1; } }

.thread { display: grid; gap: var(--s3); margin-bottom: var(--s4); }
.thread .msg { border: 1px solid var(--line); border-radius: var(--radius-control); padding: var(--s3) var(--s4); }
.thread .msg.staff { background: var(--surface-warm); }
.thread .msg header { font-size: var(--text-xs); color: var(--muted); margin-bottom: var(--s1); }

.auth { max-width: 460px; margin: var(--s8) auto; padding: 0 var(--gutter); }
.auth .panel { padding: var(--s6); }
.auth h1 { font-size: var(--text-xl); margin: 0 0 var(--s2); }
.divider { display: flex; align-items: center; gap: var(--s3); color: var(--muted); font-size: var(--text-sm); margin: var(--s4) 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.qr svg { width: 200px; height: 200px; }

details.reveal { margin-top: var(--s3); }
details.reveal > summary { cursor: pointer; color: var(--terracotta-dark); font-size: var(--text-sm); list-style-position: inside; padding: var(--s1) 0; }
details.reveal > summary:hover { text-decoration: underline; }
details.reveal[open] > summary { margin-bottom: var(--s2); }
.side-by-side { display: grid; gap: var(--s5); grid-template-columns: 1fr; }
@media (min-width: 1100px) { .side-by-side { grid-template-columns: 1fr 1fr; } }
.checklist { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s2); }
.checklist li { display: flex; gap: var(--s3); align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line-light); padding: var(--s2) 0; }
.lang-switch { color: var(--on-dark); font-weight: var(--weight-strong); font-size: var(--text-sm); }

/* Headings inside panels stay panel-sized; inputs in action rows keep their own width. */
.panel .work-head h2, .panel article h2 { font-size: var(--text-lg); margin: 0; }
.panel .work-head { margin-bottom: var(--s3); }
.actions select, .actions input:not([type=hidden]) { width: auto; min-width: 0; }
@media (max-width: 600px) {
    .topbar .brand small, .topbar .who { display: none; }
    .work-head h1 { font-size: var(--text-xl); }
}
.panel > h2:not(:first-child) { margin-top: var(--s6); }
.welcome { border-color: var(--terracotta); }

/* Payout account: only the fields of the chosen method. */
.payout-form .method-fields { display: none; }
.payout-form:has(input[value="MxnClabe"]:checked) .method-clabe,
.payout-form:has(input[value="UsdWise"]:checked) .method-wise { display: grid; gap: var(--s4); }

/* Phones: grid and flex children may shrink below their content, and long words (emails, setting keys, links) wrap
   instead of widening the page. Tables keep their own sideways scroll (.table-wrap). */
.shell > *, .panels > *, .side-by-side > *, .field-row > *, .panel, .checklist li > *, .actions > *, .form > *, .field > *, .work-head > *, dl.facts > * { min-width: 0; }
.panel p, .panel li, .panel label, .panel dd, .panel code, .panel a, .notice { overflow-wrap: break-word; }
.checklist li { flex-wrap: wrap; }

/* Identifiers never break; a long one (UUID, fingerprint) breaks only at its hyphens or at the <wbr> set in it. */
.id { white-space: nowrap; overflow-wrap: normal; }
.id.id-long { white-space: normal; overflow-wrap: normal; word-break: normal; }
@media (max-width: 600px) { .contract { max-height: none; overflow: visible; box-shadow: none; } }

/* Phone width: a data table becomes a list of cards, one per row, every cell shown with its column name (see labelTables in app.js). */
@media (max-width: 600px) {
  table.data, .data tbody, .data tfoot, .data tr, .data td { display: block; width: 100%; }
  .data thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .data tr { padding: var(--s2) 0; border-bottom: 1px solid var(--line); }
  /* A cell is two columns: the column name, and one value column holding everything the cell contains (labelTables wraps it in .cell). */
  .data td[data-label] { display: grid; grid-template-columns: minmax(5.5rem, 38%) minmax(0, 1fr); column-gap: var(--s3); align-items: baseline; }
  .data td, .data tfoot td { border: 0; padding: var(--s1) var(--s3); text-align: right; min-width: 0; overflow-wrap: break-word; }
  .data td::before { content: attr(data-label); text-align: left; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); overflow-wrap: normal; }
  .data td:not([data-label])::before { content: none; }
  .data td > .cell { min-width: 0; max-width: 100%; }
  .data td.long[data-label] { grid-template-columns: minmax(0, 1fr); row-gap: var(--s1); text-align: left; }   /* free text: the name above, the text across the card */
  .data td.num { white-space: normal; }
  .data .pill { white-space: normal; }   /* a tag with a long reason ("Likely spam: ...") wraps inside its card instead of widening the table */
  .data tfoot td.row-name { display: none; }   /* its text names the footer row's value instead ("TOTAL $11,200.00") */
}
}

/* Admin console (staff, desktop first): the compact scale of tokens.css; table rows are 32px with a mouse. */
@media (min-width: 600px) { [data-scale="compact"] .data td { height: var(--row); padding-top: 0; padding-bottom: 0; } }

/* The compact scale (admin): app headings step down with the body text. */
[data-scale="compact"] .work-head h1 { font-size: var(--text-lg); }
[data-scale="compact"] .panel > h2, [data-scale="compact"] .panel .work-head h2, [data-scale="compact"] .panel article h2 { font-size: var(--text-base); }

/* The confirmation dialog (app.js, [data-confirm]): a card over a dimmed page; Cancel has the focus. */
dialog.confirm { border: 1px solid var(--line); border-radius: var(--radius-card); padding: var(--s5); max-width: 28rem; box-shadow: var(--shadow); color: var(--graphite); }
dialog.confirm::backdrop { background: var(--overlay); }
dialog.confirm p { margin: 0 0 var(--s5); }
dialog.confirm .actions { display: flex; gap: var(--s3); justify-content: flex-end; }
