/* ── Copy Centre Calculator ───────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

/* html, body height/overflow managed by base template */

:root {
  --forest:      #1c3010;
  --forest-mid:  #2a6a1a;
  --forest-light:#e8f0e4;
  --border:      #d0dcc8;
  --border-light:#e8eee4;
  --text:        #1a2a1a;
  --text-mid:    #4a6a4a;
  --text-muted:  #7a8a7a;
  --bg:          #f2f4f0;
  --white:       #ffffff;
  --error:       #dc2626;
  --error-bg:    #fef2f2;
  --success:     #16a34a;
  --highlight:   #fefce8;
  --accent:      #8a4a1a;
  --accent-light:#fdf2e8;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: .9rem;
  line-height: 1.5;
}

/* ═══ LAYOUT ═════════════════════════════════════════════ */
.calc-page { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.calc-body {
  flex: 1; min-height: 0;
  display: flex; flex-direction: row; overflow: hidden;
  max-width: 1400px; margin: 0 auto; width: 100%;
}

/* ═══ SIDEBAR / FORM ════════════════════════════════════ */
.calc-sidebar {
  width: 340px; flex-shrink: 0; min-height: 0;
  background: var(--white);
  border-right: 2px solid var(--border);
  overflow-y: scroll;
  scrollbar-width: thin;
  scrollbar-color: var(--border) #f0f2f0;
}
.sidebar-scroll { padding: 1rem 1rem 0; }

.sidebar-section {
  background: var(--forest-light);
  border-radius: 8px;
  padding: .7rem .85rem .85rem;
  margin-bottom: .5rem;
  border: 1px solid var(--border);
}
.sidebar-section--tight {
  padding: .55rem .7rem .65rem;
}
.sidebar-section--tight .field { margin-bottom: .35rem; }
.sidebar-section--tight .field-label { font-size: .72rem; margin-bottom: .15rem; }
.sidebar-section--tight .form-input { padding: .3rem .55rem; font-size: .82rem; }
.sidebar-section--tight .radio-label { font-size: .78rem; }

.section-eyebrow {
  font-size: .62rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .12em;
  color: var(--forest-mid); margin-bottom: .55rem;
}
.sidebar-section--tight .section-eyebrow { margin-bottom: .35rem; }

/* Live job-dimension summary — sits between qty inputs and size/sides */
.job-summary {
  font-size: .68rem;
  color: var(--text-muted, #6a7a6a);
  background: var(--white, #fff);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: .25rem .5rem;
  margin: .35rem 0 .15rem;
  line-height: 1.4;
}
.job-summary b { color: var(--forest, #4a5533); font-weight: 700; }

.field { margin-bottom: .55rem; }
.field-label {
  display: block; font-size: .78rem; font-weight: 600;
  color: #2a4a2a; margin-bottom: .2rem; line-height: 1.3;
}
.field-row { display: flex; gap: .5rem; align-items: flex-end; }
.field-row .field { flex: 1; min-width: 0; }

.form-input {
  width: 100%; padding: .42rem .65rem;
  border: 1.5px solid var(--border); border-radius: 7px;
  font-size: .87rem; background: var(--white); color: var(--text);
  transition: border-color .12s, background .12s, box-shadow .12s;
  -moz-appearance: textfield;
}
.form-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.form-input:focus {
  outline: none; border-color: var(--forest-mid);
  box-shadow: 0 0 0 3px rgba(42,106,26,.12);
}

/* Radio row */
.radio-row { display: flex; gap: .75rem; }
.radio-label {
  display: flex; align-items: center; gap: .3rem;
  font-size: .82rem; cursor: pointer; color: var(--text);
}
.radio-label input[type="radio"] {
  accent-color: var(--accent);
}

/* Finishing tiles */
.finishing-tiles {
  display: grid; grid-template-columns: 1fr 1fr; gap: .35rem;
}
.finishing-tile {
  display: block; cursor: pointer;
}
.finishing-tile input[type="radio"] {
  position: absolute; opacity: 0; width: 0; height: 0;
}
.tile-card {
  display: flex; flex-direction: column; gap: .1rem;
  padding: .45rem .6rem;
  border: 2px solid var(--border);
  border-radius: 7px;
  background: var(--white);
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.finishing-tile input[type="radio"]:checked + .tile-card {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(138,74,26,.12);
}
.finishing-tile:hover .tile-card {
  border-color: var(--accent);
}
.tile-label {
  font-size: .78rem; font-weight: 700; color: var(--text);
}
.tile-cost {
  font-size: .62rem; color: var(--text-muted); line-height: 1.3;
}

/* Sticky footer */
.sidebar-footer {
  position: sticky; bottom: 0; z-index: 5;
  padding: .75rem 1rem;
  border-top: 2px solid var(--border-light);
  background: var(--white);
}
.sidebar-footer .field { margin-bottom: .5rem; }
.sidebar-footer .field-label { font-size: .75rem; }

.calc-btn {
  width: 100%; padding: .72rem;
  background: var(--accent); color: #fff;
  border: none; border-radius: 8px;
  font-size: .95rem; font-weight: 700; cursor: pointer;
  transition: background .15s, transform .1s; letter-spacing: .02em;
}
.calc-btn:hover  { background: #6a3a10; }
.calc-btn:active { transform: translateY(1px); }
.calc-btn:disabled { opacity: .55; cursor: not-allowed; }

/* ═══ RESULTS PANEL ════════════════════════════════════ */
.calc-results {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 1.25rem 1.5rem 2rem;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}

.results-placeholder {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: 300px; color: var(--text-muted); text-align: center;
}
.results-placeholder p { font-size: .95rem; margin: 0; }
.results-placeholder-icon { font-size: 3rem; margin-bottom: .75rem; opacity: .3; }

.results-loading {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: 200px; gap: .75rem;
  color: var(--text-muted); font-size: .9rem;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.results-error {
  background: var(--error-bg);
  border: 2px solid #fca5a5; border-radius: 10px;
  padding: 1rem 1.25rem; color: #991b1b;
  font-size: .88rem; line-height: 1.6;
  display: none; margin-bottom: 1rem;
  white-space: pre-wrap; word-break: break-word;
}

/* Quote summary strip */
.result-summary {
  background: var(--accent);
  color: #fff; border-radius: 10px;
  padding: .7rem 1rem; margin-bottom: 1.25rem;
  display: flex; align-items: center; flex-wrap: wrap; gap: .5rem;
}
.quote-code-badge {
  font-family: 'SF Mono', 'Fira Mono', 'Consolas', monospace;
  font-size: 1rem; font-weight: 700; letter-spacing: .02em;
  padding: .3rem .7rem; background: rgba(255,255,255,.12);
  border-radius: 6px;
}
.quote-chip {
  font-size: .75rem; padding: .2rem .55rem;
  border-radius: 4px; background: rgba(255,255,255,.15);
}

/* Quote code box */
.quote-code-box {
  display: none; margin-bottom: 1rem;
  padding: .5rem .75rem;
  background: var(--accent-light);
  border: 1.5px solid #e0c8a4;
  border-radius: 8px;
  font-family: 'SF Mono', 'Fira Mono', monospace;
  font-size: .85rem; color: var(--accent);
}

/* Section titles */
.result-section-title {
  font-size: .68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .09em;
  color: var(--text-mid);
  margin: 1.1rem 0 .65rem; padding-bottom: .3rem;
  border-bottom: 1.5px solid var(--border-light);
}

/* Component breakdown table */
.component-table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: .83rem;
  border: 1.5px solid var(--border); border-radius: 10px; overflow: hidden;
}
.component-table thead th {
  background: #edf2ea; font-size: .65rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--text-mid);
  padding: .5rem .7rem; border-bottom: 2px solid var(--border); text-align: left;
}
.component-table thead th.num { text-align: right; }
.component-table tbody td {
  padding: .4rem .7rem; border-bottom: 1px solid var(--border-light);
  font-variant-numeric: tabular-nums;
}
.component-table tbody tr:last-child td { border-bottom: none; }
.component-table tbody tr:nth-child(even) td { background: #fafbf8; }
.component-table td.num { text-align: right; }
.component-table td.muted { color: var(--text-muted); font-size: .78rem; }
.component-table tfoot td {
  padding: .55rem .7rem; background: var(--forest-light);
  border-top: 2px solid var(--border); font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.component-table tfoot td.num { text-align: right; }
.component-table tfoot .total-row td { background: #fef5e8; }

/* Price table */
.price-table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: .84rem;
  border: 1.5px solid var(--border); border-radius: 10px; overflow: hidden;
}
.price-table thead { background: #edf2ea; }
.price-table th {
  font-size: .63rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-mid); padding: .55rem .55rem;
  text-align: left; border-bottom: 2px solid var(--border); white-space: nowrap;
}
.price-table th.num, .price-table td.num { text-align: right; }
.price-table td {
  padding: .42rem .55rem; border-bottom: 1px solid var(--border-light);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.price-table tr:last-child td { border-bottom: none; }
.price-table tbody tr:nth-child(even) td { background: #fafbf8; }
.price-table tbody tr:hover td { background: #f0f5ee; }
.price-table tr.highlighted td { background: var(--highlight) !important; }
.price-table tr.highlighted td:first-child {
  border-left: 3px solid #ca8a04;
  padding-left: calc(.55rem - 3px);
}
.price-table th.total, .price-table td.total {
  color: #7c2d12; font-weight: 700; background: #fef5e8;
}
.price-table tr:hover td.total,
.price-table tr.highlighted td.total { background: #fde8c8 !important; }

.price-table th.total-top,
.price-table td.total-top { color: #1e3a5f; }
.price-table th.profit-top,
.price-table td.profit-top { color: #1e3a5f; }

.price-table th.total-ip,
.price-table td.total-ip { color: #5b21b6; }
.price-table th.profit-ip,
.price-table td.profit-ip { color: #5b21b6; }

.price-table th.total-ew,
.price-table td.total-ew { color: #047857; }
.price-table th.profit-ew,
.price-table td.profit-ew { color: #047857; }

.price-table td.muted { color: var(--text-muted); font-size: .8rem; }

.ref-tag {
  display: inline-block; margin-left: .35rem;
  font-size: .62rem; font-weight: 700;
  background: #ca8a04; color: #fff;
  padding: .1rem .4rem; border-radius: 3px;
  vertical-align: middle;
}

/* Copy rows */
.copy-row { display: flex; align-items: center; gap: .75rem; margin-bottom: .55rem; }
.copy-label {
  font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-mid);
  min-width: 60px; flex-shrink: 0;
}
.copy-box { display: flex; gap: .4rem; flex: 1; }
.copy-box input {
  flex: 1; font-family: 'SF Mono','Fira Mono',monospace; font-size: .75rem;
  padding: .38rem .6rem;
  border: 1.5px solid var(--border); border-radius: 6px;
  background: #f8fbf6; color: var(--text);
}
.copy-btn {
  flex-shrink: 0; padding: .38rem .7rem;
  background: var(--forest-light); border: 1.5px solid var(--border);
  border-radius: 6px; cursor: pointer; font-size: .77rem; font-weight: 600;
  color: var(--text-mid); transition: background .12s, color .12s;
}
.copy-btn:hover  { background: #d0e8c0; color: var(--forest); }

/* Description boxes */
.desc-box { display: flex; gap: .5rem; align-items: flex-start; }
.desc-box textarea {
  flex: 1;
  font-family: 'SF Mono','Fira Mono',monospace;
  font-size: .8rem; line-height: 1.6;
  padding: .5rem .7rem;
  border: 1.5px solid var(--border); border-radius: 8px;
  background: #f8fbf6; color: var(--text);
  resize: vertical;
}
.desc-box .copy-btn { align-self: flex-start; margin-top: .1rem; }

/* ═══ SVG ARTWORK PREVIEW — SPREAD VIEW ═════════════════ */
.preview-panel {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  align-items: stretch;
  margin-bottom: 1.25rem;
  padding: 1rem;
  background: var(--forest-light);
  border: 1.5px solid var(--border);
  border-radius: 10px;
}
.preview-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  position: relative;
}
.preview-svg {
  width: 100%;
  max-width: 520px;
  height: auto;
}
.preview-size-label {
  font-size: .7rem;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: .03em;
  text-align: center;
}

/* Grayscale mode on content */
#leftContent.bw-mode,
#rightContent.bw-mode {
  filter: url(#grayscaleFilter);
}

/* ── Upload Zone ── */
.upload-zone {
  flex: 1;
  min-width: 180px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  background: var(--white);
  transition: border-color 200ms, background 200ms;
  cursor: pointer;
}
.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
}
.upload-zone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.25rem 1rem;
  text-align: center;
}
.upload-icon {
  color: var(--text-muted);
  margin-bottom: .4rem;
}
.upload-text {
  font-size: .82rem;
  color: var(--text-mid);
  margin: 0 0 .2rem;
}
.upload-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}
.upload-hint {
  font-size: .65rem;
  color: var(--text-muted);
  margin: 0;
}
.upload-file-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .6rem .85rem;
  gap: .5rem;
}
.upload-filename {
  font-size: .78rem;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.upload-remove {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 .2rem;
  line-height: 1;
  transition: color 150ms;
}
.upload-remove:hover {
  color: var(--error);
}

/* ── PDF Page Navigation ── */
.pdf-nav {
  width: 100%;
  text-align: center;
  margin-top: .5rem;
}
.pdf-nav-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
}
.pdf-nav-btn {
  background: none;
  border: 1px solid #ccc;
  border-radius: 4px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: .75rem;
  color: #555;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 150ms, color 150ms;
}
.pdf-nav-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
.pdf-nav-btn:disabled {
  opacity: .35;
  cursor: default;
}
.pdf-nav-label {
  font-size: .8rem;
  color: #555;
  min-width: 100px;
}
.pdf-page-info {
  font-size: .72rem;
  color: #888;
  margin-top: .25rem;
}
.pdf-loading-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 24px;
  height: 24px;
  border: 3px solid #e0e0e0;
  border-top-color: var(--accent, #8a4a1a);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: translate(-50%, -50%) rotate(360deg); } }

/* Responsive: stack preview vertically on narrow screens */
@media (max-width: 600px) {
  .preview-panel {
    flex-direction: column;
    align-items: center;
  }
  .upload-zone {
    width: 100%;
  }
}

/* ══════════════════════════════════════════════════════════
   DEBUG MODAL + WORKINGS — ported from sheetfed
══════════════════════════════════════════════════════════ */
.debug-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%;
  border: 1.5px solid var(--border, #c8ccbe); background: var(--white, #fff);
  color: var(--text-muted, #888); font-size: .65rem; font-weight: 700;
  cursor: pointer; transition: background .12s, border-color .12s, color .12s;
  line-height: 1; padding: 0; flex-shrink: 0; vertical-align: middle; margin-left: .35rem;
}
.debug-btn:hover { background: var(--forest-light, #eef3e8); border-color: var(--forest-mid, #6b7c5a); color: var(--forest, #4a5533); }
.debug-modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 1.5rem;
}
.debug-modal {
  background: var(--white, #fff); border-radius: 14px; width: 100%; max-width: 720px; max-height: 85vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.25), 0 0 0 1px rgba(0,0,0,.06);
}
.debug-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .85rem 1.25rem; border-bottom: 1.5px solid var(--border-light, #e4e8dc); flex-shrink: 0;
}
.debug-modal-header strong { font-size: .9rem; color: var(--forest, #4a5533); }
.debug-modal-close {
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  border: none; background: none; font-size: 1.1rem; color: var(--text-muted, #888);
  cursor: pointer; border-radius: 6px; transition: background .12s, color .12s;
}
.debug-modal-close:hover { background: #f0f2ee; color: var(--text, #333); }
.debug-modal-body {
  overflow-y: auto; padding: 1rem 1.25rem 1.5rem;
  scrollbar-width: thin; font-size: .84rem; line-height: 1.65; color: var(--text, #333);
}
.w-section {
  font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .1em;
  color: var(--forest-mid, #6b7c5a); margin: 1.3rem 0 .5rem; padding-bottom: .3rem;
  border-bottom: 2px solid var(--border-light, #e4e8dc);
}
.w-section:first-child { margin-top: 0; }
.w-step { font-size: .8rem; font-weight: 600; color: var(--text-mid, #555); margin: .7rem 0 .25rem; }
.w-calc {
  background: #f8faf6; border: 1px solid var(--border-light, #e4e8dc);
  border-radius: 8px; padding: .55rem .8rem; margin-bottom: .4rem;
}
.w-line { padding: .12rem 0; font-size: .82rem; color: #3a4a3a; }
.w-line b { color: var(--forest, #4a5533); font-weight: 700; }
