/* ==========================================================
   Box Studio — Gold Palm Print
   Palette : workspace #F8FAFC, panneaux #FFFFFF, accents
   #D97706 (or) et #111827 (encre)
   ========================================================== */

:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --ink: #111827;
  --ink-soft: #475569;
  --ink-mute: #94a3b8;
  --gold: #d97706;
  --gold-soft: #fef3c7;
  --green: #10b981;
  --red: #ef4444;
  --blue: #3b82f6;

  --header-h: 60px;
  --rail-w: 296px;
  --insp-w: 224px;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 4px 14px rgba(15, 23, 42, 0.07);
  --shadow-lg: 0 18px 46px rgba(15, 23, 42, 0.16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Poppins', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

body { overflow: hidden; }

/* ---------------- Scrollbars ---------------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 8px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ==========================================================
   HEADER
   ========================================================== */
.app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 40;
}

.header-left, .header-center, .header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-center { flex: 1; justify-content: center; }

.logo { display: flex; align-items: center; gap: 9px; }
.logo-text { display: flex; flex-direction: column; line-height: 1.15; }
.logo-text strong { font-size: 13.5px; font-weight: 600; letter-spacing: -0.01em; }
.logo-text span {
  font-size: 10.5px;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
}

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-weight: 500;
  font-size: 13px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease, color .16s ease, transform .12s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-sm { padding: 7px 12px; font-size: 12.5px; }
.btn-xs { padding: 6px 10px; font-size: 12px; }

.btn-gold {
  background: var(--gold);
  color: #fff;
  border-color: var(--gold);
  box-shadow: 0 2px 8px rgba(217, 119, 6, .28);
}
.btn-gold:hover { background: #b45309; border-color: #b45309; }

.btn-outline {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line-strong);
}
.btn-outline:hover { background: #f1f5f9; border-color: #94a3b8; }

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border-color: transparent;
}
.btn-ghost:hover { background: #f1f5f9; color: var(--ink); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 19px;
  line-height: 1;
  transition: background .15s, color .15s;
}
.icon-btn:hover:not(:disabled) { background: #f1f5f9; color: var(--ink); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }

.w-full { width: 100%; }
.mt { margin-top: 14px; }
.mt-xs { margin-top: 6px; }

/* ---------------- View toggle ---------------- */
.view-toggle {
  display: flex;
  background: #f1f5f9;
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
.vt-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 27px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-mute);
  cursor: pointer;
  transition: background .15s, color .15s, box-shadow .15s;
}
.vt-btn:hover { color: var(--ink-soft); }
.vt-btn.active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.history-group { display: flex; gap: 2px; }

/* ==========================================================
   WORKSPACE
   ========================================================== */
.workspace {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr var(--insp-w);
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ---------------- Rail ---------------- */
.rail {
  display: flex;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: hidden;
}

.rail-tabs {
  width: 68px;
  flex: 0 0 68px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  padding: 10px 6px;
  border-right: 1px solid var(--line);
  background: #fcfdfe;
}

.rail-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 9px 2px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-mute);
  font-size: 9.5px;
  font-weight: 500;
  font-family: inherit;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.rail-tab:hover { background: #f1f5f9; color: var(--ink-soft); }
.rail-tab.active {
  background: var(--gold-soft);
  color: var(--gold);
  font-weight: 600;
}
.rail-tab.active svg { stroke: var(--gold); }

.rail-panels {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px;
  min-width: 0;
}

.rail-panel { display: none; }
.rail-panel.active { display: block; animation: fadeIn .18s ease; }

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

.panel-title {
  margin: 0 0 11px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-mute);
}

/* ---------------- Inputs ---------------- */
.input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--panel);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(217, 119, 6, .13);
}
.input-sm { padding: 6px 9px; font-size: 12.5px; }
.input-color { padding: 3px; height: 34px; cursor: pointer; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 11px; }
.field > span {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-soft);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------------- Catalogue ---------------- */
.catalog-filters { display: flex; flex-direction: column; gap: 7px; margin-bottom: 12px; }

.catalog-list { display: flex; flex-direction: column; gap: 8px; }

.cat-card {
  display: flex;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s, transform .12s;
}
.cat-card:hover {
  border-color: var(--gold);
  box-shadow: 0 2px 10px rgba(217, 119, 6, .12);
  transform: translateY(-1px);
}
.cat-card.active {
  border-color: var(--gold);
  background: #fffbeb;
  box-shadow: 0 0 0 2px rgba(217, 119, 6, .14);
}
.cat-card img {
  width: 56px; height: 56px;
  object-fit: contain;
  border-radius: 6px;
  background: #f8fafc;
  flex: 0 0 56px;
}
.cat-card-txt { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.cat-card-txt strong {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.25;
}
.cat-card-txt span {
  font-size: 10.5px;
  color: var(--ink-mute);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------------- Materials ---------------- */
.material-list { display: flex; flex-direction: column; gap: 6px; }

.mat-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: border-color .15s, background .15s;
}
.mat-row:hover { border-color: var(--line-strong); background: #f8fafc; }
.mat-row.active { border-color: var(--gold); background: #fffbeb; }
.mat-dot {
  width: 17px; height: 17px;
  border-radius: 50%;
  border: 1px solid rgba(15, 23, 42, .18);
  flex: 0 0 17px;
}
.mat-txt { display: flex; flex-direction: column; min-width: 0; }
.mat-txt strong { font-size: 12px; font-weight: 600; }
.mat-txt span { font-size: 10px; color: var(--ink-mute); }

/* ---------------- Dropzone ---------------- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 22px 12px;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  background: #fcfdfe;
  color: var(--ink-mute);
  text-align: center;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drop-active {
  border-color: var(--gold);
  background: #fffbeb;
  color: var(--gold);
}
.dropzone p { margin: 3px 0 0; font-size: 12.5px; font-weight: 500; color: var(--ink-soft); }
.dropzone small { font-size: 10.5px; }

.drop-active { border-color: var(--gold) !important; background: #fffbeb !important; }

.artwork-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 11px;
}

/* ---------------- Swatches ---------------- */
.swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.swatch {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line-strong);
  cursor: pointer;
  transition: transform .12s, box-shadow .15s, border-color .15s;
}
.swatch:hover { transform: scale(1.06); }
.swatch.active {
  border-color: var(--gold);
  box-shadow: 0 0 0 2.5px rgba(217, 119, 6, .22);
}

/* ==========================================================
   STAGE
   ========================================================== */
.stage {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  overflow: hidden;
  min-width: 0;
}

.stage.view-2d { grid-template-columns: 1fr; }
.stage.view-2d #pane3d { display: none; }
.stage.view-3d { grid-template-columns: 1fr; }
.stage.view-3d #pane2d { display: none; }

.stage-pane {
  position: relative;
  background: var(--bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.pane-label {
  position: absolute;
  top: 10px; left: 12px;
  z-index: 6;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
  background: rgba(255, 255, 255, .9);
  padding: 3px 8px;
  border-radius: 5px;
  border: 1px solid var(--line);
  pointer-events: none;
}

/* ---------------- 2D canvas ---------------- */
.canvas-wrap {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 42px 24px 56px;
  min-height: 0;
}
.canvas-inner {
  position: relative;
  line-height: 0;
  box-shadow: var(--shadow);
  border-radius: 3px;
  background: #fff;
  flex: 0 0 auto;
  margin: auto;
  transform-origin: top center;
}
#artCanvas { display: block; }

.dieline-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

/* ---------------- 3D ---------------- */
.rig-stage {
  flex: 1;
  min-height: 0;
  position: relative;
  cursor: grab;
}
.rig-stage:active { cursor: grabbing; }
.rig-stage canvas { display: block; }

.fold-ctl {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.fold-ctl label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-mute);
}
.fold-ctl input[type=range] {
  flex: 1;
  accent-color: var(--gold);
  height: 4px;
  cursor: pointer;
}
.fold-ctl output {
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  min-width: 46px;
  text-align: right;
}

.cam-presets {
  display: flex;
  gap: 5px;
  padding: 0 18px 11px;
  background: var(--panel);
  flex-wrap: wrap;
}
.chip {
  padding: 4px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: var(--panel);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all .15s;
}
.chip:hover { border-color: var(--gold); color: var(--gold); }
.chip.active { background: var(--gold); border-color: var(--gold); color: #fff; }

/* ==========================================================
   INSPECTOR
   ========================================================== */
.inspector {
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 14px;
}

.insp-block {
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.insp-block:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.insp-block h4 {
  margin: 0 0 10px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-mute);
}

/* ---------------- Switch ---------------- */
.switch {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12.5px;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 5px 0;
  user-select: none;
}
.switch input { display: none; }
.switch span {
  width: 32px; height: 18px;
  border-radius: 10px;
  background: #cbd5e1;
  position: relative;
  transition: background .18s;
  flex: 0 0 32px;
}
.switch span::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
  transition: transform .18s;
}
.switch input:checked + span { background: var(--gold); }
.switch input:checked + span::after { transform: translateX(14px); }

/* ---------------- Finitions ---------------- */
.finish-list { display: flex; flex-direction: column; gap: 5px; }
.finish-row {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  font-family: inherit;
  font-size: 12px;
  color: var(--ink-soft);
  text-align: left;
  cursor: pointer;
  transition: all .15s;
}
.finish-row:hover { border-color: var(--line-strong); background: #f8fafc; }
.finish-row.active {
  border-color: var(--gold);
  background: #fffbeb;
  color: var(--ink);
  font-weight: 600;
}

/* ---------------- Sheet info ---------------- */
.sheet-info {
  font-size: 11.5px;
  color: var(--ink-soft);
  line-height: 1.7;
  font-variant-numeric: tabular-nums;
}
.sheet-info b { color: var(--ink); font-weight: 600; }

/* ==========================================================
   MODALS
   ========================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, .48);
  backdrop-filter: blur(3px);
  animation: fadeIn .16s ease;
}
.modal-backdrop[hidden] { display: none; }

.modal-card {
  width: min(520px, 100%);
  max-height: min(88vh, 820px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: popIn .2s cubic-bezier(.2, .9, .3, 1.2);
}
.modal-wide { width: min(880px, 100%); }

@keyframes popIn {
  from { opacity: 0; transform: scale(.96) translateY(8px); }
  to { opacity: 1; transform: none; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.modal-head h2 { margin: 0; font-size: 15.5px; font-weight: 600; }

.modal-body {
  padding: 18px;
  overflow-y: auto;
  flex: 1 1 auto;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 13px 18px;
  border-top: 1px solid var(--line);
  background: #fcfdfe;
  flex: 0 0 auto;
  flex-wrap: wrap;
}

/* ---------------- Template grid ---------------- */
.tpl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}
.tpl-card {
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: border-color .15s, box-shadow .15s, transform .12s;
  padding: 0;
}
.tpl-card:hover {
  border-color: var(--gold);
  box-shadow: 0 6px 20px rgba(217, 119, 6, .15);
  transform: translateY(-2px);
}
.tpl-card.active { border-color: var(--gold); box-shadow: 0 0 0 2.5px rgba(217,119,6,.18); }
.tpl-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: #f8fafc;
  padding: 8px;
  display: block;
}
.tpl-card-body { padding: 9px 11px 11px; }
.tpl-card-body strong { display: block; font-size: 12.5px; font-weight: 600; }
.tpl-card-body em {
  display: block;
  font-style: normal;
  font-size: 10.5px;
  color: var(--ink-mute);
  margin-top: 3px;
}

/* ---------------- Export rows ---------------- */
.export-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px;
  margin-bottom: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: all .15s;
}
.export-row:hover { border-color: var(--gold); background: #fffbeb; }
.export-ico {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border-radius: 8px;
  background: var(--gold-soft);
  color: var(--gold);
  flex: 0 0 38px;
}
.export-row strong { display: block; font-size: 13px; font-weight: 600; }
.export-row em { display: block; font-style: normal; font-size: 11px; color: var(--ink-mute); }

/* ---------------- Quote ---------------- */
.quote-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; margin-bottom: 15px; }
.quote-grid .field:last-child { grid-column: 1 / -1; }

.quote-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-bottom: 15px;
}
.metric {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fcfdfe;
}
.metric-label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-mute);
  font-weight: 600;
  margin-bottom: 3px;
}
.metric strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.metric em {
  display: block;
  font-style: normal;
  font-size: 10.5px;
  color: var(--green);
  margin-top: 2px;
  font-weight: 500;
}

.quote-summary {
  padding: 12px;
  border-radius: var(--radius-sm);
  background: #f1f5f9;
  border: 1px solid var(--line);
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 11px;
  line-height: 1.62;
  color: var(--ink-soft);
  white-space: pre-wrap;
  overflow-x: auto;
}

/* ---------------- Toast ---------------- */
.toast-stack {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  padding: 9px 17px;
  border-radius: 20px;
  background: var(--ink);
  color: #fff;
  font-size: 12.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: none; }

/* ==========================================================
   RESPONSIVE
   ========================================================== */
@media (max-width: 1280px) {
  :root { --rail-w: 268px; --insp-w: 200px; }
}

@media (max-width: 1080px) {
  .workspace { grid-template-columns: var(--rail-w) 1fr; }
  .inspector { display: none; }
  .stage { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .stage.view-2d, .stage.view-3d { grid-template-rows: 1fr; }
}

@media (max-width: 820px) {
  :root { --header-h: 54px; }
  .workspace { grid-template-columns: 1fr; }
  .rail { display: none; }
  .header-center .history-group { display: none; }
  .logo-text span { display: none; }
  .stage { grid-template-rows: 1fr 1fr; }
  .btn span { display: none; }
  .btn-gold span, .btn-outline span { display: inline; }
}

@media (max-width: 560px) {
  .header-center { display: none; }
  .logo-text strong { font-size: 12px; }
  #currentTemplate { display: none; }
  .quote-grid, .quote-metrics { grid-template-columns: 1fr; }
}
