* { box-sizing: border-box; }
:root {
  --bg: #eef0f3; --panel: #fff; --text: #1d2329; --muted: #6b7480;
  --accent: #2459d6; --accent-soft: #e6edfc; --border: #d9dde3; --danger: #c23a3a;
}
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text); background: var(--bg);
  display: grid; grid-template-columns: 320px 1fr;
}
#side {
  background: var(--panel); border-right: 1px solid var(--border);
  padding: 16px; overflow-y: auto; height: 100vh; position: relative;
}
h1 { font-size: 18px; margin: 0 0 12px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
section { padding: 12px 0; border-bottom: 1px solid var(--border); }
section:last-of-type { border-bottom: 0; }
.muted, .hint { color: var(--muted); font-size: 12px; }
.hint { margin: 8px 0 0; }
#docInfo { margin-top: 6px; word-break: break-all; }

.btn {
  display: inline-block; border: 1px solid var(--border); background: #fff; color: var(--text);
  border-radius: 8px; padding: 7px 12px; font: inherit; cursor: pointer; text-align: center;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.big { width: 100%; padding: 11px; font-weight: 600; }
.btn.ghost { width: 100%; margin-top: 8px; border-color: transparent; color: var(--muted); }
.btn.file { width: 100%; }

input[type=text] {
  width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; font: inherit;
}
form { display: grid; gap: 8px; margin-top: 8px; }
form.row { grid-template-columns: 1fr auto; }
.check { display: flex; gap: 6px; align-items: center; font-size: 13px; }
details summary { cursor: pointer; color: var(--accent); margin-top: 8px; }

.list { display: grid; gap: 6px; }
.item {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer; background: #fff;
}
.item.active { border-color: var(--accent); background: var(--accent-soft); }
.item img { height: 32px; max-width: 90px; object-fit: contain;
  background: repeating-conic-gradient(#f2f2f2 0 25%, #fff 0 50%) 0 0 / 10px 10px; }
.item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .x { border: 0; background: none; color: var(--muted); font-size: 16px; cursor: pointer; padding: 0 4px; }
.item .x:hover { color: var(--danger); }
.item .meta { color: var(--muted); font-size: 12px; }

#pages { height: 100vh; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; align-items: center; gap: 24px; }
#empty { margin-top: 30vh; color: var(--muted); font-size: 16px; }
.page { position: relative; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15); width: min(100%, 900px); }
.page img.bg { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
.page .num { position: absolute; left: -2px; top: -20px; font-size: 12px; color: var(--muted); }
.page.placing { cursor: crosshair; }

.sig {
  position: absolute; outline: 1px dashed var(--accent); touch-action: none; cursor: move;
}
.sig img { width: 100%; height: 100%; display: block; pointer-events: none; user-select: none; }
.sig .handle {
  position: absolute; right: -7px; bottom: -7px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff; cursor: nwse-resize; touch-action: none;
}
.sig .tools {
  position: absolute; left: 0; top: -26px; display: flex; gap: 4px; white-space: nowrap;
}
.sig .tools button {
  font: 11px system-ui, sans-serif; border: 1px solid var(--border); background: #fff;
  border-radius: 5px; padding: 2px 6px; cursor: pointer;
}
.sig .tools button.del { color: var(--danger); }
.sig.copy { outline-style: dotted; opacity: .55; cursor: default; }
.sig.copy .handle, .sig.copy .tools { display: none; }

#toast {
  position: fixed; left: 16px; bottom: 16px; max-width: 290px; padding: 10px 14px; border-radius: 8px;
  background: #222; color: #fff; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 10;
}
#toast.show { opacity: .92; }

@media (max-width: 760px) {
  body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  #side { height: auto; max-height: 48vh; border-right: 0; border-bottom: 1px solid var(--border); }
  #pages { height: auto; padding: 28px 10px; }
}

/* login */
body.login { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.card { background: var(--panel); padding: 28px; border-radius: 12px; width: min(340px, 100%);
  box-shadow: 0 2px 12px rgba(0,0,0,.08); display: grid; gap: 12px; }
.card input[type=password] { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 8px; font: inherit; }
.err { color: var(--danger); min-height: 1.2em; font-size: 13px; }
#side h1 { display: flex; justify-content: space-between; align-items: center; }
#logoutBtn { font-size: 12px; font-weight: 400; padding: 4px 8px; }
