/* Reusable pieces: cards, buttons, chips, forms, tables, key/value grids. */

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}
.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px 0;
}
.card__header h2 span, .card__header h3 span { font-family: var(--font-body); font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 6px; }
.card__body { padding: 16px 20px; }
.card__body + .card__body { border-top: 1px solid var(--rule); }
.card__footer { padding: 12px 20px; border-top: 1px solid var(--rule); display: flex; gap: 8px; justify-content: flex-end; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--control-h);
  padding: 0 16px;
  border-radius: var(--radius);
  border: 0;
  background: var(--surface);
  box-shadow: 0 0 0 1px rgba(22, 33, 43, 0.12);
  color: var(--ink);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background 120ms ease, box-shadow 120ms ease;
}
.btn:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.btn--primary { background: var(--accent); color: #fff; box-shadow: none; }
.btn--primary:hover { background: var(--accent-strong); color: #fff; }
.btn--danger { color: var(--bad); }
.btn--danger:hover { background: var(--bad-soft); color: var(--bad); }
.btn--sm { height: 30px; padding: 0 10px; font-size: 12.5px; gap: 6px; }
.btn--block { width: 100%; }
.btn[disabled] { opacity: 0.55; cursor: default; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(22, 33, 43, 0.06); }
.sidebar .icon-btn:hover { background: var(--sidebar-hover); }

form.button_to { display: inline; }

/* Chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}
.chip--ok { background: var(--ok-soft); color: var(--ok); }
.chip--wait { background: var(--wait-soft); color: var(--wait); }
.chip--bad { background: var(--bad-soft); color: var(--bad); }
.chip--muted { background: var(--rule); color: var(--muted); }
.chip--accent { background: var(--accent-soft); color: var(--accent-strong); }
.chip__dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }

/* Avatar */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 12.5px;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}
.avatar--sm { width: 28px; height: 28px; font-size: 11px; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 16px; }
.form__row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.form__actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding-top: 4px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field__label { font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-2); }
.field__hint { font-size: 11.5px; line-height: 1.35; font-weight: 500; color: var(--muted); }
.field__error { font-size: 12.5px; color: var(--bad); font-weight: 500; }
.input, .select, .textarea {
  width: 100%;
  height: var(--control-h);
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--input-border, var(--rule-strong));
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  font-size: 13.5px;
}
.textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; }
.select { appearance: none; padding-right: 32px; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B7A88' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>"); background-repeat: no-repeat; background-position: right 10px center; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.field--invalid .input, .field--invalid .select, .field--invalid .textarea { border-color: var(--bad); }
.check { display: inline-flex; align-items: center; gap: 10px; min-height: var(--control-h); font-weight: 500; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.input--file { padding: 6px 12px; height: auto; }

/* Inline row form (add a lookup, add a size) */
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { flex: 1 1 180px; }
.inline-form .field--narrow { flex: 0 1 120px; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 12px;
  background: var(--surface-2);
  white-space: nowrap;
}
.table td { padding: 11px 12px; border-top: 1px solid var(--rule); vertical-align: middle; }
.table tr:first-child td { border-top: 0; }
.table th:first-child, .table td:first-child { padding-left: 20px; }
.table th:last-child, .table td:last-child { padding-right: 20px; }
.table .t-right { text-align: right; }
.table .t-actions { text-align: right; white-space: nowrap; }
.table .t-actions .btn + .btn, .table .t-actions .btn + form, .table .t-actions form + .btn { margin-left: 6px; }
.table tr.is-inactive td { color: var(--muted); }

/* Key / value grid */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px 20px; }
.kv__item { min-width: 0; }
.kv__value { font-size: 14px; font-weight: 500; margin-top: 2px; overflow-wrap: anywhere; }

/* Flash */
.flash {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px 10px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-weight: 500;
}
.flash--notice { background: var(--ok-soft); color: var(--ok); }
.flash--alert { background: var(--bad-soft); color: var(--bad); }

/* Empty state */
.empty {
  padding: 32px 20px;
  text-align: center;
  color: var(--muted);
}
.empty strong { display: block; color: var(--ink); font-family: var(--font-display); font-size: 15px; margin-bottom: 4px; }

/* Stat tile */
.stat { padding: 14px 16px; }
.stat__value { font-family: var(--font-display); font-size: 20px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat__hint { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Section sub-navigation (Settings) */
.subnav { display: flex; flex-direction: column; gap: 2px; }
.subnav__group { padding: 10px 12px 4px; }
.subnav__link { display: block; padding: 7px 12px; border-radius: var(--radius); color: var(--ink-2); font-weight: 500; }
.subnav__link:hover { background: rgba(22, 33, 43, 0.05); text-decoration: none; color: var(--ink); }
.subnav__link--active { background: var(--accent-soft); color: var(--accent-strong); }

/* Small helpers */
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.thumb { width: 44px; height: 44px; border-radius: var(--radius); background: var(--surface-2); display: flex; align-items: center; justify-content: center; color: var(--muted); overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.thumb svg { width: 72%; height: 72%; }
.wash-icon { display: inline-block; vertical-align: middle; flex-shrink: 0; }

@media (max-width: 720px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table th:first-child, .table td:first-child { padding-left: 14px; }
  .table th:last-child, .table td:last-child { padding-right: 14px; }
  .btn, .input, .select { --control-h: 44px; }
}

/* Autocomplete picker */
.autocomplete { position: relative; }
.autocomplete__picker { position: relative; }
.autocomplete__list {
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  max-height: 360px;
  overflow-y: auto;
}
.autocomplete__option, .autocomplete__selected {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
}
.autocomplete__option { cursor: pointer; }
.autocomplete__option:hover, .autocomplete__option[aria-selected="true"] { background: var(--accent-soft); }
.autocomplete__empty { padding: 10px 12px; color: var(--muted); font-size: 13px; }
.autocomplete__thumb { width: 36px; height: 48px; object-fit: contain; background: var(--surface-2); border-radius: 4px; flex-shrink: 0; display: block; }
.autocomplete__text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.autocomplete__text strong { font-weight: 600; }
.autocomplete__text .muted { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.autocomplete__selected { background: var(--surface-2); min-height: var(--control-h); }
.autocomplete__selected .autocomplete__text { flex: 1; }

/* Generic editable rows (contacts, sizes) */
.field-rows { display: flex; flex-direction: column; gap: 10px; }
.field-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; padding: 10px 12px; background: var(--surface-2); border-radius: var(--radius); }
.field-row .field { flex: 1 1 160px; }
.field-row .field--narrow { flex: 0 1 140px; }
.field-row__remove { color: var(--muted); flex-shrink: 0; }
.field-row__remove:hover { color: var(--bad); background: var(--bad-soft); }

/* Measurement grids */
.grid-table th, .grid-table td { white-space: nowrap; }
.grid-table--edit td { padding: 6px 8px; }
.grid-table--edit .input { min-width: 72px; height: 34px; padding: 0 8px; }
.grid-table--edit td:first-child .input { min-width: 160px; }

/* Token picker (multi-select chips) */
.tokens { display: flex; flex-wrap: wrap; gap: 6px; }
.tokens:empty { display: none; }
.token { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); font-size: 13px; font-weight: 600; }
.token__remove { border: 0; background: transparent; color: inherit; font-size: 16px; line-height: 1; width: 20px; height: 20px; border-radius: 50%; cursor: pointer; }
.token__remove:hover { background: rgba(15, 92, 94, 0.15); }

/* Tabs above a list */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; border-bottom: 1px solid var(--rule-strong); }
.tabs__tab { padding: 8px 12px; margin-bottom: -1px; border-bottom: 2px solid transparent; color: var(--ink-2); font-weight: 500; }
.tabs__tab:hover { color: var(--ink); text-decoration: none; }
.tabs__tab--active { color: var(--accent-strong); border-bottom-color: var(--accent); }
.tabs__count { display: inline-block; min-width: 20px; padding: 1px 6px; border-radius: 999px; background: var(--rule); color: var(--muted); font-size: 11.5px; text-align: center; margin-left: 4px; }
.tabs__tab--active .tabs__count { background: var(--accent-soft); color: var(--accent-strong); }

/* Yes/no marks in lists */
.tick { display: inline-flex; width: 20px; height: 20px; align-items: center; justify-content: center; border-radius: 50%; color: var(--muted); font-size: 12px; }
.tick--on { background: var(--ok-soft); color: var(--ok); }
.orders-table tr.is-late td:first-child { box-shadow: inset 3px 0 0 var(--bad); }

/* Timeline of dated events */
.timeline { display: flex; flex-direction: column; gap: 10px; border-left: 2px solid var(--rule); padding-left: 12px; margin-top: 6px; }
.timeline__item { display: flex; flex-direction: column; font-size: 13px; }

/* Modal frame: a Turbo Frame that shows as a dialog while it has content */
.modal:empty { display: none; }
.modal:not(:empty) { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; background: rgba(15, 37, 51, 0.5); }
.modal__panel { width: min(960px, 100%); background: var(--ground); border-radius: 14px; box-shadow: var(--shadow-pop); padding: 16px; }
.modal__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
body.modal-open { overflow: hidden; }

/* Hover hint: a short explanation for an abbreviation or a tick. Keyboard users get it on focus. */
.hint { position: relative; cursor: help; }
th .hint, .hint--dotted { text-decoration: underline dotted; text-underline-offset: 3px; text-decoration-color: var(--muted); }
.hint::after {
  content: attr(data-hint); position: absolute; left: 50%; bottom: calc(100% + 6px); transform: translateX(-50%);
  background: var(--sidebar); color: #fff; font-size: 12px; font-weight: 400; line-height: 1.4; letter-spacing: 0; text-transform: none; white-space: normal;
  width: max-content; max-width: 240px; padding: 6px 9px; border-radius: 6px; box-shadow: var(--shadow-pop);
  opacity: 0; pointer-events: none; transition: opacity 0.12s; z-index: 30;
}
.hint--below::after { bottom: auto; top: calc(100% + 6px); }
.hint:hover::after, .hint:focus-visible::after { opacity: 1; }
.hint:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* Pager: "1–48 of 3,350" and page links under a list */
.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid var(--rule); font-size: 13px; color: var(--muted); }
.design-grid + .pager { padding: 14px 0 0; border-top: 0; }
.pager__links { display: inline-flex; align-items: center; gap: 4px; }
.pager__link { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 30px; padding: 0 8px; border-radius: var(--radius); color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; text-decoration: none; }
a.pager__link:hover { background: var(--surface-2); text-decoration: none; }
.pager__link.is-current { background: var(--accent-soft); color: var(--accent-strong); }
.pager__link.is-disabled { color: var(--rule-strong); }
.pager__gap { min-width: 20px; text-align: center; color: var(--muted); }

/* Description cells: text on one line where it fits, pack/department underneath */
.table .t-desc { min-width: 220px; }
.desc__sub { margin-top: 2px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.table .t-tick { width: 36px; padding-left: 6px; padding-right: 6px; text-align: center; }
.table .t-nowrap { white-space: nowrap; }

/* Phones and small tablets */
@media (max-width: 720px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-header { flex-direction: column; }
  .page-header__actions { justify-content: flex-start; }
  .filters .field { max-width: none; flex-basis: 100%; }
}
@media (max-width: 520px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .stat .stat__value { font-size: 18px; }
}

/* Required fields: a red star after the label of any field whose control is required */
.field:has(:required) > .field__label::after, .fld:has(:required) > .fld__label::after, .field:has(:required) > label.field__label::after { content: " *"; color: var(--bad); font-weight: 700; }
.form-errors strong { margin-right: 4px; }
.field--required > .field__label::after, .field--required > label.field__label::after { content: " *"; color: var(--bad); font-weight: 700; }
