/* Prepare workspace: page thumbnails | the document with its fields | setup panel. */

body[data-shell="workspace"] .shell { display: block; }
.ws-loading { max-width: 640px; margin: 48px auto; padding: 0 16px; display: grid; gap: 16px; }

[data-color] { --c: var(--ink-muted); }
[data-color="1"] { --c: var(--signer-1); }
[data-color="2"] { --c: var(--signer-2); }
[data-color="3"] { --c: var(--signer-3); }
[data-color="4"] { --c: var(--signer-4); }

.ws { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100vh; height: 100dvh; }
.ws-top { display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 16px; border-bottom: 1px solid var(--border); background: var(--bg); min-width: 0; }
.ws-top .brand { padding: 0; flex: none; }
.ws-top .divider { width: 1px; height: 20px; background: var(--border); flex: none; }
.ws-top .crumbs { min-width: 0; }
.ws-top .crumbs a[aria-current] { min-width: 0; overflow: hidden; color: var(--ink); }
.ws-top .pill { flex: none; }
.saved { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-muted); font-size: 0.86rem; white-space: nowrap; }
.saved.err { color: var(--err); }
.ws-top .right { margin-left: auto; display: flex; gap: 8px; align-items: center; flex: none; }

.ws-body { display: grid; grid-template-columns: 132px minmax(0, 1fr) 340px; min-height: 0; }
.thumbs { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 16px 0; overflow-y: auto; background: var(--surface-alt); border-right: 1px solid var(--border); }
.thumb {
  flex-direction: column; gap: 6px; min-height: 0; padding: 4px; border: 0; box-shadow: none; background: none;
  font: 0.86rem var(--font-mono); color: var(--ink-muted);
}
.thumb:hover { background: var(--surface-muted); }
.tsheet { position: relative; display: block; width: 84px; background: #fff; border: 1px solid var(--border); border-radius: 3px; overflow: hidden; box-shadow: var(--shadow-sm); }
.tsheet canvas { display: block; width: 100%; height: 100%; }
.tmarks i { position: absolute; border-radius: 1px; background: var(--c); opacity: .85; }
.thumb[aria-current] { color: var(--ink); }
.thumb[aria-current] .tsheet { outline: 2px solid var(--accent); outline-offset: 2px; }

.canvas { position: relative; min-width: 0; overflow: auto; background: var(--surface-muted); }
.toolbar {
  position: sticky; top: 12px; z-index: 5; display: flex; align-items: center; gap: 4px; width: max-content; max-width: calc(100% - 24px);
  margin: 12px auto 0; padding: 4px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow-md);
}
.toolbar .sep { width: 1px; height: 20px; margin: 0 4px; background: var(--border); }
.assign { position: relative; display: inline-flex; align-items: center; gap: 6px; margin: 0; padding-left: 10px; font-weight: 500; }
.assign .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.assign select { min-height: 34px; max-width: 180px; padding: 0 26px 0 2px; border: 0; box-shadow: none; background-color: transparent; font-weight: 500; }
.tool {
  min-height: 34px; padding: 0 12px; border: 0; border-radius: 7px; box-shadow: none; background: transparent;
  color: var(--ink-2); font-size: 0.93rem;
}
.tool:hover { background: var(--surface-muted); border-color: transparent; }
.tool[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.place-hint { min-height: 1.5em; margin: 8px 0 0; text-align: center; font-size: 0.86rem; color: var(--ink-2); }
.place-hint:empty { visibility: hidden; }

.sheets { display: flex; flex-direction: column; align-items: center; gap: 24px; padding: 12px 40px 96px; }
.sheet { position: relative; width: 100%; max-width: 760px; background: #fff; border-radius: 2px; box-shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 8px 28px -8px rgba(0, 0, 0, .16); }
.sheet canvas { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 2px; }
.layer { position: absolute; inset: 0; }
.placing .layer { cursor: crosshair; }

.fld {
  position: absolute; display: flex; align-items: center; justify-content: flex-start; gap: 6px; min-height: 0; padding: 0 8px; overflow: visible;
  border: 1.5px solid var(--c); border-radius: 4px; box-shadow: none; color: var(--c); background: color-mix(in srgb, var(--c) 9%, transparent);
  font: 500 clamp(10px, 1.6cqw, 13px)/1.1 var(--font-ui); cursor: move; touch-action: none; user-select: none; white-space: nowrap;
}
.sheet { container-type: inline-size; }
.fld:hover { background: color-mix(in srgb, var(--c) 15%, transparent); border-color: var(--c); color: var(--c); }
.fld:active { transform: none; }
.fld svg.i { width: clamp(11px, 1.8cqw, 15px); height: clamp(11px, 1.8cqw, 15px); }
.fld-t { overflow: hidden; text-overflow: ellipsis; }
.fld.sel { box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 22%, transparent); z-index: 2; }
.fld:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.fld-tag { position: absolute; left: -1.5px; bottom: calc(100% + 6px); padding: 3px 7px; border-radius: 4px; background: var(--c); color: #fff; font-size: 11px; pointer-events: none; }
.grip {
  position: absolute; right: -6px; bottom: -6px; width: 12px; height: 12px; border: 1.5px solid var(--c);
  border-radius: 3px; background: #fff; cursor: nwse-resize;
}

.panel { overflow-y: auto; background: var(--surface); border-left: 1px solid var(--border); }
.panel section { padding: 18px 20px; border-bottom: 1px solid var(--border); }
.panel section:last-child { border-bottom: 0; }
.panel h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; font-size: 0.93rem; }
.panel h2 button { margin-left: auto; }
.small-gap { margin: 0 0 12px; font-size: 0.93rem; }
.recips { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.recip { display: flex; align-items: center; gap: 2px; border-radius: var(--radius); }
.recip.on { background: var(--surface-muted); }
.recip-pick {
  flex: 1; min-width: 0; justify-content: flex-start; gap: 10px; padding: 6px 8px; border: 0; box-shadow: none; background: none; text-align: left; font-weight: 400;
}
.recip-pick:hover { background: var(--surface-alt); border-color: transparent; }
.recip .ord { font: 500 11px var(--font-mono); color: var(--ink-muted); width: 10px; }
.recip .av { width: 28px; height: 28px; background: var(--c); color: #fff; }
.recip .meta { min-width: 0; flex: 1; }
.recip .meta b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.recip .meta span { display: block; font-size: 0.86rem; color: var(--ink-muted); overflow: hidden; text-overflow: ellipsis; }
.recip .fc { font: 0.82rem var(--font-mono); color: var(--ink-muted); }
.recip .fc.none { color: var(--warn); }
.add-recip { margin: 4px 0 0; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-alt); }
.add-recip label { margin-bottom: 10px; }
.add-recip .msg { margin: 10px 0 0; }
.kv { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 10px 12px; align-items: center; margin: 0; font-size: 0.93rem; }
.kv dt { color: var(--ink-muted); }
.kv dt label { margin: 0; font-weight: 400; color: inherit; }
.kv dd { margin: 0; }
.kv select { min-height: 32px; padding: 4px 8px; }
.coords { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-top: 12px; }
.coords label { margin: 0; font-size: 0.82rem; color: var(--ink-muted); }
.coords input { min-height: 30px; margin-top: 3px; padding: 4px 6px; font: 0.86rem var(--font-mono); background: var(--surface-alt); }
.hint { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 12px 0 0; font-size: 0.82rem; color: var(--ink-muted); }
.send .notice {
  display: flex; gap: 10px; margin: 0 0 10px; padding: 10px 12px; border: 1px solid var(--warn-line); border-radius: var(--radius);
  background: var(--warn-bg); color: color-mix(in srgb, var(--warn) 80%, var(--ink)); font-size: 0.9rem;
}
.send .notice svg { color: var(--warn); margin-top: 2px; }
.send .notice button {
  min-height: 0; padding: 0; border: 0; box-shadow: none; background: none; color: var(--warn); font-weight: 500;
  text-decoration: underline; text-underline-offset: 2px;
}
.send > label { margin: 12px 0 6px; }
.msg-box { min-height: 76px; font-size: 0.93rem; }
.send-row { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.credit-note { margin: 0; text-align: center; font-size: 0.82rem; color: var(--ink-muted); }

@media (max-width: 1180px) {
  .ws-body { grid-template-columns: 92px minmax(0, 1fr) 320px; }
  .tsheet { width: 64px; }
  .sheets { padding: 12px 24px 96px; }
  .ws-top .brand span, .ws-top .divider { display: none; }
}
@media (max-width: 900px) {
  .ws { height: auto; min-height: 100vh; }
  .ws-body { grid-template-columns: minmax(0, 1fr); }
  .thumbs { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 16px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .tsheet { width: 44px; }
  .canvas { overflow: visible; }
  .sheets { padding: 12px 16px 24px; }
  .panel { border-left: 0; border-top: 1px solid var(--border); padding-bottom: 84px; }
  .panel section { padding: 18px 16px; }
  .toolbar {
    position: fixed; top: auto; bottom: 12px; left: 12px; right: 12px; z-index: 20; width: auto; max-width: none; margin: 0;
    justify-content: space-between; padding-bottom: calc(4px + env(safe-area-inset-bottom) / 2);
  }
  .toolbar .assign, .toolbar .sep { display: none; }
  .tool { flex: 1; flex-direction: column; gap: 2px; min-height: 48px; padding: 0 4px; font-size: 0.78rem; }
  .saved span { display: none; }
  .ws-top { position: sticky; top: 0; z-index: 15; }
  .place-hint {
    position: fixed; left: 12px; right: 12px; bottom: 84px; z-index: 20; margin: 0; padding: 8px 12px;
    border-radius: var(--radius); background: var(--ink); color: var(--bg); box-shadow: var(--shadow-lg);
  }
  .place-hint:empty { display: none; }
}
@media (pointer: coarse) { .panel .hint { display: none; } }
@media (max-width: 640px) {
  .ws-top { gap: 8px; padding: 0 12px; }
  .ws-top .crumbs > a:first-child, .ws-top .crumbs .sep { display: none; }
  .ws-top .pill { display: none; }
  .send-top span { display: none; }
  .send-top { width: 40px; padding: 0; }
}
