/* Plak Box. Token dan rangka disalin daripada Tray Organizer (yang pula
   dikongsi dengan Box Maker) supaya alat-alat di sifulaser.com terbaca sebagai
   satu set. Bahagian paparan rata, editor grid dan pelan dulang dibuang. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --line: #e3e5e9;
  --line-strong: #d0d4da;
  --text: #16181d;
  --muted: #6b7280;
  --accent: #2f7d4f;
  --accent-soft: #e7f3ec;
  --danger: #d4383d;
  --stage: #4c4c50;
  --stage-2: #2b2b2e;
  --grid: #e8eaee;
  --panel-fill: #ffffff;
  --wall: #b9a27f;
  --cell: #fbfaf7;
  --cell-on: #e7f3ec;
  --shadow: 0 1px 2px rgba(16, 18, 21, .06), 0 8px 24px rgba(16, 18, 21, .06);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --surface: #1e2126;
    --surface-2: #23262c;
    --line: #2e323a;
    --line-strong: #3a3f48;
    --text: #e8eaed;
    --muted: #9aa1ad;
    --accent: #4ade80;
    --accent-soft: #1c2f24;
    --danger: #f87171;
    --grid: #262a31;
    --panel-fill: #1a1d21;
    --wall: #8a7658;
    --cell: #1a1d21;
    --cell-on: #1c2f24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; flex-direction: column; height: 100%; }

/* ---------- bar atas ---------- */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { color: var(--accent); font-size: 18px; }
.app-name { font: 600 15px/1.2 inherit; white-space: nowrap; }

.viewtoggle {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
}
.vt {
  border: 0; background: transparent; color: var(--muted);
  font: 600 13px/1 inherit; padding: 7px 16px; border-radius: 6px; cursor: pointer;
}
.vt[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.actions { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }

button { font-family: inherit; }

.icon-btn {
  width: 32px; height: 32px; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--text); border-radius: 8px; cursor: pointer; font-size: 15px;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--line-strong); }
.icon-btn:disabled { opacity: .35; cursor: default; }

.primary {
  border: 0; background: var(--accent); color: #fff;
  font: 600 13px/1 inherit; padding: 9px 16px; border-radius: 8px; cursor: pointer;
}
@media (prefers-color-scheme: dark) { .primary { color: #0b1410; } }
.primary:hover { filter: brightness(1.06); }

.ghost {
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font: 600 13px/1 inherit; padding: 9px 14px; border-radius: 8px; cursor: pointer;
}
.ghost:hover:not(:disabled) { background: var(--surface-2); }
.ghost:disabled { opacity: .4; cursor: default; }

/* ---------- susun atur ---------- */
.layout { flex: 1; display: flex; min-height: 0; }

.stage {
  position: relative; flex: 1; min-width: 0;
  background: radial-gradient(125% 105% at 28% 18%, var(--stage) 0%, var(--stage-2) 78%);
}
.stage[data-backdrop="light"] {
  --stage: #ffffff;
  --stage-2: #dde1e8;
  --dim-ink: #23272e;
  --dim-halo: rgba(255, 255, 255, .75);
  --dim-soft: rgba(35, 39, 46, .45);
}
.stage[data-backdrop="dark"] {
  --dim-ink: #ffffff;
  --dim-halo: rgba(0, 0, 0, .55);
  --dim-soft: rgba(255, 255, 255, .45);
}

.backdrop-pick {
  position: absolute; top: 14px; left: 14px; z-index: 5;
  display: flex; gap: 3px; padding: 4px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow);
}
.backdrop-pick[hidden] { display: none; }
.backdrop-pick button {
  width: 26px; height: 26px; padding: 0; cursor: pointer;
  border: 1.5px solid var(--line-strong); border-radius: 7px;
}
.backdrop-pick button:hover { border-color: var(--muted); }
.backdrop-pick button[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.frame-btn {
  position: absolute; top: 14px; right: 14px; z-index: 5;
  width: 34px; height: 34px; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 10px; cursor: pointer; font-size: 17px; box-shadow: var(--shadow);
}
.frame-btn[hidden] { display: none; }
.frame-btn:hover { background: var(--surface-2); }

.stage-pane { position: absolute; inset: 0; }
.stage-pane[hidden] { display: none; }
#stage3d canvas { display: block; }

.dim-overlay { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.dim-line { stroke: var(--dim-ink); stroke-width: 1.1; opacity: .85; }
.dim-ext { stroke: var(--dim-soft); stroke-width: 1; }
.dim-head { fill: var(--dim-ink); opacity: .85; }
.dim-text {
  fill: var(--dim-ink); font: 500 13px/1 ui-sans-serif, system-ui, sans-serif;
  text-anchor: middle; paint-order: stroke;
  stroke: var(--dim-halo); stroke-width: 3px; stroke-linejoin: round;
}

.warnings {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%); z-index: 6;
  max-width: min(560px, calc(100% - 120px));
  background: var(--surface); color: var(--danger);
  border: 1px solid var(--danger); border-radius: 10px;
  padding: 8px 12px; font-size: 12.5px; box-shadow: var(--shadow);
}
.warnings[hidden] { display: none; }

.stage-hint {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  background: rgba(20, 22, 26, .82); color: #fff; font-size: 12px;
  padding: 6px 12px; border-radius: 999px; pointer-events: none;
  opacity: 0; transition: opacity .2s; max-width: calc(100% - 32px); text-align: center;
}
.stage-hint.show { opacity: 1; }

/* ---------- inspector ---------- */
.inspector {
  width: 320px; flex: none; overflow-y: auto;
  background: var(--surface); border-left: 1px solid var(--line);
  padding: 12px 14px 40px;
}
/* font-size dan font-weight berasingan: "font: 600 13px/1 inherit" tidak sah
   (inherit tidak boleh jadi keluarga dalam singkatan) dan pelayar membuang
   seluruh baris, jadi h2 ini dahulu keluar dalam saiz lalai yang besar. */
.insp-title { font-size: 13px; font-weight: 600; line-height: 1; color: var(--muted); margin: 4px 0 12px; letter-spacing: .02em; }

.group { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.group > summary {
  list-style: none; cursor: pointer; padding: 11px 12px;
  font: 600 13px/1 inherit; display: flex; justify-content: space-between; align-items: center;
  background: var(--surface-2);
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::after { content: "\2304"; color: var(--muted); transition: transform .15s; }
.group[open] > summary::after { transform: rotate(180deg); }
.group-body { padding: 12px; display: grid; gap: 12px; }

/* minmax(0, 1fr): tanpanya trek grid ikut lebar minimum kandungan, dan slider
   (lebar asal 129 px) + kotak nombor menolak baris keluar dari panel sempit
   landskap telefon - unit "mm" terpotong di tepi. */
.field { display: grid; gap: 6px; grid-template-columns: minmax(0, 1fr); }
.field[hidden] { display: none; }
.field > label { font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { min-width: 0; }
.custom-mat { display: grid; gap: 12px; }
.custom-mat[hidden] { display: none; }

input[type="text"], input[type="number"], select {
  width: 100%; padding: 7px 9px; font: inherit; font-size: 13px;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 7px;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type="range"] { flex: 1; accent-color: var(--accent); }

.num { display: flex; align-items: center; gap: 6px; min-width: 0; }
/* Input mengecut di dalam kotaknya supaya unit "mm" sentiasa muat - dengan
   width:100% unit itu ditolak keluar dan terpotong di panel sempit. */
.num input { text-align: right; flex: 1 1 auto; width: auto; min-width: 0; }

.vt .short { display: none; }
.num .unit, .row .unit { font-size: 11px; color: var(--muted); white-space: nowrap; }

.seg { display: flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg button {
  flex: 1; border: 0; background: var(--surface); color: var(--muted);
  font: 500 12px/1.2 inherit; padding: 8px 4px; cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.hint, .muted { color: var(--muted); font-size: 12px; margin: 0; }
.hint { margin: -4px 0 0; }
.warn { color: var(--danger); font-size: 12px; margin: 0; }
.note.warn { color: var(--danger); }
.tick-labels { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); }
.stat { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.stat b { color: var(--text); font-weight: 600; }
.summary { display: grid; gap: 6px; }

/* ---- suis & warna ---- */
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatches button {
  width: 30px; height: 30px; padding: 0; cursor: pointer;
  border: 1.5px solid var(--line-strong); border-radius: 8px;
}
.swatches button[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.group[hidden], .field[hidden] { display: none; }

/* ---- senarai keping akrilik ---- */
.pieces { display: grid; gap: 6px; }
.piece {
  display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: baseline;
  font-size: 12.5px; padding: 7px 9px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--line);
}
.piece b { font-weight: 600; }
.piece .qty { color: var(--accent); font-weight: 700; }
.piece .mm { font-variant-numeric: tabular-nums; color: var(--text); white-space: nowrap; }

/* ---------- dialog ---------- */
.dlg { border: 0; border-radius: 14px; padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow); max-width: 480px; width: calc(100% - 32px); }
.dlg::backdrop { background: rgba(10, 12, 15, .5); }
.dlg-body { padding: 20px; display: grid; gap: 14px; }
.dlg h2 { margin: 0; font-size: 17px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--muted); }
.check input { margin-top: 2px; }
.layer-key { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.layer-key i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }
.note { font-size: 12px; color: var(--accent); margin: 0; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; font-size: 13px; }
.steps li { color: var(--text); }
.steps li span { color: var(--muted); }

@media (max-width: 900px) {
  .inspector { width: 270px; }
  .topbar { grid-template-columns: auto 1fr auto; }
  .vt .long { display: none; }
  .vt .short { display: inline; }
  /* Saiz tapak sudah ada dalam Ringkasan dan pada garis dimensi. */
  #sizeReadout { display: none; }
}

/* Skrin sentuh, apa pun lebarnya (landskap telefon jatuh di atas 640 px):
   sasaran jari sekurang-kurangnya ~36-40 px. */
@media (pointer: coarse) {
  .backdrop-pick button { width: 34px; height: 34px; }
  .frame-btn { width: 40px; height: 40px; }
  .swatches button { width: 38px; height: 38px; }
  .vt { min-height: 36px; }
  .seg button { min-height: 38px; }
  input[type="range"] { height: 28px; }
}

/* ---------- telefon ---------- */
/* Di bawah 640px susun atur bersebelahan berhenti berfungsi: pentas mengecut
   jadi sehelai dan tiga lajur bar atas melimpah. Jadi susun menegak -
   pratonton di atas selebar skrin, tetapan dalam panel menatal di bawah. */
@media (max-width: 640px) {
  /* Dua baris: nama + butang di atas, tiga paparan selebar skrin di bawah.
     Dahulu tiga paparan berkongsi baris dengan nama, dan pada 320 px ia
     menutup "Plak Box" sehingga tinggal "Pl". */
  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand actions"
      "mid   mid";
    gap: 6px 8px;
    padding: 6px 10px 8px;
  }
  .brand { grid-area: brand; gap: 6px; }
  .midbar { grid-area: mid; }
  .viewtoggle { display: flex; width: 100%; }
  .vt { flex: 1; padding: 9px 6px; font-size: 13px; }
  .actions { grid-area: actions; gap: 6px; }
  .logo { font-size: 16px; }
  .icon-btn { width: 40px; height: 40px; font-size: 16px; }
  .primary, .ghost { padding: 12px 16px; }
  .insp-title { display: none; }
  /* Dalam halaman SifuLaser nama alat sudah ada di bar atasnya: satu baris
     sahaja di sini - tiga paparan, bantuan dan Export. */
  .embedded .brand { display: none; }
  .embedded .topbar { grid-template-areas: "mid actions"; padding: 6px 8px; }
  .embedded .vt { padding: 9px 4px; }

  .layout { flex-direction: column; }
  .stage { flex: 5 1 0; min-height: 230px; overflow: hidden; }
  .warnings { top: auto; bottom: 48px; max-width: calc(100% - 16px); font-size: 11.5px; }
  .stage-hint { bottom: 10px; font-size: 11px; padding: 5px 10px; }

  .inspector {
    flex: 6 1 0; width: auto; min-height: 0;
    border-left: 0; border-top: 1px solid var(--line);
    padding: 10px 12px 28px;
    -webkit-overflow-scrolling: touch;
  }
  .group > summary { padding: 14px 12px; }
  input[type="text"], input[type="number"], select { font-size: 16px; padding: 10px 11px; }
  .seg button { padding: 12px 4px; font-size: 12px; }
  input[type="range"] { height: 28px; }

  .dlg-body { padding: 16px; gap: 12px; }
  .dlg-actions { flex-wrap: wrap; gap: 8px; }
  .dlg-actions button { flex: 1 1 42%; min-width: 0; }
}
[hidden] { display: none !important; }
