
/* ==========================================================================
   BUTTONS
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: var(--touch); padding: 0 16px;
  border: 1px solid var(--line2); border-radius: var(--radius-sm);
  background: var(--panel); color: var(--ink);
  font-size: 14px; font-weight: 600; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, transform 0.06s;
}
.btn svg { width: 17px; height: 17px; flex: none; }
.btn:hover { background: var(--panel2); border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-primary:active { background: var(--brand-press); }

.btn-danger { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); }
.btn-danger:hover { background: var(--warn-soft); border-color: var(--warn); }

.btn-ghost { background: none; border-color: transparent; color: var(--ink2); }
.btn-ghost:hover { background: var(--panel2); border-color: var(--line); color: var(--ink); }

.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn-sm svg { width: 15px; height: 15px; }
.btn-icon { min-height: var(--touch); width: var(--touch); padding: 0; }
.btn-block { width: 100%; }

/* ==========================================================================
   PILLS / CHIPS
   ========================================================================== */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 99px;
  /* A status colour is set per status (Settings), so its text is mixed toward the page's own text colour to stay readable in light and dark. */
  background: var(--s-wash, var(--panel2)); color: color-mix(in srgb, var(--s, var(--ink2)) 62%, var(--ink));
  font-size: 12px; font-weight: 700;
  letter-spacing: 0.03em; text-transform: uppercase; white-space: nowrap;
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--s, currentColor); flex: none; }

.chiprow { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  padding: 6px 12px; border-radius: 99px; min-height: 34px;
  border: 1px solid var(--line2); background: var(--panel);
  color: var(--ink2); font-size: 13px; font-weight: 600;
}
.chip:hover { border-color: var(--muted); color: var(--ink); }
.chip[aria-pressed='true'] {
  background: var(--brand-wash); border-color: var(--brand); color: var(--brand-quiet);
}

/* ==========================================================================
   STAT TILES
   ========================================================================== */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 18px; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat {
  position: relative; overflow: hidden;
  padding: 13px 14px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--panel);
}
.stat::before {
  content: ''; position: absolute; inset: 0 auto 0 0;
  width: var(--stripe); background: var(--s, var(--muted));
}
.stat .n {
  font-family: var(--font-figures); font-weight: 600; font-size: 28px;
  line-height: 1.05; font-variant-numeric: tabular-nums; color: var(--ink);
}
.stat .k {
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted); margin-top: 3px;
}
.stat.is-zero .n { color: var(--muted); }

/* ==========================================================================
   ALERT PANEL
   ========================================================================== */
.alert {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 13px 15px; margin-bottom: 16px;
  border: 1px solid color-mix(in srgb, var(--s, var(--warn)) 35%, var(--line));
  border-left: var(--stripe) solid var(--s, var(--warn));
  border-radius: var(--radius); background: var(--s-wash, var(--warn-soft));
}
.alert svg { width: 20px; height: 20px; color: var(--s, var(--warn)); flex: none; margin-top: 1px; }
.alert .at { font-family: var(--font-heading); font-weight: 700; font-size: 15px; }
.alert .ab { font-size: 13.5px; color: var(--ink2); margin-top: 2px; }
.alert .ab strong { color: var(--ink); font-weight: 600; }

/* ==========================================================================
   TOOL ROW
   ========================================================================== */
.rows { display: flex; flex-direction: column; gap: 9px; }
.row {
  position: relative; overflow: hidden;
  display: grid; gap: 10px 14px; grid-template-columns: 1fr auto;
  padding: 13px 14px 13px 18px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel);
  transition: border-color 0.12s, background 0.12s;
}
.row::before {
  content: ''; position: absolute; inset: 0 auto 0 0;
  width: var(--stripe); background: var(--s, var(--muted));
  border-radius: var(--radius) 0 0 var(--radius);
}
/* An open "more" menu sits on top of the rows below it instead of being clipped. */
.row:has(.menu) { overflow: visible; z-index: 30; }
.row:hover { border-color: var(--line2); }
.row.is-overdue {
  background: var(--warn-soft);
  border-color: color-mix(in srgb, var(--warn) 35%, var(--line));
}

.row .r-main { min-width: 0; }
.row .r-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row .r-name {
  font-family: var(--font-heading); font-weight: 600; font-size: 15.5px;
  letter-spacing: -0.01em; overflow-wrap: anywhere;
}
.row .r-id {
  font-family: var(--font-mono); font-size: 12px; font-weight: 500;
  color: var(--muted); letter-spacing: 0.02em;
}
.row .r-meta {
  display: flex; gap: 6px 14px; flex-wrap: wrap; align-items: baseline;
  margin-top: 6px; font-size: 13px; color: var(--ink2);
}
.row .r-meta b { font-weight: 600; color: var(--ink); }
.row .r-meta .lbl { color: var(--muted); }
.row .timer {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-weight: 600; font-size: 13px; color: var(--info-text);
}
.row.is-overdue .timer { color: var(--warn); }
.row .r-note {
  margin-top: 6px; font-size: 13px; color: var(--ink2);
  padding-left: 10px; border-left: 2px solid var(--line2);
}
.row .r-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

@media (max-width: 559px) {
  .row { grid-template-columns: 1fr; }
  .row .r-actions { justify-content: flex-start; }
  .row .r-actions .btn { flex: 1 1 auto; }
  .row .r-actions .btn-icon { flex: 0 0 auto; }
}

/* --- Kebab menu --------------------------------------------------------- */
.menu-wrap { position: relative; }
.menu {
  position: absolute; z-index: 25; right: 0; top: calc(100% + 6px);
  min-width: 196px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line2);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-pop);
}
.menu button {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 9px 10px; border: 0; border-radius: var(--radius-xs);
  background: none; color: var(--ink); font-size: 13.5px; font-weight: 500;
  text-align: left;
}
.menu button:hover { background: var(--panel2); }
.menu button svg { width: 17px; height: 17px; flex: none; color: var(--muted); }
/* Near the bottom of the screen the menu opens upwards. */
.menu.up { top: auto; bottom: calc(100% + 6px); }
.menu button .sw { width: 8px; height: 8px; border-radius: 50%; background: var(--s, var(--muted)); flex: none; }
.menu button.danger { color: var(--warn); }
.menu button.danger:hover { background: var(--warn-soft); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 2px; }

/* ==========================================================================
   FORMS
   ========================================================================== */
.field { margin-bottom: 14px; }
.field > label, .field > .label-row > label {
  display: block; margin-bottom: 5px;
  font-size: 12.5px; font-weight: 600; letter-spacing: 0.02em; color: var(--ink2);
}
.field .hint { margin-top: 5px; font-size: 12.5px; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line2); border-radius: var(--radius-sm);
  background: var(--panel); color: var(--ink); font-size: 15px;
}
.textarea { min-height: 76px; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--muted); }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--brand); outline: none; box-shadow: var(--ring);
}
.select { appearance: none; padding-right: 34px; background-repeat: no-repeat; background-position: right 11px center; background-size: 16px; }
.input-mono { font-family: var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; }
.field-error { color: var(--warn); font-size: 12.5px; margin-top: 5px; font-weight: 500; }
.input.invalid, .select.invalid { border-color: var(--warn); }

.toolbar { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.search-wrap { position: relative; flex: 1 1 210px; }
.search-wrap svg {
  position: absolute; left: 11px; top: 50%; translate: 0 -50%;
  width: 17px; height: 17px; color: var(--muted); pointer-events: none;
}
.search-wrap .input { padding-left: 35px; }

/* ==========================================================================
   MODAL
   ========================================================================== */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
  background: var(--scrim); backdrop-filter: blur(3px);
}
@media (min-width: 640px) { .modal-backdrop { align-items: center; padding: 24px; } }
.modal {
  width: 100%; max-width: 480px; max-height: 92dvh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line2);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow-pop);
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom, 0px));
  animation: sheet 0.2s ease both;
}
@media (min-width: 640px) { .modal { border-radius: var(--radius); padding-bottom: 18px; } }
@keyframes sheet { from { transform: translateY(16px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .modal { animation: none; } }
.modal.wide { max-width: 560px; }
.modal-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 15px; }
.modal-head h2 { font-size: 19px; font-weight: 700; flex: 1; }
.modal-head .mh-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.modal-actions { display: flex; gap: 9px; margin-top: 18px; }
.modal-actions .btn { flex: 1; min-height: 44px; }

/* ==========================================================================
   TOAST
   ========================================================================== */
.toasts {
  position: fixed; z-index: 80; left: 50%; translate: -50% 0;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 12px);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: calc(100% - 28px); max-width: 420px; pointer-events: none;
}
@media (min-width: 700px) {
  .toasts { bottom: 20px; left: auto; right: 20px; translate: none; align-items: flex-end; }
}
.toast {
  display: flex; align-items: center; gap: 9px;
  padding: 11px 14px; border-radius: var(--radius-sm);
  background: var(--panel); border: 1px solid var(--line2);
  border-left: var(--stripe) solid var(--s, var(--ok));
  box-shadow: var(--shadow-pop); font-size: 14px; font-weight: 500;
  animation: rise 0.18s ease both;
}
.toast svg { width: 18px; height: 18px; color: var(--s, var(--ok)); flex: none; }

/* ==========================================================================
   EMPTY STATE
   ========================================================================== */
.empty {
  text-align: center; padding: 42px 20px;
  border: 1px dashed var(--line2); border-radius: var(--radius);
  background: var(--panel2);
}
.empty svg { width: 34px; height: 34px; color: var(--muted); margin-bottom: 10px; }
.empty h3 { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.empty p { margin: 0 auto 14px; max-width: 34ch; color: var(--muted); font-size: 13.5px; }

/* Select chevron. Two copies so the arrow stays legible in dark mode. */
.select {
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b8090' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .select {
    background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238ca0b3' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  }
}
:root[data-theme='dark'] .select {
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238ca0b3' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

/* A small icon button should match the small text button beside it. */
.btn-sm.btn-icon { min-height: 36px; width: 36px; }
/* Touch screens (the production floor): every control at least 44px. */
/* The :root prefix lets these win over the menu's own sizes in nav.css, which loads later. */
@media (pointer: coarse) {
  :root :is(.btn-sm, .chip:not(.static), .seg-opt span, .sb-tab, .subnav-link) { min-height: var(--touch); }
  :root :is(.btn-sm.btn-icon, .sb-fold, .userchip .btn-icon, .sb-ib) { width: var(--touch); }
  :root :is(.userchip .btn-icon, .sb-ib) { min-height: var(--touch); height: var(--touch); }
  :root .sb-foot { gap: 0; }
  :root .sb-fold { height: var(--touch); }
  .seg-opt span { display: flex; align-items: center; }
  /* 16px stops phones zooming the page in when a field is tapped. */
  :root :is(input:not([type='checkbox']):not([type='radio']):not([type='range']):not([type='file']):not([type='color']), select, .select, textarea, .textarea) { font-size: 16px; }
}

/* Row actions get full-size tap targets on a phone, where they are used most. */
@media (max-width: 559px) {
  .row .r-actions .btn { min-height: 42px; }
  .row .r-actions .btn-sm.btn-icon { min-height: 42px; width: 42px; }
}

/* The QR card is always light so codes scan; keep its text readable there. */
.qr-card { color: var(--paper-ink); }

/* Scan stage keeps its dark backdrop in both themes - it frames the video. */
.scan-stage { color-scheme: dark; }

/* ==========================================================================
   TOOL CRIB - equipment: calibration chips, document count, category
   filter chips, the Documents dialog and the tool form extras.
   ========================================================================== */
.pill.tc-cal-pill svg { width: 13px; height: 13px; color: var(--s); flex: none; }
.tc-docs-btn {
  display: inline-flex; align-items: center; gap: 3px; padding: 0 4px; border: 0; background: none;
  color: var(--ink2); font: inherit; font-weight: 600; cursor: pointer; border-radius: 6px;
}
.tc-docs-btn:hover { color: var(--ink); background: var(--panel2); }
.tc-docs-btn svg { width: 14px; height: 14px; color: var(--muted); }
.tc-two { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 520px) { .tc-two { grid-template-columns: 1fr 1fr; } }
.tc-tick { display: flex !important; align-items: center; gap: 8px; min-height: var(--touch, 40px); font-size: 14px; font-weight: 600; cursor: pointer; }
.tc-tick input { width: 18px; height: 18px; margin: 0; accent-color: var(--brand); flex: none; }
.tc-cal-when { margin-top: 8px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel2); }
.tc-cat-chips { margin-bottom: 8px; }
@media (max-width: 639px) {
  /* Phones: one row that scrolls sideways instead of a tall wall of chips. */
  .tc-cat-chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .tc-cat-chips::-webkit-scrollbar { display: none; }
  .tc-cat-chips .chip { flex: none; }
}
.tc-doc-adds { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.tc-add { padding: 12px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel2); }
.tc-add .field { margin-bottom: 10px; }
.tc-add-name { font-size: 13.5px; overflow-wrap: anywhere; }
.tc-add-acts { display: flex; gap: 8px; justify-content: flex-end; }
.tc-count { font-family: var(--font-mono); }
.tc-none { color: var(--muted); font-size: 13.5px; margin: 4px 0 8px; }
.tc-doc-list { list-style: none; margin: 0 0 6px; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.tc-doc { display: grid; grid-template-columns: 20px 1fr auto; gap: 10px; align-items: start; padding: 10px 12px; border-top: 1px solid var(--line); }
.tc-doc:first-child { border-top: 0; }
.tc-doc-ico svg { width: 18px; height: 18px; color: var(--muted); margin-top: 2px; }
.tc-doc-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tc-doc-title { font-size: 14px; overflow-wrap: anywhere; }
.tc-doc-title a, .tc-doc-meta a { color: var(--brand-quiet); font-weight: 600; text-underline-offset: 2px; }
.tc-doc-meta { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.tc-doc-acts { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.tc-doc-acts .btn { min-height: 34px; padding: 0 10px; font-size: 12.5px; }
.tc-doc-acts .btn svg { width: 15px; height: 15px; }
@media (max-width: 520px) {
  .tc-doc { grid-template-columns: 20px 1fr; }
  .tc-doc-acts { grid-column: 2; justify-content: flex-start; }
}
.tc-cal-sum { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 2px 0 8px; font-size: 13.5px; color: var(--ink2); }
.tc-warn svg { color: var(--warn); }
/* Return dialog: where the tool lives. */
.tc-return-to { display: flex; align-items: center; gap: 9px; margin: 0 0 14px; padding: 10px 12px; border-radius: var(--radius); background: var(--brand-wash); font-size: 14px; }
.tc-return-to svg { width: 18px; height: 18px; flex: none; color: var(--brand-quiet); }
/* All tools: Tools | Barcodes switch (Barcodes lives here, not in its own tab). */
.tc-mode { display: inline-flex; gap: 4px; margin: 0 0 14px; padding: 3px; border-radius: 999px; border: 1px solid var(--line); }
.tc-mode button { border: 0; background: none; font: inherit; font-size: 13.5px; padding: 6px 14px; border-radius: 999px; cursor: pointer; color: var(--ink2); min-height: 32px; }
.tc-mode button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }

/* Kits: row pill, the contents box (checkout / read-only), the return count, the contents editor. */
.pill.tc-kit-pill { gap: 5px; }
.pill.tc-kit-pill svg { width: 13px; height: 13px; flex: none; }
.tc-kit-box { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 0 0 14px; min-width: 0; }
.tc-kit-head { display: flex; align-items: center; gap: 7px; font-weight: 600; font-size: 13.5px; padding: 0 4px; }
.tc-kit-head svg { width: 16px; height: 16px; color: var(--brand-quiet); flex: none; }
.tc-kit-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.tc-kit-list li { display: flex; flex-wrap: wrap; gap: 2px 10px; }
.tc-kit-sub { font-size: 12px; color: var(--muted); font-family: var(--font-mono); overflow-wrap: anywhere; }
.tc-kit-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); }
.tc-kit-row:first-of-type { border-top: 0; }
.tc-kit-name { display: flex; flex-direction: column; min-width: 0; font-size: 14px; overflow-wrap: anywhere; }
.tc-kit-qty { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); flex: none; }
.tc-kit-qty .input { width: 76px; min-height: 40px; text-align: center; }
.tc-kit-one { margin: 0; flex: none; }
.tc-kit-count .hint { margin-top: 8px; }
.tc-kit-count .tc-warn { display: inline-flex; align-items: center; gap: 6px; }
.tc-kit-count .tc-warn svg { width: 15px; height: 15px; }
.tc-kit-edit-head, .tc-kit-edit-row { display: grid; grid-template-columns: minmax(0, 1.4fr) 72px minmax(0, 1.4fr) 40px; gap: 6px; align-items: center; }
.tc-kit-edit-head { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.tc-kit-edit-row { margin-bottom: 6px; }
@media (max-width: 520px) {
  .tc-kit-edit-head { display: none; }
  .tc-kit-edit-row { grid-template-columns: minmax(0, 1fr) 72px 40px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
  .tc-kit-edit-row .select { grid-column: 1 / 3; grid-row: 2; }
}
