:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --ink: #16202e;
  --muted: #667085;
  --line: #e3e7ee;
  --brand: #0f547b;
  --brand-ink: #ffffff;
  --brand-soft: #e7f0f6;
  --danger: #c0392b;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; }
h3 { font-size: 15px; margin: 18px 0 10px; }
.hidden, [hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 24px; height: 56px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.tabs { display: flex; gap: 4px; }
.tab {
  border: 0; background: transparent; padding: 8px 14px; border-radius: 8px; cursor: pointer;
  font: inherit; color: var(--muted);
}
.tab.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

.layout { display: grid; grid-template-columns: 380px 1fr; gap: 20px; padding: 20px 24px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 20px 20px; }
.controls { max-height: calc(100vh - 96px); overflow: auto; position: sticky; top: 76px; }
.preview-panel { position: sticky; top: 76px; }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.row-between h2 { margin: 18px 0; }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
input, textarea, select {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px; font: inherit; color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
input:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea { resize: vertical; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #c9d1dc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.actions.sticky { position: sticky; bottom: -20px; background: var(--panel); padding: 14px 0 6px; border-top: 1px solid var(--line); margin-top: 20px; }
.dirty { font-size: 12px; color: #b26b00; }

.emp-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 8px; max-height: 220px; overflow: auto; }
.emp-list li { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; }
.emp-list li:last-child { border-bottom: 0; }
.emp-list li:hover { background: #f8fafc; }
.emp-list li.active { background: var(--brand-soft); }
.emp-list .t { font-size: 12px; color: var(--muted); }
.emp-list .empty { color: var(--muted); cursor: default; }

.hint { color: var(--muted); font-size: 12px; margin: -4px 0 10px; }
.slots { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.slot {
  border: 1px dashed #c9d1dc; border-radius: 8px; padding: 8px; text-align: center; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px; transition: border-color .15s, background .15s;
}
.slot:hover, .slot.drag { border-color: var(--brand); background: var(--brand-soft); }
.slot .thumb { height: 52px; display: flex; align-items: center; justify-content: center; width: 100%; }
.slot img { max-height: 52px; max-width: 100%; }
.slot .name { font-size: 12px; font-weight: 600; }
.slot .meta { font-size: 11px; color: var(--muted); }
.slot.busy { opacity: .5; pointer-events: none; }

.slider { display: grid; grid-template-columns: 1fr 64px; gap: 4px 10px; align-items: center; margin-bottom: 10px; }
.slider span { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.slider input[type=range] { margin: 0; padding: 0; border: 0; accent-color: var(--brand); }
.slider input[type=number] { margin: 0; padding: 5px 6px; text-align: right; }

.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.toggles label { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 13px; margin: 0; cursor: pointer; }
.toggles input { width: auto; margin: 0; accent-color: var(--brand); }

.canvas {
  background: repeating-conic-gradient(#f4f6f9 0% 25%, #fff 0% 50%) 50% / 20px 20px;
  border: 1px solid var(--line); border-radius: 8px; padding: 24px; overflow: auto;
}
.sheet { display: inline-block; background: #fff; padding: 16px; box-shadow: 0 1px 3px rgba(16,24,40,.08); }

.howto { margin-top: 14px; color: var(--muted); font-size: 13px; }
.howto summary { cursor: pointer; }
.howto ol { margin: 8px 0 0; padding-left: 20px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .controls, .preview-panel { position: static; max-height: none; }
  .topbar { padding: 0 16px; }
}
.btn.disabled { opacity: .5; }

/* overall scale */
.scale-box { border: 1px solid var(--line); border-radius: 8px; padding: 12px 12px 10px; background: #fafbfc; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.presets .btn.active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.size-readout { font-size: 12px; color: var(--muted); margin-top: 8px; }
.sheet-wrap { position: relative; display: inline-block; }
.resize-handle {
  position: absolute; right: -9px; bottom: -9px; width: 18px; height: 18px; padding: 0;
  border: 2px solid #fff; border-radius: 4px; background: var(--brand); cursor: nwse-resize;
  box-shadow: 0 1px 4px rgba(16,24,40,.3); touch-action: none;
}
.resize-handle::after {
  content: ""; position: absolute; inset: 3px; border-right: 2px solid #fff; border-bottom: 2px solid #fff; border-radius: 1px;
}
.resizing .sheet { outline: 2px dashed var(--brand); outline-offset: 2px; }
.size-badge { font-size: 12px; color: var(--muted); margin-top: 10px; }

.height-handle {
  position: absolute; left: 50%; bottom: -7px; transform: translateX(-50%); width: 44px; height: 12px; padding: 0;
  border: 2px solid #fff; border-radius: 6px; background: var(--brand); cursor: ns-resize;
  box-shadow: 0 1px 4px rgba(16,24,40,.3); touch-action: none;
}
.height-handle::after { content: ""; position: absolute; left: 12px; right: 12px; top: 2px; border-top: 1px solid #fff; border-bottom: 1px solid #fff; height: 2px; }
