:root {
  --bg: #f4f5f7; --panel: #ffffff; --fg: #15191e; --muted: #5d6773; --line: #cfd5dc; --desk: #dde1e6;
  --accent: #0b5cd5; --accent-fg: #fff; --bad: #c4262e; --ok: #1a7f46;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bg: #101418; --panel: #171c22; --fg: #e4e8ed; --muted: #95a0ac; --line: #2d353e; --desk: #0b0e11; --accent: #5aa2ff; --accent-fg: #06101f; --bad: #ff7b82; --ok: #5bd18a; } }
:root[data-theme="dark"] { --bg: #101418; --panel: #171c22; --fg: #e4e8ed; --muted: #95a0ac; --line: #2d353e; --desk: #0b0e11; --accent: #5aa2ff; --accent-fg: #06101f; --bad: #ff7b82; --ok: #5bd18a; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.4 var(--sans); -webkit-tap-highlight-color: transparent; }
body { display: flex; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
button, input, select, textarea { font: inherit; color: inherit; }
button, .btn { background: var(--panel); border: 1px solid var(--line); border-radius: 3px; padding: 6px 10px; min-height: 34px; cursor: pointer; display: inline-flex; align-items: center; }
@media (hover: hover) { button:hover, .btn:hover { border-color: var(--muted); } }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--bad); }
input[type=text], input[type=search], input[type=url], input[type=number], input[type=date], select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 3px; padding: 6px 8px; min-height: 34px; max-width: 100%; }
textarea { width: 100%; resize: vertical; font-family: var(--mono); font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#top { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-family: var(--mono); letter-spacing: -.02em; margin-right: 4px; }
.grow { flex: 1; }
.inl { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); font-size: 13px; }
.inl select, .inl input { color: var(--fg); }
#warn { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 8px 12px; background: #fff3cd; color: #4a3b00; border-bottom: 1px solid #e6d28a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) #warn { background: #3b3210; color: #f1deaa; border-color: #5c4e1c; } }
:root[data-theme="dark"] #warn { background: #3b3210; color: #f1deaa; border-color: #5c4e1c; }
#layout { flex: 1; display: flex; min-height: 0; }
#viewer { flex: 1; overflow: auto; background: var(--desk); position: relative; min-width: 0; }
#viewbar { position: sticky; top: 0; z-index: 5; display: flex; gap: 6px; align-items: center; padding: 6px 12px; background: var(--bg); border-bottom: 1px solid var(--line); }
#viewbar button { white-space: nowrap; }
#status { color: var(--muted); font-size: 13px; margin-left: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
#empty { max-width: 560px; margin: 8vh auto; padding: 0 16px; }
#empty h1 { font-size: 22px; font-family: var(--mono); letter-spacing: -.02em; margin: 0 0 12px; }
#empty form { margin-top: 28px; border-top: 1px solid var(--line); padding-top: 16px; }
#empty label { color: var(--muted); font-size: 13px; }
#urlIn { flex: 1; min-width: 0; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 8px; }
.bad { color: var(--bad); }
.page { position: relative; margin: 12px auto; background: #fff; box-shadow: 0 0 0 1px var(--line); }
.page canvas { position: absolute; left: 0; top: 0; }
.over { position: absolute; inset: 0; cursor: crosshair; }
.stamp { position: absolute; white-space: pre; line-height: 1.15; color: #000; cursor: move; touch-action: none; user-select: none; -webkit-user-select: none; outline: 1px dashed transparent; min-width: 8px; min-height: 8px; }
@media (hover: hover) { .stamp:hover { outline-color: #8a94a0; } }
.stamp.sel { outline: 1px solid var(--accent); background: rgba(11, 92, 213, .1); }
.stamp.warn { color: var(--bad); outline: 1px dashed var(--bad); }
.stamp.empty { outline: 1px dashed var(--bad); }
.stamp.img img { width: 100%; height: 100%; display: block; pointer-events: none; }
.field { position: absolute; display: flex; align-items: center; padding: 0 2px; overflow: hidden; white-space: pre; color: #000; outline: 1px dashed rgba(11, 92, 213, .6); background: rgba(11, 92, 213, .07); cursor: pointer; line-height: 1.1; }
.field.mapped { background: rgba(26, 127, 70, .14); outline-color: rgba(26, 127, 70, .8); }
.field.warn { background: rgba(196, 38, 46, .16); outline-color: var(--bad); }
#selbar { position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 15; display: flex; gap: 4px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
#selbar button { min-width: 44px; justify-content: center; min-height: 40px; }
#panel { width: 380px; flex: none; display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); min-height: 0; }
#tabs { display: flex; border-bottom: 1px solid var(--line); }
#tabs button { flex: 1; border: 0; border-radius: 0; border-bottom: 2px solid transparent; justify-content: center; background: none; min-height: 40px; }
#tabs button[aria-selected="true"] { border-bottom-color: var(--accent); font-weight: 600; }
#tabs .narrow { flex: none; }
#tabbody { flex: 1; overflow: auto; padding: 12px; }
#tabbody section { margin-bottom: 20px; }
h3 { font: 600 12px var(--mono); text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 0 6px; }
#tabbody > div > section:first-child h3:first-child { margin-top: 0; }
.row { display: flex; gap: 8px; align-items: center; margin: 4px 0; }
.row > span { flex: 0 0 38%; font-size: 13px; color: var(--muted); }
.row > input, .row > select { flex: 1; min-width: 0; }
.row2 { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0; }
.row2 > input[type=text], .row2 > input[type=url] { flex: 1; min-width: 0; }
.check { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.card { border: 1px solid var(--line); border-radius: 3px; padding: 8px; margin: 8px 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { margin: 2px 0; }
.list li > button { width: 100%; text-align: left; justify-content: flex-start; gap: 8px; font-family: var(--mono); font-size: 13px; }
.list li > button.on { border-color: var(--accent); background: rgba(11, 92, 213, .1); }
.pg { color: var(--muted); }
.tpl { display: flex; justify-content: space-between; gap: 8px; align-items: center; border-bottom: 1px solid var(--line); padding: 6px 0; flex-wrap: wrap; }
.tpl small, .tok, .fname small { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.field-row { border-bottom: 1px solid var(--line); padding: 8px 0; display: grid; gap: 4px; }
.field-row input[type=text], .field-row select, .field-row textarea { width: 100%; }
.fname { display: flex; flex-direction: column; }
.lab { flex: 1; font-weight: 600; }
.pad { width: 100%; max-width: 360px; height: auto; border: 1px dashed var(--line); background: #fff; touch-action: none; display: block; margin: 8px 0; }
.sigprev { max-width: 220px; max-height: 80px; background: #fff; border: 1px solid var(--line); padding: 4px; display: block; }
#menu { position: fixed; z-index: 30; min-width: 230px; max-width: 320px; max-height: 70vh; overflow: auto; background: var(--panel); border: 1px solid var(--muted); border-radius: 3px; box-shadow: 0 4px 14px rgba(0,0,0,.25); padding: 4px; }
#menu button { display: flex; width: 100%; justify-content: space-between; gap: 12px; border: 0; background: none; text-align: left; min-height: 38px; }
#menu button i { color: var(--muted); font-style: normal; font-family: var(--mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55%; }
#menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
body.drop #viewer { outline: 3px dashed var(--accent); outline-offset: -6px; }
.narrow { display: none; }
@media (max-width: 899px) {
  .narrow { display: inline-flex; }
  #panel { position: fixed; inset: 0; width: auto; z-index: 20; display: none; border-left: 0; padding-top: env(safe-area-inset-top); }
  #panel.open { display: flex; }
  #top { gap: 6px; }
  .brand { display: none; }
  .inl { font-size: 12px; }
}
@media print { #top, #panel, #viewbar, #selbar { display: none; } }
