:root {
  --ink: #2b2622; --ink2: #5d544b; --paper: #f6f2ea; --card: #fffdf8; --line: #e2d9c8;
  --wood: #c8692c; --wood2: #e9a46a; --ok: #2f855a; --warn: #c27c0e; --err: #c0392b; --info: #3b6ea5;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --sans: 'Archivo', system-ui, -apple-system, Segoe UI, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); font: 14px/1.4 var(--sans); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 7px 12px; font-weight: 600; }
button:hover { border-color: var(--wood2); }
button.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
button.ghost { background: transparent; }

.top { display: flex; align-items: center; gap: 12px; padding: 8px 14px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--ink); color: #f6f2ea; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { width: 30px; height: 30px; color: var(--wood2); flex: none; }
.brand b { display: block; font-weight: 800; letter-spacing: .2px; }
.brand small { display: block; color: #cbbfae; font-size: 12px; }
.pname { flex: 1; min-width: 80px; max-width: 320px; background: #3a332d; border: 1px solid #4b423a; color: #fff; border-radius: 8px; padding: 6px 10px; }
.actions { display: flex; gap: 6px; margin-left: auto; }
.actions button { background: #3a332d; color: #f6f2ea; border-color: #4b423a; }
.actions button.primary { background: var(--wood); border-color: var(--wood); }

main { display: grid; grid-template-columns: 1fr minmax(380px, 470px); height: calc(100% - 52px); }
.stage { position: relative; min-height: 0; }
#viewer { position: absolute; inset: 0; }
#viewer canvas { display: block; touch-action: none; }
.chips { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; flex-wrap: wrap; gap: 5px; pointer-events: none; }
.chips button { pointer-events: auto; padding: 3px 9px; font-size: 12px; border-radius: 999px; background: rgba(255,253,248,.92); }
.chips button.off { opacity: .45; text-decoration: line-through; }
.chips button i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
.hud { position: absolute; left: 10px; right: 10px; bottom: 10px; background: rgba(43,38,34,.86); color: #f6f2ea; border-radius: 12px; padding: 8px 12px; display: grid; gap: 4px; font-size: 12.5px; backdrop-filter: blur(4px); }
.hud-row { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.hud label { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.hud input[type=range] { width: 120px; accent-color: var(--wood2); }
.hud output { font-family: var(--mono); min-width: 34px; color: var(--wood2); }
.hud select { background: #3a332d; border: 1px solid #4b423a; border-radius: 6px; padding: 2px 6px; color: #fff; }
.hud-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
#hudToggle { background: transparent; border: 0; color: #f6f2ea; padding: 0; font-size: 12.5px; }
.hud.collapsed .hud-row { display: none; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #3a332d; }
.pill.ok { background: var(--ok); } .pill.warn { background: var(--warn); }

.panel { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--line); background: var(--paper); }
.tabs { display: flex; gap: 2px; overflow-x: auto; padding: 8px 8px 0; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs button { border: 0; border-radius: 8px 8px 0 0; background: transparent; color: var(--ink2); padding: 8px 10px; white-space: nowrap; }
.tabs button.on { background: var(--card); color: var(--ink); box-shadow: 0 -2px 0 var(--wood) inset; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; font-size: 11px; color: #fff; background: var(--ok); }
.badge.warn { background: var(--warn); } .badge.err { background: var(--err); }
.tabbody { flex: 1; overflow: auto; padding: 12px; -webkit-overflow-scrolling: touch; }

.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 7px 9px; }
.kpi span { display: block; font-size: 11px; color: var(--ink2); text-transform: uppercase; letter-spacing: .4px; }
.kpi b { font-family: var(--mono); font-weight: 600; font-size: 13px; }

details.sec { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; }
details.sec > summary { cursor: pointer; padding: 10px 12px; font-weight: 700; list-style: none; display: flex; justify-content: space-between; }
details.sec > summary::after { content: '+'; color: var(--wood); }
details.sec[open] > summary::after { content: '–'; }
.fields { padding: 0 12px 10px; display: grid; gap: 8px; }
.field { display: grid; grid-template-columns: 1fr 130px; gap: 8px; align-items: center; }
.field > span { font-size: 13px; color: var(--ink2); }
.field .ctl { display: flex; align-items: center; gap: 4px; }
.field input[type=number], .field select { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; background: #fff; font-family: var(--mono); font-size: 13px; }
.field select { font-family: var(--sans); }
.field input:disabled { background: #f1ece2; color: var(--wood); font-weight: 600; }
.field em { font-style: normal; font-size: 11px; color: var(--ink2); min-width: 30px; }
.field.wide { grid-template-columns: 1fr; }
.field.bool { grid-template-columns: 1fr auto; }
.field input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--wood); }

h4 { margin: 16px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--wood); }
h4:first-child { margin-top: 0; }
table.t { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; font-size: 12.5px; }
.t th, .t td { padding: 6px 7px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.t th { background: #efe8da; font-weight: 700; font-size: 11.5px; color: var(--ink2); }
.t td.n, .t th.n { text-align: right; font-family: var(--mono); white-space: nowrap; }
.t td small { color: var(--ink2); display: block; }
.t tr.total td { font-weight: 800; background: #efe8da; }
.t .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.note { font-size: 12px; color: var(--ink2); margin: 8px 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.toolbar button { font-size: 12.5px; padding: 6px 10px; }

.check { display: grid; grid-template-columns: 22px 1fr; gap: 8px; background: var(--card); border: 1px solid var(--line); border-left-width: 4px; border-radius: 10px; padding: 8px 10px; margin-bottom: 6px; }
.check.ok { border-left-color: var(--ok); } .check.warn { border-left-color: var(--warn); } .check.err { border-left-color: var(--err); } .check.info { border-left-color: var(--info); }
.check b { display: block; }
.check p { margin: 2px 0 0; font-size: 12.5px; color: var(--ink2); }
.check .ic { font-weight: 800; }
.check.ok .ic { color: var(--ok); } .check.warn .ic { color: var(--warn); } .check.err .ic { color: var(--err); } .check.info .ic { color: var(--info); }

.bars { display: grid; gap: 4px; margin-bottom: 14px; }
.bar { display: grid; grid-template-columns: 54px 1fr; gap: 6px; align-items: center; font-family: var(--mono); font-size: 11px; }
.bar svg { width: 100%; height: 26px; display: block; }

.stock input { width: 100%; border: 1px solid transparent; background: transparent; padding: 3px 4px; border-radius: 5px; font-family: var(--mono); font-size: 12px; }
.stock input:focus { border-color: var(--wood2); background: #fff; outline: none; }
.stock td { padding: 3px 4px; }

.modal { position: fixed; inset: 0; background: rgba(30,26,22,.5); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal[hidden] { display: none; }
.modal .sheet { background: var(--paper); border-radius: 14px; width: min(640px, 100%); max-height: 86vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--paper); }
.modal h3 { margin: 0; }
.modal .x { border: 0; font-size: 22px; padding: 0 8px; background: transparent; }
#modalBody { padding: 14px; }
#modalBody textarea { width: 100%; height: 260px; font-family: var(--mono); font-size: 11.5px; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.plist { display: grid; gap: 6px; }
.plist .row { display: flex; gap: 6px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.plist .row b { flex: 1; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 9px 14px; border-radius: 10px; z-index: 30; font-size: 13px; }
.toast[hidden] { display: none; }

@media (max-width: 860px) {
  .top { flex-wrap: wrap; gap: 8px; }
  .pname { order: 3; max-width: none; flex-basis: 100%; }
  .brand small { display: none; }
  main { display: flex; flex-direction: column; height: auto; }
  .stage { height: 58vh; min-height: 340px; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .tabs { position: sticky; top: 0; z-index: 2; background: var(--paper); }
  .tabbody { overflow: visible; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  .hud input[type=range] { width: 90px; }
  .field { grid-template-columns: 1fr 120px; }
}
@media print {
  .top, .stage, .tabs, .toolbar { display: none !important; }
  main { display: block; height: auto; }
  .tabbody { overflow: visible; }
  .t { font-size: 10px; }
}
