/* ==========================================================================
   Editorial Audio Design System - 3D Print Cost Calculator UI Components
   Enhanced Editorial Color Specification
   ========================================================================== */

/* Touch & Mobile Base Ergonomics */
html {
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

button, select, input, .margin-card, .step-pill, .btn-theme-toggle {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* App Container Layout */
.app-wrapper {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 20px 60px 20px;
  width: 100%;
  box-sizing: border-box;
}

/* Header Bar */
.header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-panel);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent-sage);
  border-radius: var(--radius-lg);
  padding: 18px 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-card);
  position: relative;
}

.brand-title {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}

.brand-title h1 {
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.brand-badge {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  background: rgba(87, 135, 122, 0.15);
  color: var(--accent-sage);
  padding: 3px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(87, 135, 122, 0.35);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Theme Toggle Button */
.btn-theme-toggle {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition-fast);
}

.btn-theme-toggle:hover {
  background: var(--surface-panel);
  border-color: var(--accent-active);
  color: var(--accent-sage);
}

/* Clear Local Memory / Reset Button */
.btn-reset-memory {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition-fast);
}

.btn-reset-memory:hover {
  background: var(--surface-panel);
  border-color: var(--accent-danger);
  color: var(--accent-danger);
}

/* Workflow Stepper with Individual Color Identities */
.workflow-stepper {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.step-pill {
  flex: 1;
  background: var(--surface-panel);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  transition: all var(--transition-fast);
  cursor: default;
}

.step-pill .step-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  transition: all var(--transition-fast);
}

/* Step 1: Machine & Rates - Slate Blue */
#pill_step1.active {
  background: var(--surface-elevated);
  border-color: var(--accent-slate);
  color: var(--text-primary);
  box-shadow: 0 2px 10px rgba(142, 156, 163, 0.15);
}
#pill_step1.active .step-num {
  background: var(--accent-slate);
  color: #FFFFFF;
}

/* Step 2: Model Specs - Warm Ochre */
#pill_step2.active {
  background: var(--surface-elevated);
  border-color: var(--accent-ochre);
  color: var(--text-primary);
  box-shadow: 0 2px 10px rgba(210, 158, 85, 0.15);
}
#pill_step2.active .step-num {
  background: var(--accent-ochre);
  color: #FFFFFF;
}

/* Step 3: Cost & Margin - Sage Green */
#pill_step3.active {
  background: var(--surface-elevated);
  border-color: var(--accent-sage);
  color: var(--text-primary);
  box-shadow: 0 2px 10px rgba(87, 135, 122, 0.15);
}
#pill_step3.active .step-num {
  background: var(--accent-sage);
  color: #FFFFFF;
}

/* Step 4: Quote & Invoice - Dusty Mauve */
#pill_step4.active {
  background: var(--surface-elevated);
  border-color: var(--accent-mauve);
  color: var(--text-primary);
  box-shadow: 0 2px 10px rgba(158, 142, 156, 0.15);
}
#pill_step4.active .step-num {
  background: var(--accent-mauve);
  color: #FFFFFF;
}

/* 2-Column Split Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 24px;
  width: 100%;
  min-width: 0;
}

.column-left,
.column-right {
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

@media (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
  }
}

/* Card Component with Semantic Accent Borders */
.editorial-card {
  background-color: var(--surface-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-card);
  margin-bottom: 24px;
  transition: all var(--transition-fast);
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.editorial-card:hover {
  box-shadow: var(--shadow-elevated);
}

/* Distinct Card Accent Ribbons */
.card-step1 {
  border-left: 4px solid var(--accent-slate);
}
.card-step1 .card-title svg {
  color: var(--accent-slate);
}

.card-step2 {
  border-left: 4px solid var(--accent-ochre);
}
.card-step2 .card-title svg {
  color: var(--accent-ochre);
}

.card-step3 {
  border-left: 4px solid var(--accent-sage);
}
.card-step3 .card-title svg {
  color: var(--accent-sage);
}

.card-step4 {
  border-left: 4px solid var(--accent-mauve);
}
.card-step4 .card-title svg {
  color: var(--accent-mauve);
}

.card-history {
  border-left: 4px solid var(--accent-steel);
}
.card-history .card-title svg {
  color: var(--accent-steel);
}

.card-catalog {
  border-left: 4px solid var(--accent-amber);
}
.card-catalog .card-title svg {
  color: var(--accent-amber);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  flex-wrap: wrap;
  width: 100%;
}

.card-title {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  min-width: 0;
  flex: 1 1 auto;
}

/* Semantic Badges */
.card-badge {
  font-family: var(--font-sans);
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 12px;
  border-radius: var(--radius-pill);
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.badge-slate {
  background: rgba(142, 156, 163, 0.15);
  color: var(--accent-slate);
  border-color: rgba(142, 156, 163, 0.35);
}

.badge-ochre {
  background: rgba(210, 158, 85, 0.15);
  color: var(--accent-ochre);
  border-color: rgba(210, 158, 85, 0.35);
}

.badge-sage {
  background: rgba(87, 135, 122, 0.15);
  color: var(--accent-sage);
  border-color: rgba(87, 135, 122, 0.35);
}

.badge-mauve {
  background: rgba(158, 142, 156, 0.15);
  color: var(--accent-mauve);
  border-color: rgba(158, 142, 156, 0.35);
}

.badge-steel {
  background: rgba(90, 130, 150, 0.15);
  color: var(--accent-steel);
  border-color: rgba(90, 130, 150, 0.35);
}

.badge-amber {
  background: rgba(201, 151, 87, 0.15);
  color: var(--accent-amber);
  border-color: rgba(201, 151, 87, 0.35);
}

/* Form Controls */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  width: 100%;
  min-width: 0;
}

.form-grid-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  min-width: 0;
}

.form-group.full-width {
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
}

label {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.input-wrapper {
  display: flex;
  align-items: center;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  overflow: hidden;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.input-wrapper:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(87, 135, 122, 0.2);
}

.input-wrapper input,
.input-wrapper select {
  flex-grow: 1;
  background: transparent;
  border: none;
  padding: 8px 10px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
  min-width: 0;
}

/* Colorful Unit Tints */
.input-wrapper .unit {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 0 10px;
  background: var(--surface-panel);
  border-left: 1px solid var(--border);
  height: 100%;
  display: flex;
  align-items: center;
  color: var(--text-muted);
}

.input-wrapper .unit.unit-slate {
  background: rgba(142, 156, 163, 0.12);
  color: var(--accent-slate);
  border-left-color: rgba(142, 156, 163, 0.3);
}

.input-wrapper .unit.unit-mauve {
  background: rgba(158, 142, 156, 0.12);
  color: var(--accent-mauve);
  border-left-color: rgba(158, 142, 156, 0.3);
}

.input-wrapper .unit.unit-ochre {
  background: rgba(210, 158, 85, 0.12);
  color: var(--accent-ochre);
  border-left-color: rgba(210, 158, 85, 0.3);
}

.input-wrapper .unit.unit-terracotta {
  background: rgba(196, 116, 99, 0.12);
  color: var(--accent-terracotta);
  border-left-color: rgba(196, 116, 99, 0.3);
}

.input-wrapper .unit.unit-sage {
  background: rgba(87, 135, 122, 0.12);
  color: var(--accent-sage);
  border-left-color: rgba(87, 135, 122, 0.3);
}

.input-wrapper .unit.unit-steel {
  background: rgba(90, 130, 150, 0.12);
  color: var(--accent-steel);
  border-left-color: rgba(90, 130, 150, 0.3);
}

input[type="text"],
select {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input[type="text"]:focus,
select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(87, 135, 122, 0.2);
}

/* Colorful Buttons */
.btn {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  color: var(--text-primary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all var(--transition-fast);
}

.btn:hover {
  background: var(--surface-panel);
  border-color: var(--accent-active);
}

.btn-primary,
.btn-sage {
  background: var(--accent-sage);
  border-color: var(--accent-sage);
  color: #FFFFFF;
  font-weight: 600;
}

.btn-primary:hover,
.btn-sage:hover {
  filter: brightness(1.08);
  color: #FFFFFF;
}

.btn-ochre {
  background: rgba(210, 158, 85, 0.15);
  border-color: var(--accent-ochre);
  color: var(--accent-ochre);
  font-weight: 600;
}

.btn-ochre:hover {
  background: var(--accent-ochre);
  color: #FFFFFF;
}

.btn-steel {
  background: rgba(90, 130, 150, 0.15);
  border-color: var(--accent-steel);
  color: var(--accent-steel);
  font-weight: 600;
}

.btn-steel:hover {
  background: var(--accent-steel);
  color: #FFFFFF;
}

.btn-mauve {
  background: rgba(158, 142, 156, 0.15);
  border-color: var(--accent-mauve);
  color: var(--accent-mauve);
  font-weight: 600;
}

.btn-mauve:hover {
  background: var(--accent-mauve);
  color: #FFFFFF;
}

.btn-outline-sage {
  background: rgba(87, 135, 122, 0.12);
  border: 1px solid var(--accent-sage);
  color: var(--accent-sage);
  font-weight: 600;
  border-radius: var(--radius-pill);
}

.btn-outline-sage:hover {
  background: var(--accent-sage);
  color: #FFFFFF;
}

.btn-outline-slate {
  background: rgba(142, 156, 163, 0.12);
  border: 1px solid var(--accent-slate);
  color: var(--accent-slate);
  font-weight: 600;
  border-radius: var(--radius-pill);
}

.btn-outline-slate:hover {
  background: var(--accent-slate);
  color: #FFFFFF;
}

.btn-danger {
  background: rgba(196, 116, 99, 0.12);
  border-color: rgba(196, 116, 99, 0.35);
  color: var(--accent-danger);
  font-weight: 600;
}

.btn-danger:hover {
  background: var(--accent-danger);
  color: #FFFFFF;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
}

/* Headline Stats Hero Card */
.headline-stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 20px;
}

.headline-stat-box {
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  transition: all var(--transition-fast);
}

.headline-stat-box.box-cost {
  background: rgba(142, 156, 163, 0.08);
  border: 1px solid rgba(142, 156, 163, 0.35);
}

.headline-stat-box.box-cost .stat-label {
  color: var(--accent-slate);
  font-weight: 700;
}

.headline-stat-box.box-cost .stat-value {
  color: var(--text-primary);
  font-size: 24px;
  font-weight: 700;
}

.headline-stat-box.box-cost .stat-sub {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
}

.headline-stat-box.box-price {
  background: rgba(87, 135, 122, 0.10);
  border: 1px solid rgba(87, 135, 122, 0.35);
}

.headline-stat-box.box-price .stat-label {
  color: var(--accent-sage);
  font-weight: 700;
}

.headline-stat-box.box-price .stat-value {
  color: var(--accent-sage);
  font-size: 24px;
  font-weight: 700;
}

.headline-stat-box.box-price .stat-sub {
  display: inline-block;
  background: rgba(87, 135, 122, 0.20);
  color: var(--accent-sage);
  font-weight: 700;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-size: 12px;
  margin-top: 4px;
  border: 1px solid rgba(87, 135, 122, 0.35);
}

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
}

/* Segmented Cost Breakdown Bar */
.cost-bar-container {
  margin-bottom: 20px;
}

.cost-bar-header {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.cost-bar {
  height: 16px;
  width: 100%;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  overflow: hidden;
  display: flex;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.06);
}

.cost-bar-segment {
  height: 100%;
  transition: width 0.3s ease;
}

.cost-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  margin-top: 12px;
  font-size: 11px;
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 500;
  font-family: var(--font-mono);
  transition: transform var(--transition-fast);
}

.legend-chip:hover {
  transform: translateY(-1px);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chip-mat {
  background: rgba(87, 135, 122, 0.12);
  border: 1px solid rgba(87, 135, 122, 0.3);
  color: var(--text-primary);
}

.chip-mach {
  background: rgba(142, 156, 163, 0.12);
  border: 1px solid rgba(142, 156, 163, 0.3);
  color: var(--text-primary);
}

.chip-pow {
  background: rgba(210, 158, 85, 0.12);
  border: 1px solid rgba(210, 158, 85, 0.3);
  color: var(--text-primary);
}

.chip-lab {
  background: rgba(158, 142, 156, 0.12);
  border: 1px solid rgba(158, 142, 156, 0.3);
  color: var(--text-primary);
}

.chip-hw {
  background: rgba(90, 130, 150, 0.12);
  border: 1px solid rgba(90, 130, 150, 0.3);
  color: var(--text-primary);
}

.chip-risk {
  background: rgba(196, 116, 99, 0.12);
  border: 1px solid rgba(196, 116, 99, 0.3);
  color: var(--text-primary);
}

/* Profit Margins Interactive Grid with Distinct Color Tiers */
.margins-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.margin-card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 10px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}

.margin-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.margin-price {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 6px 0;
}

.margin-profit {
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
}

/* 0% Break-Even (Slate Blue) */
.margin-card[data-margin="0"]:hover {
  border-color: var(--accent-slate);
  transform: translateY(-2px);
}
.margin-card[data-margin="0"].active {
  border-color: var(--accent-slate);
  background: rgba(142, 156, 163, 0.14);
  box-shadow: 0 0 0 2px rgba(142, 156, 163, 0.25);
}
.margin-card[data-margin="0"].active .margin-price {
  color: var(--accent-slate);
}

/* 30% Wholesale (Dusty Mauve) */
.margin-card[data-margin="30"]:hover {
  border-color: var(--accent-mauve);
  transform: translateY(-2px);
}
.margin-card[data-margin="30"].active {
  border-color: var(--accent-mauve);
  background: rgba(158, 142, 156, 0.14);
  box-shadow: 0 0 0 2px rgba(158, 142, 156, 0.25);
}
.margin-card[data-margin="30"] .margin-profit {
  color: var(--accent-mauve);
}
.margin-card[data-margin="30"].active .margin-price {
  color: var(--accent-mauve);
}

/* 50% Retail (Steel Teal) */
.margin-card[data-margin="50"]:hover {
  border-color: var(--accent-steel);
  transform: translateY(-2px);
}
.margin-card[data-margin="50"].active {
  border-color: var(--accent-steel);
  background: rgba(90, 130, 150, 0.14);
  box-shadow: 0 0 0 2px rgba(90, 130, 150, 0.25);
}
.margin-card[data-margin="50"] .margin-profit {
  color: var(--accent-steel);
}
.margin-card[data-margin="50"].active .margin-price {
  color: var(--accent-steel);
}

/* 70% Commercial (Sage Green - Highlight) */
.margin-card[data-margin="70"]:hover {
  border-color: var(--accent-sage);
  transform: translateY(-2px);
}
.margin-card[data-margin="70"].active {
  border-color: var(--accent-sage);
  background: rgba(87, 135, 122, 0.16);
  box-shadow: 0 0 0 2px rgba(87, 135, 122, 0.30);
}
.margin-card[data-margin="70"] .margin-profit {
  color: var(--accent-sage);
}
.margin-card[data-margin="70"].active .margin-price {
  color: var(--accent-sage);
}

/* 100% Prototype (Warm Ochre) */
.margin-card[data-margin="100"]:hover {
  border-color: var(--accent-ochre);
  transform: translateY(-2px);
}
.margin-card[data-margin="100"].active {
  border-color: var(--accent-ochre);
  background: rgba(210, 158, 85, 0.16);
  box-shadow: 0 0 0 2px rgba(210, 158, 85, 0.30);
}
.margin-card[data-margin="100"] .margin-profit {
  color: var(--accent-ochre);
}
.margin-card[data-margin="100"].active .margin-price {
  color: var(--accent-ochre);
}

/* Quotation Box */
.quote-box {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent-sage);
  border-radius: var(--radius-md);
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--text-primary);
  max-height: 150px;
  overflow-y: auto;
  margin-bottom: 14px;
}

/* Quote Action Buttons Layout */
.quote-actions-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quote-btn-primary {
  width: 100%;
  font-weight: 600;
  padding: 10px 16px;
  justify-content: center;
}

.quote-actions-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.quote-actions-row .btn {
  justify-content: center;
  padding: 8px 10px;
}

/* Data Tables */
.table-container {
  max-height: 280px;
  overflow-y: auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-elevated);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 12px;
  min-width: 460px;
}

th {
  background: var(--surface-panel);
  color: var(--text-primary);
  font-family: var(--font-serif);
  font-weight: 600;
  padding: 10px 12px;
  position: sticky;
  top: 0;
  z-index: 2;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

tr:hover td {
  background: rgba(87, 135, 122, 0.04);
}

/* Material Tags in Tables */
.mat-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
}

.mat-tag.tag-pla {
  background: rgba(87, 135, 122, 0.15);
  color: var(--accent-sage);
  border-color: rgba(87, 135, 122, 0.35);
}

.mat-tag.tag-petg {
  background: rgba(142, 156, 163, 0.18);
  color: var(--accent-slate);
  border-color: rgba(142, 156, 163, 0.35);
}

.mat-tag.tag-abs {
  background: rgba(210, 158, 85, 0.18);
  color: var(--accent-ochre);
  border-color: rgba(210, 158, 85, 0.35);
}

.mat-tag.tag-tpu {
  background: rgba(158, 142, 156, 0.18);
  color: var(--accent-mauve);
  border-color: rgba(158, 142, 156, 0.35);
}

.mat-tag.tag-cf {
  background: rgba(196, 116, 99, 0.18);
  color: var(--accent-terracotta);
  border-color: rgba(196, 116, 99, 0.35);
}

/* Modal Overlay & Invoice Sheet */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 800px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-elevated);
  padding: 24px;
  position: relative;
}

.modal-close-corner {
  position: absolute;
  top: 14px;
  right: 14px;
  background: var(--surface-panel);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.modal-close-corner:hover {
  background: var(--accent-danger);
  color: #FFFFFF;
}

/* Modal Header Actions */
.modal-header-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-right: 40px;
  gap: 12px;
}

.modal-title {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
}

.modal-btn-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.invoice-paper {
  background: #FFFFFF;
  color: #2D2B2A;
  padding: 30px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.invoice-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
}

.invoice-table th {
  background: #F4F2EE;
  color: #2D2B2A;
  font-weight: 600;
  border-bottom: 1px solid #E5E2DC;
  padding: 8px 10px;
}

.invoice-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #E5E2DC;
  color: #2D2B2A;
}

/* Toast */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--accent-sage);
  color: #FFFFFF;
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-elevated);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 2000;
}

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

.hidden {
  display: none !important;
}

/* ==========================================================================
   Responsive Breakpoints & Mobile Phone Screen Optimizations
   ========================================================================== */

/* Tablets & Small Desktops (<= 768px) */
@media (max-width: 768px) {
  .app-wrapper {
    padding: 16px 14px 48px 14px;
  }

  .header-bar {
    padding: 14px 18px;
    margin-bottom: 18px;
  }

  .quote-actions-row {
    grid-template-columns: 1fr 1fr;
  }

  .quote-actions-row .btn:last-child {
    grid-column: 1 / -1;
  }
}

/* Mobile Phones (<= 640px) */
@media (max-width: 640px) {
  .app-wrapper {
    padding: 12px 10px 40px 10px;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    box-sizing: border-box;
  }

  /* Header Bar */
  .header-bar {
    padding: 12px 14px;
    margin-bottom: 14px;
    border-radius: var(--radius-md);
    width: 100%;
    box-sizing: border-box;
  }

  .brand-title {
    gap: 8px;
    min-width: 0;
  }

  .brand-title h1 {
    font-size: 18px;
  }

  .brand-badge {
    font-size: 10px;
    padding: 2px 8px;
  }

  .btn-theme-toggle,
  .btn-reset-memory {
    font-size: 11px;
    padding: 5px 10px;
  }

  /* Workflow Stepper: Clean 2x2 Grid */
  .workflow-stepper {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
    width: 100%;
    box-sizing: border-box;
  }

  .step-pill {
    padding: 8px 10px;
    gap: 8px;
    min-width: 0;
  }

  .step-pill span {
    font-size: 11px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .step-pill .step-num {
    width: 22px;
    height: 22px;
    font-size: 11px;
    flex-shrink: 0;
  }

  /* Unified Grid Columns & Identical Panel Sizes */
  .dashboard-grid {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 16px;
    width: 100% !important;
    min-width: 0 !important;
  }

  .column-left,
  .column-right {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    display: flex;
    flex-direction: column;
  }

  /* Cards & Forms: Guaranteed 100% width across all panels */
  .editorial-card {
    padding: 16px 12px;
    margin-bottom: 16px;
    border-radius: var(--radius-md);
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    overflow: hidden;
  }

  .card-header {
    margin-bottom: 14px;
    padding-bottom: 10px;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
    min-width: 0;
  }

  .card-title {
    font-size: 15px;
    gap: 8px;
    min-width: 0;
    flex: 1 1 auto;
    word-break: break-word;
  }

  .card-badge {
    flex-shrink: 0;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 12px;
    width: 100%;
    min-width: 0;
  }

  .form-grid-pair {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
    min-width: 0;
  }

  .form-group {
    width: 100%;
    min-width: 0;
  }

  /* Mobile Input Ergonomics */
  .input-wrapper input,
  .input-wrapper select,
  select,
  input[type="text"],
  input[type="number"] {
    font-size: 16px !important;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .input-wrapper {
    min-height: 42px;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .input-wrapper input {
    padding: 8px 10px;
    min-width: 0;
  }

  .input-wrapper .unit {
    padding: 0 8px;
    font-size: 11px;
    flex-shrink: 0;
  }

  select {
    min-height: 42px;
    padding: 8px 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
  }

  .btn {
    min-height: 40px;
    font-size: 13px;
    box-sizing: border-box;
  }

  /* Step 3: Single Column Headline Stat Grid on Mobile */
  .headline-stat-grid {
    grid-template-columns: 1fr;
    gap: 10px;
    width: 100%;
    min-width: 0;
  }

  .headline-stat-box {
    padding: 12px 14px;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .headline-stat-box .stat-label {
    white-space: normal;
    word-break: break-word;
  }

  .headline-stat-box.box-price .stat-value,
  .headline-stat-box.box-cost .stat-value {
    font-size: 22px;
    word-break: break-all;
  }

  /* Margins Grid: 2-column balanced grid with 5th spanning full */
  .margins-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
    min-width: 0;
  }

  .margin-card:nth-child(5) {
    grid-column: 1 / -1;
  }

  .margin-card {
    padding: 10px 8px;
    min-width: 0;
    box-sizing: border-box;
  }

  .margin-title {
    font-size: 11px;
    white-space: normal;
  }

  .margin-price {
    font-size: 14px;
  }

  .margin-profit {
    font-size: 11px;
  }

  /* Quote Actions: Stacked for full-width finger tapping */
  .quote-actions-group {
    gap: 8px;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .quote-btn-primary {
    min-height: 44px;
    font-size: 14px;
    width: 100%;
    box-sizing: border-box;
  }

  .quote-actions-row {
    grid-template-columns: 1fr;
    gap: 8px;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .quote-actions-row .btn {
    min-height: 40px;
    width: 100%;
    box-sizing: border-box;
  }

  .table-container {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Bottom Sheet Invoice Modal for Mobile */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal-card {
    width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
    padding: 16px 12px;
    margin: 0;
  }

  .modal-header-actions {
    flex-direction: column;
    align-items: flex-start;
    padding-right: 36px;
    gap: 10px;
  }

  .modal-title {
    font-size: 16px;
  }

  .modal-btn-group {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .modal-btn-group .btn {
    width: 100%;
    padding: 8px;
  }

  .invoice-paper {
    padding: 14px 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .invoice-table {
    min-width: 480px;
  }

  /* Toast Notification: Centered bottom pill */
  #toast {
    left: 50%;
    right: auto;
    bottom: 16px;
    transform: translate(-50%, 10px);
    width: max-content;
    max-width: calc(100vw - 32px);
    text-align: center;
    padding: 8px 16px;
    font-size: 12px;
  }

  #toast.show {
    transform: translate(-50%, 0);
  }
}

/* Extra Small Phones (<= 420px) */
@media (max-width: 420px) {
  .header-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
  }

  .headline-stat-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .headline-stat-box {
    padding: 12px 14px;
  }

  .headline-stat-box .stat-value {
    font-size: 20px;
  }

  .cost-legend {
    gap: 6px;
  }

  .legend-chip {
    padding: 3px 8px;
    font-size: 10px;
  }

  .form-grid-pair {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .form-grid-pair .input-wrapper input {
    padding: 8px 6px;
  }

  .form-grid-pair .input-wrapper .unit {
    padding: 0 6px;
    font-size: 10px;
  }
}

@media print {
  body * { visibility: hidden; }
  #invoice_printable_area, #invoice_printable_area * { visibility: visible; }
  #invoice_printable_area {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    margin: 0;
    padding: 0;
    background: #ffffff !important;
  }
}
