/* ── Books & Booklets Calculator ──────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; overflow: hidden; margin: 0; }

: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: 370px; 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);
}
.section-eyebrow {
  font-size: .62rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .12em;
  color: var(--forest-mid); margin-bottom: .55rem;
}

.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);
}

/* Checkbox */
.checkbox-label {
  display: flex; align-items: center; gap: .45rem; cursor: pointer;
  font-size: .78rem; font-weight: 600; color: #2a4a2a;
}
.form-checkbox {
  width: 15px; height: 15px;
  accent-color: var(--forest-mid); flex-shrink: 0; cursor: pointer;
}

/* 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.compact { font-size: .78rem; }
.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 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: .67rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-mid); padding: .55rem .7rem;
  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: .45rem .7rem; 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(.7rem - 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 td.muted { color: var(--text-muted); font-size: .8rem; }

.cost-only-table { margin-bottom: 1rem; }

.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); }
.copy-btn.copied { background: #dcfce7; color: var(--success); border-color: #bbf7d0; }

/* 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; }

/* ═══ BINDING RADIO CARDS ═══════════════════════════════ */
.binding-options {
  display: flex; flex-direction: column; gap: .4rem;
}
.binding-options.compact {
  gap: .25rem;
}
.binding-option {
  display: flex; align-items: flex-start; gap: 0; cursor: pointer;
}
.binding-option input[type="radio"] {
  position: absolute; opacity: 0; width: 0; height: 0;
}
.binding-card {
  display: flex; flex-direction: column; gap: .15rem;
  width: 100%; padding: .6rem .8rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--white);
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.compact .binding-card {
  flex-direction: row; align-items: baseline; gap: .4rem;
  padding: .4rem .65rem;
}
.binding-option input[type="radio"]:checked + .binding-card {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(138,74,26,.12);
}
.binding-option:hover .binding-card {
  border-color: var(--accent);
}
.binding-label {
  font-size: .85rem; font-weight: 700; color: var(--text);
}
.binding-desc {
  font-size: .72rem; color: var(--text-muted); line-height: 1.4;
}

/* ═══ DEBUG / ? BUTTON & MODAL ═══════════════════════════ */
.debug-btn {
  display: inline-flex;
  align-items: center; justify-content: center;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--white);
  color: var(--text-muted);
  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);
  border-color: var(--forest-mid);
  color: var(--forest);
}

/* Modal overlay */
.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;
}

/* Modal box */
.debug-modal {
  background: var(--white);
  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);
  flex-shrink: 0;
}
.debug-modal-header strong {
  font-size: .9rem; color: var(--accent);
}
.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);
  cursor: pointer; border-radius: 6px;
  transition: background .12s, color .12s;
}
.debug-modal-close:hover {
  background: #f0f2ee; color: var(--text);
}

/* Scrollable body */
.debug-modal-body {
  overflow-y: auto;
  padding: 1rem 1.25rem 1.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  font-size: .84rem; line-height: 1.65;
  color: var(--text);
}

/* Workings sections */
.w-section {
  font-size: .72rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--accent);
  margin: 1.3rem 0 .5rem;
  padding-bottom: .3rem;
  border-bottom: 2px solid var(--border-light);
}
.w-section:first-child { margin-top: 0; }

.w-step {
  font-size: .8rem; font-weight: 600;
  color: var(--text-mid);
  margin: .7rem 0 .25rem;
}

.w-calc {
  background: #fdf8f2;
  border: 1px solid #e8dcd0;
  border-radius: 8px;
  padding: .55rem .8rem;
  margin-bottom: .4rem;
}
.w-line {
  padding: .12rem 0;
  font-size: .82rem;
  color: #3a3020;
}
.w-line b {
  color: var(--accent);
  font-weight: 700;
}

/* ═══ SEARCHABLE SELECT ═══════════════════════════════════ */
.ss-wrap {
  position: relative;
}
.ss-input {
  padding-right: 1.8rem !important;
}
.ss-clear {
  position: absolute; right: .45rem; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; border: none; background: none;
  color: var(--text-muted); font-size: .7rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; transition: background .12s, color .12s;
}
.ss-clear:hover { background: #eee; color: var(--text); }
.ss-dropdown {
  display: none;
  position: absolute; left: 0; right: 0; top: 100%;
  z-index: 50;
  max-height: 260px; overflow-y: auto;
  background: var(--white);
  border: 1.5px solid var(--forest-mid);
  border-top: none;
  border-radius: 0 0 7px 7px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
  scrollbar-width: thin;
}
.ss-group {
  font-size: .62rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-muted);
  padding: .45rem .7rem .2rem; background: #f6f8f4;
  border-top: 1px solid var(--border-light);
  position: sticky; top: 0;
}
.ss-group:first-child { border-top: none; }
.ss-option {
  padding: .38rem .7rem; font-size: .84rem; cursor: pointer;
  transition: background .08s;
}
.ss-option:hover, .ss-option.ss-active {
  background: var(--forest-light);
}
.ss-option.ss-selected {
  font-weight: 600; color: var(--forest-mid);
}
.ss-option mark {
  background: #fef08a; color: inherit;
  border-radius: 2px; padding: 0 1px;
}
.ss-empty {
  padding: .7rem; text-align: center;
  color: var(--text-muted); font-size: .82rem;
}

/* ── Push to Album box ── */
.push-album-box {
  background: #f0ecf8;
  border: 1px solid #d0c8e4;
  border-radius: 8px;
  padding: .75rem 1rem;
}
.linked-product-chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .82rem;
  font-weight: 600;
  padding: .25rem .6rem;
  background: var(--white);
  border: 1px solid #d0c8e4;
  border-radius: 6px;
  margin-right: .35rem;
  margin-bottom: .3rem;
}
.linked-product-chip .synced-date {
  font-size: .7rem;
  font-weight: 400;
  color: var(--text-muted);
}

@media (max-width: 860px) {
  .calc-page    { height: auto; overflow: visible; }
  .calc-body    { flex-direction: column; overflow: visible; }
  .calc-sidebar { width: 100%; overflow-y: visible; border-right: none; border-bottom: 2px solid var(--border); }
  .sidebar-footer { position: static; }
  .calc-results { overflow: visible; min-height: unset; }
}
