/* ===================================================
   Fowler Order Tracker — Main Stylesheet
   Direction: Precision Instrument
   See DESIGN.md for full token reference.
   =================================================== */

/* Design Tokens
   --------------------------------------------------- */
:root {
  /* Type */
  --font-body: 'Barlow Semi Condensed', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;

  /* Ink (text) */
  --ink: #111318;
  --ink-hover: #2A2D35;
  --ink-subtle: #3C3F47;
  --ink-muted: #6B6E78;
  --ink-faint: #8B8E97;
  --ink-disabled: #ADB0B8;

  /* Paper (surfaces) */
  --paper: #FAFAF9;
  --paper-raised: #FFFFFF;
  --paper-sunken: #F1F0EC;
  --paper-subtle: #F5F4F0;
  --paper-header: #F6F5F1;
  --paper-hover: #ECEAE4;

  /* Lines */
  --line: #E3E0D9;
  --line-subtle: #EDEBE5;

  /* Accent — anodized violet (Fowler purple-trigger nod) */
  --accent: #6D28D9;
  --accent-strong: #5B21B6;
  --accent-soft: #EDE9FE;
  --accent-ring: rgba(109, 40, 217, 0.4);

  /* Semantic */
  --success-bg: #F0FFF4;
  --success-border: #22C55E;
  --success-text: #15803D;
  --warn-bg: #FEF3E0;
  --warn-border: #F59E0B;
  --warn-text: #B45309;
  --error-bg: #FFF1F2;
  --error-border: #EF4444;
  --error-text: #B91C1C;

  /* Elevation — tinted shadows */
  --shadow-sm: 0 1px 2px rgba(17, 19, 24, 0.04), 0 1px 1px rgba(17, 19, 24, 0.03);
  --shadow-md: 0 4px 12px rgba(17, 19, 24, 0.07), 0 2px 4px rgba(17, 19, 24, 0.04);
  --shadow-lg: 0 12px 32px rgba(17, 19, 24, 0.10), 0 4px 8px rgba(17, 19, 24, 0.05);
  --shadow-accent: 0 4px 12px rgba(90, 63, 145, 0.30), 0 2px 4px rgba(90, 63, 145, 0.18);

  /* Motion */
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --duration-fast: 80ms;
  --duration-base: 160ms;
  --duration-slow: 280ms;

  /* Radius — square where precision matters, subtle where it softens */
  --radius-none: 0;
  --radius-xs: 2px;
  --radius-sm: 3px;
  --radius-md: 6px;

  /* Z-index scale */
  --z-sticky: 15;
  --z-table-header: 15;
  --z-sticky-header: 20;
  --z-dropdown: 100;
  --z-modal: 200;
}

html.theme-dark {
  --ink: #E8E7E3;
  --ink-hover: #CFCEC9;
  --ink-subtle: #B8B7B3;
  --ink-muted: #82817D;
  --ink-faint: #6A6965;
  --ink-disabled: #5A5955;

  --paper: #0D0E11;
  --paper-raised: #1C1D22;
  --paper-sunken: #131418;
  --paper-subtle: #0F1013;
  --paper-header: #141519;
  --paper-hover: #1D1E22;

  --line: #2A2C32;
  --line-subtle: #242529;

  --accent: #A855F7;
  --accent-strong: #C084FC;
  --accent-soft: #3B1F66;
  --accent-ring: rgba(168, 85, 247, 0.5);

  --success-bg: #0F2A1A;
  --success-border: #166534;
  --success-text: #4AD94A;
  --warn-bg: #2E1F0A;
  --warn-border: #B45309;
  --warn-text: #FCD34D;
  --error-bg: #2A0F12;
  --error-border: #8B2500;
  --error-text: #D94A4A;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.50), 0 2px 4px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55), 0 4px 8px rgba(0, 0, 0, 0.40);
  --shadow-accent: 0 4px 12px rgba(165, 144, 212, 0.28), 0 2px 4px rgba(165, 144, 212, 0.18);
}

/* Reset & Base
   --------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.6;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* Accessibility: keyboard focus ring */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* Nav
   --------------------------------------------------- */
.nav {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0 2rem;
  height: 56px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-raised);
}

a.nav-brand,
a.nav-brand-mobile {
  text-decoration: none;
  color: inherit;
}

.nav-brand {
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  white-space: nowrap;
  flex-shrink: 0;
}

.nav-brand-bold {
  font-weight: 700;
}

.nav-brand-light {
  font-weight: 400;
  color: var(--ink-subtle);
}

.nav-links {
  display: flex;
  gap: 1.5rem;
  flex: 1;
}

.nav-link {
  text-decoration: none;
  color: var(--ink);
  font-weight: 500;
  font-size: 0.95rem;
  letter-spacing: 0.03em;
  padding: 0.25rem 0;
  border-bottom: 2px solid transparent;
  transition: border-color var(--duration-base) var(--ease-out),
              color var(--duration-base) var(--ease-out);
}

.nav-link:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.nav-link.active {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

.nav-badge {
  display: inline-block;
  margin-left: 0.35rem;
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: #DC2626;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.15rem;
  text-align: center;
  vertical-align: 1px;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.nav-username {
  font-size: 0.9rem;
  color: var(--ink-subtle);
}

.nav-account-btn {
  text-decoration: none;
  font-size: 0.75rem;
}

.nav-user-btn {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--ink-subtle);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem 0;
  transition: color var(--duration-base) var(--ease-out);
}
.nav-user-btn:hover { color: var(--ink); }

/* Mobile brand — hidden on desktop */
.nav-brand-mobile {
  display: none;
}
.nav-logo-mobile {
  height: 28px;
  width: auto;
}
html.theme-dark .nav-logo-mobile {
  filter: invert(1);
}

/* Hamburger — hidden on desktop */
.nav-hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.4rem;
  flex-direction: column;
  gap: 4px;
}
.nav-hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--ink-faint);
  transition: transform var(--duration-base), opacity var(--duration-base);
}

.nav-user-menu {
  position: relative;
}

.user-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.35rem;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: var(--z-dropdown);
  min-width: 160px;
  overflow: hidden;
}

.user-dropdown-item {
  display: block;
  width: 100%;
  padding: 0.55rem 1rem;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  box-sizing: border-box;
  transition: background var(--duration-fast) var(--ease-out);
}

.user-dropdown-item:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.user-dropdown-logout {
  color: var(--error-text);
  border-top: 1px solid var(--line-subtle);
}
.user-dropdown-logout:hover {
  background: var(--error-bg);
  color: var(--error-text);
}

.lights-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-right: 0.25rem;
}

/* Buttons
   --------------------------------------------------- */
.btn-primary,
.btn-secondary {
  display: inline-block;
  padding: 0.65rem 1.25rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  border-radius: var(--radius-none);
  border: none;
  transition: background var(--duration-base) var(--ease-out),
              color var(--duration-base) var(--ease-out),
              border-color var(--duration-base) var(--ease-out),
              transform var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-base) var(--ease-out);
}

.btn-primary {
  background: var(--ink);
  color: var(--paper-raised);
  border: 2px solid var(--ink);
}

.btn-primary:hover {
  background: var(--accent);
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-accent);
}

.btn-primary:active {
  transform: translateY(1px);
  box-shadow: none;
}

.btn-secondary {
  background: transparent;
  color: var(--ink);
  border: 2px solid var(--ink);
}

.btn-secondary:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: var(--accent);
}

.btn-secondary:active {
  transform: translateY(1px);
}

.btn-full {
  width: 100%;
  text-align: center;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

/* Forms
   --------------------------------------------------- */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-subtle);
  margin-bottom: 0.4rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  display: block;
  width: 100%;
  padding: 0.75rem;
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  transition: border-color var(--duration-base) var(--ease-out),
              box-shadow var(--duration-base) var(--ease-out);
  appearance: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

/* Flash Messages
   --------------------------------------------------- */
.flash {
  padding: 0.75rem 1.5rem;
  font-size: 0.95rem;
  font-weight: 500;
  border-left: 4px solid;
  margin: 0;
  border-radius: var(--radius-sm);
}

.flash-success {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.flash-error {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--error-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.flash-temp-password {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success-text);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 1rem 1.5rem;
}

.flash-action-btn {
  background: var(--paper-raised);
  color: var(--ink);
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.flash-action-btn:hover {
  background: var(--paper-hover);
}

/* Login Page
   --------------------------------------------------- */
.login-wrapper {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper-subtle);
  padding: 2rem;
}

.login-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--ink);
  line-height: 1.2;
}

.login-subtitle {
  font-size: 0.85rem;
  color: var(--ink-faint);
  margin-top: 0.4rem;
  letter-spacing: 0.04em;
}

.login-card .flash {
  margin-bottom: 1.25rem;
}

.login-form {
  margin-top: 0;
}

/* Tables
   --------------------------------------------------- */
.table-wrapper {
  -webkit-overflow-scrolling: touch;
}
@media (max-width: 768px) {
  .hide-mobile { display: none !important; }
  table { font-size: 0.8rem; table-layout: fixed; width: 100%; }
  table th, table td { padding: 0.4rem 0.3rem; overflow: hidden; text-overflow: ellipsis; }
  .page-content { padding-left: 8px; padding-right: 8px; }
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

table th {
  text-align: left;
  padding: 0.6rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-subtle);
  background: var(--paper-header);
  border-bottom: 2px solid var(--line);
  position: sticky;
  top: 0;
  z-index: var(--z-table-header);
}

table td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--line-subtle);
  vertical-align: middle;
  transition: background var(--duration-fast) var(--ease-out);
}

table tr:nth-child(even) td {
  background: var(--paper-sunken);
}

table tr:hover td {
  background: var(--accent-soft);
}

/* Stage Badges
   Softer, more harmonized palette — keeps stage color coding,
   reduces saturation so the UI isn't shouty.
   --------------------------------------------------- */
.badge {
  display: inline-block;
  padding: 0.22rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: var(--radius-xs);
  line-height: 1.35;
}

.badge-order_created    { background: #E5EEF8; color: #1E4372; }
.badge-machining        { background: #F0DADA; color: #8B3030; }
.badge-initial_fitting  { background: #F5E6C9; color: #8A5410; }
.badge-fitting          { background: #F5E6C9; color: #8A5410; }
.badge-coating          { background: #D8F0E3; color: #14665E; }
.badge-final_fitting    { background: #EBDCF7; color: #5E2FA8; }
.badge-test_firing      { background: #F6DDE8; color: #9B1F51; }
.badge-shipping         { background: #DDF0DD; color: #13682F; }
.badge-type-dealer    { background: #E8E9F5; color: #2E3294; }
.badge-type-warranty  { background: #F5E9D4; color: #844020; }
.badge-type-demo      { background: #E0EEF4; color: #0A5B72; }

/* Coating status row (below stage dots on order detail at coating stage).
   Acts as a toggle for the Coating Parts panel. */
.coating-status-row {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--paper-sunken);
  border: 1px solid var(--line);
  margin: 1rem 0;
  color: var(--ink);
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
}
.coating-status-row:hover { background: var(--paper-hover); }
.coating-status-row__sep { color: var(--ink-muted); }
.coating-status-row__pulled { color: var(--error-text, #b91c1c); font-weight: 600; }
.coating-status-row__shipped { color: var(--ink-muted); }
.coating-status-row__caret { color: var(--ink-muted); margin-left: 0.25rem; font-size: 0.75rem; }

.coating-parts-panel {
  margin: 0 0 1rem;
  border: 1px solid var(--line);
  background: var(--paper-raised);
  max-width: 720px;
}
.coating-parts-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.coating-parts-table th, .coating-parts-table td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--line);
}
.coating-parts-table th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
  font-weight: 600;
}
.coating-parts-table tbody tr:last-child td { border-bottom: 0; }
.coating-parts-row__label { font-weight: 600; }
.coating-parts-row__section { color: var(--ink-muted); font-size: 0.8rem; }
.coating-parts-row__action { text-align: right; }

.coating-status-pill {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  border-radius: 2px;
  background: var(--paper-sunken);
  color: var(--ink-muted);
}
.coating-status-pill--staged    { background: #d8f0e3; color: #14665e; }
.coating-status-pill--shipped   { background: #fef3c7; color: #92400e; }
.coating-status-pill--returned_ok    { background: #d8f0e3; color: #14665e; }
.coating-status-pill--returned_short { background: #fee2e2; color: #b91c1c; }
.coating-status-pill--rejected_recoat { background: #fee2e2; color: #b91c1c; }
.coating-status-pill--pulled    { background: #fee2e2; color: #b91c1c; }
.coating-status-pill--written_off { background: #e5e7eb; color: #4b5563; }
.coating-status-pill--lost       { background: #e5e7eb; color: #4b5563; }
html.theme-dark .coating-status-pill--staged    { background: #0e3b2e; color: #8edfbe; }
html.theme-dark .coating-status-pill--shipped   { background: #4a3414; color: #fcd34d; }
html.theme-dark .coating-status-pill--returned_ok    { background: #0e3b2e; color: #8edfbe; }
html.theme-dark .coating-status-pill--returned_short { background: #4a1414; color: #fca5a5; }
html.theme-dark .coating-status-pill--rejected_recoat { background: #4a1414; color: #fca5a5; }
html.theme-dark .coating-status-pill--pulled    { background: #4a1414; color: #fca5a5; }
html.theme-dark .coating-status-pill--written_off { background: #2a2a2a; color: #9ca3af; }
html.theme-dark .coating-status-pill--lost       { background: #2a2a2a; color: #9ca3af; }

.coating-restage-form { margin: 0; }
.coating-restage-btn {
  background: var(--paper-raised);
  color: var(--ink);
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 2px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  font-family: inherit;
}
.coating-restage-btn:hover { background: var(--paper-hover); }

/* Layout / Page
   --------------------------------------------------- */
main {
  /* padding added per-page to allow full-bleed sections */
}

.orders-sticky-header {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky-header);
  background: var(--paper-raised);
  border-bottom: 1px solid var(--line);
}
@media (max-width: 768px) {
  .orders-sticky-header { position: static; }
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 1.5rem 2rem 1rem;
  border-bottom: 1px solid var(--line-subtle);
  background: var(--paper-raised);
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.page-content {
  padding: 1.5rem 2rem;
}

/* Constrains inner page content to a max width while allowing the
   surrounding surface (e.g. sticky header bg) to stay full-bleed.
   Stacks with .page-header / .page-content padding. */
.page-band {
  max-width: 1600px;
  margin-left: auto;
  margin-right: auto;
}

/* Color Swatches (finish/coating)
   --------------------------------------------------- */
.color-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 1px solid rgba(17, 19, 24, 0.15);
  border-radius: var(--radius-xs);
  vertical-align: middle;
  flex-shrink: 0;
}
.finish-label { color: var(--ink-subtle); }
.order-num-cell { color: var(--ink-subtle); }

.tux-swatch {
  background: linear-gradient(to right, #1a1a1a 50%, #c0c0c0 50%);
}

/* Filter bar (order list)
   --------------------------------------------------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.filter-group-search {
  flex: 1;
  min-width: 200px;
}

.filter-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.filter-select,
.filter-input {
  padding: 0.5rem 0.75rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  appearance: none;
  transition: border-color var(--duration-base) var(--ease-out),
              box-shadow var(--duration-base) var(--ease-out);
  height: 36px;
}

.filter-select:focus,
.filter-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.filter-select {
  padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236B6E78'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
}

/* Responsive
   --------------------------------------------------- */
@media (max-width: 768px) {
  .nav {
    flex-wrap: wrap;
    height: auto;
    padding: 0.5rem 0.75rem;
    gap: 0;
    position: relative;
  }

  .nav-hamburger {
    display: flex;
    order: 1;
  }

  .nav-brand {
    display: none;
  }

  .nav-brand-mobile {
    display: block;
    order: 2;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-body);
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: var(--ink);
  }

  .nav-user {
    order: 3;
    margin-left: auto;
    gap: 0.35rem;
  }

  /* Nav links: dropdown overlay below header */
  .nav-links {
    order: 4;
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    display: none;
    flex-direction: column;
    gap: 0;
    padding: 0.25rem 0;
    background: var(--paper-raised);
    border-top: 1px solid var(--line-subtle);
    box-shadow: var(--shadow-md);
    z-index: var(--z-dropdown);
  }

  .nav-links.open {
    display: flex;
  }

  .nav-links a {
    text-align: left;
    font-size: 0.85rem;
    padding: 0.6rem 1rem;
    border-bottom: none;
  }

  .nav-links .btn-primary.btn-sm {
    margin-left: 0;
  }

  .lights-label {
    display: none;
  }

  .nav-account-btn {
    font-size: 0.68rem;
    padding: 0.2rem 0.4rem;
  }

  .user-dropdown {
    right: 0;
  }

  .page-header {
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem;
  }

  .page-content {
    padding: 1rem;
  }

  .login-card {
    padding: 1.75rem 1.25rem;
  }
}

/* ===================================================
   Toggle Switch
   =================================================== */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
  vertical-align: middle;
  cursor: pointer;
}
.toggle-switch input { display: none; }
.toggle-slider {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--ink-subtle);
  border-radius: 18px;
  transition: background var(--duration-base) var(--ease-out);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  left: 2px; bottom: 2px;
  background: var(--paper-raised);
  border-radius: 50%;
  transition: transform var(--duration-base) var(--ease-out);
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(14px); }

/* ===================================================
   Reduce motion for users who request it
   =================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ===================================================
   Dark Mode — supplementary overrides for selectors
   that live in other view files (specs grids, forecast,
   admin users, etc.) and don't yet use tokens.
   =================================================== */
html.theme-dark .nav {
  background: var(--paper-header);
}

html.theme-dark .btn-primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
html.theme-dark .btn-primary:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--paper);
}
html.theme-dark .btn-secondary {
  border-color: var(--ink-muted);
  color: var(--ink-subtle);
}
html.theme-dark .btn-secondary:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: var(--accent);
}

html.theme-dark .badge-order_created    { background: #1B2E4A; color: #9CBFE3; }
html.theme-dark .badge-machining        { background: #3B1717; color: #E89A9A; }
html.theme-dark .badge-initial_fitting  { background: #3B2A0F; color: #E8C370; }
html.theme-dark .badge-fitting          { background: #3B2A0F; color: #E8C370; }
html.theme-dark .badge-coating          { background: #0E3B2E; color: #8EDFBE; }
html.theme-dark .badge-final_fitting    { background: #2E1448; color: #C4A8E8; }
html.theme-dark .badge-test_firing      { background: #3B0F24; color: #E89AB8; }
html.theme-dark .badge-shipping         { background: #0F3B14; color: #94E8A4; }
html.theme-dark .badge-type-dealer      { background: #1A1B3F; color: #B0B9E8; }
html.theme-dark .badge-type-warranty    { background: #331F0A; color: #E8B382; }
html.theme-dark .badge-type-demo        { background: #0C3647; color: #94D0E3; }

/* Legacy view-specific dark-mode overrides
   (to be migrated to tokens in a follow-up pass) */
html.theme-dark .finish-label { color: var(--ink-subtle) !important; }
html.theme-dark .order-num-cell, html.theme-dark .order-num-cell a { color: var(--ink) !important; }

/* Order detail dark mode */
html.theme-dark .order-detail { color: var(--ink); }
html.theme-dark .order-hero-title { color: var(--ink); }
html.theme-dark .order-hero-meta { color: var(--ink-muted); }
html.theme-dark .section-heading { color: var(--ink-muted); border-color: var(--line); }
html.theme-dark .specs-grid { border-color: var(--line); }
html.theme-dark .spec-item { border-color: var(--line); }
html.theme-dark .spec-label { color: var(--ink-muted); }
html.theme-dark .spec-value { color: var(--ink); }
html.theme-dark .payment-row { border-color: var(--line); }
html.theme-dark .payment-label { color: var(--ink-subtle); }
html.theme-dark .payment-amount { color: var(--ink); }
html.theme-dark .notes-block { background: var(--paper-raised); border-color: var(--line); color: var(--ink-subtle); }
html.theme-dark .timeline::before { background: var(--line); }
html.theme-dark .timeline-date { color: var(--ink-muted); }
html.theme-dark .timeline-by { color: var(--ink-muted); }
html.theme-dark .meta-strip { background: var(--paper-raised); border-color: var(--line); color: var(--ink-subtle); }
html.theme-dark .meta-strip strong { color: var(--ink); }

html.theme-dark .edit-specs-form { border-color: var(--line); }
html.theme-dark .edit-field label { color: var(--ink-muted); }
html.theme-dark .edit-field input,
html.theme-dark .edit-field textarea,
html.theme-dark .edit-field select {
  background: var(--paper-raised); color: var(--ink); border-color: var(--line);
}
.edit-field input[readonly] { background: var(--paper-sunken); color: var(--ink-muted); }
html.theme-dark .edit-field input[readonly] { background: var(--paper-sunken); color: var(--ink-muted); }
html.theme-dark .set-stage-select { background: var(--paper-raised); color: var(--ink); border-color: var(--line); }
html.theme-dark .btn-set-stage { background: var(--paper-raised); color: var(--ink-subtle); border-color: var(--line); }
html.theme-dark .btn-save-specs { background: var(--ink); color: var(--paper); }

html.theme-dark .fitting-section { background: var(--paper-raised); border-color: var(--line); color: var(--ink); }
html.theme-dark .fitting-task { border-color: var(--line); }
html.theme-dark .fitting-title { color: var(--ink); }
html.theme-dark .fitting-count { color: var(--ink-subtle); }
html.theme-dark .fitting-task.done .fitting-task-name { color: var(--ink-muted); }
html.theme-dark .fitting-task-meta { color: var(--ink-muted); }
html.theme-dark .fitting-checkbox { border-color: var(--ink-subtle); }
html.theme-dark .fitting-checkbox:checked { background: var(--ink); border-color: var(--ink); }
html.theme-dark .fitting-checkbox:checked::after { color: var(--paper); }
html.theme-dark .fitting-checkbox:hover { border-color: var(--accent); }

html.theme-dark .extras-list { border-color: var(--line); }
html.theme-dark .extra-row { border-color: var(--line); }
html.theme-dark .extra-specs { color: var(--ink); }
html.theme-dark .extra-specs .extra-label { color: var(--ink-muted); }
html.theme-dark .extra-notes { color: var(--ink-subtle); }
html.theme-dark .extra-delete-btn { border-color: var(--line); color: var(--ink-muted); }
html.theme-dark .extra-delete-btn:hover { border-color: var(--error-text); color: var(--error-text); }
html.theme-dark .add-extra-form select,
html.theme-dark .add-extra-form input { background: var(--paper-raised); color: var(--ink); border-color: var(--line); }
html.theme-dark .add-extra-form button { background: var(--ink); color: var(--paper); }
html.theme-dark .add-extra-form button:hover { background: var(--ink-hover); }

html.theme-dark .login-input { background: var(--paper-raised); color: var(--ink); border-color: var(--line); }

/* Forecast page dark mode */
html.theme-dark .forecast-table th { background: var(--paper-header); color: var(--ink-muted); border-color: var(--line); }
html.theme-dark .forecast-table th:first-child { background: var(--paper-header); }
html.theme-dark .forecast-table td { border-color: var(--line); color: var(--ink); }
html.theme-dark .forecast-table td:first-child { background: var(--paper); }
html.theme-dark .forecast-table .row-total td { border-color: var(--line); }
html.theme-dark .forecast-table .row-revenue { color: var(--success-text); }
html.theme-dark .forecast-table .cell-zero { color: var(--line); }
html.theme-dark .forecast-table .cell-cap { background: #3d3d1a; }
html.theme-dark .forecast-table .row-past td { background: var(--error-bg); }
html.theme-dark .forecast-table .row-past td:first-child { background: var(--error-bg); }
html.theme-dark .forecast-meta strong { color: var(--ink); }

/* Account page dark mode */
html.theme-dark .account-section-title { color: var(--ink-muted); border-color: var(--line); }
html.theme-dark .info-row { border-color: var(--line); }
html.theme-dark .info-label { color: var(--ink-muted); }
html.theme-dark .info-value { color: var(--ink); }
html.theme-dark .password-form .form-field label { color: var(--ink-muted); }
html.theme-dark .password-form .form-field input { background: var(--paper-raised); color: var(--ink); border-color: var(--line); }
html.theme-dark .btn-save-password { background: var(--ink); color: var(--paper); }
html.theme-dark .btn-save-password:hover { background: var(--ink-hover); }

/* Admin users page dark mode */
html.theme-dark .add-user-form { border-color: var(--line); }
html.theme-dark .add-user-grid .form-field label { color: var(--ink-muted); }
html.theme-dark .add-user-grid .form-field input,
html.theme-dark .add-user-grid .form-field select { background: var(--paper-raised); color: var(--ink); border-color: var(--line); }
html.theme-dark .btn-add-user { background: var(--ink); color: var(--paper); }
html.theme-dark .btn-add-user:hover { background: var(--ink-hover); }
html.theme-dark .users-table th { color: var(--ink-muted); border-color: var(--line); }
html.theme-dark .users-table td { border-color: var(--line); color: var(--ink); }
html.theme-dark .users-table tr.current-user td { background: var(--paper-raised); }
html.theme-dark .role-form select { background: var(--paper-raised); color: var(--ink); border-color: var(--line); }
html.theme-dark .btn-role { background: var(--paper-raised); color: var(--ink-subtle); border-color: var(--line); }
html.theme-dark .btn-role:hover { background: var(--paper-hover); color: var(--ink); }
html.theme-dark .reset-pwd-toggle { background: var(--paper-raised); color: var(--ink-subtle); border-color: var(--line); }
html.theme-dark .reset-pwd-toggle:hover { background: var(--paper-hover); }
html.theme-dark .reset-pwd-form input { background: var(--paper-raised); color: var(--ink); border-color: var(--line); }
html.theme-dark .you-badge { background: var(--paper-raised); color: var(--ink-muted); border-color: var(--line); }

/* FastBound sync badges */
.fb-badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  font-weight: 600;
  margin-left: 0.5rem;
  vertical-align: middle;
}
.fb-green  { background: #DDF0DD; color: #13682F; }
.fb-blue   { background: #E5EEF8; color: #1E4372; }
.fb-yellow { background: #F5E6C9; color: #8A5410; }
.fb-red    { background: #F6E0E0; color: #993030; }

html.theme-dark .fb-green  { background: #0F3B14; color: #94E8A4; }
html.theme-dark .fb-blue   { background: #1B2E4A; color: #9CBFE3; }
html.theme-dark .fb-yellow { background: #3B2A0F; color: #E8C370; }
html.theme-dark .fb-red    { background: #3B1717; color: #E89A9A; }
