/* ===================================================================
   P&D PD05 Scale Master - Modern Industrial Design System & Print CSS
   =================================================================== */

:root {
  /* Color Palette - Dark Slate Industrial (Default) */
  --bg-app: #0b0f19;
  --bg-card: #111827;
  --bg-card-hover: #162032;
  --bg-input: #1f293d;
  --border-subtle: #1e293b;
  --border-focus: #3b82f6;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  /* Industrial Accent Colors */
  --primary: #3b82f6;
  --primary-glow: rgba(59, 130, 246, 0.35);
  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.4);
  --warning: #f59e0b;
  --warning-glow: rgba(245, 158, 11, 0.4);
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.4);
  --info: #06b6d4;

  /* LED Display Colors */
  --led-bg: #030712;
  --led-border: #1e293b;
  --led-text: #10b981; /* Emerald LED */
  --led-glow: 0 0 20px rgba(16, 185, 129, 0.45);
  --led-amber: #f59e0b;
  --led-amber-glow: 0 0 20px rgba(245, 158, 11, 0.45);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Share Tech Mono', 'Courier New', monospace;
  --font-industrial: 'Chakra Petch', var(--font-sans);

  /* Layout & Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;
  --shadow-card: 0 8px 24px -4px rgba(0, 0, 0, 0.45);

  /* Print Sticker Dimensions (Dynamic) */
  --sticker-width: 80mm;
  --sticker-height: 50mm;
}

/* Light Theme Variables */
[data-theme="light"] {
  --bg-app: #f1f5f9;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-input: #f1f5f9;
  --border-subtle: #e2e8f0;
  --border-focus: #2563eb;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;

  --primary: #2563eb;
  --primary-glow: rgba(37, 99, 235, 0.25);
  --success: #059669;
  --success-glow: rgba(5, 150, 105, 0.25);

  --led-bg: #090d16;
  --led-border: #334155;
  --shadow-card: 0 4px 18px -2px rgba(15, 23, 42, 0.08);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===================================================================
   Header & Navigation
   =================================================================== */

.app-header {
  height: 64px;
  padding: 0 24px;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo-img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: #ffffff;
  padding: 3px;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  flex-shrink: 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.brand-badge:hover .brand-logo-img {
  transform: scale(1.05);
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
}

.brand-icon {
  font-size: 28px;
  line-height: 1;
}

.brand-title {
  font-family: var(--font-industrial);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-main);
  margin: 0;
}

.brand-highlight {
  color: var(--primary);
  font-weight: 700;
}

.brand-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.2px;
  margin: 0;
}

/* Connection Pill in Center */
.header-center {
  display: flex;
  align-items: center;
}

.connection-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.25s ease;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  transition: background-color 0.3s ease;
}

.status-dot.disconnected {
  background-color: var(--danger);
  box-shadow: 0 0 8px var(--danger-glow);
}

.status-dot.connected {
  background-color: var(--success);
  box-shadow: 0 0 10px var(--success-glow);
  animation: pulse-dot 2s infinite;
}

.status-dot.connecting {
  background-color: var(--warning);
  box-shadow: 0 0 8px var(--warning-glow);
  animation: blink-dot 1s infinite;
}

@keyframes pulse-dot {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.2); opacity: 0.8; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes blink-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.status-text {
  color: var(--text-main);
}

.port-name-badge {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 2px 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  color: var(--text-muted);
}

/* Header Controls Right */
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle-switch-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 6px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  user-select: none;
  transition: border-color 0.2s;
}

.toggle-switch-label:hover {
  border-color: var(--primary);
}

.toggle-switch-label input[type="checkbox"] {
  display: none;
}

.toggle-slider {
  width: 28px;
  height: 16px;
  background-color: var(--border-subtle);
  border-radius: var(--radius-full);
  position: relative;
  transition: background-color 0.2s;
}

.toggle-slider::after {
  content: '';
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
}

.toggle-switch-label input:checked + .toggle-slider {
  background-color: var(--warning);
}

.toggle-switch-label input:checked + .toggle-slider::after {
  transform: translateX(12px);
}

.btn-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-input);
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: var(--bg-card-hover);
  border-color: var(--primary);
}

/* Unsupported Browser Banner */
.unsupported-banner {
  background: #7f1d1d;
  color: #fee2e2;
  border-bottom: 2px solid #ef4444;
  padding: 12px 24px;
}

.unsupported-content {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 1200px;
  margin: 0 auto;
}

.alert-icon {
  font-size: 28px;
}

/* ===================================================================
   Main Dashboard Layout
   =================================================================== */

.main-container {
  max-width: 1720px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 24px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
  flex: 1;
}

@media (max-width: 1380px) {
  .main-container {
    grid-template-columns: 1fr 1fr;
  }
  .panel-preview {
    grid-column: span 2;
  }
}

@media (max-width: 900px) {
  .main-container {
    grid-template-columns: 1fr;
  }
  .panel-preview {
    grid-column: span 1;
  }
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Reusable Card Style */
.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-family: var(--font-industrial);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===================================================================
   Digital Scale LED Readout Card
   =================================================================== */

.digital-scale-card {
  background: linear-gradient(180deg, #131c2d 0%, var(--bg-card) 100%);
  border-color: #2a3952;
}

.scale-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 12px;
}

.scale-meta {
  display: flex;
  flex-direction: column;
}

.scale-model-tag {
  font-family: var(--font-industrial);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 1px;
}

.baud-tag {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.scale-annunciators {
  display: flex;
  gap: 6px;
}

.annunciator {
  font-family: var(--font-industrial);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-dim);
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: all 0.2s ease;
}

.annunciator.active {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border-color: #10b981;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.3);
}

.annunciator.unstable {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border-color: #f59e0b;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.3);
  animation: pulse-dot 1s infinite;
}

/* Giant LED Readout Box */
.weight-display-wrapper {
  background: var(--led-bg);
  border: 2px solid var(--led-border);
  border-radius: var(--radius-md);
  padding: 24px 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  box-shadow: inset 0 2px 14px rgba(0, 0, 0, 0.8);
}

.weight-display {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
  width: 100%;
}

.weight-digits {
  font-family: var(--font-mono);
  font-size: 5rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 2px;
  color: var(--led-text);
  text-shadow: var(--led-glow);
  user-select: none;
  transition: color 0.2s ease, text-shadow 0.2s ease;
}

.weight-digits.unstable-val {
  color: var(--led-amber);
  text-shadow: var(--led-amber-glow);
}

.weight-unit {
  font-family: var(--font-industrial);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}

.weight-sub-readout {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-top: 18px;
  padding-top: 10px;
  border-top: 1px dashed rgba(255, 255, 255, 0.1);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.sub-col {
  display: flex;
  gap: 6px;
}

.sub-label {
  color: var(--text-dim);
}

.sub-value {
  color: var(--text-main);
  font-weight: 600;
}

.raw-value {
  color: var(--info);
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Checkweigher Bar */
.checkweigher-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.check-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
}

.check-status-tag {
  font-family: var(--font-industrial);
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bg-input);
  color: var(--text-muted);
}

.check-status-tag.status-ok {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border: 1px solid var(--success);
}

.check-status-tag.status-under {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border: 1px solid var(--warning);
}

.check-status-tag.status-over {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
  border: 1px solid var(--danger);
}

.check-target-info {
  font-family: var(--font-mono);
  color: var(--text-dim);
}

.check-bar {
  height: 12px;
  width: 100%;
  border-radius: 6px;
  background: #1e293b;
  position: relative;
  display: flex;
  overflow: hidden;
}

.check-zone {
  height: 100%;
}

.zone-under {
  flex: 40;
  background: rgba(245, 158, 11, 0.5);
}

.zone-ok {
  flex: 20;
  background: rgba(16, 185, 129, 0.75);
}

.zone-over {
  flex: 40;
  background: rgba(239, 68, 68, 0.5);
}

.check-needle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 4px;
  background: #ffffff;
  box-shadow: 0 0 6px #fff;
  transition: left 0.15s ease-out;
  transform: translateX(-50%);
}

/* Scale Control Buttons (Z, T, R, Clear) */
.scale-control-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.scale-control-buttons .btn {
  flex-direction: column;
  padding: 8px 4px;
  font-size: 0.78rem;
  gap: 2px;
}

.btn-shortcut {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--primary);
  font-weight: 700;
}

/* ===================================================================
   Buttons & Form Controls
   =================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  font-family: var(--font-sans);
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 10px var(--primary-glow);
}

.btn-primary:hover:not(:disabled) {
  background-color: #2563eb;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-secondary {
  background-color: var(--bg-input);
  color: var(--text-main);
  border-color: var(--border-subtle);
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--bg-card-hover);
  border-color: var(--text-dim);
}

.btn-success {
  background-color: var(--success);
  color: #ffffff;
  box-shadow: 0 2px 12px var(--success-glow);
}

.btn-success:hover:not(:disabled) {
  background-color: #059669;
  box-shadow: 0 4px 16px var(--success-glow);
}

.btn-danger {
  background-color: var(--danger);
  color: #ffffff;
  box-shadow: 0 2px 10px var(--danger-glow);
}

.btn-danger:hover:not(:disabled) {
  background-color: #dc2626;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.78rem;
  border-radius: var(--radius-sm);
}

.btn-large {
  padding: 16px 20px;
  font-size: 1.05rem;
}

.btn-label-stack {
  display: flex;
  flex-direction: column;
  text-align: left;
}

.btn-label-stack .main-text {
  font-family: var(--font-industrial);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.btn-label-stack .sub-text {
  font-size: 0.72rem;
  opacity: 0.85;
  font-weight: 400;
}

/* Forms */
.form-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.flex-1 { flex: 1; }
.flex-2 { flex: 2; }

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

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.required {
  color: var(--danger);
}

.form-input, .form-select {
  width: 100%;
  padding: 10px 12px;
  background-color: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus, .form-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.font-mono {
  font-family: var(--font-mono) !important;
}

.input-with-select, .input-with-button {
  display: flex;
  gap: 6px;
}

.select-addon {
  max-width: 130px;
}

.toggle-switch-inline {
  display: flex;
  align-items: center;
  height: 42px;
  gap: 6px;
  cursor: pointer;
}

.toggle-text-sm {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary);
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-main);
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
}

/* ===================================================================
   Simulator Drawer
   =================================================================== */

.simulator-drawer {
  background: rgba(245, 158, 11, 0.08);
  border: 1px dashed var(--warning);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.simulator-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--warning);
}

.sim-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  background: var(--warning);
  color: #000;
  border-radius: 3px;
}

.slider-label-row {
  display: flex;
  justify-content: space-between;
}

.sim-val-display {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--warning);
}

.form-range {
  width: 100%;
  accent-color: var(--warning);
  cursor: pointer;
}

.sim-presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-chip {
  padding: 4px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-chip:hover {
  border-color: var(--warning);
  color: var(--warning);
}

.sim-toggles {
  display: flex;
  gap: 16px;
}

/* ===================================================================
   Serial Monitor Terminal
   =================================================================== */

.terminal-card {
  padding: 12px 16px;
}

.terminal-header {
  cursor: pointer;
  user-select: none;
}

.terminal-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
}

.badge-count {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 2px 6px;
  background: var(--bg-input);
  border-radius: 4px;
  color: var(--text-muted);
}

.collapse-chevron {
  font-size: 0.75rem;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.collapse-chevron.collapsed {
  transform: rotate(-90deg);
}

.terminal-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.terminal-body.collapsed {
  display: none;
}

.terminal-log {
  height: 140px;
  background: #030712;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: #a7f3d0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.terminal-line.system-line {
  color: #60a5fa;
}

.terminal-line.tx-line {
  color: #facc15;
}

.terminal-line.rx-line {
  color: #34d399;
}

.terminal-line.err-line {
  color: #f87171;
}

.terminal-input-bar {
  display: flex;
  gap: 6px;
}

/* ===================================================================
   Middle Panel: Production Form & Print Config
   =================================================================== */

.print-settings-card {
  background: linear-gradient(180deg, var(--bg-card) 0%, #151e30 100%);
}

.print-options-row {
  align-items: center;
  padding-top: 4px;
}

.inline-group {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.form-label-inline {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.input-narrow {
  width: 60px;
  text-align: center;
}

.print-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.secondary-print-buttons {
  display: flex;
  gap: 10px;
}

.secondary-print-buttons .btn {
  flex: 1;
  font-size: 0.82rem;
}

/* ===================================================================
   Live Sticker Preview
   =================================================================== */

.sticker-preview-card {
  background: var(--bg-card);
}

.badge-size {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--primary-glow);
  color: #93c5fd;
  border: 1px solid var(--primary);
}

.preview-stage {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  background: repeating-conic-gradient(#1e293b 0% 25%, #0f172a 0% 50%) 50% / 20px 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  min-height: 260px;
  overflow: auto;
}

/* The Realistic Physical Sticker Styling (White thermal paper) */
.label-sticker {
  background: #ffffff !important;
  color: #000000 !important;
  border: 1px solid #d1d5db;
  border-radius: 2px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  font-family: Arial, Helvetica, sans-serif;
  user-select: none;
  box-sizing: border-box;
  transition: width 0.25s, height 0.25s;
}

/* Dimension Classes on Preview */
.label-sticker.size-50-30 {
  width: 280px;
  min-height: 170px;
  padding: 6px 8px;
  gap: 4px;
}

.label-sticker.size-80-50 {
  width: 360px;
  min-height: 230px;
  padding: 10px 14px;
  gap: 6px;
}

.label-sticker.size-100-75 {
  width: 420px;
  min-height: 310px;
  padding: 14px 18px;
  gap: 8px;
}

.label-sticker.size-100-150 {
  width: 420px;
  min-height: 520px;
  padding: 18px 22px;
  gap: 12px;
}

.sticker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid #000;
  padding-bottom: 4px;
}

.sticker-logo-area {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sticker-logo-img {
  width: 24px;
  height: 24px;
  object-fit: contain;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

.sticker-badge-icon {
  font-size: 16px;
}

.sticker-company {
  font-weight: 800;
  font-size: 11px;
  letter-spacing: 0.5px;
}

.sticker-type-tag {
  font-size: 9px;
  font-weight: 700;
  border: 1px solid #000;
  padding: 1px 4px;
  border-radius: 2px;
}

.sticker-product {
  font-size: 13px;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sticker-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  font-size: 10px;
  border-bottom: 1px dashed #666;
  padding-bottom: 4px;
}

.sticker-cell {
  display: flex;
  flex-direction: column;
}

.cell-label {
  font-size: 8px;
  color: #444;
  font-weight: 700;
}

.cell-value {
  font-weight: 700;
  font-size: 10px;
}

/* Net Weight Highlight Box on Sticker */
.sticker-weight-box {
  background: #f3f4f6;
  border: 2px solid #000;
  border-radius: 4px;
  padding: 6px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.weight-label-col {
  display: flex;
  flex-direction: column;
}

.net-title {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.3px;
}

.tare-gross-line {
  font-size: 8px;
  color: #555;
  font-family: monospace;
}

.weight-value-col {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.net-digits {
  font-family: monospace, Arial;
  font-size: 24px;
  font-weight: 900;
  color: #000;
}

.net-unit {
  font-size: 13px;
  font-weight: 800;
}

/* Barcode & QR Code Row */
.sticker-codes-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

.barcode-wrapper {
  flex: 1;
  display: flex;
  justify-content: center;
  overflow: hidden;
}

.barcode-wrapper svg {
  max-width: 100%;
  height: 48px;
}

.qrcode-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
}

.qrcode-wrapper img {
  width: 52px;
  height: 52px;
}

/* Footer Details */
.sticker-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid #000;
  padding-top: 3px;
  font-size: 8px;
  font-weight: 700;
}

.qc-badge {
  background: #000;
  color: #fff;
  padding: 1px 4px;
  border-radius: 2px;
}

/* Small sticker adjustments */
.label-sticker.size-50-30 .sticker-header {
  border-bottom-width: 1px;
}
.label-sticker.size-50-30 .sticker-logo-img {
  width: 16px;
  height: 16px;
}
.label-sticker.size-50-30 .sticker-product {
  font-size: 11px;
}
.label-sticker.size-50-30 .net-digits {
  font-size: 18px;
}
.label-sticker.size-50-30 .barcode-wrapper svg {
  height: 34px;
}
.label-sticker.size-50-30 .qrcode-wrapper img {
  width: 38px;
  height: 38px;
}

.label-sticker.size-100-75 .sticker-logo-img {
  width: 30px;
  height: 30px;
}

.label-sticker.size-100-150 .sticker-logo-img {
  width: 38px;
  height: 38px;
}

/* ===================================================================
   Weighing History Table
   =================================================================== */

.history-card {
  flex: 1;
}

.history-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-actions {
  display: flex;
  gap: 6px;
}

.table-responsive {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.history-table th {
  background: var(--bg-input);
  color: var(--text-muted);
  font-weight: 600;
  text-align: left;
  padding: 8px 10px;
  position: sticky;
  top: 0;
  z-index: 2;
  border-bottom: 1px solid var(--border-subtle);
}

.history-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-main);
}

.history-table tr:hover {
  background: var(--bg-card-hover);
}

.history-table .text-right {
  text-align: right;
}

.history-table .text-center {
  text-align: center;
}

.history-table .text-muted {
  color: var(--text-dim);
}

.tag-pass {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
}

/* ===================================================================
   Modals
   =================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  max-width: 620px;
  width: 100%;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-family: var(--font-industrial);
  font-size: 1.1rem;
  font-weight: 700;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.btn-close:hover {
  color: var(--text-main);
}

.modal-body {
  padding: 20px;
  max-height: 70vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.settings-section-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--primary);
  margin-top: 6px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 4px;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--bg-input);
}

.code-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border-subtle);
}

.tab-btn {
  padding: 8px 14px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.code-content-wrapper {
  background: #030712;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.code-block {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: #38bdf8;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 250px;
  overflow-y: auto;
}

/* ===================================================================
   Toast Notifications
   =================================================================== */

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  color: var(--text-main);
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
  max-width: 380px;
  pointer-events: auto;
  animation: slideToast 0.25s ease-out;
}

.toast.toast-success { border-left-color: var(--success); }
.toast.toast-warning { border-left-color: var(--warning); }
.toast.toast-danger  { border-left-color: var(--danger); }

@keyframes slideToast {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ===================================================================
   CRITICAL CSS @media print
   Strictly formatted for Thermal & Sticker Label Printers
   =================================================================== */

.print-only {
  display: none;
}

@media print {
  /* Dynamic page size according to chosen sticker dimension */
  @page {
    size: var(--sticker-width) var(--sticker-height);
    margin: 0 !important;
  }

  html, body {
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    color: #000000 !important;
  }

  /* Completely hide every UI component */
  .app-header,
  .unsupported-banner,
  .main-container,
  .modal-backdrop,
  .toast-container {
    display: none !important;
  }

  /* Only display the print container */
  .print-only {
    display: block !important;
    position: absolute;
    top: 0;
    left: 0;
    width: var(--sticker-width);
    height: var(--sticker-height);
    margin: 0;
    padding: 0;
    background: #ffffff;
    box-sizing: border-box;
    overflow: hidden;
    page-break-inside: avoid;
    break-inside: avoid;
  }

  /* Print version of sticker fits exact millimeter area */
  .print-only .label-sticker {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    box-shadow: none !important;
    border: none !important;
    padding: 3mm 4mm !important;
    gap: 1.5mm !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
  }

  /* Ensure pure solid black lines & texts for thermal printheads */
  .print-only * {
    color: #000000 !important;
    background-color: transparent !important;
    border-color: #000000 !important;
    text-shadow: none !important;
    box-shadow: none !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .print-only .sticker-weight-box {
    border: 1.5pt solid #000000 !important;
    background-color: transparent !important;
  }

  .print-only .barcode-wrapper svg {
    filter: contrast(200%);
  }

  .print-only .qrcode-wrapper img {
    image-rendering: pixelated;
  }

  .print-only .sticker-logo-img {
    width: 6.5mm !important;
    height: 6.5mm !important;
    object-fit: contain !important;
    display: inline-block !important;
    vertical-align: middle !important;
  }
}
