/* ==========================================================================
   SwissTimepieces Watch Desk — internal dashboard
   Design concept: private-bank luxury. Deep ink + antique gold on warm ivory
   surfaces (never stark white/black). Brooklyn for display/brand moments,
   Atkinson Hyperlegible Next for every form/body/label — George is dyslexic,
   so legible body text is a hard requirement everywhere except the wordmark.
   ========================================================================== */

@font-face {
  font-family: 'Brooklyn';
  src: url('./assets/fonts/Brooklyn-Normal.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Brooklyn';
  src: url('./assets/fonts/Brooklyn-SemiBold.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Brooklyn';
  src: url('./assets/fonts/Brooklyn-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Brooklyn';
  src: url('./assets/fonts/Brooklyn-Heavy.woff2') format('woff2');
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

:root,
[data-theme='light'] {
  /* Surfaces */
  --color-bg: #faf7f0;
  --color-surface: #ffffff;
  --color-surface-2: #f4efe2;
  --color-surface-offset: #ede6d4;
  --color-divider: #e2d9c4;
  --color-border: #d6cbae;

  /* Text */
  --color-text: #1a1512;
  --color-text-muted: #6b6156;
  --color-text-faint: #9a8f80;
  --color-text-inverse: #faf7f0;

  /* Primary accent — deep ink (buttons, focus, active states) */
  --color-primary: #17130f;
  --color-primary-hover: #2c241a;
  --color-primary-active: #0b0908;
  --color-primary-highlight: #f1e6c9;

  /* Gold accent — the SwissTimepieces mark colour, used for brand moments */
  --color-brass: #96721f;
  --color-brass-highlight: #f1e2b8;

  /* Warning / Error / Success */
  --color-warning: #a3610a;
  --color-warning-hover: #824c07;
  --color-warning-highlight: #f1ddc0;

  --color-error: #ab3a3a;
  --color-error-hover: #8a2d2d;
  --color-error-highlight: #f0d5d3;

  --color-success: #2f7d4f;
  --color-success-hover: #23623d;
  --color-success-highlight: #d5e8db;

  --radius-sm: 0.5rem;
  --radius-md: 0.875rem;
  --radius-lg: 1.25rem;
  --radius-xl: 1.75rem;
  --radius-full: 9999px;

  --transition-interactive: 160ms cubic-bezier(0.16, 1, 0.3, 1);

  --shadow-sm: 0 1px 3px oklch(0.2 0.03 150 / 0.08);
  --shadow-md: 0 6px 20px oklch(0.2 0.03 150 / 0.1);
  --shadow-lg: 0 16px 40px oklch(0.2 0.03 150 / 0.16);

  --content-narrow: 640px;
  --content-default: 880px;
  --content-wide: 1180px;

  --font-body: 'Atkinson Hyperlegible Next', 'Atkinson Hyperlegible', 'Segoe UI', sans-serif;
  --font-display: 'Brooklyn', 'Atkinson Hyperlegible Next', 'Segoe UI', sans-serif;
}

[data-theme='dark'] {
  --color-bg: #14120f;
  --color-surface: #1c1916;
  --color-surface-2: #221e19;
  --color-surface-offset: #27221b;
  --color-divider: #332c23;
  --color-border: #3e3527;

  --color-text: #f3ede0;
  --color-text-muted: #b3a998;
  --color-text-faint: #7d7364;
  --color-text-inverse: #14120f;

  --color-primary: #d9b054;
  --color-primary-hover: #e4c274;
  --color-primary-active: #c49a3c;
  --color-primary-highlight: #2e2717;

  --color-brass: #e0bd6c;
  --color-brass-highlight: #3a3324;

  --color-warning: #e0a24f;
  --color-warning-hover: #eab873;
  --color-warning-highlight: #3d3222;

  --color-error: #e08484;
  --color-error-hover: #e89f9f;
  --color-error-highlight: #3c2a2a;

  --color-success: #6fbf8f;
  --color-success-hover: #8ecca7;
  --color-success-highlight: #223a2c;

  --shadow-sm: 0 1px 3px oklch(0 0 0 / 0.3);
  --shadow-md: 0 6px 20px oklch(0 0 0 / 0.35);
  --shadow-lg: 0 16px 40px oklch(0 0 0 / 0.45);
}

/* Type scale — capped for a functional internal tool (max --text-xl) */
:root {
  --text-xs: clamp(0.8rem, 0.77rem + 0.15vw, 0.9rem);
  --text-sm: clamp(0.95rem, 0.9rem + 0.2vw, 1.05rem);
  --text-base: clamp(1.05rem, 1rem + 0.25vw, 1.15rem);
  --text-lg: clamp(1.25rem, 1.15rem + 0.5vw, 1.45rem);
  --text-xl: clamp(1.55rem, 1.35rem + 1vw, 2rem);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
}

body {
  letter-spacing: 0.01em;
  overflow-x: hidden;
}

/* ---------- Layout shell ---------- */

#app {
  display: none;
  min-height: 100dvh;
  flex-direction: column;
}
#app.visible {
  display: flex;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-divider);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.brand-mark {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  object-fit: contain;
}
.brand-text h1 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: 0.01em;
}
.brand-text span {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: 500;
}
.tab-btn.role-denied {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}
.icon-btn:hover {
  color: var(--color-text);
  border-color: var(--color-primary);
}
.icon-btn svg {
  width: 22px;
  height: 22px;
}

/* Tabs */
.tabbar {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6) 0;
  max-width: var(--content-wide);
  margin: 0 auto;
  width: 100%;
}
.tab-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  font-weight: 700;
  font-size: var(--text-base);
  color: var(--color-text-muted);
  border: 1px solid transparent;
  min-height: 56px;
}
.tab-btn svg {
  width: 24px;
  height: 24px;
}
.tab-btn.active {
  color: var(--color-primary);
  background: var(--color-surface);
  border-color: var(--color-divider);
  border-bottom-color: var(--color-surface);
  margin-bottom: -1px;
}
.tab-btn:not(.active):hover {
  color: var(--color-text);
  background: var(--color-surface-2);
}

main {
  flex: 1;
  background: var(--color-surface);
  border-top: 1px solid var(--color-divider);
}

.view {
  display: none;
  max-width: var(--content-wide);
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) var(--space-20);
}
.view.active {
  display: block;
}

/* ---------- Workshop Tracking: sub-tab pills ---------- */
.workshop-subtabs {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin: var(--space-5) 0;
}
.workshop-subtab-btn {
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-full);
  font-weight: 700;
  font-size: var(--text-sm);
  border: 1px solid var(--color-divider);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  min-height: 44px;
}
.workshop-subtab-btn.active {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-primary);
}
.workshop-subtab-btn:not(.active):hover {
  color: var(--color-text);
  border-color: var(--color-text-muted);
}
.workshop-subview {
  display: none;
}
.workshop-subview.active {
  display: block;
}

/* ---------- Login screen ---------- */

.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  background: var(--color-bg);
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-xl);
  padding: var(--space-10) var(--space-8);
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-card .brand-mark {
  width: 72px;
  height: 72px;
  margin: 0 auto var(--space-4);
}
.login-wordmark {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--color-text);
  margin-bottom: var(--space-4);
}
.login-card h1 {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  margin-bottom: var(--space-2);
}
.login-purpose {
  font-size: var(--text-sm);
  line-height: 1.7;
  color: var(--color-text-muted);
  font-style: italic;
  margin-bottom: var(--space-8);
  padding-bottom: var(--space-6);
  border-bottom: 1px solid var(--color-divider);
}
.login-card p {
  color: var(--color-text-muted);
  margin-bottom: var(--space-6);
}
.login-card .field-row {
  margin-bottom: var(--space-4);
  text-align: left;
}
.login-card label.field-label {
  display: block;
  font-weight: 700;
  font-size: var(--text-sm);
  margin-bottom: var(--space-2);
}
.login-card input {
  width: 100%;
  padding: var(--space-4) var(--space-5);
  font-size: var(--text-lg);
  text-align: left;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
}
.login-card input:focus {
  border-color: var(--color-primary);
  outline: none;
}
.login-error {
  color: var(--color-error);
  font-weight: 600;
  margin-bottom: var(--space-4);
  min-height: 1.4em;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-weight: 700;
  font-size: var(--text-base);
  padding: var(--space-4) var(--space-6);
  border-radius: var(--radius-md);
  min-height: 56px;
  border: 2px solid transparent;
  white-space: nowrap;
}
.btn svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}
.btn-primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}
.btn-primary:hover {
  background: var(--color-primary-hover);
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}
.btn-danger {
  background: var(--color-error-highlight);
  color: var(--color-error);
  border-color: var(--color-error);
}
.btn-danger:hover {
  background: var(--color-error);
  color: var(--color-text-inverse);
}
.btn-danger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-block {
  width: 100%;
}
.btn-lg {
  font-size: var(--text-lg);
  padding: var(--space-5) var(--space-8);
  min-height: 64px;
}

/* ---------- Deal picker ---------- */

.section-heading {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 800;
  margin-bottom: var(--space-2);
}
.section-sub {
  color: var(--color-text-muted);
  font-size: var(--text-base);
  margin-bottom: var(--space-6);
}

.search-box {
  position: relative;
  margin-bottom: var(--space-6);
}
.search-box svg {
  position: absolute;
  left: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  color: var(--color-text-faint);
}
.search-box input {
  width: 100%;
  padding: var(--space-4) var(--space-4) var(--space-4) var(--space-12);
  font-size: var(--text-base);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
}
.search-box input:focus {
  border-color: var(--color-primary);
  outline: none;
}

.deal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
}

.deal-card {
  text-align: left;
  background: var(--color-surface-2);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.deal-card:hover {
  border-color: var(--color-primary);
  background: var(--color-surface);
  box-shadow: var(--shadow-md);
}
.deal-card-title {
  font-weight: 700;
  font-size: var(--text-base);
  color: var(--color-text);
}
.deal-card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}
.deal-card-value {
  font-weight: 700;
  color: var(--color-primary);
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 700;
}
.badge-photo-yes {
  background: var(--color-success-highlight);
  color: var(--color-success);
}
.badge-photo-no {
  background: var(--color-warning-highlight);
  color: var(--color-warning);
}
.badge-qc-done {
  background: var(--color-success-highlight);
  color: var(--color-success);
}
.badge-qc-open {
  background: var(--color-primary-highlight);
  color: var(--color-primary);
}
.badge-qc-pending {
  background: var(--color-warning-highlight);
  color: var(--color-warning);
}
.deal-card svg {
  width: 14px;
  height: 14px;
}
.deal-card-flagged {
  border-color: var(--color-error);
  background: var(--color-error-highlight);
}
.qc-flag-banner {
  display: block;
  background: var(--color-error);
  color: #fff;
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.4;
}
.qc-flag-banner strong {
  font-weight: 800;
}
.qc-flag-by {
  font-weight: 500;
  opacity: 0.9;
}

.empty-state {
  text-align: center;
  padding: var(--space-16) var(--space-6);
  color: var(--color-text-muted);
}
.empty-state svg {
  width: 64px;
  height: 64px;
  margin: 0 auto var(--space-4);
  color: var(--color-text-faint);
}
.empty-state h3 {
  font-size: var(--text-lg);
  color: var(--color-text);
  margin-bottom: var(--space-2);
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-16);
  color: var(--color-text-muted);
}
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--color-divider);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Inspection form ---------- */

.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-muted);
  font-weight: 700;
  margin-bottom: var(--space-6);
  font-size: var(--text-sm);
}
.back-link:hover {
  color: var(--color-primary);
}
.back-link svg {
  width: 20px;
  height: 20px;
}

.deal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: var(--space-4);
  padding: var(--space-6);
  background: var(--color-primary-highlight);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-8);
}
.deal-header h2 {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  color: var(--color-text);
}
.deal-header p {
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}
.deal-header a {
  color: var(--color-primary);
  font-weight: 700;
  font-size: var(--text-sm);
}

.form-section {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-5);
}
.form-section-title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 800;
  margin-bottom: var(--space-5);
  color: var(--color-text);
}
.form-section-title svg {
  width: 26px;
  height: 26px;
  color: var(--color-primary);
  flex-shrink: 0;
}

.field {
  margin-bottom: var(--space-6);
}
.field:last-child {
  margin-bottom: 0;
}
.field label.field-label {
  display: block;
  font-weight: 700;
  font-size: var(--text-base);
  margin-bottom: var(--space-3);
}
.field-hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-top: var(--space-2);
}
.required-mark {
  color: var(--color-error);
  font-weight: 700;
}

.field input[type='text'],
.field input[type='number'],
.field input[type='password'],
.field textarea {
  width: 100%;
  padding: var(--space-4);
  font-size: var(--text-base);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  min-height: 56px;
}
.field textarea {
  min-height: 100px;
  resize: vertical;
}
.field input:focus,
.field textarea:focus {
  border-color: var(--color-primary);
  outline: none;
  background: var(--color-surface);
}

/* Chip toggle groups (radio & checkbox alike) */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}
.chip {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  font-weight: 600;
  font-size: var(--text-base);
  min-height: 56px;
}
.chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.chip .chip-dot {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  border: 2px solid var(--color-text-faint);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chip.checkbox .chip-dot {
  border-radius: var(--radius-sm);
}
.chip .chip-dot svg {
  width: 14px;
  height: 14px;
  color: var(--color-text-inverse);
  opacity: 0;
}
.chip:hover {
  border-color: var(--color-primary);
}
.chip.selected {
  border-color: var(--color-primary);
  background: var(--color-primary-highlight);
  color: var(--color-primary);
}
.chip.selected .chip-dot {
  background: var(--color-primary);
  border-color: var(--color-primary);
}
.chip.selected .chip-dot svg {
  opacity: 1;
}

/* Photo upload */
.photo-drop {
  border: 3px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-10) var(--space-6);
  text-align: center;
  background: var(--color-surface-2);
  position: relative;
}
.photo-drop.dragover {
  border-color: var(--color-primary);
  background: var(--color-primary-highlight);
}
.photo-drop svg {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-4);
  color: var(--color-text-faint);
}
.photo-drop p {
  color: var(--color-text-muted);
  margin-bottom: var(--space-4);
}
.photo-drop input[type='file'] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.photo-buttons {
  display: flex;
  gap: var(--space-3);
  justify-content: center;
  flex-wrap: wrap;
  position: relative;
  z-index: 2;
}
.photo-preview {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4);
  background: var(--color-surface-2);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
}
.photo-preview img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: var(--radius-md);
}
.photo-preview-info {
  flex: 1;
}
.photo-preview-info strong {
  display: block;
  font-size: var(--text-base);
}
.photo-remove {
  color: var(--color-error);
  font-weight: 700;
  font-size: var(--text-sm);
}

.form-actions {
  position: sticky;
  bottom: 0;
  background: var(--color-surface);
  border-top: 2px solid var(--color-divider);
  padding: var(--space-5) var(--space-6);
  margin: var(--space-8) calc(var(--space-6) * -1) 0;
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.form-actions .btn {
  flex: 1;
  min-width: 220px;
}

.toast {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--color-success);
  color: var(--color-text-inverse);
  padding: var(--space-4) var(--space-6);
  border-radius: var(--radius-md);
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  max-width: 90vw;
}
.toast svg {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.toast.error {
  background: var(--color-error);
}

/* ---------- QC view ---------- */

.qc-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}
.qc-card {
  background: var(--color-surface-2);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}
.qc-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.qc-card-header h3 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 800;
}
.qc-card-header .deal-card-value {
  font-size: var(--text-lg);
}
.qc-note {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
  font-size: var(--text-sm);
  line-height: 1.7;
  overflow-x: auto;
}
.qc-note table {
  width: 100%;
  font-size: var(--text-sm);
}
.qc-note td,
.qc-note th {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-divider);
  text-align: left;
}
.qc-note h1,
.qc-note h2,
.qc-note h3 {
  font-size: var(--text-base);
  margin: var(--space-3) 0 var(--space-2);
}
.qc-note ul {
  padding-left: var(--space-6);
  list-style: disc;
}
.qc-fields-fallback {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}
.qc-field-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
}
.qc-field-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--color-primary-highlight);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.qc-field-icon svg {
  width: 16px;
  height: 16px;
}
.qc-field-item .k {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.qc-field-item .v {
  font-size: var(--text-sm);
  font-weight: 600;
  margin-top: var(--space-1);
}

.qc-note-toggle {
  margin-top: var(--space-4);
}
.qc-note-toggle summary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-primary);
  list-style: none;
}
.qc-note-toggle summary::-webkit-details-marker {
  display: none;
}
.qc-note-toggle summary svg {
  width: 16px;
  height: 16px;
  transition: transform 0.15s ease;
}
.qc-note-toggle[open] summary svg {
  transform: rotate(180deg);
}
.qc-note-toggle .qc-note {
  margin-top: var(--space-3);
  margin-bottom: 0;
}

.qc-complete-row {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  flex-wrap: wrap;
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-divider);
}
.qc-complete-row input {
  flex: 1;
  min-width: 160px;
  max-width: 240px;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-base);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}
.qc-complete-row input:focus {
  border-color: var(--color-primary);
  outline: none;
}
.qc-done-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  background: var(--color-success-highlight);
  color: var(--color-success);
  font-weight: 700;
}
.qc-done-badge svg {
  width: 20px;
  height: 20px;
}

/* Responsive */
@media (max-width: 640px) {
  .topbar {
    padding: var(--space-3) var(--space-4);
  }
  .tabbar {
    padding: var(--space-3) var(--space-4) 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabbar::-webkit-scrollbar {
    display: none;
  }
  .tab-btn {
    flex: 0 0 auto;
    justify-content: center;
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);
    white-space: nowrap;
  }
  .view {
    padding: var(--space-5) var(--space-4) var(--space-16);
  }
  .form-actions {
    margin: var(--space-6) calc(var(--space-4) * -1) 0;
    flex-direction: column;
  }
  .form-actions .btn {
    min-width: 0;
    width: 100%;
    white-space: normal;
    text-align: center;
    padding: var(--space-4) var(--space-4);
  }
  .brand-text span {
    display: none;
  }
}

/* ---------- Analytics bar (top of each tab) ---------- */
.analytics-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}
.analytics-card {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  background: var(--color-surface-2);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}
.analytics-card .analytics-icon {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  background: var(--color-primary-highlight);
  color: var(--color-brass);
  display: flex;
  align-items: center;
  justify-content: center;
}
.analytics-card .analytics-icon svg {
  width: 26px;
  height: 26px;
}
.analytics-card .analytics-number {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 800;
  line-height: 1;
  color: var(--color-text);
}
.analytics-card .analytics-label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-weight: 600;
}

/* ---------- Watch brand field pairing ---------- */
.field-row-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}
@media (max-width: 640px) {
  .field-row-pair {
    grid-template-columns: 1fr;
  }
}

/* ---------- Rolex link-count hint ---------- */
.link-hint {
  margin-top: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  display: none;
}
.link-hint.visible {
  display: block;
}
.link-hint.match {
  background: var(--color-success-highlight);
  color: var(--color-success);
}
.link-hint.mismatch {
  background: var(--color-warning-highlight);
  color: var(--color-warning);
}

/* ---------- ST Stock toggle ---------- */
.stock-toggle-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6);
  background: var(--color-brass-highlight);
  border: 2px solid var(--color-brass);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}
.stock-toggle-card .stock-toggle-text strong {
  display: block;
  font-family: var(--font-display);
  font-size: var(--text-base);
  color: var(--color-text);
  margin-bottom: var(--space-1);
}
.stock-toggle-text p {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 60px;
  height: 34px;
  flex-shrink: 0;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  z-index: 2;
}
.switch .switch-track {
  position: absolute;
  inset: 0;
  background: var(--color-border);
  border-radius: var(--radius-full);
  transition: background var(--transition-interactive);
}
.switch .switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 28px;
  height: 28px;
  background: var(--color-surface);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-interactive);
}
.switch input:checked ~ .switch-track {
  background: var(--color-brass);
}
.switch input:checked ~ .switch-thumb {
  transform: translateX(26px);
}

/* ---------- Certificate download banner ---------- */
.certificate-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6);
  background: var(--color-primary-highlight);
  border: 2px solid var(--color-brass);
  border-radius: var(--radius-lg);
  margin-top: var(--space-5);
  flex-wrap: wrap;
}
.certificate-banner p {
  font-weight: 700;
  color: var(--color-text);
}
.certificate-banner .field-hint {
  font-weight: 500;
  margin-top: var(--space-1);
}
.certificate-banner.st-stock-banner {
  background: var(--color-warning-highlight);
  border-color: var(--color-warning);
}
.certificate-banner.st-stock-banner p {
  color: var(--color-warning);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.certificate-banner.st-stock-banner svg {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
}

/* ---------- QC: yes/no checkbox rows ---------- */
.qc-check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}
.qc-check-item {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}
.qc-check-item .k {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-2);
  display: block;
}
.qc-check-item .chip-group {
  gap: var(--space-2);
}
.qc-check-item .chip {
  padding: var(--space-2) var(--space-4);
  min-height: 44px;
  font-size: var(--text-sm);
}
.timegraph-qc-item {
  grid-column: 1 / -1;
}
.timegraph-recorded-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-2);
}
.timegraph-recorded-row .btn {
  padding: var(--space-2) var(--space-3);
  min-height: 36px;
  font-size: var(--text-sm);
}
.timegraph-recorded-row .btn svg {
  width: 16px;
  height: 16px;
}

/* ---------- QC: refurbishment cost inputs ---------- */
.qc-cost-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}
.qc-cost-item label {
  display: block;
  font-weight: 700;
  font-size: var(--text-sm);
  margin-bottom: var(--space-2);
}
.qc-cost-item .currency-input {
  position: relative;
}
.qc-cost-item .currency-input span {
  position: absolute;
  left: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  font-weight: 700;
}
.qc-cost-item input {
  width: 100%;
  padding: var(--space-3) var(--space-4) var(--space-3) var(--space-8);
  font-size: var(--text-base);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  min-height: 48px;
}
.qc-cost-item input:focus {
  border-color: var(--color-primary);
  outline: none;
  background: var(--color-surface);
}
.qc-cost-summary {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  background: var(--color-surface-offset);
  border-radius: var(--radius-md);
  font-weight: 700;
  flex-wrap: wrap;
}
.qc-cost-summary .amount {
  font-family: var(--font-display);
  color: var(--color-brass);
}

/* ---------- QC: product created / view product ---------- */
.qc-product-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-5);
}
.qc-product-status.created {
  background: var(--color-success-highlight);
  color: var(--color-success);
}
.qc-product-status.missing {
  background: var(--color-warning-highlight);
  color: var(--color-warning);
}
.qc-product-status svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.qc-product-status strong {
  font-weight: 800;
}
.qc-product-status a.btn {
  min-height: 40px;
  padding: var(--space-2) var(--space-5);
  font-size: var(--text-sm);
}

/* ---------- QC: stage routing buttons ---------- */
.qc-stage-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-3);
}
.qc-stage-buttons .btn {
  width: 100%;
  white-space: normal;
  line-height: 1.25;
  text-align: center;
}

/* ---------- Archive tab ---------- */
.archive-filters {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}
.archive-filters .search-box {
  flex: 1;
  min-width: 220px;
  margin-bottom: 0;
}
.archive-filters select {
  padding: var(--space-4);
  font-size: var(--text-base);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
}
.archive-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
}
table.archive-table {
  width: 100%;
  min-width: 720px;
  font-size: var(--text-sm);
}
table.archive-table th {
  text-align: left;
  padding: var(--space-4);
  background: var(--color-surface-2);
  font-weight: 800;
  border-bottom: 2px solid var(--color-divider);
  white-space: nowrap;
}
table.archive-table td {
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  vertical-align: top;
}
table.archive-table tr:last-child td {
  border-bottom: none;
}
.archive-type-badge {
  display: inline-flex;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 700;
}
.archive-type-badge.inspection {
  background: var(--color-primary-highlight);
  color: var(--color-brass);
}
.archive-type-badge.qc {
  background: var(--color-success-highlight);
  color: var(--color-success);
}

/* ---------- Multi-account login ---------- */
.role-badge-row {
  display: flex;
  gap: var(--space-2);
  justify-content: center;
  margin-top: var(--space-3);
  flex-wrap: wrap;
}

@media (max-width: 640px) {
  .qc-stage-buttons {
    grid-template-columns: 1fr;
  }
  .analytics-bar {
    grid-template-columns: 1fr 1fr;
  }
  .analytics-card {
    min-width: 0;
    padding: var(--space-4);
  }
  .analytics-card > div {
    min-width: 0;
  }
  .qc-check-item .k,
  .field label.field-label,
  .field-label {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-2);
  }
}

/* ---------------------------------------------------------------------- */
/* Fault Found tab */
/* ---------------------------------------------------------------------- */
.fault-tile-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.fault-tile {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-error);
  border-left-width: 4px;
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  text-decoration: none;
  color: var(--color-text);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.fault-tile:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.workshop-tile {
  border-color: var(--color-divider);
}
.workshop-tile .fault-tile-icon {
  background: var(--color-surface-2);
  color: var(--color-text-muted);
}
.workshop-tile.overdue {
  border-color: var(--color-error);
}
.workshop-tile.overdue .fault-tile-icon {
  background: var(--color-error-highlight);
  color: var(--color-error);
}
.fault-tile-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--color-error-highlight);
  color: var(--color-error);
  display: flex;
  align-items: center;
  justify-content: center;
}
.fault-tile-icon svg {
  width: 20px;
  height: 20px;
}
.fault-tile-body {
  flex: 1;
  min-width: 0;
}
.fault-tile-top {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.fault-tile-top h4 {
  font-size: var(--text-base);
  font-weight: 700;
  margin: 0;
}
.fault-tile-reason {
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  line-height: 1.5;
}
.fault-tile-arrow {
  flex-shrink: 0;
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}
.fault-tile-arrow svg {
  width: 18px;
  height: 18px;
}
button.fault-tile {
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}
.fault-age-badge {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  white-space: nowrap;
}
.fault-age-badge.age-fresh {
  background: var(--color-success-highlight);
  color: var(--color-success);
}
.fault-age-badge.age-warn {
  background: var(--color-warning-highlight);
  color: var(--color-warning);
}
.fault-age-badge.age-danger {
  background: var(--color-error-highlight);
  color: var(--color-error);
}
@media (max-width: 640px) {
  .fault-tile {
    flex-direction: column;
  }
  .fault-tile-arrow {
    display: none;
  }
  .fault-age-badge {
    white-space: normal;
    max-width: 100%;
  }
}

/* ---------- Small button variant (Archive certificate action) ---------- */
.btn-sm {
  min-height: 40px;
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
}
.btn-sm svg {
  width: 18px;
  height: 18px;
}
.archive-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

/* ---------- ST Stock checklist ---------- */
.ststock-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  background: var(--color-surface-2);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}
.ststock-item-main h3 {
  margin: 0 0 var(--space-1) 0;
  font-size: var(--text-lg);
}
.ststock-item-main .field-hint {
  margin: 0 0 var(--space-3) 0;
}
.ststock-fields {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-5);
}
.ststock-fields .k {
  font-weight: 700;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}
.ststock-fields .v {
  font-size: var(--text-sm);
}
.ststock-item-action {
  flex-shrink: 0;
}
@media (max-width: 640px) {
  .ststock-item {
    flex-direction: column;
  }
  .ststock-item-action .btn {
    width: 100%;
  }
}

/* ---------- Analytics detail tab ---------- */
.analytics-section {
  margin-bottom: var(--space-8);
}
.analytics-section-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  margin-bottom: var(--space-4);
}
.analytics-section-title svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  color: var(--color-brass);
}
.analytics-data-note {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  background: var(--color-warning-highlight);
  color: var(--color-warning);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-6);
}
.analytics-data-note svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  margin-top: 1px;
}
.analytics-table-wrap {
  overflow-x: auto;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
}
.analytics-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 480px;
}
.analytics-table th,
.analytics-table td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
.analytics-table th {
  background: var(--color-surface-2);
  font-weight: 700;
  color: var(--color-text-muted);
}
.analytics-brand-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3);
}
.analytics-brand-card {
  background: var(--color-surface-2);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}
.analytics-brand-card .brand-name {
  font-weight: 700;
  margin-bottom: var(--space-1);
}
.analytics-brand-card .brand-days {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 800;
  color: var(--color-brass);
}

/* ---------- Settings / user management ---------- */
.settings-user-row {
  background: var(--color-surface-2);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}
.settings-user-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.settings-user-header h3 {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-size: var(--text-lg);
}
.settings-user-header h3 svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  color: var(--color-text-muted);
}
.settings-role-checks {
  display: flex;
  gap: var(--space-5);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.settings-role-checks label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-base);
  font-weight: 600;
  cursor: pointer;
}
.settings-role-checks input[type="checkbox"] {
  width: 22px;
  height: 22px;
  cursor: pointer;
}
.settings-user-actions {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  align-items: center;
}
.settings-user-actions .field-hint {
  margin: 0;
}
.settings-reset-row {
  display: flex;
  gap: var(--space-3);
  align-items: flex-end;
  flex-wrap: wrap;
}
.settings-reset-row .field {
  margin: 0;
  min-width: 220px;
  flex: 1 1 220px;
}
@media (max-width: 640px) {
  .settings-user-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
