:root {
  --ut-bg: #0a1d4d;
  --ut-bg-deep: #030b24;
  --ut-card: #1e293b;
  --ut-accent: #f7d106;
  --ut-text: #f8fafc;
  --ut-muted: #94a3b8;
  --ut-border: #334155;
  --ut-danger: #ef4444;
  --ut-success: #10b981;
  --ut-radius: 12px;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background: #0b1f63;
}

body {
  padding: 12px;
  background: radial-gradient(circle at top, var(--ut-bg), var(--ut-bg-deep));
  color: var(--ut-text);
  font-family: 'Inter', system-ui, sans-serif;
  min-height: 100dvh;
  line-height: 1.5;
}

@media (display-mode: standalone) {
  body {
    min-height: 100vh;
  }

  .brand-header {
    padding-top: calc(env(safe-area-inset-top, 0px) + 18px);
  }

  footer {
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
  }
}

.container {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Static Header */
.brand-header {
  max-width: 900px;
  margin: 6px auto 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

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

.brand-logo {
  width: 80px;
  height: 80px;
  border-radius: 12px;
  object-fit: cover;
  border: 2px solid var(--ut-accent);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.brand-text h1 {
  font-size: 1.8rem;
  font-weight: 800;
  margin: 0;
  color: #fff;
  line-height: 1;
}

.brand-subtitle {
  color: var(--ut-text);
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0.8;
  margin-top: 2px;
}

.tool-title {
  color: var(--ut-accent);
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

/* Legacy mode switch hidden */
.mode-switch,
.legacy-mode-switch {
  display: none !important;
}

/* Basic / Pro mode system */
body.mode-basic #optimizerCard,
body.mode-basic #efficiencyCard,
body.mode-basic #valueCard,
body.mode-basic #resultsCard,
body.mode-basic #archive-pane,
body.mode-basic #printTableContainer {
  display: none !important;
}

body.mode-basic #filmFieldGroup {
  display: none !important;
}

body.mode-pro #filmFieldGroup {
  display: block !important;
}

body.mode-pro #optimizerCard {
  display: block !important;
}

body.mode-pro #efficiencyCard,
body.mode-pro #valueCard,
body.mode-pro #resultsCard {
  display: block !important;
}

/* Old sales/pro classes left harmless */
body.sales-mode .admin-only,
body.sales-mode .pro-only,
body.sales-mode #efficiencyCard,
body.sales-mode #valueCard {
  display: none !important;
}

/* Card */
.card {
  background: rgba(30,41,59,0.7);
  border-radius: var(--ut-radius);
  padding: 16px;
  border: 1px solid rgba(255,255,255,0.08);
  backdrop-filter: blur(6px);
  min-width: 0;
  overflow-x: hidden;
}

.card h2 {
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--ut-text);
  margin: 0 0 12px 0;
  text-transform: uppercase;
  border-bottom: 1px solid var(--ut-border);
  padding-bottom: 8px;
}

.photo-card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--ut-border);
}

.photo-card-heading h2 {
  margin: 0;
  padding: 0;
  border: 0;
}

.photo-card-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
}

.photo-card-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 999px;
  border: 1px solid rgba(247,209,6,0.28);
  background: rgba(247,209,6,0.08);
  color: var(--ut-accent);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.photo-card-toggle:hover {
  transform: translateY(-1px);
  background: rgba(247,209,6,0.14);
}

.photo-card-toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0.9em;
  font-size: 0.84rem;
  line-height: 1;
}

.photo-card-body[hidden] {
  display: none !important;
}

#photoCard.is-collapsed {
  padding-bottom: 14px;
}

#photoCard.is-collapsed .photo-card-heading {
  margin-bottom: 0;
}

/* Instructions */
.instructions-card {
  cursor: pointer;
}

.instructions-card summary {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--ut-accent);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.instructions-card summary::before {
  content: '\2139\FE0F';
  font-size: 1rem;
}

.instructions-card summary::-webkit-details-marker {
  display: none;
}

.instructions-content {
  margin-top: 12px;
  font-size: 0.82rem;
  color: var(--ut-muted);
  border-top: 1px solid var(--ut-border);
  padding-top: 12px;
  line-height: 1.7;
}

.instructions-content strong {
  color: var(--ut-accent);
}

#previewInstructions .inst-icon {
  font-size: 0;
}

#previewInstructions .inst-step:nth-child(1) .inst-icon::before {
  content: "PHOTO";
}

#previewInstructions .inst-step:nth-child(2) .inst-icon::before {
  content: "SHAPE";
}

#previewInstructions .inst-step:nth-child(3) .inst-icon::before {
  content: "VIEW";
}

#previewInstructions .inst-step:nth-child(4) .inst-icon::before {
  content: "FILM";
}

#previewInstructions .inst-icon::before {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

/* Buttons */
button {
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.btn {
  padding: 12px 14px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  transition: 0.2s;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

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

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--ut-accent);
  color: #111;
}

.btn-secondary {
  background: #334155;
  color: #fff;
}

.btn-danger-outline {
  background: transparent;
  color: var(--ut-danger);
  border: 1px solid rgba(239,68,68,0.3);
}

.btn-success {
  background: var(--ut-success);
  color: #fff;
}

.btn-archive {
  background: #6366f1;
  color: #fff;
}

/* Photo Section Layout */
.photo-controls {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  margin-bottom: 12px;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  padding-bottom: 4px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.photo-controls::-webkit-scrollbar {
  display: none;
}

.photo-controls .btn {
  flex: 0 0 auto;
  white-space: nowrap;
  padding: 10px 16px;
  font-size: 0.78rem;
  min-height: 44px;
}

.photo-controls .tool-btn {
  position: relative;
  border: 1px solid rgba(255,255,255,0.08);
}

.photo-controls .tool-btn.tool-active {
  background: linear-gradient(135deg, #ffe45c 0%, #f7d106 100%);
  color: #111827;
  border-color: rgba(247,209,6,0.85);
  box-shadow: 0 12px 28px rgba(247,209,6,0.22);
  transform: translateY(-1px);
}

.photo-controls .tool-btn.tool-active::after {
  content: "ACTIVE";
  position: absolute;
  top: 5px;
  right: 8px;
  font-size: 0.52rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  opacity: 0.65;
}

/* Themed Shape Selector */
#tapShapeSelector {
  display: none;
  gap: 8px;
  margin-bottom: 12px;
  justify-content: space-between;
}

.shape-btn {
  flex: 1;
  text-align: center;
  padding: 10px 4px;
  background: rgba(255,255,255,0.03);
  color: var(--ut-muted);
  border: 1px solid var(--ut-border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.2s ease;
  user-select: none;
}

input[name="tapToolShape"]:checked + .shape-btn {
  background: var(--ut-accent);
  color: #111;
  border-color: var(--ut-accent);
  box-shadow: 0 4px 12px rgba(247, 209, 6, 0.3);
  transform: translateY(-1px);
}

.photo-workflow-tabs {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  margin-bottom: 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
}

.photo-tab {
  min-width: 112px;
  padding: 10px 16px;
  border-radius: 999px;
  background: transparent;
  color: var(--ut-muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.photo-tab.is-active {
  background: linear-gradient(135deg, #ffe45c 0%, #f7d106 100%);
  color: #111827;
  box-shadow: 0 10px 24px rgba(247,209,6,0.2);
}

.preview-controls {
  margin-bottom: 12px;
  padding: 14px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(16,185,129,0.08), rgba(30,41,59,0.5));
  border: 1px solid rgba(16,185,129,0.24);
}

.preview-guidance-title {
  font-size: 0.82rem;
  font-weight: 800;
  color: #d1fae5;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.preview-guidance p {
  margin: 6px 0 0;
  color: #dbe7f5;
  font-size: 0.82rem;
}

.preview-preset-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.preview-context-block {
  margin-top: 12px;
}

.preview-context-label {
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #a7f3d0;
  margin-bottom: 8px;
}

.preview-context-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.preset-chip {
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  color: var(--ut-text);
  font-size: 0.78rem;
  font-weight: 700;
}

.preset-chip[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

.preset-chip.is-active {
  background: rgba(16,185,129,0.16);
  border-color: rgba(16,185,129,0.75);
  color: #d1fae5;
  box-shadow: 0 8px 18px rgba(16,185,129,0.15);
}

.preview-context-modal-actions {
  margin-top: 10px;
}

.preview-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.preview-status {
  min-height: 1.2em;
  margin-top: 12px;
  font-size: 0.8rem;
  color: #bfdbfe;
}

.preview-status.is-error {
  color: #fecaca;
}

.preview-status.is-success {
  color: #d1fae5;
}

.preview-diagnostics {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.22);
  font-size: 0.75rem;
  color: #dbeafe;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.preview-diagnostics.is-error {
  border-color: rgba(248, 113, 113, 0.35);
  color: #fecaca;
}

.preview-diagnostics.is-success {
  border-color: rgba(74, 222, 128, 0.28);
  color: #dcfce7;
}

.film-preview-panel {
  margin-top: 12px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(7,14,34,0.72);
  border: 1px solid rgba(255,255,255,0.08);
}

.film-preview-stage {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  background: #020617;
  min-height: 180px;
}

.preview-result-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(148, 163, 184, 0.35);
  color: #e2e8f0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: 0 10px 24px rgba(2, 6, 23, 0.35);
}

.preview-result-badge.is-ai {
  background: rgba(20, 83, 45, 0.9);
  border-color: rgba(74, 222, 128, 0.45);
  color: #dcfce7;
}

.preview-result-badge.is-fallback {
  background: rgba(127, 29, 29, 0.9);
  border-color: rgba(248, 113, 113, 0.45);
  color: #fee2e2;
}

.film-preview-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  padding: 20px;
  color: var(--ut-muted);
  font-size: 0.82rem;
  text-align: center;
}

.film-preview-image {
  display: none;
}

.film-preview-panel.has-result .film-preview-empty {
  display: none;
}

.film-preview-panel.has-result .film-preview-image {
  display: block;
}

.film-preview-image {
  width: 100%;
  height: auto;
  object-fit: contain;
  max-height: 70vh;
}

@keyframes ut-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Selection bar */
#selectionBar {
  display: none;
  flex-direction: column;
  gap: 10px;
  background: rgba(247,209,6,0.08);
  border: 1px solid rgba(247,209,6,0.3);
  border-radius: 10px;
  padding: 12px;
  margin-top: 12px;
  margin-bottom: 4px;
}

#selectionHint {
  font-size: 0.85rem;
  color: var(--ut-accent);
  font-weight: 700;
  text-align: center;
}

.sel-btns {
  display: flex;
  gap: 8px;
  justify-content: center;
  width: 100%;
  flex-wrap: wrap;
}

.sel-btns button {
  padding: 10px 20px;
  font-size: 0.8rem;
  border-radius: 999px;
  font-weight: 700;
  font-family: inherit;
  transition: transform 0.2s, box-shadow 0.2s;
}

.sel-btns button:hover {
  transform: translateY(-1px);
}

@media (max-width: 680px) {
  .photo-controls .tool-btn.tool-active::after {
    top: 4px;
    right: 7px;
  }
}

.sel-btns .btn-confirm {
  background: var(--ut-success);
  color: #fff;
}

.sel-btns .btn-cancel {
  background: var(--ut-card);
  color: var(--ut-muted);
  border: 1px solid var(--ut-border);
}

.sel-btns .btn-addwin {
  background: var(--ut-accent);
  color: #111;
  box-shadow: 0 2px 8px rgba(247, 209, 6, 0.3);
}

/* Undo Button */
#undoBtn {
  background: var(--ut-danger);
  color: white;
  border: none;
  padding: 10px 20px;
  font-size: 0.8rem;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
  display: none;
  transition: 0.2s;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
}

#undoBtn:hover {
  transform: translateY(-1px);
}

#undoBtn.visible {
  display: inline-block !important;
}

/* Thumbnails */
#thumbSection {
  display: none;
  position: relative;
  width: 100%;
  padding-top: 8px;
}

#thumbCount {
  font-size: 0.72rem;
  color: var(--ut-muted);
  text-align: left;
  margin-bottom: 6px;
  min-height: 1em;
  font-weight: 600;
}

#thumbBarWrapper {
  position: relative;
  width: 100%;
}

#thumbBar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(247,209,6,0.4) transparent;
}

#thumbBar::-webkit-scrollbar {
  height: 4px;
}

#thumbBar::-webkit-scrollbar-thumb {
  background: rgba(247,209,6,0.4);
  border-radius: 4px;
}

.thumb-wrap {
  position: relative;
  flex-shrink: 0;
  width: 68px;
  height: 68px;
}

.thumb {
  width: 68px;
  height: 68px;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,0.15);
  cursor: pointer;
  display: block;
  transition: border-color 0.2s;
}

.thumb.active {
  border-color: var(--ut-accent);
}

.thumb-delete {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--ut-danger);
  color: white;
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  cursor: pointer;
  border: 1.5px solid var(--ut-bg-deep);
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.18s, transform 0.18s;
  min-width: unset;
  padding: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
  z-index: 5;
}

.thumb-wrap:hover .thumb-delete {
  opacity: 1;
  transform: scale(1);
}

/* Preview Container */
#previewContainer {
  position: relative;
  width: calc(100% - 30px);
  margin: 0 15px;
  border-radius: var(--ut-radius);
  overflow: hidden;
  background: #000;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

#imageWrapper {
  position: relative;
  transform-origin: 0 0;
  will-change: transform;
  touch-action: none;
}

#previewImg {
  width: 100%;
  display: block;
  pointer-events: none;
}

#drawCanvas,
#selectCanvas {
  position: absolute;
  inset: 0;
}

#drawCanvas {
  touch-action: none;
  background: transparent;
}

#selectCanvas {
  touch-action: none;
  display: none;
  pointer-events: none;
  background: transparent;
}

/* Empty state */
#emptyState {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 200px;
  border: 2px dashed rgba(247,209,6,0.35);
  border-radius: var(--ut-radius);
  background: rgba(28,39,72,0.35);
  cursor: pointer;
  padding: 28px 16px;
  text-align: center;
  user-select: none;
  transition: border-color 0.25s;
}

#emptyState:hover {
  border-color: rgba(247,209,6,0.75);
}

.empty-icon {
  width: 48px;
  height: 48px;
  opacity: 0.55;
}

.empty-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}

.empty-sub {
  font-size: 0.82rem;
  color: var(--ut-muted);
  margin: 0;
  max-width: 240px;
  line-height: 1.5;
}

.empty-cta {
  background: var(--ut-accent);
  color: #111;
  font-weight: 700;
  padding: 8px 20px;
  border-radius: 999px;
  font-size: 0.88rem;
  pointer-events: none;
}

/* Measurement List & Global Settings */
.job-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.job-label {
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--ut-accent);
  white-space: nowrap;
}

.job-input {
  background: var(--ut-bg-deep);
  color: white;
  padding: 10px;
  border: 1px solid var(--ut-border);
  border-radius: 6px;
  flex-grow: 1;
  min-width: 50px;
  font-size: 16px;
  outline: none;
  font-family: inherit;
  transition: 0.2s;
}

.job-header-notes {
  align-items: flex-start;
}

.job-textarea {
  background: var(--ut-bg-deep);
  color: white;
  padding: 10px 12px;
  border: 1px solid var(--ut-border);
  border-radius: 6px;
  flex-grow: 1;
  min-width: 220px;
  min-height: 88px;
  font-size: 15px;
  outline: none;
  font-family: inherit;
  line-height: 1.45;
  resize: vertical;
  transition: 0.2s;
}

.job-input:focus,
.job-textarea:focus,
.job-select:focus {
  border-color: var(--ut-accent);
  box-shadow: 0 0 0 3px rgba(247,209,6,0.14);
}

.job-input:disabled {
  background: rgba(255,255,255,0.02);
  color: var(--ut-muted);
  border-style: dashed;
  cursor: not-allowed;
  -webkit-text-fill-color: var(--ut-muted);
  opacity: 1;
}

.job-select {
  background: var(--ut-bg-deep);
  color: white;
  padding: 10px;
  border: 1px solid var(--ut-border);
  border-radius: 6px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
  transition: 0.2s;
  appearance: none;
}

.finance-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.finance-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.03);
  padding: 8px 10px;
  border-radius: 8px;
}

.finance-label {
  flex: 1;
  font-weight: 600;
  font-size: 0.85rem;
  color: #fff;
}

.finance-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Select All bar */
.select-all-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(255,255,255,0.03);
  border-radius: 8px;
  margin-bottom: 10px;
}

.select-all-bar label {
  font-size: 0.82rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--ut-accent);
}

.select-all-bar .pane-total {
  font-size: 0.78rem;
  color: var(--ut-muted);
}

/* Sections */
.measurement-section {
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  margin-bottom: 10px;
  overflow: hidden;
  transition: box-shadow 0.4s;
}

.measurement-section.highlight {
  box-shadow: 0 0 0 2px var(--ut-accent), 0 0 20px rgba(247,209,6,0.15);
}

.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  user-select: none;
}

.section-header input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--ut-accent);
  cursor: pointer;
  flex-shrink: 0;
}

.section-icon {
  font-size: 0.9rem;
  flex-shrink: 0;
}

.section-title {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--ut-accent);
  flex: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.section-title:hover {
  text-decoration: underline;
}

.section-meta {
  font-size: 0.72rem;
  color: var(--ut-muted);
  white-space: nowrap;
}

.section-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.section-mini-btn {
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(15,23,42,0.45);
  color: #e2e8f0;
  border-radius: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 4px 8px;
  cursor: pointer;
}

.section-mini-btn.section-mini-danger {
  color: #fecaca;
  border-color: rgba(248,113,113,0.35);
  background: rgba(127,29,29,0.3);
}

.section-body {
  padding: 0 12px 10px;
}

.section-deselected .section-body {
  opacity: 0.35;
  pointer-events: none;
}

.film-badge {
  background: #334155;
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 600;
  border: 1px solid rgba(255,255,255,0.1);
}

/* Section row headers */
.section-list-headers {
  display: grid;
  grid-template-columns: 40px 46px 1fr 1fr 50px 30px;
  gap: 6px;
  font-size: 0.62rem;
  font-weight: 800;
  color: var(--ut-accent);
  text-transform: uppercase;
  text-align: center;
  padding: 0 0 4px;
  margin-bottom: 4px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.section-row {
  display: grid;
  grid-template-columns: 40px 46px 1fr 1fr 50px 30px;
  gap: 6px;
  align-items: center;
  padding: 4px 0;
}

.section-row .pane-label {
  text-align: center;
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--ut-muted);
}

.section-row .pane-dim {
  text-align: center;
  font-size: 0.85rem;
  color: var(--ut-text);
  font-weight: 600;
  background: rgba(255,255,255,0.03);
  padding: 8px 4px;
  border-radius: 6px;
}

.section-row .pane-dim-input {
  background: var(--ut-bg-deep);
  color: white;
  padding: 8px 0;
  border: 1px solid var(--ut-border);
  border-radius: 6px;
  width: 100%;
  text-align: center;
  font-size: 15px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  font-family: inherit;
  box-sizing: border-box;
}

.section-row .pane-qty {
  background: var(--ut-bg-deep);
  color: white;
  padding: 8px 0;
  border: 1px solid var(--ut-border);
  border-radius: 6px;
  width: 100%;
  text-align: center;
  font-size: 15px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  font-family: inherit;
  box-sizing: border-box;
}

.section-row .row-delete {
  background: none;
  color: var(--ut-danger);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px;
  text-align: center;
  border: none;
}

.photo-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.65rem;
  color: var(--ut-muted);
  background: rgba(247,209,6,0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  justify-content: center;
}

.btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 14px 0;
}

.btn-grid .span2 {
  grid-column: span 2;
}

/* Roll toggles */
.roll-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--ut-border);
}

.toggle-label {
  background: var(--ut-bg-deep);
  border: 1px solid var(--ut-border);
  padding: 7px 11px;
  border-radius: 20px;
  font-size: 0.72rem;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  font-weight: 600;
}

.toggle-label input {
  accent-color: var(--ut-accent);
}

.toggle-label input[type="radio"] {
  accent-color: var(--ut-accent);
}

/* Efficiency / Value / Results */
#efficiency-data {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.eff-film-group {
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
  padding: 12px;
}

.eff-film-title {
  font-weight: 800;
  color: var(--ut-accent);
  font-size: 0.9rem;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  padding-bottom: 4px;
}

.eff-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  justify-content: center;
}

.eff-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 4px 0;
  min-width: 0;
}

.eff-value {
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1.1;
  color: #fff;
  text-align: center;
}

.eff-label {
  font-size: 0.62rem;
  color: var(--ut-muted);
  text-transform: uppercase;
  font-weight: 700;
  margin-top: 4px;
  text-align: center;
}

.eff-divider {
  grid-column: 1 / -1;
  width: 100%;
  height: 1px;
  background: var(--ut-border);
  margin: 4px 0;
}

.text-success {
  color: var(--ut-success) !important;
}

.text-danger {
  color: var(--ut-danger) !important;
}

.text-accent {
  color: var(--ut-accent) !important;
}

.text-white {
  color: #fff !important;
}

#value-data {
  font-size: 2rem;
  font-weight: 900;
  color: var(--ut-accent);
}

#render-area,
#jobsheet-area {
  overflow: visible;
}

#jobsheetCard {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 9000;
  inset: 0;
  background: rgba(2, 8, 23, 0.72);
  backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-box {
  width: min(92vw, 420px);
  background: rgba(15,23,42,0.98);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
}

.modal-box h3 {
  margin: 0 0 8px 0;
  color: var(--ut-text);
}

.modal-box p {
  margin: 0 0 12px 0;
  color: var(--ut-muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.modal-box label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ut-accent);
}

.modal-box input,
.modal-box select {
  width: 100%;
  background: var(--ut-bg-deep);
  color: white;
  padding: 12px;
  border: 1px solid var(--ut-border);
  border-radius: 8px;
  font-size: 16px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.modal-box input:focus,
.modal-box select:focus {
  border-color: var(--ut-accent);
  box-shadow: 0 0 0 3px rgba(247,209,6,0.14);
}

.modal-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.modal-buttons .btn-save,
.modal-buttons .btn-cancel {
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 0.8rem;
}

.modal-buttons .btn-save {
  background: var(--ut-accent);
  color: #111;
}

.modal-buttons .btn-cancel {
  background: #334155;
  color: #fff;
}

/* Unlock PIN modal */
.pin-modal-box {
  max-width: 380px;
}

.pin-error {
  color: var(--ut-danger);
  font-size: 0.8rem;
  font-weight: 700;
  margin-top: 8px;
}

/* Footer */
footer {
  position: relative;
  max-width: 900px;
  margin: 18px auto 0;
  padding: 14px 0 18px;
  color: var(--ut-muted);
  font-size: 0.76rem;
  text-align: center;
  line-height: 1.6;
}

footer a {
  color: var(--ut-muted);
  text-decoration: none;
}

footer a:hover {
  color: var(--ut-accent);
}

.footer-main {
  padding-right: 96px;
}

.footer-access-btn {
  position: absolute;
  right: 0;
  bottom: 12px;
  min-width: 84px;
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--ut-text);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  backdrop-filter: blur(6px);
}

.footer-access-btn:hover {
  transform: translateY(-1px);
  background: rgba(247,209,6,0.14);
  border-color: rgba(247,209,6,0.3);
  color: var(--ut-accent);
}

/* Print */
#printTableContainer {
  display: none;
}

.jobsheet-pages {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.jobsheet-empty {
  margin: 0;
  padding: 20px;
  border-radius: 18px;
  border: 1px dashed rgba(15,23,42,0.16);
  color: #475569;
  background: #ffffff;
  text-align: center;
}

.a4-page {
  width: min(100%, 794px);
  min-height: 1123px;
  margin: 0 auto;
  padding: 42px;
  background: #ffffff;
  color: #0f172a;
  border-radius: 20px;
  box-shadow: 0 18px 50px rgba(2,8,23,0.32);
}

.jobsheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 2px solid #0f172a;
  padding-bottom: 16px;
  margin-bottom: 16px;
}

.jobsheet-header h1 {
  margin: 0 0 4px;
  color: #0f172a;
  font-size: 1.55rem;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.jobsheet-header-meta {
  display: grid;
  gap: 3px;
}

.jobsheet-header .meta,
.jobsheet-header-customer,
.jobsheet-page-number {
  color: #334155;
  font-size: 0.82rem;
  font-weight: 700;
}

.jobsheet-page-number {
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.jobsheet-notes {
  margin-bottom: 18px;
  border: 1px solid rgba(15,23,42,0.14);
  background: #f8fafc;
  padding: 12px 14px;
  border-radius: 12px;
  break-inside: avoid;
  page-break-inside: avoid;
}

.jobsheet-notes-label {
  margin-bottom: 6px;
  color: #0f172a;
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.jobsheet-notes-body {
  color: #334155;
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.jobsheet-groups {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.jobsheet-group {
  break-inside: avoid;
  page-break-inside: avoid;
}

.jobsheet-group-heading {
  margin-bottom: 8px;
  color: #0f172a;
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.35;
}

.jobsheet-group-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  align-content: start;
}

.jobsheet-pane-card {
  background: transparent;
  padding: 0;
  break-inside: avoid;
  page-break-inside: avoid;
}

.jobsheet-pane-figure {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
}

.jobsheet-pane-figure text {
  fill: #0f172a;
  font-family: 'Inter', system-ui, sans-serif;
}

.jobsheet-pane-shape {
  fill: #f8fafc;
  stroke: #0f172a;
  stroke-width: 2.2;
}

.jobsheet-pane-dimline {
  stroke: #64748b;
  stroke-width: 1.2;
}

.jobsheet-pane-dimtext {
  fill: #334155;
  font-size: 12px;
  font-weight: 700;
}

.jobsheet-pane-caption {
  fill: #0f172a;
  font-size: 12px;
  font-weight: 800;
}

.jobsheet-pane-subcaption {
  fill: #64748b;
  font-size: 10px;
  font-weight: 600;
}

@media print {
  html,
  body {
    background: #fff !important;
    color: #000 !important;
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
    height: auto !important;
    min-height: auto !important;
    overflow: visible !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    font-size: 10pt !important;
    line-height: 1.3 !important;
  }

  body.jobsheet-print-mode .brand-header,
  body.jobsheet-print-mode .instructions-card,
  body.jobsheet-print-mode #photoCard,
  body.jobsheet-print-mode #optimizerCard,
  body.jobsheet-print-mode #resultsCard,
  body.jobsheet-print-mode #efficiencyCard,
  body.jobsheet-print-mode #valueCard,
  body.jobsheet-print-mode #archiveCard,
  body.jobsheet-print-mode footer {
    display: none !important;
  }

  body.jobsheet-print-mode #jobsheetCard,
  body.jobsheet-print-mode .container,
  body.jobsheet-print-mode #jobsheet-area {
    display: block !important;
    visibility: visible !important;
    overflow: visible !important;
  }

  h1 {
    font-size: 16pt !important;
    margin-bottom: 8px !important;
  }

  h2 {
    font-size: 14pt !important;
    margin-bottom: 8px !important;
  }

  .container {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    max-width: none !important;
    width: 100% !important;
    overflow: visible !important;
  }

  .brand-header,
  .instructions-card,
  #photoCard,
  #optimizerCard,
  .mode-switch,
  footer,
  .modal,
  .btn,
  .btn-grid,
  #unlockPinModal {
    display: none !important;
  }

  #resultsCard,
  #jobsheetCard {
    display: block !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
  }

  #resultsCard {
    page-break-after: always !important;
    break-after: page !important;
  }

  #resultsCard h2 {
    color: #000 !important;
    border-bottom: 2px solid #000 !important;
    padding-bottom: 5px;
    margin-bottom: 15px;
    font-size: 16pt !important;
    text-transform: uppercase;
  }

  #efficiencyCard {
    display: block !important;
    page-break-inside: avoid;
    border: 1px solid #000 !important;
    padding: 10px !important;
    margin-bottom: 20px !important;
  }

  .eff-film-group {
    border: none !important;
    padding: 0 !important;
    margin-bottom: 15px !important;
  }

  .eff-film-title {
    font-size: 12pt !important;
    color: #000 !important;
    border-bottom: 1px solid #000 !important;
    margin-bottom: 10px !important;
  }

  .eff-value {
    font-size: 12pt !important;
    font-weight: bold !important;
    color: #000 !important;
  }

  .eff-label {
    font-size: 8pt !important;
    color: #000 !important;
  }

  .text-success {
    color: #0000ff !important;
    -webkit-text-fill-color: #0000ff !important;
  }

  .text-danger {
    color: #ff0000 !important;
    -webkit-text-fill-color: #ff0000 !important;
  }

  .text-accent,
  .text-white {
    color: #000000 !important;
    -webkit-text-fill-color: #000000 !important;
  }

  .canvas-wrapper {
    display: block !important;
    overflow: visible !important;
    border: none !important;
    padding: 0 !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    margin-bottom: 10mm !important;
    background: transparent !important;
  }

  .roll-title {
    color: #000 !important;
    font-weight: bold !important;
    margin-bottom: 5px !important;
    font-size: 10pt !important;
  }

  img {
    background-color: #fff !important;
  }

  .canvas-wrapper img {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: 250mm !important;
    object-fit: contain !important;
    border: 1px solid #000 !important;
    display: block !important;
  }

  #jobsheetCard {
    padding-top: 5mm !important;
  }

  .a4-page {
    background: #fff !important;
    padding: 10mm !important;
    box-shadow: none !important;
    min-height: 297mm !important;
    border: none !important;
    width: 210mm !important;
    border-radius: 0 !important;
    page-break-after: always !important;
    break-after: page !important;
  }

  .jobsheet-header {
    border-bottom: 2px solid #000 !important;
    margin-bottom: 15px !important;
    padding-bottom: 8px !important;
  }

  .jobsheet-header h1,
  .jobsheet-header .meta,
  .jobsheet-header-customer,
  .jobsheet-page-number {
    color: #000 !important;
  }

  .jobsheet-header h1 {
    font-size: 18pt !important;
  }

  .jobsheet-header .meta,
  .jobsheet-header-customer,
  .jobsheet-page-number {
    font-size: 10pt !important;
  }

  .jobsheet-notes {
    background: #f8fafc !important;
    border: 1px solid rgba(15,23,42,0.18) !important;
    margin-bottom: 12px !important;
  }

  .jobsheet-groups {
    gap: 12px !important;
  }

  .jobsheet-group-grid {
    gap: 3mm !important;
  }

  .jobsheet-group-heading {
    color: #000 !important;
  }

  .jobsheet-pane-figure {
    background: #fff !important;
  }
}

/* Mobile tweaks */
@media (max-width: 720px) {
  body {
    padding: 10px;
  }

  .container,
  .brand-header,
  footer {
    max-width: 100%;
  }

  .brand-logo {
    width: 68px;
    height: 68px;
  }

  .brand-text h1 {
    font-size: 1.45rem;
  }

  .tool-title {
    font-size: 0.78rem;
  }

  .jobsheet-group-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
  }

  .card {
    padding: 14px;
  }

  .photo-card-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .photo-card-header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .photo-card-toggle {
    min-height: 42px;
  }

  #previewContainer {
    width: 100%;
    margin: 0;
  }

  .btn-grid {
    grid-template-columns: 1fr;
  }

  .footer-main {
    padding-right: 72px;
    padding-bottom: 0;
  }

  .footer-access-btn {
    right: 0;
    bottom: 0;
    min-width: 48px;
    width: 48px;
    height: 48px;
    padding: 0;
    border-radius: 50%;
    font-size: 1.1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transform: none;
  }

  .footer-access-btn:hover {
    transform: translateY(-1px);
  }
}

@media (max-width: 520px) {
  .photo-card-header-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .photo-card-toggle {
    justify-content: center;
    width: 100%;
  }

  .section-list-headers,
  .section-row {
    grid-template-columns: 34px 40px 1fr 1fr 42px 24px;
    gap: 4px;
  }

  .section-row .pane-dim-input,
  .section-row .pane-qty,
  .job-input,
  .modal-box input,
  .modal-box select {
    font-size: 16px;
  }

  .select-all-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .job-textarea {
    min-width: 100%;
  }
}
