/* Page components, docs/design.md §4: page header, panel, table, form row, toast. */
.ph {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
}

.ph > div:first-child {
  flex: 1 1 380px;
  min-width: 0;
}

.ph h1 {
  margin: 10px 0 12px;
  font-family: var(--f-display);
  font-size: clamp(1.7rem, 4.2cqi, 2.7rem);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.01em;
}

.acts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 4px;
}

.btn .ms {
  font-size: 19px;
}

.btn.sm {
  height: 30px;
  padding: 0 12px;
  font-size: 13px;
}

.panel {
  min-width: 0;
  margin-bottom: 22px;
  border: var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.panel > .hd {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
  border-bottom: var(--border);
}

.panel > .hd h2 {
  margin: 0;
  font-family: var(--f-display);
  font-size: 1.2rem;
  font-weight: 400;
}

.panel > .hd .note {
  margin-top: 2px;
  color: var(--muted);
  font-size: 14px;
}

.panel > .bd {
  padding: 16px 20px;
}

.panel > .bd.flush {
  padding: 0;
}

/* Arrow list (docs/design.md §4): import findings, a bold lead-in per line. */
.arrow {
  margin: 0;
  padding: 0;
  list-style: none;
}

.arrow li {
  position: relative;
  margin-bottom: 8px;
  padding-left: 24px;
  color: var(--muted);
}

.arrow li::before {
  position: absolute;
  left: 0;
  color: var(--blue);
  content: "→";
}

.arrow li b {
  color: var(--fg);
  font-weight: 600;
}

.scroll {
  overflow-x: auto;
}

table.t {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  font-size: 14px;
}

/* A table of one to three short columns fits a phone without scrolling (Profile: "Your organizations"). */
table.t.narrow {
  min-width: 0;
}

.t th {
  padding: 12px 16px;
  border-bottom: var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

.t td {
  padding: 12px 16px;
  border-bottom: var(--border);
  vertical-align: middle;
}

.t tr:last-child td {
  border-bottom: 0;
}

.chip {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  height: 24px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  background: var(--grey-tint);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.chip.wait {
  background: var(--lime-tint);
  color: var(--on-lime-tint);
}

.chip.ok {
  background: var(--blue);
  color: #fff;
}

/* Two equal columns, one below 900px (Profile: form and "Your organizations"). */
.g2e {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
  align-items: start;
}

@container app (max-width: 899px) {
  .g2e {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Cards: panels side by side in one grid (#2387). Every row has the same gap, its cards start at the
   same top edge and end at the same bottom edge; every row has the same two equal columns, so the
   edges line up from row to row and charts side by side get one width; one column below 900px. A
   page puts its cards into .cards instead of offsetting single panels. */
.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--panel-gap);
  margin-bottom: var(--panel-gap);
}

.cards > .panel {
  margin-bottom: 0;
}

@container app (max-width: 899px) {
  .cards {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* A choice row (#2387): dropdowns or a field in one row that wraps on a phone. A changed dropdown
   applies itself (auto_submit_controller.js, #2629); the button that applies them shows only
   without JavaScript (.noscript-submit). The fields and the button have one height and the button
   sits at the fields' foot, so their top and bottom edges line up. */
.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: flex-end;
  margin-bottom: 16px;
}

.choice-row .field {
  flex: 1 1 200px;
  margin-bottom: 0;
}

.choice-row .field input,
.choice-row .field select,
.choice-row > .btn {
  height: var(--control-height);
}

/* The submit button of a form whose dropdowns apply themselves (auto_submit_controller.js, #2629):
   only a browser without JavaScript shows it. */
@media (scripting: enabled) {
  .btn.noscript-submit {
    display: none;
  }
}

.field input:disabled {
  background: var(--grey-tint);
  color: var(--muted);
}

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

/* Account → Members: a refused role change or removal, under the member's name. */
.field__error.member__error {
  margin: 4px 0 0;
}

/* Plattform → Organisationen: name over "seit …". */
.tenant {
  display: grid;
}

.tenant__name {
  font-weight: 600;
}

.tenant__since {
  color: var(--muted);
  font-size: 13px;
}

/* A row's actions on Platform → Organizations: Edit limits and Switch side by side (#1201). */
.tenant__acts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Plattform → Organisationen: texts, images and API requests of the month, right-aligned with
   equal-width digits; positioned, so the hidden text of a dash ("none") stays in its cell. */
.t .tenant__usage {
  position: relative;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.frow {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 16px;
}

@container app (max-width: 599px) {
  .frow {
    grid-template-columns: minmax(0, 1fr);
  }
}

.field select {
  width: 100%;
  padding: 10px 12px;
  border: var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}

/* A text field; .big for long texts (Editorial: the house style). */
.field textarea {
  width: 100%;
  min-height: 130px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  line-height: 1.55;
  resize: vertical;
}

.field textarea.big {
  min-height: 230px;
  font-size: 16px;
}

.field textarea:focus {
  outline: 2px solid var(--blue);
  outline-offset: -1px;
}

.field--narrow {
  max-width: 360px;
}

.field__error {
  margin: 0 0 16px;
  color: var(--red);
  font-size: 14px;
}

.field .field__error {
  margin: 0;
}

.field_with_errors {
  display: contents;
}

/* An option: a checkbox with its title and description, the whole box clickable (mockup .opt). */
.opt {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 16px;
  padding: 12px 14px;
  border: var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
}

.opt input {
  flex: none;
  width: 18px;
  height: 18px;
  margin-top: 3px;
  accent-color: var(--blue);
}

.opt .tt {
  display: block;
  font-weight: 600;
}

.opt .ds {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.opt:has(input:checked) {
  border-color: var(--blue);
  background: var(--surface);
}

/* A select with its submit button inside a table cell (mapping-table select, §4.4). */
.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.inline-form select {
  padding: 5px 8px;
  border: var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
}

.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  z-index: 50;
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  background: var(--nav);
  color: #fff;
  font-size: 14px;
  transform: translateX(-50%);
  /* Rises in, stays 2.4s, fades out (#2376). */
  animation: toast-in var(--duration) var(--ease-out), toast-out var(--duration-swap) var(--ease-in) 2.4s forwards;
}

.toast .ms {
  color: var(--accent);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 6px);
  }
}

@keyframes toast-out {
  to {
    visibility: hidden;
    opacity: 0;
  }
}

/* Pager (shared/_pager): the count and the page links of a list. */
.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: space-between;
  margin-top: 18px;
}

.pager__count {
  color: var(--muted);
  font-size: 13px;
}

.pager__pages {
  display: flex;
  gap: 4px;
  align-items: center;
}

.pager__pages a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  border: var(--border);
  border-radius: var(--radius-pill);
  color: var(--fg);
  font-size: 13px;
  text-decoration: none;
}

.pager__pages a[aria-current="page"] {
  border-color: var(--nav);
  background: var(--nav);
  color: var(--white);
}

/* Segmented control (§4.10): a binary view switch, the shown option filled. Options are links
   (aria-current) or buttons (aria-pressed). */
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  margin-bottom: 12px;
  border: var(--border);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.seg a,
.seg button {
  padding: 6px 14px;
  border: 0;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  text-decoration: none;
}

.seg a[aria-current="page"],
.seg button[aria-pressed="true"] {
  background: var(--nav);
  color: var(--white);
}

/* Inside the outline, which the rounded border would clip. */
.seg a:focus-visible,
.seg button:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
}

/* Read by screen readers, not shown. It is positioned against its nearest positioned ancestor: give
   that one position: relative inside a scroll area, or the 1px box can widen the page on a phone. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Bar chart (docs/design.md §4.15), drawn by bar_chart_controller.js. Holds the height before the
   SVG is drawn and positions the tooltip and the screen-reader table. */
.chart {
  position: relative;
  min-height: 200px;
}

.chart svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart .gl {
  stroke: var(--chart-grid);
  stroke-width: 1;
}

.chart .tk {
  fill: var(--muted);
  font-family: var(--f-body);
  font-size: 12px;
}

.chart .bar {
  fill: var(--chart);
}

/* The slot's hit area takes the hover, also where its bar or a label lies on top of it. */
.chart .bar,
.chart .tk {
  pointer-events: none;
}

.chart .bar.on {
  opacity: 0.75;
}

.chart .hit {
  fill: transparent;
}

.chart .tip {
  position: absolute;
  top: 0;
  z-index: 3;
  padding: 6px 10px;
  border: var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  box-shadow: var(--shadow-tooltip);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}

.chart .tip b {
  font-family: var(--f-display);
}

/* Dialog (confirmations, small forms); .dlg--wide is large enough to edit a long text. */
.dlg {
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 20px;
  border: var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
}

.dlg::backdrop {
  background: rgba(10, 10, 10, .4);
}

/* Opening fades in and scales from .98, closing fades out (#2376). Pure CSS: @starting-style gives
   the first frame, allow-discrete keeps the dialog in the top layer until it has faded. Browsers
   without it open and close at once, as before. */
.dlg,
.dlg::backdrop {
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease-in), display var(--duration-fast) allow-discrete,
    overlay var(--duration-fast) allow-discrete;
}

.dlg[open],
.dlg[open]::backdrop {
  opacity: 1;
  transition: opacity var(--duration) var(--ease-out), transform var(--duration) var(--ease-out),
    display var(--duration) allow-discrete, overlay var(--duration) allow-discrete;
}

@starting-style {
  .dlg[open] {
    opacity: 0;
    transform: scale(.98);
  }

  .dlg[open]::backdrop {
    opacity: 0;
  }
}

.dlg h2 {
  margin: 0 0 12px;
  font-family: var(--f-display);
  font-size: 1.2rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.dlg__acts {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.dlg--wide {
  width: min(960px, calc(100vw - 32px));
}

.dlg--wide textarea.big {
  min-height: 60vh;
}

/* Page changes and the switch transition (#2376, docs/design.md §2.3; the demo's m-swap without
   its rise): every Turbo visit renders the main content region anew (the app's main.page, the
   handbook's main), and it fades in; the navigation and the bars change at once. .swap gives the
   same fade to a part that changes outside a visit's main region; inside it the part fades once,
   with the region. It is a plain CSS animation of the page itself, not a view transition, so
   there is no overlay and a click during the fade lands. A frame reload or a morphing page refresh
   (a run's progress) keeps the region and does not replay it. Under prefers-reduced-motion
   --duration-swap is 0ms (tokens.css), so nothing changes. Only the opacity animates: a moving
   part would let an early click land beside its target and would place fixed popups by a position
   it then leaves. */
main.page,
.handbook__main,
.swap {
  animation: swap-in var(--duration-swap) var(--ease) backwards;
}

main.page .swap {
  animation: none;
}

/* Turbo's cached preview of a page does not animate; the fresh render that follows does, once. */
html[data-turbo-preview] main.page,
html[data-turbo-preview] .handbook__main,
html[data-turbo-preview] .swap {
  animation: none;
}

@keyframes swap-in {
  from {
    opacity: 0;
  }
}

/* Platform → Organizations → Create organization: the hard limits, week and month side by side. */
.hard-limits {
  margin: 0 0 8px;
  padding: 0;
  border: 0;
}

.hard-limits legend {
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 600;
}

.hard-limits__hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

/* A row per counter, a column per period (week, month); each input names its limit (aria-label). */
.hard-limits__grid {
  display: grid;
  grid-template-columns: minmax(0, max-content) repeat(2, minmax(0, 1fr));
  gap: 0 16px;
  align-items: start;
}

.hard-limits__period {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.hard-limits__counter {
  padding-top: 10px;
  font-weight: 600;
}

/* On a phone the counter heads its row, so both inputs keep their width. */
@container app (max-width: 599px) {
  .hard-limits__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hard-limits__grid > span:first-child {
    display: none;
  }

  .hard-limits__counter {
    grid-column: 1 / -1;
    padding-top: 0;
    margin-bottom: 6px;
  }
}

/* Account → Members: the Admin's unobtrusive link to the open-source licenses page (#2364). */
.members__licenses {
  margin: 32px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.members__licenses a {
  color: inherit;
}
