:root {
  --bg: #e9ebef; --panel: #fff; --line: #dcdfe5; --text: #1c2330; --muted: #6b7385;
  --accent: #2563eb; --accent-soft: rgba(37, 99, 235, .14); --danger: #c62828;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 11px; cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { color: var(--danger); }
button.wide { width: 100%; }
input, select, textarea { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; width: 100%; }
input[type=color] { height: 34px; padding: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.logo { display: inline-block; background: var(--danger); color: #fff; font-weight: 800; border-radius: 8px; padding: 10px 12px; letter-spacing: 1px; }
.logo.small { font-size: 11px; padding: 4px 6px; border-radius: 4px; }
.muted { color: var(--muted); font-size: 12.5px; }

body.login { display: grid; place-items: center; min-height: 100vh; }
.login form { background: var(--panel); padding: 36px; border-radius: 14px; width: 320px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.1); display: grid; gap: 12px; justify-items: center; }
.login h1 { margin: 0; font-size: 20px; }
.login input, .login button { width: 100%; }
.login p { color: var(--danger); margin: 0; min-height: 1.4em; }

body.app { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
header { display: flex; gap: 6px; align-items: center; padding: 8px 10px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; flex: none; }
header #docname { width: 240px; min-width: 120px; border-color: transparent; font-weight: 600; }
header #docname:hover:not(:disabled), header #docname:focus { border-color: var(--line); }
header #docname:disabled { background: transparent; }
header #home { border: 0; padding: 4px; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; flex: none; }
.grow { flex: 1; }
.tools { display: flex; gap: 4px; }
.tools button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
#zoomfit { min-width: 62px; }

main { flex: 1; display: flex; min-height: 0; }
#thumbs { width: 150px; flex: none; overflow-y: auto; background: #f6f7f9; border-right: 1px solid var(--line); padding: 10px; }
.thumb { display: block; width: 100%; border: 0; background: none; padding: 0; margin-bottom: 10px; text-align: center; color: var(--muted); font-size: 12px; }
.thumb img { display: block; width: 100%; background: #fff; border: 2px solid var(--line); border-radius: 3px; min-height: 40px; }
.thumb.active img { border-color: var(--accent); }
#inspector { width: 300px; flex: none; overflow-y: auto; background: var(--panel); border-left: 1px solid var(--line); padding: 14px; }
#inspector h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
#inspector section, #insp-empty, #insp-erase { margin-bottom: 18px; }
#inspector label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 9px; }
#inspector label > * { margin-top: 3px; color: var(--text); font-size: 14px; }
#inspector label.check { display: flex; gap: 8px; align-items: center; }
label.check input { width: auto; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; min-width: 0; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-bottom: 8px; }
.grid button { padding: 6px 2px; font-size: 12.5px; }
.grid .span { grid-column: 1 / -1; }
.fontname { font-size: 18px; font-weight: 700; overflow-wrap: anywhere; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 8px 0; font-size: 13px; }
dt { color: var(--muted); }
dd { margin: 0; overflow-wrap: anywhere; }
.swatch { display: inline-block; width: 12px; height: 12px; border: 1px solid #999; border-radius: 3px; vertical-align: -1px; margin-right: 5px; }
#docfonts { list-style: none; padding: 0; margin: 0 0 12px; }
#docfonts li { padding: 7px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
#docfonts small { display: block; color: var(--muted); }

#stage { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
#home-view { overflow: auto; flex: 1; padding: 30px; width: 100%; max-width: 760px; margin: 0 auto; }
#drop { border: 2px dashed #aab2c2; border-radius: 14px; background: var(--panel); text-align: center; padding: 38px 20px; }
#drop h2 { margin: 0; }
body.dragging #drop, body.dragging #stage { outline: 3px dashed var(--accent); outline-offset: -6px; }
#doclist { list-style: none; padding: 0; }
#doclist li { display: flex; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-bottom: 8px; align-items: center; }
#doclist .name { flex: 1; text-align: left; border: 0; overflow: hidden; text-overflow: ellipsis; }
#page-view { flex: 1; overflow: auto; padding: 24px; }
#notice { max-width: 700px; margin: 0 auto 14px; background: #fff4ce; border: 1px solid #e8cf73; border-radius: 8px; padding: 9px 13px; }
#page { position: relative; margin: 0 auto; background: #fff; box-shadow: 0 2px 18px rgba(0,0,0,.18); user-select: none; }
#pageimg { display: block; width: 100%; height: 100%; pointer-events: none; }
#overlay { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
#overlay.add { cursor: text; }
#overlay.erase { cursor: crosshair; }
.item { position: absolute; border: 1px solid transparent; border-radius: 2px; cursor: move; }
#overlay.select .item:hover { border-color: var(--accent); background: rgba(37, 99, 235, .07); }
.item.sel { border-color: var(--accent); background: var(--accent-soft); }
.item.hiddentext { display: none; }
#overlay.add .item, #overlay.erase .item { pointer-events: none; }
.ghost { position: absolute; pointer-events: none; outline: 1px dashed var(--accent); background-repeat: no-repeat; opacity: .85; mix-blend-mode: multiply; }
.guide { position: absolute; background: #e91e63; pointer-events: none; }
.guide.v { width: 1px; top: 0; bottom: 0; }
.guide.h { height: 1px; left: 0; right: 0; }
.band { position: absolute; border: 1px dashed var(--accent); background: var(--accent-soft); pointer-events: none; }
.editor { position: absolute; z-index: 5; min-width: 80px; border: 2px solid var(--accent); border-radius: 2px; padding: 0 2px; background: #fff; resize: none; overflow: hidden; white-space: pre; line-height: 1.2; }
.coords { position: absolute; z-index: 6; background: #1c2330; color: #fff; font-size: 11px; border-radius: 4px; padding: 2px 6px; pointer-events: none; white-space: nowrap; }
#pager { display: flex; justify-content: center; align-items: center; gap: 8px; padding: 7px; background: var(--panel); border-top: 1px solid var(--line); }
#pageno { width: 54px; text-align: center; }

#toasts { position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 20; width: min(520px, 92vw); }
.toast { background: #1c2330; color: #fff; padding: 11px 15px; border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.25); cursor: pointer; }
.toast.warn { background: #7a5300; }
.toast.error { background: #8e1b1b; }
#busy { position: fixed; right: 320px; top: 62px; z-index: 30; }
.spinner { width: 26px; height: 26px; border: 3px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  #thumbs { display: none; }
  #inspector { width: 240px; padding: 10px; }
  #busy { right: 260px; }
}
