/* ── Shared components ──
   Buttons, form controls, cards, tables, pills and alerts, built on tokens.css.
   Loaded after styles.css, so these rules replace the older glass styling.
   The dashboard thread reuses these classes and tokens for its widgets. */

/* Components set their own display, so [hidden] needs to win over them. */
[hidden] {
  display: none !important;
}

html,
body {
  background: var(--c-bg);
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.5;
  color: var(--c-text);
}

body::before {
  display: none;
}

/* Glass effects off everywhere: they cost paint time and fight the flat surfaces. */
.sidebar,
.topbar,
.stat-card,
.orders-table,
.options-drawer,
.logs-drawer,
.bulk-actions,
.search-group,
.ui-button,
.ui-table,
.status-bar:not(:empty),
.grid-stack-item-content .widget {
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

:focus-visible {
  outline: none;
  box-shadow: var(--c-ring);
}

code,
kbd,
.mono {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

/* ── Buttons ── */
button,
.btn,
a.btn-primary,
a.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--control-h);
  padding: 0 14px;
  border: 1px solid var(--c-line-strong);
  border-radius: var(--r-sm);
  background: var(--c-surface);
  color: var(--c-text);
  font: inherit;
  font-size: var(--fs-base);
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  box-shadow: none;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

button:hover:not(:disabled),
.btn:hover:not(:disabled) {
  background: var(--c-surface-2);
  border-color: var(--c-muted);
  transform: none;
}

button:disabled,
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button i[class^="ri-"],
.btn i[class^="ri-"] {
  font-size: 16px;
  line-height: 1;
}

.btn-primary,
button.btn-primary,
a.btn-primary {
  background: var(--c-accent);
  border-color: var(--c-accent);
  color: var(--c-accent-ink);
  box-shadow: none;
}

.btn-primary:hover:not(:disabled),
button.btn-primary:hover:not(:disabled),
a.btn-primary:hover {
  background: var(--c-accent-hover);
  border-color: var(--c-accent-hover);
  color: var(--c-accent-ink);
}

.btn-secondary,
button.btn-secondary {
  background: var(--c-surface);
  color: var(--c-text);
}

.btn-danger,
button.btn-danger {
  background: var(--c-surface);
  border-color: color-mix(in srgb, var(--c-bad) 45%, var(--c-line-strong));
  color: var(--c-bad);
}

.btn-danger:hover:not(:disabled),
button.btn-danger:hover:not(:disabled) {
  background: var(--c-bad-soft);
  border-color: var(--c-bad);
}

.btn-ghost,
button.btn-ghost {
  background: transparent;
  border-color: transparent;
}

.btn-ghost:hover:not(:disabled),
button.btn-ghost:hover:not(:disabled) {
  background: var(--c-surface-2);
  border-color: transparent;
}

.btn-sm,
button.btn-sm {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

.btn-icon,
button.btn-icon {
  padding: 0 10px;
}

.ui-button {
  border-radius: var(--r-sm);
}

/* ── Form controls ── */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
select,
textarea,
.ui-control,
.search-input {
  min-height: var(--control-h);
  padding: 6px 10px;
  border: 1px solid var(--c-line-strong) !important;
  border-radius: var(--r-sm) !important;
  background: var(--c-surface) !important;
  color: var(--c-text);
  font: inherit;
  font-size: var(--fs-base);
  font-weight: 400;
  box-shadow: none !important;
}

textarea {
  min-height: 80px;
  line-height: 1.45;
}

input::placeholder,
textarea::placeholder {
  color: var(--c-muted);
  opacity: 0.85;
}

input:not([type="checkbox"]):not([type="radio"]):focus,
select:focus,
textarea:focus,
.ui-control:focus {
  outline: none;
  border-color: var(--c-accent) !important;
  box-shadow: var(--c-ring) !important;
}

/* A field that can't be saved as typed: red border until it is edited. Set aria-invalid="true". */
input[aria-invalid="true"]:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--c-bad) !important;
}

/* As specific as the field rule above, or its !important background wins and nothing greys. */
input[readonly]:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
input:disabled:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
select:disabled,
textarea:disabled {
  background: var(--c-surface-2) !important;
  color: var(--c-muted);
}

/* Touch screens: fields are 16px, or iPhone zooms the page in when one is focused and leaves it
   zoomed, so the page then scrolls sideways (task panel, comments, every form). !important because
   page rules shrink some fields (dashboard widget selects, JP price checker inputs). */
@media (hover: none) and (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
  select,
  textarea,
  .ui-control,
  .search-input {
    font-size: var(--fs-field-touch) !important;
  }

  /* One height for every field in a row: the larger text alone made inputs, date fields and selects differ. */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
  select,
  .ui-control:not(textarea),
  .search-input {
    min-height: var(--control-h-touch);
  }
}

/* Date and time fields shrink to their column; iPhone otherwise sizes them to their own content. */
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="month"] {
  min-width: 0;
  max-width: 100%;
}

input[type="date"]::-webkit-date-and-time-value,
input[type="time"]::-webkit-date-and-time-value,
input[type="datetime-local"]::-webkit-date-and-time-value,
input[type="month"]::-webkit-date-and-time-value {
  text-align: start;
}

input[type="checkbox"],
input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: var(--c-accent);
}

.field-group > span,
.field-group > label,
label.field-group > span:first-child {
  font-size: var(--fs-label);
  font-weight: 600;
  color: var(--c-text-2);
}

.field-note,
.field-hint {
  font-size: var(--fs-sm);
  color: var(--c-muted);
}

/* ── Cards ── */
.card,
.tool-card {
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: var(--r-md);
  box-shadow: none;
}

.tool-card {
  padding: 18px;
}

/* .page-panel-kicker is the same kicker in dialog headers (.app-modal-header). */
.tool-card-kicker,
.page-panel-kicker {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--c-muted);
}

.tool-card-header h3,
.card-title {
  margin: 0;
  font-size: var(--fs-md);
  font-weight: 650;
  color: var(--c-text);
  text-wrap: balance;
}

.tool-card-header p {
  color: var(--c-muted);
  max-width: 70ch;
}

/* ── Tables ── */
.ui-table,
.orders-table,
.tool-result-table {
  width: 100%;
  border-collapse: collapse;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.ui-table th,
.orders-table th,
.tool-result-table th {
  padding: 8px 12px;
  background: var(--c-surface-2);
  border-bottom: 1px solid var(--c-line);
  color: var(--c-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  text-align: left;
  white-space: nowrap;
}

.ui-table td,
.orders-table td,
.tool-result-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--c-line);
  vertical-align: middle;
  color: var(--c-text);
  font-variant-numeric: tabular-nums;
}

.ui-table tbody tr:hover,
.orders-table tbody tr:hover {
  background: var(--c-surface-2);
}

.table-scroll,
.tool-result-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--c-line);
  border-radius: var(--r-md);
  background: var(--c-surface);
}

/* ── Pills and badges ── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}

.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.pill-ok { background: var(--c-ok-soft); color: var(--c-ok); }
.pill-warn { background: var(--c-warn-soft); color: var(--c-warn); }
.pill-bad { background: var(--c-bad-soft); color: var(--c-bad); }
.pill-info { background: var(--c-info-soft); color: var(--c-info); }
.pill-neutral { background: var(--c-surface-2); color: var(--c-muted); box-shadow: inset 0 0 0 1px var(--c-line); }

.paid-badge {
  border-radius: 999px;
  padding: 1px 8px;
  border: 0;
  background: var(--c-ok-soft);
  color: var(--c-ok);
  font-size: 12px;
  font-weight: 600;
}

.paid-badge.no {
  background: var(--c-bad-soft);
  color: var(--c-bad);
}

.country-code-badge,
.chip-code {
  display: inline-block;
  min-width: 30px;
  padding: 0 6px;
  border: 1px solid var(--c-line-strong);
  border-radius: 5px;
  background: var(--c-surface);
  color: var(--c-text-2);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-align: center;
}

.country-code-badge.non-pt {
  background: var(--c-text);
  border-color: var(--c-text);
  color: var(--c-surface);
}

.tag {
  display: inline-block;
  padding: 0 6px;
  border: 1px solid var(--c-line);
  border-radius: 5px;
  background: var(--c-surface-2);
  color: var(--c-text-2);
  font-size: var(--fs-xs);
}

/* ── Alerts (status bar and inline) ── */
.alert,
.status-bar:not(:empty) {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--c-info) 25%, transparent);
  border-radius: var(--r-md);
  background: var(--c-info-soft);
  color: var(--c-text);
  font-size: var(--fs-base);
  box-shadow: none;
}

.status-bar.error,
.alert-bad {
  border-color: color-mix(in srgb, var(--c-bad) 30%, transparent);
  background: var(--c-bad-soft);
  color: var(--c-text);
}

.status-bar.success,
.alert-ok {
  border-color: color-mix(in srgb, var(--c-ok) 30%, transparent);
  background: var(--c-ok-soft);
}

/* The icon and the close button centre on the first line of text, so a one-line message
   lines up and a longer one keeps them at the top. */
.status-bar .status-icon {
  flex: none;
  height: calc(var(--fs-base) * 1.5);
  font-size: 18px;
  line-height: calc(var(--fs-base) * 1.5);
  color: var(--c-info);
}

.status-bar.error .status-icon { color: var(--c-bad); }
.status-bar.success .status-icon { color: var(--c-ok); }

.status-bar .status-copy {
  flex: 1;
  min-width: 0;
}

.status-bar .status-title {
  display: block;
  font-weight: 600;
}

.status-bar .status-details {
  margin-top: 4px;
  color: var(--c-muted);
  font-size: var(--fs-sm);
}

.status-bar .status-details summary {
  cursor: pointer;
}

.status-bar .status-details code {
  display: block;
  margin-top: 4px;
  white-space: pre-wrap;
  word-break: break-word;
}

.status-bar .status-dismiss {
  flex: none;
  min-height: 28px;
  margin: -4px -6px -4px 0;
  padding: 0 8px;
  border-color: transparent;
  background: transparent;
  color: var(--c-muted);
}

/* ── Loading banner ── */
.loading-banner {
  border: 1px solid var(--c-line);
  border-radius: 999px;
  background: var(--c-surface);
  color: var(--c-text-2);
  box-shadow: var(--c-shadow);
}

.loading-spinner {
  border-color: var(--c-line-strong);
  border-top-color: var(--c-accent);
}

/* ── Segmented control ── */
.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--c-line);
  border-radius: 10px;
  background: var(--c-surface-2);
}

.segmented button {
  min-height: 30px;
  padding: 0 14px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--c-muted);
  font-weight: 600;
}

.segmented button[aria-pressed="true"],
.segmented button.is-active {
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: var(--c-shadow);
}

/* ── Tabs ──
   One look for every tab bar that switches what a page or card shows: muted labels,
   an accent underline under the active one. The dashboard tabs use the same sizes.
   JS marks the active tab with aria-selected="true" (real tabs with panels), aria-pressed="true"
   (a switch that changes what one view shows) or .active. */
.tabs {
  display: flex;
  align-items: stretch;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
  border: 0;
  /* The baseline is a shadow, not a border, so the active underline sits on top of it. */
  box-shadow: inset 0 -1px 0 var(--c-line);
  scrollbar-width: none;
}

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

.tabs > button {
  position: relative;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: var(--c-muted);
  font-size: var(--fs-base);
  font-weight: 550;
  letter-spacing: 0;
  text-transform: none;
}

.tabs > button::after {
  content: "";
  position: absolute;
  right: 8px;
  bottom: 0;
  left: 8px;
  height: 2px;
  background: transparent;
}

.tabs > button:hover:not(:disabled) {
  background: transparent;
  color: var(--c-text);
}

.tabs > button:focus-visible {
  border-radius: var(--r-sm);
  box-shadow: inset 0 0 0 2px var(--c-accent);
}

.tabs > button[aria-selected="true"],
.tabs > button[aria-pressed="true"],
.tabs > button.active {
  background: transparent;
  color: var(--c-text);
  font-weight: 650;
}

.tabs > button[aria-selected="true"]::after,
.tabs > button[aria-pressed="true"]::after,
.tabs > button.active::after {
  background: var(--c-accent);
}

.tabs .tab-count {
  min-width: 18px;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--c-surface-2);
  color: var(--c-muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 16px;
  text-align: center;
}

.tabs > button[aria-selected="true"] .tab-count,
.tabs > button[aria-pressed="true"] .tab-count,
.tabs > button.active .tab-count {
  background: var(--c-accent-soft);
  color: var(--c-accent);
}

/* ── Empty state ── */
.empty-state {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 40px 16px;
  color: var(--c-muted);
  text-align: center;
}

.empty-state strong {
  color: var(--c-text);
  font-size: var(--fs-md);
}

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

/* ── Card header ──
   Kicker, title and description on the left; the card's own actions on the right. */
.tool-card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px 16px;
  margin-bottom: 16px;
}

.tool-card-header > div:first-child {
  flex: 1 1 320px;
  min-width: 0;
}

.tool-card-header > .tool-actions {
  margin: 0;
}

.tool-card-kicker,
.page-panel-kicker {
  margin-bottom: 4px;
}

.tool-card-header h3 {
  margin: 0;
  line-height: 1.3;
}

.tool-card-header p {
  margin: 4px 0 0;
  font-size: var(--fs-sm);
  line-height: 1.5;
}

/* Notes under a field are help text, not labels. */
.field-group > .field-note,
.field-group > .field-hint {
  font-size: var(--fs-sm);
  font-weight: 400;
  color: var(--c-muted);
}

/* A field note that warns takes its tone's colour over the muted default. */
.field-group > .field-note.tone-bad { color: var(--c-bad); }
.field-group > .field-note.tone-warn { color: var(--c-warn); }

/* Long text boxes start compact and grow by dragging. */
.field-group textarea,
.cardmarket-csv-field textarea {
  min-height: 120px;
  resize: vertical;
}

/* Short notes (rows="2", such as the courier note) keep the height their rows give them. */
.field-group textarea[rows="2"] {
  min-height: 0;
}

/* File pickers: the native button styled like a secondary button. */
input[type="file"] {
  padding: 4px;
  color: var(--c-muted);
  font-size: var(--fs-sm);
}

input[type="file"]::file-selector-button {
  height: 26px;
  margin-right: 10px;
  padding: 0 12px;
  border: 1px solid var(--c-line-strong);
  border-radius: var(--r-sm);
  background: var(--c-surface-2);
  color: var(--c-text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

/* Field text is regular weight; only the label above it is semibold. */
.field-group input,
.field-group select,
.field-group textarea {
  font-weight: 400;
}

/* Every page stacks its cards with the same gap. */
.invoice-orders-page-content,
.refunds-page-content,
.invoice-exporter-page-content,
.import-psa-page-content,
.other-tools-page-content,
.jp-price-checker-page-content,
.b2b-order-page-content,
.cardmarket-orders-page-content {
  display: grid;
  gap: 18px;
  min-width: 0;
}

/* A button inside a field column sizes to its label, like every other button. */
.field-group > button {
  align-self: flex-start;
}

/* ---------- Modal ----------
   Every `.app-modal` dialog: a surface card on the scrim, like ⌘K. Overrides the legacy
   light-only card in styles.css so dialogs follow the theme. */
.app-modal-backdrop {
  background: var(--c-scrim);
  backdrop-filter: none;
}

.app-modal-card {
  border: 1px solid var(--c-line);
  border-radius: var(--r-lg);
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: var(--c-shadow-pop);
}

.app-modal-header {
  border-bottom: 1px solid var(--c-line);
}

.app-modal-header h3 {
  font-size: var(--fs-xl);
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.invoice-flow-modal-error {
  border: 1px solid var(--c-bad);
  border-radius: var(--r-md);
  background: var(--c-bad-soft);
  color: var(--c-bad);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
}

/* ── Tool card body ──
   Shared by every tool page (Maintenance, Invoice export, Cardmarket, JP tools …): a form, a row of
   actions, then a result block with figures, a short note and a table. */
.tool-form {
  display: grid;
  gap: 16px;
  min-width: 0;
}

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

/* A secondary action that sits apart at the end of the row. */
.tool-actions > .tool-actions-end {
  margin-left: auto;
}

.tool-card > .tool-actions,
.tool-card > .tool-form + .tool-result,
.tool-card > .field-group + .tool-actions {
  margin-top: 16px;
}

.tool-result {
  min-width: 0;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--c-line);
}

.tool-result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 14px;
}

.tool-result-meta {
  min-width: 0;
  margin-bottom: 14px;
  color: var(--c-text-2);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}

.tool-inline-meta {
  display: block;
  margin-top: 2px;
  color: var(--c-muted);
  font-size: var(--fs-sm);
}

.tool-inline-meta.danger {
  color: var(--c-bad);
}

.tool-result-table td {
  vertical-align: top;
}

.tool-result-table-wrap table {
  min-width: max-content;
}

.tool-result-empty {
  padding: 24px 12px !important;
  color: var(--c-muted) !important;
  text-align: center;
}

/* ── Figures strip ──
   A row of labelled numbers. At the top of a card it bleeds to the card edge; `.is-boxed`
   (and the tool result summary) draws it as its own bordered box inside the card. */
.kpi-strip,
.tool-result-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  min-width: 0;
}

.kpi-strip.is-boxed,
.tool-result-summary {
  margin: 0 0 16px;
  border: 1px solid var(--c-line);
  border-radius: var(--r-md);
  background: var(--c-surface);
  overflow: hidden;
}

.kpi,
.tool-summary-card {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: 12px 16px;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.kpi + .kpi,
.tool-summary-card + .tool-summary-card {
  border-left: 1px solid var(--c-line);
}

.kpi span,
.tool-summary-label {
  margin: 0;
  color: var(--c-muted);
  font-size: var(--fs-sm);
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

.kpi b,
.tool-summary-value {
  color: var(--c-text);
  font-size: var(--fs-lg);
  font-weight: 650;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}

.tone-bad { color: var(--c-bad); }
.tone-warn { color: var(--c-warn); }

/* ── Search field ──
   A search box with its icon inside the frame. Label element wraps the icon and the input. */
.search-field {
  display: flex;
  flex: 0 1 280px;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: var(--control-h);
  padding: 0 10px;
  border: 1px solid var(--c-line-strong);
  border-radius: var(--r-sm);
  background: var(--c-surface);
  color: var(--c-muted);
}

.search-field:focus-within {
  border-color: var(--c-accent);
  box-shadow: var(--c-ring);
}

.search-field i {
  font-size: 16px;
}

/* components forces a frame on every input; this one sits inside the field's frame. */
.search-field input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
.search-field input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):focus {
  flex: 1;
  min-width: 0;
  min-height: 32px;
  padding: 0;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  color: var(--c-text);
}

@media (max-width: 640px) {
  .tool-actions > .btn-primary,
  .tool-actions > .btn-secondary {
    flex: 1 1 auto;
  }

  .tool-actions > .tool-actions-end {
    margin-left: 0;
  }

  .kpi + .kpi,
  .tool-summary-card + .tool-summary-card {
    border-left: 0;
  }

  .kpi-strip,
  .tool-result-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kpi:nth-child(even),
  .tool-summary-card:nth-child(even) {
    border-left: 1px solid var(--c-line);
  }

  .kpi:nth-child(n + 3),
  .tool-summary-card:nth-child(n + 3) {
    border-top: 1px solid var(--c-line);
  }
}

/* ── Product thumbnail ──
   A product's picture in a framed square (productThumbHTML in public/app/ui/product-thumb.js):
   40px in lists, 64px with .product-thumb-lg. .is-empty is the placeholder for a product with no
   picture; .is-pending is the empty frame while the picture is looked up. */
.product-thumb {
  box-sizing: border-box;
  width: 40px;
  height: 40px;
  flex: none;
  border: 1px solid var(--c-line);
  border-radius: var(--r-sm);
  background: var(--c-surface-2);
  object-fit: contain;
}

.product-thumb-lg {
  width: 64px;
  height: 64px;
}

.product-thumb.is-empty {
  display: grid;
  place-items: center;
  color: var(--c-muted);
  font-size: var(--fs-md);
}

.product-thumb-lg.is-empty {
  font-size: var(--fs-lg);
}

.product-thumb.is-pending {
  display: block;
}

/* A table cell with the product's thumbnail before its name and details (Stock, TOC products,
   TOC stock adjustment). The text keeps its own block layout beside the picture. */
.product-thumb-cell {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.product-thumb-cell > .product-thumb-cell-text {
  min-width: 0;
  flex: 1;
}

/* ── Side panel ──
   Details of one record beside the list it came from: a surface panel sliding in from the right
   over the scrim, full screen on phones. Header and footer stay put; the body scrolls.
   Markup: .side-panel > .side-panel-backdrop + .side-panel-card[role=dialog] >
   .side-panel-header, .side-panel-body (.side-panel-section > .side-panel-section-title), .side-panel-footer.
   Behaviour (Escape, backdrop, focus) comes from public/app/ui/side-panel.js. */
.side-panel {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: flex;
  justify-content: flex-end;
}

.side-panel-backdrop {
  position: absolute;
  inset: 0;
  background: var(--c-scrim);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.side-panel-card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(440px, 100%);
  height: 100%;
  border-left: 1px solid var(--c-line);
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: var(--c-shadow-pop);
  opacity: 0;
  transform: translateX(24px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.side-panel-card:focus,
.side-panel-card:focus-visible {
  outline: none;
  box-shadow: var(--c-shadow-pop);
}

.side-panel.is-visible .side-panel-backdrop {
  opacity: 1;
}

.side-panel.is-visible .side-panel-card {
  opacity: 1;
  transform: none;
}

:root.has-side-panel body {
  overflow: hidden;
}

.side-panel-header {
  flex: none;
  display: grid;
  gap: 12px;
  padding: calc(18px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px)) 16px 20px;
  border-bottom: 1px solid var(--c-line);
}

.side-panel-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.side-panel-heading {
  min-width: 0;
}

.side-panel-title {
  margin: 0;
  color: var(--c-text);
  font-size: var(--fs-xl);
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.side-panel-sub {
  margin: 4px 0 0;
  color: var(--c-muted);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}

.side-panel-close {
  flex: none;
  margin: -4px -6px 0 0;
}

.side-panel-close i {
  font-size: 18px;
}

.side-panel-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  /* A panel only scrolls down; a too-wide child must never pan it sideways on a phone. */
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 0 calc(20px + env(safe-area-inset-right, 0px)) 8px 20px;
}

.side-panel-section {
  padding: 16px 0 18px;
  border-top: 1px solid var(--c-line);
}

.side-panel-section:first-child {
  border-top: 0;
}

.side-panel-section-title {
  margin: 0 0 10px;
  color: var(--c-muted);
  font-size: var(--fs-xs);
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.side-panel-footer {
  flex: none;
  padding: 14px calc(20px + env(safe-area-inset-right, 0px)) calc(14px + env(safe-area-inset-bottom, 0px)) 20px;
  border-top: 1px solid var(--c-line);
  background: var(--c-surface);
}

.side-panel-footer:empty {
  display: none;
}

/* Phones: a full-screen sheet. */
@media (max-width: 700px) {
  .side-panel-card {
    width: 100%;
    border-left: 0;
    box-shadow: none;
    transform: translateY(16px);
  }

  .side-panel-card:focus,
  .side-panel-card:focus-visible {
    box-shadow: none;
  }

  /* The whole sheet scrolls so a tall header (status, reasons) doesn't squeeze the body; the
     title row with the close button stays at the top and the footer at the bottom. */
  .side-panel-card {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .side-panel-header {
    display: contents;
  }

  .side-panel-title-row {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: calc(14px + env(safe-area-inset-top, 0px)) calc(12px + env(safe-area-inset-right, 0px)) 12px calc(16px + env(safe-area-inset-left, 0px));
    border-bottom: 1px solid var(--c-line);
    background: var(--c-surface);
  }

  .side-panel-header > :not(.side-panel-title-row) {
    padding: 12px calc(16px + env(safe-area-inset-right, 0px)) 16px calc(16px + env(safe-area-inset-left, 0px));
    border-bottom: 1px solid var(--c-line);
  }

  .side-panel-header > :not(.side-panel-title-row):empty {
    display: none;
  }

  .side-panel-body {
    flex: none;
    overflow: visible;
  }

  .side-panel-body,
  .side-panel-footer {
    padding-left: calc(16px + env(safe-area-inset-left, 0px));
    padding-right: calc(16px + env(safe-area-inset-right, 0px));
  }

  .side-panel-footer {
    position: sticky;
    bottom: 0;
    margin-top: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .side-panel-backdrop,
  .side-panel-card {
    transition: none;
  }
}

/* ── Timeline ──
   Events of one record, oldest first: a dot per event on a vertical line, the title, the time
   under it and a muted detail line. The dot takes the event's tone (data-tone ok, warn, bad,
   info); the words say what happened, so colour is never the only signal.
   Markup: ol.timeline > li.timeline-item[data-tone] > .timeline-dot + .timeline-content >
   .timeline-title, time.timeline-time, .timeline-detail. Loading, empty and error lines use .timeline-state. */
.timeline {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
}

.timeline-item {
  position: relative;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  column-gap: 10px;
  padding-bottom: 14px;
}

.timeline-item:last-child {
  padding-bottom: 0;
}

/* The line from this dot down to the next one. */
.timeline-item:not(:last-child)::before {
  content: "";
  position: absolute;
  top: 16px;
  bottom: -2px;
  left: 9px;
  width: 2px;
  background: var(--c-line);
}

.timeline-dot {
  position: relative;
  width: 10px;
  height: 10px;
  margin: 5px 0 0 5px;
  border: 2px solid var(--c-line-strong);
  border-radius: 999px;
  background: var(--c-surface);
}

.timeline-item[data-tone="ok"] .timeline-dot { border-color: var(--c-ok); background: var(--c-ok); }
.timeline-item[data-tone="info"] .timeline-dot { border-color: var(--c-info); background: var(--c-info); }
.timeline-item[data-tone="warn"] .timeline-dot { border-color: var(--c-warn); background: var(--c-warn); }
.timeline-item[data-tone="bad"] .timeline-dot { border-color: var(--c-bad); background: var(--c-bad); }

.timeline-content {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.timeline-title {
  color: var(--c-text);
  font-weight: 600;
  line-height: 1.45;
}

.timeline-item[data-tone="bad"] .timeline-title {
  color: var(--c-bad);
}

.timeline-time {
  color: var(--c-muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

.timeline-detail {
  color: var(--c-text-2);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.timeline-item[data-tone="bad"] .timeline-detail {
  color: var(--c-bad);
}

/* Events with no date, under the dated list: muted, with no dot, since they have no place on it. */
.timeline-undated {
  display: grid;
  gap: 4px;
  margin: 12px 0 0;
  padding: 10px 0 0;
  border-top: 1px dashed var(--c-line);
  color: var(--c-muted);
  font-size: var(--fs-sm);
  list-style: none;
}

.timeline-undated:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.timeline-state {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 0 14px;
  color: var(--c-muted);
  font-size: var(--fs-sm);
  line-height: 1.5;
}

.timeline-state:only-child {
  margin-bottom: 0;
}

.timeline-state > i {
  flex: none;
  font-size: 16px;
  line-height: 18px;
}

.timeline-state > .loading-spinner {
  margin-top: 3px;
}

.timeline-state.tone-warn {
  color: var(--c-warn);
}

.timeline-state.timeline-error {
  color: var(--c-bad);
}

/* The message, then its retry button under it. */
.timeline-state-text {
  display: grid;
  justify-items: start;
  gap: 6px;
  min-width: 0;
}

.timeline-state-text .btn-sm {
  margin-left: -10px;
}

/* ── Combobox: a field's own suggestion menu (public/app/ui/combobox.js) ── */
.combobox-menu {
  position: fixed;
  z-index: 120;
  max-height: min(320px, 50vh);
  padding: 6px;
  overflow-y: auto;
  border: 1px solid var(--c-line);
  border-radius: var(--r-md);
  background: var(--c-surface);
  box-shadow: var(--c-shadow-pop);
}

.combobox-option {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  color: var(--c-text);
  font-size: var(--fs-base);
  font-weight: 500;
  line-height: 1.35;
  cursor: pointer;
}

.combobox-option small {
  color: var(--c-muted);
  font-size: var(--fs-sm);
  font-weight: 400;
}

.combobox-option.is-active,
.combobox-option:hover {
  background: var(--c-accent-soft);
}

.combobox-empty {
  padding: 10px;
  color: var(--c-muted);
  font-size: var(--fs-sm);
}

/* Document lines: product lines typed by hand into a TOC document (Supplier invoices, Proforma).
   Behaviour in public/app/ui/document-lines.js. */
.doc-lines-table td {
  vertical-align: top;
}

.doc-lines-table input,
.doc-lines-table select {
  width: 100%;
  min-width: 0;
}

.doc-line-item {
  display: grid;
  gap: 6px;
  min-width: 118px;
}

.doc-line-item > * {
  min-width: 0;
}

.doc-lines-table th.num-col {
  text-align: right;
}

/* Narrow number columns so the product column gets the room. */
.doc-lines-table th,
.doc-lines-table td {
  padding-right: 6px;
  padding-left: 6px;
}

.doc-lines-table th:first-child,
.doc-lines-table td:first-child {
  padding-left: 12px;
}

/* Let "Product and description" wrap instead of setting the column's width. */
.doc-lines-table th:first-child {
  white-space: normal;
}

.doc-lines-table .doc-line-qty-cell { width: 64px; }
.doc-lines-table .doc-line-price-cell { width: 94px; }
.doc-lines-table .doc-line-discount-cell { width: 84px; }
.doc-lines-table .doc-line-tax-cell { width: 84px; }
.doc-lines-table .doc-line-amount-cell { width: 90px; }

/* Numbers never squeeze below what they need; the product column gives way first. */
.doc-lines-table .doc-line-qty-cell input { min-width: 52px; }
.doc-lines-table .doc-line-price-cell input { min-width: 82px; }
.doc-lines-table .doc-line-discount-cell input { min-width: 56px; }
.doc-lines-table .doc-line-tax-cell select { min-width: 72px; }
.doc-lines-table .doc-line-amount-cell input { min-width: 78px; }

.doc-lines-table .num-col input {
  padding-right: 8px;
  padding-left: 8px;
}

/* Left only: right padding would hide the select's chevron. */
.doc-lines-table .doc-line-tax-cell select {
  padding-left: 8px;
}

/* Right above the lines: an optional default for every line on the left (Proforma's
   discount), Prices include VAT on the right. */
.doc-lines-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 12px;
}

.doc-lines-default {
  display: grid;
  gap: 4px;
}

.doc-lines-default-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  color: var(--c-text-2);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.doc-lines-default-input {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--c-muted);
  font-weight: 400;
}

.doc-lines-default-input input {
  width: 72px;
  padding-right: 8px;
  padding-left: 8px;
  text-align: right;
}

.doc-lines-default .field-note:empty {
  display: none;
}

.doc-lines-vat {
  min-height: 36px;
  margin-left: auto;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--c-text-2);
  cursor: pointer;
}

.doc-lines-table th.doc-lines-discount-head {
  white-space: nowrap;
}

/* "without VAT" / "with VAT" under the Line total header, following Prices include VAT. */
.doc-lines-basis {
  display: block;
  color: var(--c-muted);
  font-size: var(--fs-xs);
  font-weight: 400;
  text-transform: none;
}

.doc-lines-table .num-col input {
  text-align: right;
}

.doc-line-note,
.doc-line-hint,
.doc-line-error {
  font-size: var(--fs-sm);
}

.doc-line-note:empty,
.doc-line-hint:empty,
.doc-line-error:empty {
  display: none;
}

.doc-line-actions {
  width: 1%;
}

.doc-lines-table td.doc-line-actions {
  padding-left: 0;
}

/* Add line sits right under the last line, where typing happens. */
.doc-lines-add {
  margin-top: 8px;
}

/* Reason for 0% VAT under the lines, shown only while a line is at 0% (exemption-reason.js). */
.doc-lines-reason {
  max-width: 560px;
  margin-top: 16px;
}

/* Totals under the lines, with an optional field on the right (Total on the PDF). */
.doc-lines-totals-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 220px);
  align-items: start;
  gap: 16px;
  margin: 16px 0;
}

.doc-lines-totals-row.is-single {
  grid-template-columns: minmax(0, 1fr);
}

.doc-lines-totals-row .kpi-strip.is-boxed {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0;
}

@media (max-width: 700px) {
  .doc-lines-totals-row {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Keep every column readable; the table scrolls sideways instead of squeezing. */
  .doc-lines-table {
    min-width: 680px;
  }

  /* The three totals stay on one row, so they keep their dividers instead of the
     phone strip's two-column ones. */
  .doc-lines-totals-row .kpi-strip.is-boxed .kpi {
    border-top: 0;
  }

  .doc-lines-totals-row .kpi-strip.is-boxed .kpi + .kpi {
    border-left: 1px solid var(--c-line);
  }

  /* Once Prices include VAT wraps under the discount, it lines up on the left with it. */
  .doc-lines-vat {
    margin-left: 0;
  }
}

/* A document beside the form that types it in (Supplier invoices). The form keeps a
   fixed, readable width and the preview takes all the width left, so wide screens get
   a bigger PDF. The preview stays in view while the form scrolls. */
.pdf-form-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) min(680px, max(568px, 45%));
  align-items: start;
  gap: 18px;
  min-width: 0;
}

.pdf-form-split > * {
  min-width: 0;
}

.pdf-form-split-preview {
  position: sticky;
  top: calc(18px + var(--sticky-offset, 0px));
  height: calc(100vh - 140px - var(--sticky-offset, 0px));
  min-height: 420px;
}

/* Small laptops: no room for the form's own width, so share the space. */
@media (max-width: 1280px) {
  .pdf-form-split {
    grid-template-columns: minmax(0, 4fr) minmax(0, 6fr);
  }
}

@media (max-width: 1100px) {
  .pdf-form-split {
    grid-template-columns: minmax(0, 1fr);
  }

  .pdf-form-split-preview {
    position: static;
    height: 70vh;
  }
}

/* ── Account avatar: the signed-in person's initials ── */
.account-avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: var(--c-accent-soft);
  color: var(--c-accent);
  font-size: var(--fs-xs);
  font-weight: 650;
  letter-spacing: 0.02em;
  line-height: 1;
  user-select: none;
}

.account-avatar:empty {
  visibility: hidden;
}

.account-avatar-lg {
  width: 44px;
  height: 44px;
  font-size: var(--fs-md);
}

/* 24px initials for people listed beside a record (task assignees, comment authors). */
.account-avatar-sm {
  width: 24px;
  height: 24px;
  font-size: var(--fs-xs);
  letter-spacing: 0;
}

/* ── Avatar stack: the people on a record, overlapping, with "+N" for the rest ── */
.avatar-stack {
  display: inline-flex;
  align-items: center;
  flex: none;
}

.avatar-stack > .account-avatar {
  box-shadow: 0 0 0 2px var(--c-surface);
}

.avatar-stack > .account-avatar + .account-avatar {
  margin-left: -2px;
}

.avatar-stack > .avatar-stack-more {
  background: var(--c-surface-2);
  color: var(--c-muted);
}

/* ── Person picker: choose several people, one toggle per person ──
   Markup: .person-picker[role=group] > button.person-toggle[aria-pressed] > .account-avatar-sm + span */
.person-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.person-toggle,
button.person-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 12px 0 4px;
  border: 1px solid var(--c-line-strong);
  border-radius: 999px;
  background: var(--c-surface);
  color: var(--c-text-2);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
}

button.person-toggle:hover:not(:disabled) {
  border-color: var(--c-line-strong);
  background: var(--c-surface-2);
}

button.person-toggle[aria-pressed="true"],
button.person-toggle[aria-pressed="true"]:hover:not(:disabled) {
  border-color: var(--c-accent);
  background: var(--c-accent-soft);
  color: var(--c-text);
}

.person-toggle[aria-pressed="true"] .account-avatar {
  background: var(--c-accent);
  color: var(--c-accent-ink);
}

.person-toggle small {
  color: var(--c-muted);
  font-size: var(--fs-xs);
  font-weight: 400;
}

/* ── File drop ──
   A dashed box that takes a dropped file or opens the file picker (Cardmarket export, bulk label CSV).
   The label wraps a visually hidden input[type=file]; .is-dragging while a file is over it, .is-loaded once read. */
.file-drop {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 28px 16px;
  border: 1px dashed var(--c-line-strong);
  border-radius: var(--r-md);
  background: var(--c-surface-2);
  color: var(--c-muted);
  font-size: var(--fs-sm);
  text-align: center;
  cursor: pointer;
}

.file-drop i {
  color: var(--c-accent);
  font-size: var(--fs-xl);
}

.file-drop strong {
  color: var(--c-text);
  font-size: var(--fs-base);
  font-weight: 600;
}

.file-drop:hover,
.file-drop.is-dragging {
  border-color: var(--c-accent);
  background: var(--c-accent-soft);
}

.file-drop:focus-within {
  border-color: var(--c-accent);
  box-shadow: var(--c-ring);
}

.file-drop.is-loaded {
  border-style: solid;
}

.file-drop.is-loaded i {
  color: var(--c-ok);
}
