/* ============================================================
   Damage Code Tool - RASTools Design System
   Unified flush board on desktop, app-style step flow on mobile.
   Brand: navy/crimson chrome; green = completed, red = danger.
   NOTE: the mobile progressive-disclosure mechanics (media query
   step machinery, fixed panels, show/hide classes) are load-bearing
   for js/damage-code.js - restyle freely, but do not change the
   display/position semantics without testing the full flow.
   ============================================================ */

/* Prevent swipe-to-navigate gestures */
html, body {
  overscroll-behavior-x: none;
  overscroll-behavior-y: auto;
}

.damage-container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 20px 20px;
  box-sizing: border-box;
}

/* ---------- Board header (desktop) ---------- */
.damage-header {
  background: var(--brand-header-gradient);
  border: 1px solid var(--border);
  border-bottom: 2px solid var(--brand-red);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.brand {
  font-size: 17px;
  font-weight: 800;
  color: #fff;
  margin: 0 0 2px 0;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.brand-subtitle {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.72);
}

/* ---------- Unified board ---------- */
.main-content {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-top: none;
  box-shadow: var(--shadow-medium);
  margin-bottom: 20px;
}

.builder-section {
  padding: 18px;
  max-width: 100%;
  overflow: hidden;
  min-width: 0;
}

.code-output {
  padding: 18px;
  border-left: 1px solid var(--border);
  min-width: 0;
}

.section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1.4px;
  margin: 0 0 14px 0;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* ---------- Recent parts strip ---------- */
.recent-parts {
  margin-bottom: 14px;
  padding: 8px 10px;
  background: var(--row-alt);
  border: 1px solid var(--border);
}

.recent-parts-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 6px;
}

.recent-parts-grid {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.recent-part-chip {
  padding: 5px 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  white-space: nowrap;
}

.recent-part-chip:hover {
  border-color: var(--brand-navy);
  background: var(--row-hover);
}

.recent-part-chip:active {
  transform: translateY(1px);
}

/* ---------- Category selection ---------- */
.category-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.category-button {
  padding: 14px 10px;
  border: 1px solid var(--border);
  background: var(--row);
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  text-align: center;
  font-weight: 700;
  font-size: 13px;
}

.category-button:hover {
  border-color: var(--brand-navy);
  background: var(--row-hover);
}

.category-button.active {
  border-color: var(--brand-navy);
  background: rgba(30, 58, 138, 0.14);
  box-shadow: inset 0 -2px 0 var(--brand-red);
}

.category-icon {
  width: 40px;
  height: 40px;
  display: block;
  margin: 0 auto 6px auto;
  object-fit: contain;
  filter: invert(1) brightness(1.15);
  opacity: 0.75;
  transition: opacity 0.2s, filter 0.2s;
}

/* Light mode: don't invert icons */
[data-theme="light"] .category-icon {
  filter: invert(0) brightness(0.3);
}

.category-button:hover .category-icon,
.category-button.active .category-icon {
  opacity: 1;
  filter: invert(1) brightness(1.3) drop-shadow(0 0 6px rgba(59, 90, 181, 0.6));
}

[data-theme="light"] .category-button:hover .category-icon,
[data-theme="light"] .category-button.active .category-icon {
  filter: invert(0) brightness(0.15) drop-shadow(0 0 6px rgba(59, 90, 181, 0.5));
}

/* ---------- Part selection within category ---------- */
.parts-list {
  display: none;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.parts-list.show {
  display: block;
}

.parts-grid {
  display: grid;
  gap: 6px;
}

.part-button {
  padding: 11px 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
}

.part-button:hover {
  border-color: var(--brand-navy);
  background: var(--row-hover);
}

.part-button.selected {
  border-color: var(--ok);
  background: rgba(56, 161, 105, 0.12);
  font-weight: 700;
}

.part-button.highlighted-option {
  animation: multiPulse 2s ease-in-out infinite;
  border: 2px solid var(--primary-300) !important;
  box-shadow: 0 0 0 3px rgba(59, 90, 181, 0.25);
}

@keyframes multiPulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(59, 90, 181, 0.25); }
  50% { box-shadow: 0 0 0 6px rgba(59, 90, 181, 0.45); }
}

/* ---------- Selected part display ---------- */
.selected-part-display {
  display: none;
  padding: 10px 12px;
  background: rgba(56, 161, 105, 0.10);
  border: 1px solid rgba(56, 161, 105, 0.4);
  border-left: 3px solid var(--ok);
  color: var(--text);
  border-radius: 4px;
  margin-bottom: 14px;
  font-weight: 700;
  font-size: 13px;
  align-items: center;
  justify-content: space-between;
}

.selected-part-display.show {
  display: flex;
}

.change-part-btn,
.change-zone-btn,
.change-damage-btn {
  padding: 4px 10px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.change-part-btn:hover,
.change-zone-btn:hover,
.change-damage-btn:hover {
  border-color: var(--brand-navy);
  color: var(--text);
}

/* ---------- View diagram button ---------- */
.view-diagram-inline {
  width: 100%;
  padding: 12px 16px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin: 16px 0;
  display: none;
}

.view-diagram-inline.show {
  display: block;
}

.view-diagram-inline:hover {
  border-color: var(--brand-navy);
  background: var(--row-hover);
}

/* Diagram helper text - hidden (diagram shows inline) */
.diagram-helper-text {
  display: none !important;
}

/* ---------- Inline zone diagram (mobile fallback) ---------- */
.zone-diagram-inline {
  width: 100%;
  max-width: 400px;
  margin: 0 auto 16px auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card);
  padding: 6px;
  display: none; /* Hidden by default, shown via JS */
}

.zone-diagram-inline img {
  width: 100%;
  height: auto;
  display: block;
}

.zone-diagram-inline.show {
  display: block;
}

@media (min-width: 769px) {
  .zone-diagram-inline {
    display: none !important;
  }
}

/* Floating diagram button - retired (diagram shows inline) */
.floating-diagram-btn {
  display: none !important;
}

@media (max-width: 768px) {
  .view-diagram-inline {
    display: none !important;
  }
}

/* ---------- Diagram overlay modal ---------- */
.diagram-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(4, 10, 25, 0.85);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.diagram-overlay.active {
  display: flex;
}

.diagram-modal {
  background: #fff;
  border-radius: 6px;
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
  position: relative;
  box-shadow: var(--shadow-large);
}

.diagram-modal img {
  width: 100%;
  height: auto;
  display: block;
}

.close-diagram {
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--brand-red);
  color: #fff;
  border: none;
  border-radius: 4px;
  width: 36px;
  height: 36px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-medium);
  transition: background 0.15s;
}

.close-diagram:hover {
  background: var(--brand-red-deep);
}

/* ---------- Form groups ---------- */
.form-group {
  margin-bottom: 16px;
  max-width: 100%;
  overflow: hidden;
}

.form-label {
  display: block;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ---------- Step 3 context display (mobile only) ---------- */
.damage-step-context-inline {
  display: none;
}

@media (max-width: 768px) {
  .damage-step-context-inline {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex: 1;
    /* Fill the space between breadcrumb and fixed damage selector */
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }
}

.context-svg-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.context-svg-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0.85;
}

.context-svg-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

.context-info {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(11, 32, 60, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.16);
  padding: 7px 14px;
  border-radius: 4px;
  backdrop-filter: blur(8px);
  z-index: 10;
  white-space: nowrap;
}

.context-part {
  font-weight: 600;
  color: rgba(255, 255, 255, 0.72);
}

.context-zone {
  color: #fff;
  font-weight: 800;
}

/* Pulsing ring used by the JS zone highlight indicator */
@keyframes zonePulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  50% { transform: translate(-50%, -50%) scale(1.25); opacity: 0.6; }
}

/* ---------- Damage type selector ----------
   Inline section on desktop; fixed bottom panel on mobile (step 3). */
.damage-selector-fixed {
  display: block;
}

@media (max-width: 768px) {
  .damage-selector-fixed {
    display: none; /* Hidden by default, shown via JS when Step 3 is active */
    position: fixed;
    bottom: 108px; /* Above sticky footer */
    left: 0;
    right: 0;
    z-index: 50;
    background: var(--bg);
    padding: 8px 12px 12px;
    border-top: 1px solid var(--border);
  }

  .damage-selector-fixed.show {
    display: block;
  }
}

/* Search bar */
.damage-search-fixed {
  position: relative;
  margin-bottom: 10px;
}

.damage-search-fixed .damage-search-input {
  width: 100%;
  padding: 10px 40px 10px 12px;
  border: 1px solid var(--input-border);
  border-radius: 4px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.damage-search-fixed .damage-search-input:focus {
  border-color: var(--brand-navy);
  box-shadow: 0 0 0 2px rgba(30, 58, 138, 0.25);
}

.damage-search-fixed .damage-search-input::placeholder {
  color: var(--muted);
  font-weight: 400;
}

.damage-search-fixed .search-clear-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  display: none;
}

.damage-search-fixed .search-clear-btn.show {
  display: block;
}

.damage-search-fixed .search-clear-btn:hover {
  color: var(--brand-red);
}

/* Damage type groups */
.damage-type-groups {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.damage-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.damage-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  padding-left: 2px;
}

.damage-group-strip-wrapper {
  position: relative;
  background: var(--row-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 0 6px 6px;
}

/* Right fade indicator - shows there's more to scroll */
.damage-group-strip-wrapper::after {
  content: '';
  position: absolute;
  top: 1px;
  right: 1px;
  bottom: 1px;
  width: 44px;
  background: linear-gradient(to right, transparent, var(--row-alt));
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.2s;
}

.damage-group-strip-wrapper.scrolled-end::after {
  opacity: 0;
}

.damage-group-strip {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-right: 30px; /* Extra space so last chip isn't under fade */
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}

.damage-group-strip::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.damage-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px 7px 7px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  font-family: inherit;
  min-height: 40px;
  flex-shrink: 0; /* Don't shrink in scroll container */
}

.damage-pill:hover {
  border-color: var(--brand-navy);
  background: var(--row-hover);
}

.damage-pill:active {
  transform: translateY(1px);
}

.damage-pill.active {
  border-color: var(--brand-navy);
  background: rgba(30, 58, 138, 0.14);
  box-shadow: inset 0 -2px 0 var(--brand-red);
}

.damage-pill .pill-code {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: var(--brand-navy);
  color: #fff;
  border-radius: 3px;
  font-size: 13px;
  font-weight: 800;
  font-family: 'Consolas', 'Courier New', monospace;
  flex-shrink: 0;
}

.damage-pill .pill-name {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.damage-pill.hidden {
  display: none;
}

/* Legacy mobile bottom-sheet remnants - retired */
.damage-type-backdrop {
  display: none !important;
}

.select-damage-btn {
  display: none !important;
}

/* ---------- Step indicator (mobile only) ---------- */
.breadcrumb-nav {
  display: none;
  position: sticky;
  top: 0;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  margin: 0;
  z-index: 100;
}

.breadcrumb-items {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.breadcrumb-items::-webkit-scrollbar {
  display: none;
}

.breadcrumb-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 3px;
  transition: background 0.15s, border-color 0.15s;
  background: transparent;
  min-width: 36px;
}

.breadcrumb-item .step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  background: var(--row-alt);
  border: 1px solid var(--border);
  border-radius: 2px;
  font-size: 9px;
  font-weight: 800;
  font-style: normal;
  color: var(--muted);
  flex-shrink: 0;
}

.breadcrumb-item.active {
  color: var(--text);
  background: rgba(30, 58, 138, 0.14);
  border-color: var(--brand-navy);
  font-weight: 700;
}

.breadcrumb-item.active .step-num {
  background: var(--brand-navy);
  border-color: var(--brand-navy);
  color: #fff;
}

.breadcrumb-item.completed {
  color: var(--text);
  cursor: pointer;
  background: rgba(56, 161, 105, 0.10);
  border-color: rgba(56, 161, 105, 0.45);
  font-weight: 700;
}

.breadcrumb-item.completed .step-num {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
  font-size: 0;
}

.breadcrumb-item.completed .step-num::before {
  content: '\2713';
  font-size: 10px;
}

.breadcrumb-item.completed:hover {
  background: rgba(56, 161, 105, 0.18);
}

.breadcrumb-item.completed:active {
  transform: scale(0.98);
}

.breadcrumb-separator {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  opacity: 0.5;
}

/* ---------- Sticky code footer (mobile) ---------- */
.sticky-code-footer {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--brand-header-gradient);
  border-top: 2px solid var(--brand-red);
  padding: 10px 14px 12px 14px;
  z-index: 100;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.25);
}

/* Row 1: code (large) + copy (hero action) */
.sticky-code-row-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.sticky-code-display {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  flex: 1;
  word-break: break-all;
  line-height: 1.3;
}

.sticky-code-display.empty {
  color: rgba(255, 255, 255, 0.55);
  font-size: 13px;
  font-family: inherit;
  font-weight: 400;
  word-break: normal;
}

.sticky-copy-btn {
  padding: 12px 22px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  background: var(--brand-red);
  color: #fff;
  box-shadow: inset 0 -2px 0 var(--brand-red-deep);
  white-space: nowrap;
  flex-shrink: 0;
}

.sticky-copy-btn:hover:not(:disabled) {
  background: #e53535;
}

.sticky-copy-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.sticky-copy-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Row 2: meta + clear. Left padding clears the shared quick-issue FAB
   (fixed at left 14px / bottom 14px, 34px wide) that overlays this row. */
.sticky-code-row-secondary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-left: 40px;
}

.sticky-code-meta {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.6);
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sticky-clear-btn {
  padding: 5px 12px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 3px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  background: transparent;
  color: rgba(255, 255, 255, 0.75);
  white-space: nowrap;
  flex-shrink: 0;
}

.sticky-clear-btn:hover:not(:disabled) {
  background: rgba(220, 38, 38, 0.25);
  border-color: var(--brand-red);
  color: #fff;
}

.sticky-clear-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ---------- Progressive disclosure mobile layout ---------- */
@media (max-width: 768px) {
  .breadcrumb-nav {
    display: block;
  }

  .sticky-code-footer {
    display: block;
  }

  /* Single-surface app layout: builder fills the viewport */
  .main-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    border: none;
    box-shadow: none;
    margin-bottom: 0;
  }

  .code-output {
    display: none !important;
  }

  /* Header hidden on mobile (brand shows in topbar) */
  .damage-header {
    display: none;
  }

  .section-title {
    display: none;
  }

  /* Full viewport for steps */
  .damage-container {
    padding: 0;
    margin: 0;
    height: 100vh;
    max-width: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .app {
    padding: 0;
    margin: 0;
  }

  .builder-section {
    flex: 1;
    padding: 16px;
    border: none;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    padding-bottom: 110px; /* Space for footer with buttons */
    overflow-y: auto;
    min-height: 0;
  }

  /* Edge-to-edge display for zone and damage type steps */
  .builder-section:has(#zoneGroup.active-step),
  .builder-section:has(#damageTypeGroup.active-step) {
    padding: 0;
    padding-bottom: 110px;
  }

  /* Step containers - only show active step */
  .form-group {
    display: none !important;
    flex: 1;
    margin-bottom: 0;
  }

  .form-group.active-step {
    display: flex !important;
    flex-direction: column;
  }

  /* Hide legacy desktop add button group on mobile */
  #addButtonGroup {
    display: none !important;
  }

  /* Hide form labels on mobile (step indicator shows progress) */
  .form-label {
    display: none;
  }

  /* Make steps fill available space */
  .category-grid,
  .zone-grid {
    flex: 1;
    align-content: start;
  }

  /* Zone group fills full height when SVG selector is active */
  #zoneGroup {
    position: relative;
    padding: 0 !important;
    margin: 0;
  }

  #zoneGroup.active-step {
    /* Fill available space: viewport - topbar(~56px) - breadcrumb(~44px) - footer(~108px) */
    min-height: calc(100vh - 210px);
    height: calc(100vh - 210px);
  }

  #zoneGroup .svg-zone-selector-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    padding: 0;
  }

  /* Allow SVG to fill available height on mobile */
  .svg-zone-interactive {
    aspect-ratio: unset !important;
    height: 100%;
    width: 100%;
    position: relative;
  }

  .svg-layer-base {
    object-fit: contain;
    width: 100%;
    height: 100%;
  }

  .svg-layer-clickbox svg {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  /* Damage type group fills full height for Step 3 */
  #damageTypeGroup {
    position: relative;
    padding: 0 !important;
  }

  #damageTypeGroup.active-step {
    /* Fill available space between breadcrumb and fixed damage selector */
    min-height: calc(100vh - 390px);
    height: calc(100vh - 390px);
    overflow: hidden;
  }

  /* Slide transitions */
  .form-group.slide-in-right {
    animation: slideInRight 0.3s ease-out;
  }

  .form-group.slide-in-left {
    animation: slideInLeft 0.3s ease-out;
  }

  /* Step 3 hosts a position:fixed child (the damage selector), so it must
     not animate transform - fade only, or the fixed panel jumps. */
  #damageTypeGroup.slide-in-right,
  #damageTypeGroup.slide-in-left {
    animation: fadeIn 0.25s ease-out;
  }

  @keyframes slideInRight {
    from {
      opacity: 0;
      transform: translateX(30px);
    }
    to {
      opacity: 1;
      transform: translateX(0);
    }
  }

  @keyframes slideInLeft {
    from {
      opacity: 0;
      transform: translateX(-30px);
    }
    to {
      opacity: 1;
      transform: translateX(0);
    }
  }

  /* Hide compact summary displays on mobile - full grids shown instead */
  .selected-zone-display,
  .selected-damage-display {
    display: none !important;
  }

  /* Hide admin footer on mobile */
  .admin-footer {
    display: none !important;
  }
}

/* ---------- Selected zone display (desktop compact) ---------- */
.selected-zone-display {
  display: none;
  padding: 10px 12px;
  background: rgba(56, 161, 105, 0.10);
  border: 1px solid rgba(56, 161, 105, 0.4);
  border-left: 3px solid var(--ok);
  color: var(--text);
  border-radius: 4px;
  margin-bottom: 14px;
  font-weight: 700;
  font-size: 13px;
  align-items: center;
  justify-content: space-between;
}

.selected-zone-display.show {
  display: flex;
}

/* ---------- SVG zone selector ---------- */
.svg-zone-selector-container {
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
  width: 100%;
}

.svg-zone-interactive {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  aspect-ratio: 592 / 748;
}

.svg-zone-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.svg-layer-base {
  pointer-events: none;
  z-index: 1;
}

/* Invert SVG in light mode for better visibility */
[data-theme="light"] .svg-layer-base {
  filter: invert(1) brightness(1.1);
}

.svg-layer-clickbox {
  z-index: 2;
  opacity: 0;
}

[data-theme="light"] .svg-layer-clickbox {
  filter: invert(1) brightness(1.1);
}

/* ---------- Zone grid (fallback) ---------- */
.zone-grid-container {
  display: block;
}

.zone-grid-container.collapsed {
  display: none;
}

.zone-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 8px;
}

.zone-button {
  padding: 14px 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-size: 18px;
  font-weight: 700;
  font-family: 'Consolas', 'Courier New', monospace;
  text-align: center;
  min-width: 48px;
}

.zone-button:hover {
  border-color: var(--brand-navy);
  background: var(--row-hover);
}

.zone-button.active {
  border-color: var(--ok);
  background: rgba(56, 161, 105, 0.14);
  box-shadow: inset 0 -2px 0 var(--ok);
}

/* ---------- Selected damage display (desktop compact) ---------- */
.selected-damage-display {
  display: none;
  padding: 10px 12px;
  background: rgba(56, 161, 105, 0.10);
  border: 1px solid rgba(56, 161, 105, 0.4);
  border-left: 3px solid var(--ok);
  color: var(--text);
  border-radius: 4px;
  margin-bottom: 14px;
  font-weight: 700;
  font-size: 13px;
  align-items: center;
  justify-content: space-between;
}

.selected-damage-display.show {
  display: flex;
}

/* ---------- Hours selector ---------- */
.hours-selector-container {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 18px;
  margin-bottom: 14px;
}

.hours-stepper-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.hours-stepper-btn {
  min-width: 48px;
  min-height: 48px;
  padding: 8px;
  border: none;
  background: var(--brand-navy);
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: inset 0 -2px 0 var(--primary-700);
}

.hours-stepper-btn:hover {
  background: var(--primary-300);
}

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

.hours-stepper-display {
  flex: 1;
  text-align: center;
  padding: 10px 16px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 4px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.hours-stepper-display span {
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  font-family: 'Consolas', 'Courier New', monospace;
}

/* Hours slider */
.hours-slider-container {
  margin-bottom: 18px;
  padding: 0 6px;
}

.hours-slider {
  width: 100%;
  height: 6px;
  background: var(--row-hover);
  border-radius: 3px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.hours-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  background: var(--brand-navy);
  border: 3px solid var(--card);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  transition: background 0.15s;
}

.hours-slider::-webkit-slider-thumb:hover {
  background: var(--primary-300);
}

.hours-slider::-moz-range-thumb {
  width: 26px;
  height: 26px;
  background: var(--brand-navy);
  border: 3px solid var(--card);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  transition: background 0.15s;
}

.hours-slider::-moz-range-thumb:hover {
  background: var(--primary-300);
}

.hours-slider-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
  padding: 0 4px;
}

/* Hours presets */
.hours-presets-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.hours-preset-btn {
  min-width: 48px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-size: 15px;
  font-weight: 700;
  font-family: 'Consolas', 'Courier New', monospace;
  flex-shrink: 0;
}

.hours-preset-btn:hover {
  border-color: var(--brand-navy);
  background: var(--row-hover);
}

.hours-preset-btn.active {
  border-color: var(--brand-navy);
  background: var(--brand-navy);
  color: #fff;
  box-shadow: inset 0 -2px 0 var(--brand-red);
}

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

/* Hours section header */
.hours-section-header {
  text-align: center;
  margin-bottom: 18px;
}

.hours-section-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  margin: 0 0 4px 0;
  letter-spacing: 0.4px;
}

.hours-section-subtitle {
  font-size: 12px;
  color: var(--muted);
}

.hours-helper-text {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

/* Auto-capitalize all text inputs */
input[type="text"],
input[type="search"],
textarea {
  text-transform: uppercase;
}

/* ---------- Primary action button ---------- */
.add-button {
  width: 100%;
  padding: 14px 16px;
  background: var(--brand-navy);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  box-shadow: inset 0 -3px 0 var(--brand-red);
}

.add-button:hover {
  background: var(--primary-700);
}

.add-button:active {
  transform: translateY(1px);
}

.add-button:disabled {
  background: var(--muted);
  box-shadow: none;
  opacity: 0.5;
  cursor: not-allowed;
}

/* Legacy duplicate add-button group - the step 4 button covers all viewports */
#addButtonGroup {
  display: none !important;
}

/* ---------- Code output panel ---------- */
.current-part-header {
  background: rgba(30, 58, 138, 0.08);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand-navy);
  border-radius: 4px;
  padding: 8px 12px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.current-part-label {
  font-size: 10px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.current-part-name {
  font-size: 13px;
  color: var(--text);
  font-weight: 800;
}

.code-display-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 14px;
}

.code-display {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  word-break: break-all;
  text-align: center;
  margin-bottom: 8px;
}

.code-display.empty {
  color: var(--muted);
  font-size: 13px;
  font-family: inherit;
  font-weight: 400;
  word-break: normal;
}

.total-hours {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.total-hours strong {
  color: var(--text);
  font-size: 15px;
}

/* Code breakdown */
.code-breakdown-section {
  margin-bottom: 14px;
}

.code-breakdown-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 6px;
  letter-spacing: 0.8px;
}

.code-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.code-item {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.code-item:last-child {
  border-bottom: none;
}

.code-item-info {
  flex: 1;
  min-width: 0;
}

.code-item-text {
  font-family: 'Consolas', 'Courier New', monospace;
  font-weight: 700;
  color: var(--text);
  font-size: 13px;
  margin-bottom: 2px;
}

.code-item-desc {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.3;
}

.remove-button {
  padding: 3px 8px;
  background: transparent;
  color: var(--brand-red);
  border: 1px solid rgba(220, 38, 38, 0.35);
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.remove-button:hover {
  background: rgba(220, 38, 38, 0.12);
  border-color: var(--brand-red);
}

/* Action buttons */
.code-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}

.copy-button-large {
  flex: 1;
  padding: 13px 20px;
  background: var(--brand-navy);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  box-shadow: inset 0 -3px 0 var(--brand-red);
}

.copy-button-large:hover:not(:disabled) {
  background: var(--primary-700);
}

.copy-button-large:active:not(:disabled) {
  transform: translateY(1px);
}

.copy-button-large:disabled {
  background: var(--muted);
  box-shadow: none;
  opacity: 0.5;
  cursor: not-allowed;
}

.clear-button {
  padding: 13px 18px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.clear-button:hover:not(:disabled) {
  background: rgba(220, 38, 38, 0.08);
  border-color: var(--brand-red);
  color: var(--brand-red);
}

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

/* ---------- Undo button ---------- */
.undo-button {
  display: none;
  position: fixed;
  bottom: 160px; /* Above sticky footer */
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary-700);
  color: #fff;
  padding: 10px 22px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: var(--shadow-large);
  z-index: 1000;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  transition: background 0.15s;
  opacity: 0;
  animation: undoSlideUp 0.3s ease-out forwards;
  white-space: nowrap;
}

.undo-button.show {
  display: block;
}

.undo-button.hiding {
  animation: undoSlideDown 0.3s ease-in forwards;
}

@keyframes undoSlideUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@keyframes undoSlideDown {
  from {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
  to {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
}

.undo-button:hover {
  background: var(--brand-navy);
}

/* ---------- Confirmation modal ---------- */
.confirm-modal-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(4, 10, 25, 0.65);
  z-index: 9999;
  animation: fadeIn 0.2s ease-out;
}

.confirm-modal-backdrop.show {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.confirm-modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0;
  max-width: 400px;
  width: 100%;
  overflow: hidden;
  box-shadow: var(--shadow-large);
  animation: modalSlideUp 0.25s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.confirm-modal-header {
  background: var(--brand-header-gradient);
  color: #fff;
  padding: 12px 16px;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--brand-red);
}

.confirm-modal-body {
  padding: 16px 18px 4px;
}

.confirm-modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 10px 0;
}

.confirm-modal-message {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 12px 0;
  line-height: 1.5;
}

.confirm-modal-message strong {
  color: var(--text);
}

.confirm-modal-code {
  background: rgba(220, 38, 38, 0.08);
  border: 1px solid rgba(220, 38, 38, 0.35);
  border-radius: 4px;
  padding: 10px 12px;
  margin: 12px 0;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 15px;
  font-weight: 700;
  color: var(--brand-red);
  text-align: center;
  word-break: break-all;
}

.confirm-modal-actions {
  display: flex;
  gap: 10px;
  padding: 4px 18px 18px;
}

.confirm-modal-btn {
  flex: 1;
  padding: 12px 16px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.confirm-modal-btn-cancel {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.confirm-modal-btn-cancel:hover {
  border-color: var(--brand-navy);
  background: var(--row-hover);
}

.confirm-modal-btn-confirm {
  background: var(--brand-red);
  color: #fff;
  border: none;
  box-shadow: inset 0 -2px 0 var(--brand-red-deep);
}

.confirm-modal-btn-confirm:hover {
  background: #e53535;
}

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

/* ---------- Start New Part (mobile, above sticky footer) ---------- */
.done-with-part-section {
  display: none;
}

.done-with-part-section.show {
  display: block;
  position: fixed;
  bottom: 115px; /* Above sticky footer */
  left: 16px;
  right: 16px;
  z-index: 99;
}

.done-helper-text,
.done-main-text {
  display: none;
}

.done-with-part-btn {
  width: 100%;
  padding: 11px 16px;
  background: var(--primary-700);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  cursor: pointer;
  transition: background 0.15s;
  box-shadow: var(--shadow-medium);
}

.done-with-part-btn:active {
  background: var(--brand-navy);
}

@media (min-width: 769px) {
  .done-with-part-section {
    display: none !important;
  }
}

/* ---------- Recent codes ---------- */
.recent-codes-section {
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.recent-codes-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin: 0 0 8px 0;
}

.recent-codes-list {
  display: flex;
  flex-direction: column;
}

.recent-code-item {
  border-bottom: 1px solid var(--border);
  padding: 6px 2px;
  font-size: 11px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  transition: background 0.15s;
}

.recent-code-item:hover {
  background: var(--row-hover);
}

.recent-code-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.recent-code-part {
  font-weight: 700;
  color: var(--ok);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  flex-shrink: 0;
}

.recent-code-code {
  font-family: 'Consolas', 'Courier New', monospace;
  color: var(--text);
  font-weight: 600;
  font-size: 12px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-code-time {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
  flex-shrink: 0;
}

.recent-code-copy {
  background: transparent;
  color: var(--brand-navy);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.4px;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1.4;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

[data-theme="dark"] .recent-code-copy {
  color: var(--primary-300);
}

.recent-code-copy:hover {
  background: var(--brand-navy);
  border-color: var(--brand-navy);
  color: #fff;
}

.recent-code-copy:active {
  transform: translateY(1px);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--ok);
  color: #fff;
  padding: 12px 18px;
  border-radius: 4px;
  box-shadow: var(--shadow-large);
  z-index: 1000;
  opacity: 0;
  transform: translateX(24px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  font-weight: 700;
  font-size: 13px;
  max-width: 300px;
}

.toast.show {
  opacity: 1;
  transform: translateX(0);
}

/* Toast variants */
.toast.success {
  background: var(--ok);
}

.toast.info {
  background: var(--brand-navy);
}

.toast.error {
  background: var(--brand-red);
}

@media (max-width: 768px) {
  .toast {
    right: 50%;
    top: 56px;
    transform: translateX(50%) translateY(-12px);
    max-width: calc(100% - 40px);
  }

  .toast.show {
    transform: translateX(50%) translateY(0);
  }
}

/* ---------- Step highlight pulse ---------- */
@keyframes stepPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(59, 90, 181, 0.5);
  }
  25% {
    box-shadow: 0 0 0 10px rgba(59, 90, 181, 0);
  }
  50% {
    box-shadow: 0 0 0 0 rgba(59, 90, 181, 0.4);
  }
  75% {
    box-shadow: 0 0 0 8px rgba(59, 90, 181, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(59, 90, 181, 0);
  }
}

.step-highlight {
  animation: stepPulse 2s ease-out;
}

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .main-content {
    grid-template-columns: 1fr;
  }

  .code-output {
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

@media (max-width: 768px) {
  .category-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .zone-grid {
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
    gap: 6px;
  }

  .zone-button {
    padding: 12px 6px;
    font-size: 16px;
  }

  .hours-selector-container {
    padding: 16px;
  }

  .hours-stepper-display span {
    font-size: 20px;
  }

  .hours-presets-row {
    gap: 6px;
  }

  .hours-preset-btn {
    font-size: 14px;
    padding: 6px 12px;
    min-width: 44px;
    min-height: 44px;
  }

  /* Position hours selector in the thumb-friendly zone */
  #hoursGroup {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: calc(100vh - 200px);
    padding-bottom: 200px; /* Space for sticky footer and action buttons */
  }
}
