/*
 * EqualDoc application (authenticated dashboard) – shell and shared components.
 * Loaded after css/style.css and reuses its tokens, buttons, typography,
 * .visually-hidden, .skip-link, .lang-switch, .field and .error-summary.
 * Feature stylesheets (app-pdfs.css, app-job.css, app-admin.css, …) only add
 * feature-specific rules.
 *
 *   1. Tokens (additional colours; nothing below uses a literal colour)
 *   2. Shell: grid, topbar, sidebar (disclosure menu below 60rem), main
 *   3. Typography and page header
 *   4. Components: card, grid, table, status badge, notices, small buttons, dev badge
 *   5. Overview page
 *   6. Forced colours and motion
 *
 * Contrast (WCAG 2.x) of the new pairs (style.css lists the brand pairs):
 *   neutral-text #374151 on neutral-light #F3F4F6 9.4:1
 *   info #1E40AF on info-light #EFF6FF 8.0:1 · on #FFFFFF 8.7:1
 *   warning-text #78350F on warning-strong #FDE68A 7.3:1 (WARNING badge)
 *   warning #92400E on #FFFFFF 7.1:1 · on warning-light #FFFBEB 6.8:1 ·
 *     on #FDE68A 5.7:1 (badge border, notice bar)
 *   text #1F2937 on warning-light #FFFBEB 14.2:1 · on info-light 13.5:1 ·
 *     on dev-light #F5F3FF 13.4:1
 *   dev #5B21B6 on dev-light #F5F3FF 8.2:1 · white on dev-strong #6D28D9 7.1:1
 *   error #B91C1C on error-light #FEF2F2 5.9:1 (FAILED badge)
 *   primary-dark #166534 on primary-light #DCFCE7 6.5:1 (DONE badge)
 *   muted #6B7280 is only used on #FFFFFF (4.8:1) and #F9FAFB (4.6:1).
 */

/* ---------- 1. Tokens ---------- */
:root {
  --color-neutral-light: #F3F4F6;
  --color-neutral-text: #374151;
  --color-info: #1E40AF;
  --color-info-light: #EFF6FF;
  --color-warning: #92400E;
  --color-warning-text: #78350F;
  --color-warning-light: #FFFBEB;
  --color-warning-strong: #FDE68A;
  --color-dev: #5B21B6;
  --color-dev-strong: #6D28D9;
  --color-dev-light: #F5F3FF;

  --app-sidebar-width: 15.5rem;
  --app-topbar-height: 4rem;
  /* Main content inset; asymmetric beside the sidebar (see >=60rem) */
  --app-main-pad-start: var(--gutter);
  --app-main-pad-end: var(--gutter);
}

@media (min-width: 60rem) {
  :root {
    --app-main-pad-start: clamp(2rem, 1rem + 1.5vw, 3rem);
    --app-main-pad-end: clamp(2.5rem, 0.5rem + 3vw, 5rem);
  }
}

/* ---------- 2. Shell ---------- */
.app-body {
  display: block;
  min-height: 100vh;
  background: var(--color-bg-alt);
}

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

/*
 * Topbar: brand | organization context | language · user (name + role badge).
 * Below 48rem two rows (brand, language, avatar / organization, user); 48-60rem
 * one flex row; from 60rem a grid whose first column is the sidebar's width,
 * so the organization starts at the content's left edge.
 */
.app-topbar {
  grid-area: top;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 1.25rem;
  min-height: var(--app-topbar-height);
  padding: 0.5rem var(--gutter);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  min-width: 0;
}

.app-brand {
  flex: none;
  font-size: 1.25rem;
}

.app-topbar-org {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
}

/* Organization initials (decorative): primary-dark on primary-light 6.5:1 */
.app-org-mark {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-sm);
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  font-size: 0.8125rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.app-context {
  display: flex;
  flex-direction: column;
  margin: 0;
  min-width: 0;
  line-height: 1.25;
}

/* Muted on white 4.8:1 */
.app-org-label {
  color: var(--color-text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.app-context-org {
  max-width: 28rem;
  overflow: hidden;
  font-size: var(--text-base);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-topbar-end {
  display: flex;
  flex: none;
  align-items: center;
  gap: 1rem;
  margin-left: auto;
  min-width: 0;
}

.app-topbar-divider {
  flex: none;
  width: 1px;
  height: 1.75rem;
  background: var(--color-border);
}

.app-user {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
}

/* User initials (decorative): neutral-text on neutral-light 9.4:1 */
.app-avatar {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  background: var(--color-neutral-light);
  color: var(--color-neutral-text);
  font-size: 0.8125rem;
  font-weight: 700;
}

.app-user-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.125rem;
  margin: 0;
  min-width: 0;
  line-height: 1.25;
}

.app-context-user {
  max-width: 16rem;
  overflow: hidden;
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Role badge, not a button: no outline; primary-dark on primary-light 6.5:1.
   The transparent border shows in forced colours. */
.app-role {
  display: inline-block;
  padding: 0 0.5rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.5;
  white-space: nowrap;
}

/* 48-60rem: the organization label is announced but not shown */
@media (max-width: 59.99rem) {
  .app-org-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* Narrow: row 1 brand and language; row 2 organization and user (the
   decorative initials would sit apart from the name, so they are left out) */
@media (max-width: 47.99rem) {
  .app-topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "brand . lang"
      "org org user";
    gap: 0.25rem 0.75rem;
    padding-block: 0.375rem;
  }

  .app-topbar:not(:has(.app-topbar-org, .app-user)) {
    grid-template-areas: "brand . lang";
  }

  .app-topbar-end,
  .app-user {
    display: contents;
  }

  .app-brand {
    grid-area: brand;
  }

  .app-lang-switch {
    grid-area: lang;
    justify-self: end;
  }

  .app-avatar {
    display: none;
  }

  .app-topbar-divider {
    display: none;
  }

  .app-topbar-org {
    grid-area: org;
  }

  .app-org-mark {
    width: 1.75rem;
    height: 1.75rem;
  }

  .app-context-org {
    font-size: var(--text-sm);
  }

  /* Name and role badge on one line keep the topbar at two rows */
  .app-user-text {
    grid-area: user;
    flex-direction: row;
    align-items: center;
    justify-self: end;
    gap: 0.375rem;
    text-align: right;
  }

  .app-context-user {
    max-width: 100%;
  }
}

@media (min-width: 60rem) {
  .app-topbar {
    display: grid;
    grid-template-columns: var(--app-sidebar-width) minmax(0, 1fr) auto;
    gap: 0;
    padding: 0 var(--app-main-pad-end) 0 0;
  }

  /* Same x as the sidebar's Convert button; the sidebar line continues up */
  .app-brand {
    display: flex;
    grid-column: 1;
    align-items: center;
    align-self: stretch;
    padding-inline: 0.75rem;
    border-right: 1px solid var(--color-border);
  }

  .app-topbar-org {
    grid-column: 2;
    padding-left: var(--app-main-pad-start);
  }

  .app-topbar-end {
    grid-column: 3;
  }
}

/* Sidebar: below 60rem a bar (menu button + Convert PDF) with a disclosure panel */
.app-sidebar {
  grid-area: side;
  min-width: 0;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

.app-sidebar[hidden] {
  display: none;
}

/* Without a sidebar (not signed in, notices) the main area uses the full width */
.app-sidebar[hidden] + .app-main {
  grid-column: 1 / -1;
}

.app-sidebar-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem var(--gutter);
}

.app-menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0.5rem 0.875rem;
  border: 1px solid var(--color-text-muted);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.app-menu-toggle:hover {
  border-color: var(--color-primary-dark);
  color: var(--color-primary-dark);
}

.app-menu-toggle[aria-expanded="true"] {
  background: var(--color-primary-light);
  border-color: var(--color-primary-dark);
  color: var(--color-primary-dark);
}

.app-icon {
  flex: none;
  width: 1.125em;
  height: 1.125em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The shell's primary action: white on #16A34A, valid because the label is 19px bold */
.app-convert {
  gap: 0.5rem;
  margin-left: auto;
  box-shadow: 0 2px 8px -2px var(--shadow-tint);
}

.app-sidebar-panel {
  display: none;
  padding: 0 var(--gutter) 1rem;
}

.app-sidebar-panel.is-open {
  display: block;
}

.app-nav-group {
  padding-block: 0.75rem;
}

.app-nav-group + .app-nav-group {
  border-top: 1px solid var(--color-border);
}

/* Muted on white 4.8:1 */
.app-nav-heading {
  margin: 0 0 0.25rem;
  padding-inline: 0.75rem;
  color: var(--color-text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.app-nav-list {
  display: grid;
  gap: 0.125rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.app-nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  min-height: 2.5rem;
  padding: 0.4375rem 0.75rem;
  border: 0;
  border-left: 4px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--color-text);
  font: inherit;
  font-weight: 550;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.app-nav-link:hover {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
}

.app-nav-link:focus-visible {
  outline-offset: -3px;
}

/* Current page: bar on the left + bold (not colour alone) */
.app-nav-link[aria-current="page"] {
  border-left-color: var(--color-primary-dark);
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  font-weight: 750;
}

.app-nav-button[aria-disabled="true"] {
  cursor: progress;
}

/* "Coming later" tag of the Billing placeholder; muted on white 4.8:1 */
.app-nav-tag {
  color: var(--color-text-muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.app-nav-link:hover .app-nav-tag,
.app-nav-link[aria-current="page"] .app-nav-tag {
  color: var(--color-primary-dark);
}

.app-nav-message {
  margin: 0.25rem 0 0;
  padding: 0.5rem 0.75rem;
  border-left: 4px solid var(--color-error);
  border-radius: var(--radius-sm);
  background: var(--color-error-light);
  font-size: var(--text-sm);
}

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

.app-main {
  grid-area: main;
  min-width: 0;
  padding: clamp(1.25rem, 1rem + 1vw, 2rem) var(--app-main-pad-end) 3rem var(--app-main-pad-start);
}

.app-content,
.app-shell-notice {
  max-width: 72rem;
}

.app-content[hidden] {
  display: none;
}

/* Loading text; afterwards the element stays as a quiet live region */
.app-status {
  color: var(--color-text-muted);
}

.app-status.is-quiet {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (min-width: 60rem) {
  .app {
    grid-template-columns: var(--app-sidebar-width) minmax(0, 1fr);
    grid-template-areas:
      "top top"
      "side main";
    grid-template-rows: auto 1fr;
  }

  .app-sidebar {
    position: sticky;
    top: 0;
    align-self: start;
    max-height: 100vh;
    overflow-y: auto;
    border-bottom: 0;
    border-right: 1px solid var(--color-border);
    min-height: calc(100vh - var(--app-topbar-height));
  }

  .app-menu-toggle {
    display: none;
  }

  .app-sidebar-bar {
    padding: 1rem 0.75rem 0.25rem;
  }

  .app-convert {
    width: 100%;
    margin-left: 0;
  }

  .app-sidebar-panel,
  .app-sidebar-panel.is-open {
    display: block;
    padding: 0 0.75rem 1.5rem;
  }

  .app-nav-link {
    padding-left: 0.5rem;
  }
}

/* ---------- 3. Typography and page header ---------- */
/* Compact application headings instead of the marketing scale (not inside the embedded
   accessibility review, .a11yr, which styles its own; :where keeps the specificity) */
.app-main h1:where(:not(.a11yr *)) {
  font-size: clamp(1.5rem, 1.25rem + 1vw, 2rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.app-main h2:where(:not(.a11yr *)) {
  font-size: var(--text-xl);
  font-weight: 750;
  letter-spacing: -0.01em;
}

.app-main h3:where(:not(.a11yr *)) {
  font-size: var(--text-lg);
}

.app-page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 1.25rem;
}

.app-page-header h1 {
  margin: 0;
}

.app-page-header p {
  flex-basis: 100%;
  margin: 0;
  color: var(--color-text-muted);
}

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

/* ---------- 4. Components ---------- */
.app-card {
  min-width: 0;
  margin-bottom: 1rem;
  padding: 1.25rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
  box-shadow: 0 1px 2px var(--shadow-neutral);
}

.app-card > :last-child {
  margin-bottom: 0;
}

.app-card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  margin-bottom: 0.75rem;
}

.app-card-header h2,
.app-card-header h3 {
  margin: 0;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.app-grid > .app-card {
  margin-bottom: 0;
}

/* Key/value lists inside cards */
.app-facts {
  display: grid;
  gap: 0.5rem 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
  margin: 0;
}

.app-facts dt {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.app-facts dd {
  margin: 0;
  font-weight: 700;
}

/*
 * Tables: the wrapper scrolls inside itself, never the page. A wrapper that can
 * scroll should be focusable (tabindex="0", role="region", aria-label) so
 * keyboard users can scroll it.
 */
.app-table-wrap {
  /* Containing block for visually hidden (absolutely positioned) text in the
     cells, so it is clipped here instead of widening the page. */
  position: relative;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
}

.app-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.app-table caption {
  padding: 0.75rem 1rem 0.25rem;
  font-weight: 700;
  text-align: left;
}

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

.app-table thead th {
  background: var(--color-bg-alt);
  color: var(--color-text);
  font-weight: 700;
  white-space: nowrap;
}

.app-table tbody tr:last-child > * {
  border-bottom: 0;
}

.app-table tbody th {
  font-weight: 600;
}

/*
 * Status badge (js/app/status.js createStatusBadge): icon + text, never colour
 * alone. WARNING is the strongest fill so it draws attention.
 */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.125rem 0.625rem 0.125rem 0.5rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1.5;
  white-space: nowrap;
}

.status-badge .status-icon {
  flex: none;
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.status-badge--uploaded,
.status-badge--unknown {
  background: var(--color-neutral-light);
  color: var(--color-neutral-text);
}

.status-badge--processing {
  background: var(--color-info-light);
  color: var(--color-info);
}

.status-badge--done {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
}

.status-badge--warning {
  border: 2px solid var(--color-warning);
  background: var(--color-warning-strong);
  color: var(--color-warning-text);
}

.status-badge--failed {
  border-width: 2px;
  background: var(--color-error-light);
  color: var(--color-error);
}

/* A converted PDF whose check found errors (status.js OUTCOME_META review_required):
   error colours like --failed, but with the alert icon and its own label. */
.status-badge--review {
  border-width: 2px;
  background: var(--color-error-light);
  color: var(--color-error);
}

/* Notices: text #1F2937 on the light fills (>= 13.4:1), coloured bar on the left */
.app-notice {
  margin-bottom: 1rem;
  padding: 0.875rem 1.125rem;
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-primary-dark);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
}

.app-notice > :last-child {
  margin-bottom: 0;
}

.app-notice p {
  margin: 0 0 0.5rem;
}

.app-notice p:last-child {
  margin-bottom: 0;
}

.app-notice--info {
  border-color: var(--color-info);
  background: var(--color-info-light);
}

.app-notice--success {
  border-color: var(--color-primary-dark);
  background: var(--color-primary-light);
}

.app-notice--warning {
  border-color: var(--color-warning);
  border-left-width: 6px;
  background: var(--color-warning-light);
}

.app-notice--error {
  border-color: var(--color-error);
  border-left-width: 6px;
  background: var(--color-error-light);
}

.app-notice--dev {
  border: 2px dashed var(--color-dev);
  background: var(--color-dev-light);
}

/* Small buttons (table actions etc.): 14px text is not "large", so the primary
   fill switches to primary-dark (white 7.1:1) */
.button-small {
  min-height: 2.25rem;
  padding: 0.25rem 0.75rem;
  font-size: var(--text-sm);
}

.button-small.button-primary {
  background: var(--color-primary-dark);
  border-color: var(--color-primary-dark);
}

.button-small.button-primary:hover,
.button-small.button-primary:active {
  background: var(--color-text);
  border-color: var(--color-text);
}

/* Disabled buttons; muted on #F9FAFB 4.6:1 */
.button:disabled,
.button[aria-disabled="true"] {
  background: var(--color-bg-alt);
  border-color: var(--color-border-strong);
  color: var(--color-text-muted);
  box-shadow: none;
  cursor: not-allowed;
}

/* Development-only marker; white on #6D28D9 7.1:1 */
.dev-badge {
  display: inline-block;
  padding: 0.0625rem 0.5rem;
  border-radius: 999px;
  background: var(--color-dev-strong);
  color: var(--color-on-primary);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: middle;
}

/* Notice shown by the shell instead of the content */
.app-shell-notice h1 {
  margin-bottom: 1rem;
}

/* ---------- 5. Overview page ---------- */
.overview-convert {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 2rem;
  margin-bottom: 1rem;
  padding: 1.5rem;
  border: 2px solid var(--color-primary);
  border-radius: var(--radius);
  background: var(--color-bg);
  box-shadow: 0 1px 3px var(--shadow-neutral), 0 12px 32px -18px var(--shadow-tint);
}

.overview-convert h2 {
  margin-bottom: 0.25rem;
}

.overview-convert p {
  margin: 0;
  color: var(--color-text-muted);
}

.overview-convert-text {
  flex: 1 1 18rem;
  min-width: 0;
}

.overview-convert-cta {
  flex: none;
  gap: 0.625rem;
  min-height: 3.5rem;
  padding-inline: 1.75rem;
  font-size: var(--text-xl);
}

@media (max-width: 30rem) {
  .overview-convert-cta {
    width: 100%;
  }
}

.overview-usage-value {
  margin: 0 0 0.5rem;
  font-size: var(--text-xl);
  font-weight: 800;
}

/* Usage (and, for ADMIN/OWNER, the organization summary) below the recent jobs */
.overview-cards {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}

.overview-cards > .app-card {
  margin-bottom: 0;
}

@media (min-width: 48rem) {
  .overview-cards {
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    align-items: start;
  }
}

.overview-cards > .app-card[hidden] {
  display: none;
}

.app-card-links {
  margin: 0;
  font-size: var(--text-sm);
}

.overview-org-activity {
  margin: 1rem 0 0;
  font-size: var(--text-sm);
}

/* Usage bar (decorative: the text above states the values) */
.overview-usage-bar {
  height: 0.5rem;
  margin-bottom: 0.5rem;
  overflow: hidden;
  border: 1px solid var(--color-text-muted);
  border-radius: 999px;
  background: var(--color-bg-alt);
}

.overview-usage-bar span {
  display: block;
  height: 100%;
  background: var(--color-primary);
}

.overview-usage-bar.is-high span {
  background: var(--color-warning);
}

.overview-list {
  margin: 0.25rem 0 0;
  padding-left: 1.25rem;
}

.overview-org h3 {
  margin: 1.25rem 0 0.25rem;
  font-size: var(--text-base);
}

/* Owner overview: wider content (capped so ultra-wide screens keep a
   readable chart), organization usage card, team strip */
.app-content--wide {
  max-width: 136rem;
}

.overview-owner {
  display: grid;
  gap: 1.25rem;
  margin-bottom: 1rem;
}

.overview-owner[hidden],
.overview-cards[hidden] {
  display: none;
}

.overview-owner > .app-card {
  margin-bottom: 0;
}

@media (min-width: 80rem) {
  .overview-owner {
    gap: 1.5rem;
  }

  .app-content--wide .overview-convert {
    padding: 1.75rem 2rem;
  }
}

.usage-card {
  padding: clamp(1.25rem, 0.75rem + 1vw, 2rem);
}

.usage-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem 2rem;
  margin-bottom: 1.5rem;
}

.usage-heading {
  flex: 1 1 20rem;
  min-width: 0;
}

.usage-heading h2 {
  margin: 0 0 0.5rem;
}

.usage-headline {
  margin: 0;
  font-size: var(--text-lg);
  line-height: 1.35;
}

.usage-total {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.usage-support {
  margin: 0.375rem 0 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.usage-support:empty {
  display: none;
}

/* Period selector: buttons with aria-pressed; the pressed one like the current
   language (white on primary-dark 7.1:1) */
.segmented {
  display: inline-flex;
  flex: none;
  gap: 0.125rem;
  padding: 0.1875rem;
  border: 1px solid var(--color-text-muted);
  border-radius: 999px;
  background: var(--color-bg);
}

.segmented button {
  min-height: 2.25rem;
  padding: 0.25rem 0.875rem;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.segmented button:hover {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
}

.segmented button[aria-pressed="true"],
.segmented button[aria-pressed="true"]:hover {
  background: var(--color-primary-dark);
  color: var(--color-on-primary);
  font-weight: 700;
}

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

@media (max-width: 47.99rem) {
  .segmented {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .segmented--two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Chart: y labels | plot (gridlines + one column per day), x labels below */
.usage-chart {
  position: relative;
  margin-bottom: 1rem;
}

.usage-plot {
  display: grid;
  grid-template-columns: 3rem minmax(0, 1fr);
  column-gap: 0.5rem;
}

.usage-chart.is-loading .usage-plot {
  opacity: 0.5;
}

.usage-ylabels,
.usage-area {
  position: relative;
  height: 12rem;
}

@media (min-width: 48rem) {
  .usage-ylabels,
  .usage-area {
    height: 14rem;
  }
}

@media (min-width: 64rem) {
  .usage-ylabels,
  .usage-area {
    height: 16rem;
  }
}

@media (min-width: 90rem) {
  .usage-ylabels,
  .usage-area {
    height: 18rem;
  }
}

/* Muted on white 4.8:1 */
.usage-ylabels span {
  position: absolute;
  right: 0;
  transform: translateY(50%);
  color: var(--color-text-muted);
  font-size: 0.75rem;
  line-height: 1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.usage-grid {
  position: absolute;
  inset: 0;
}

.usage-grid span {
  position: absolute;
  right: 0;
  left: 0;
  border-top: 1px solid var(--color-border);
}

.usage-grid span.is-base {
  border-top-color: var(--color-border-strong);
}

.usage-bars {
  position: absolute;
  inset: 0;
  display: grid;
  align-items: end;
}

.usage-bars--7 {
  column-gap: 1.5rem;
}

.usage-bars--30 {
  column-gap: 0.375rem;
}

.usage-bars--90 {
  column-gap: 2px;
}

@media (max-width: 47.99rem) {
  .usage-bars--7 {
    column-gap: 0.5rem;
  }

  .usage-bars--30 {
    column-gap: 2px;
  }

  .usage-bars--90 {
    column-gap: 1px;
  }
}

/* Each column is the full-height hover/focus target of its day */
.usage-col {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: 100%;
  min-width: 0;
}

.usage-col:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 1px;
}

/* Bars: primary on white 3.3:1 (graphic); zero days a visible 2px stub */
.usage-bar {
  display: block;
  width: 100%;
  border-radius: 3px 3px 0 0;
  background: var(--color-primary);
}

.usage-bars--7 .usage-bar {
  max-width: 4rem;
}

.usage-bar.is-zero {
  height: 2px;
  border-radius: 0;
  background: var(--color-border-strong);
}

.usage-col:hover .usage-bar,
.usage-col:focus .usage-bar {
  background: var(--color-primary-dark);
}

.usage-col:hover .usage-bar.is-zero,
.usage-col:focus .usage-bar.is-zero {
  background: var(--color-text-muted);
}

.usage-xlabels {
  display: grid;
  padding-top: 0.5rem;
  color: var(--color-text-muted);
  font-size: 0.75rem;
  line-height: 1.3;
}

.usage-xlabel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-self: center;
  text-align: center;
  white-space: nowrap;
}

/* 30/90 days: the outer labels stay inside the chart */
.usage-xlabels:not(.usage-bars--7) .usage-xlabel.is-first {
  align-items: flex-start;
  justify-self: start;
  text-align: left;
}

.usage-xlabels:not(.usage-bars--7) .usage-xlabel.is-last {
  align-items: flex-end;
  justify-self: end;
  text-align: right;
}

.usage-x-narrow {
  display: none;
}

@media (max-width: 47.99rem) {
  .usage-xlabel.usage-x-wide,
  .usage-xlabel .usage-x-wide {
    display: none;
  }

  .usage-xlabel .usage-x-narrow {
    display: inline;
  }
}

/* Tooltip: white on text #1F2937 14.7:1 */
.usage-tooltip {
  position: absolute;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 0.375rem 0.625rem;
  border-radius: var(--radius-sm);
  background: var(--color-text);
  box-shadow: var(--shadow-card);
  color: var(--color-on-primary);
  font-size: var(--text-sm);
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
}

.usage-tooltip[hidden] {
  display: none;
}

.usage-tooltip strong {
  font-weight: 800;
}

/* The values as a table (disclosure); the table scrolls inside itself */
.usage-details {
  margin-bottom: 0.25rem;
  font-size: var(--text-sm);
}

.usage-details > summary {
  padding-block: 0.375rem;
  color: var(--color-link);
  font-weight: 600;
  cursor: pointer;
}

.usage-details[open] > summary {
  margin-bottom: 0.5rem;
}

.usage-table-wrap {
  max-height: 20rem;
  overflow: auto;
}

.app-table .usage-table-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Page quota below the chart */
.usage-quota {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--color-border);
}

.app-main .usage-quota h3 {
  margin: 0 0 0.75rem;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.usage-quota-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.25rem 2rem;
}

@media (min-width: 48rem) {
  .usage-quota-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .usage-quota-cell--used {
    grid-column: 1 / -1;
  }
}

@media (min-width: 64rem) {
  .usage-quota-grid {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr);
  }

  .usage-quota-cell--used {
    grid-column: auto;
  }
}

.usage-quota-cell {
  min-width: 0;
}

.usage-quota-figure {
  margin: 0 0 0.5rem;
}

.usage-quota-figure strong {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

/* Remaining pages and days left: the figure above its caption */
.usage-quota-cell:not(.usage-quota-cell--used) .usage-quota-figure strong {
  display: block;
}

.usage-quota-meter {
  height: 0.625rem;
  margin: 0.25rem 0 0.5rem;
}

.overview-usage-bar.is-full span {
  background: var(--color-error);
}

.usage-quota-alert {
  margin: 0 0 0.25rem;
  font-size: var(--text-sm);
}

.usage-quota-note {
  margin: 0.25rem 0 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.usage-quota-none {
  margin: 0 0 0.25rem;
}

/* Team strip: facts in a row, links on the right */
.overview-team {
  display: grid;
  align-items: center;
  gap: 0.75rem 2.5rem;
}

.overview-team h2 {
  margin: 0;
}

.overview-team > .app-notice {
  margin-bottom: 0;
}

.overview-team-facts {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* One row only where the facts fit beside the links (beside the sidebar
   the DE facts need ~20rem; at 64rem they ran under the links) */
@media (min-width: 72rem) {
  .overview-team {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .overview-team-facts {
    grid-template-columns: repeat(2, max-content);
    gap: 0.25rem 3rem;
  }
}

/* ---------- 6. Forced colours and motion ---------- */
@media (prefers-reduced-motion: no-preference) {
  .usage-plot {
    transition: opacity 0.15s ease;
  }

  .status-icon--spinner {
    animation: app-spin 1.2s linear infinite;
  }

  /* A job that cannot advance in this environment (status.canAdvance): no endless spin */
  .status-badge--still .status-icon--spinner {
    animation: none;
  }
}

@keyframes app-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (forced-colors: active) {
  .app-nav-link[aria-current="page"] {
    border-left-color: Highlight;
    text-decoration: underline;
  }

  .app-role,
  .status-badge,
  .app-notice,
  .dev-badge,
  .overview-convert {
    border-color: CanvasText;
  }

  .dev-badge {
    border: 1px solid CanvasText;
  }

  .overview-usage-bar span,
  .usage-bar {
    background: CanvasText;
  }

  .usage-bar.is-zero {
    background: GrayText;
  }

  .usage-grid span {
    border-color: GrayText;
  }

  .usage-col:focus-visible {
    outline: 2px solid Highlight;
  }

  .segmented button[aria-pressed="true"],
  .segmented button[aria-pressed="true"]:hover {
    background: Highlight;
    color: HighlightText;
    text-decoration: underline;
  }

  .usage-tooltip,
  .app-org-mark,
  .app-avatar {
    border: 1px solid CanvasText;
  }
}

/* ---------- Job result actions (job-actions.js): history table, overview, detail page ---------- */
.job-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.job-actions--compact {
  gap: 0.375rem;
}

/* "Review required": Download stays available but neutral, so it does not compete with Inspect. */
.job-actions--review-required .job-action--download.button-secondary {
  border-color: var(--color-text-muted);
  color: var(--color-text);
}

.job-actions--review-required .job-action--download.button-secondary:hover,
.job-actions--review-required .job-action--download.button-secondary:active {
  background: var(--color-neutral-light);
  border-color: var(--color-text);
  color: var(--color-text);
}

.job-action-disabled {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.5rem;
}

/* In compact tables the reason goes below the disabled button instead of squeezing beside it. */
.job-actions--compact .job-action-disabled {
  flex-direction: column;
  align-items: flex-start;
}

.job-action-reason {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

@media (prefers-reduced-motion: reduce) {
  .job-actions .button {
    transition: none;
  }
}
