/* Doc Scanner - © compact. All rights reserved. */
:root {
  --bg: #0b1118; --panel: #111a24; --panel2: #16212d; --line: #223142;
  --text: #e6edf5; --muted: #8aa0b5; --accent: #22d3ee; --accent2: #3b82f6;
  --warn: #fbbf24; --ok: #34d399; --danger: #f87171;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, #12304a55, transparent), var(--bg);
  color: var(--text); font: 14px/1.5 "Segoe UI", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  display: flex; flex-direction: column; min-height: 100vh;
}
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* header */
.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: #0d151ecc; backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; letter-spacing: .5px;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; box-shadow: 0 4px 14px #22d3ee44;
}
.brand h1 { margin: 0; font-size: 17px; letter-spacing: .3px; }
.brand p { margin: 0; font-size: 11px; color: var(--muted); }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer; user-select: none;
  border: 1px solid var(--line); background: var(--panel2); padding: 8px 14px; border-radius: 8px; transition: .15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: #36506a; background: #1b2938; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, #1e3a5f, #1d4ed8); border-color: #2c5aa0; }
.btn.accent { background: linear-gradient(135deg, #0e7490, #22d3ee); border-color: #22d3ee; color: #031018; font-weight: 700; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.block { width: 100%; margin-top: 6px; }
.icon-btn {
  width: 34px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2);
  cursor: pointer; font-size: 18px; line-height: 1;
}
.icon-btn:hover { border-color: var(--accent); }

/* layout */
.layout { flex: 1; display: grid; grid-template-columns: 170px 1fr 270px; min-height: 0; }
.pages, .settings { background: var(--panel); border-right: 1px solid var(--line); padding: 12px; overflow: auto; }
.settings { border-right: 0; border-left: 1px solid var(--line); max-height: calc(100vh - 92px); position: sticky; top: 59px; }
.pages { max-height: calc(100vh - 92px); position: sticky; top: 59px; }
.panel-title { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .08em; margin: 14px 0 8px; display: flex; align-items: center; gap: 6px; }
.panel-title:first-child { margin-top: 0; }
.badge { background: var(--panel2); border: 1px solid var(--line); border-radius: 99px; padding: 0 8px; font-size: 11px; color: var(--text); }

.page-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.page-item { position: relative; border: 2px solid transparent; border-radius: 8px; padding: 4px; background: var(--panel2); cursor: pointer; }
.page-item.on { border-color: var(--accent); }
.page-item img { width: 100%; display: block; border-radius: 4px; background: #fff; aspect-ratio: 210/297; object-fit: contain; }
.page-item .pn { position: absolute; left: 8px; top: 8px; background: #000a; color: #fff; font-size: 11px; padding: 0 6px; border-radius: 4px; }
.page-item .warn { position: absolute; right: 8px; top: 8px; background: var(--warn); color: #000; font-size: 10px; font-weight: 700; padding: 0 5px; border-radius: 4px; }
.page-item .ops { display: flex; gap: 4px; margin-top: 4px; }
.page-item .ops button { flex: 1; border: 1px solid var(--line); background: var(--panel); border-radius: 5px; font-size: 11px; padding: 2px 0; cursor: pointer; }
.page-item .ops button:hover { border-color: var(--accent); }
.page-item .ops .del:hover { border-color: var(--danger); color: var(--danger); }
.page-item .name { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

/* workspace */
.workspace { padding: 12px; min-width: 0; display: flex; flex-direction: column; }
.empty { flex: 1; display: grid; place-items: center; }
.drop {
  border: 2px dashed #2b4157; border-radius: 16px; padding: 40px 36px; text-align: center; cursor: pointer; max-width: 560px;
  background: linear-gradient(180deg, #13202d, #0f1822); transition: .2s;
}
.drop:hover { border-color: var(--accent); }
.drop-icon { font-size: 44px; color: var(--accent); }
.drop-main { font-size: 18px; font-weight: 700; margin: 6px 0 2px; }
.drop-sub { color: var(--muted); margin: 0 0 18px; }
.features { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; text-align: left; }
.features li { background: #0b131c; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; }
.features li::before { content: "✓ "; color: var(--ok); font-weight: 700; }

.views { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; flex: 1; min-height: 0; }
.view { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.view-title { font-weight: 700; }
.muted { color: var(--muted); font-size: 12px; }
.toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.spacer { flex: 1; }
.fine { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.fine input { min-width: 70px; }
.fine input { width: 110px; }
.fine output { min-width: 34px; color: var(--text); font-variant-numeric: tabular-nums; }

.stage { position: relative; flex: 1; min-height: 420px; height: calc(100vh - 260px); background: #070b10; overflow: hidden; touch-action: pan-x pan-y; }
.stage.editing { touch-action: none; }
.stage canvas#srcCanvas, .stage canvas#outCanvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage.out { background: repeating-conic-gradient(#0c131b 0 25%, #0a1017 0 50%) 0 0/20px 20px; }
.stage.out.tool-brush, .stage.out.tool-rect { cursor: crosshair; }
.loupe { position: absolute; width: 160px; height: 160px; border-radius: 50%; border: 2px solid var(--accent); box-shadow: 0 6px 24px #000a; pointer-events: none; display: none; background: #000; }
.busy { position: absolute; right: 10px; top: 10px; background: #000c; padding: 4px 10px; border-radius: 99px; font-size: 12px; display: none; align-items: center; gap: 6px; }
.busy.on { display: inline-flex; }
.spin { width: 12px; height: 12px; border: 2px solid #fff4; border-top-color: var(--accent); border-radius: 50%; animation: sp 0.8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.status { padding: 6px 10px; font-size: 12px; color: var(--muted); min-height: 30px; }
.status .ok { color: var(--ok); } .status .warn { color: var(--warn); }

.seg { display: inline-flex; background: #0b131c; border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 12.5px; color: var(--muted); }
.seg button.on { background: linear-gradient(135deg, #0e7490, #1d4ed8); color: #fff; }
.seg.full { display: flex; width: 100%; } .seg.full button { flex: 1; }
.seg.four button { padding: 5px 2px; }

/* settings */
.field { margin-bottom: 10px; }
.field > label { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.field output { color: var(--text); font-variant-numeric: tabular-nums; }
select { width: 100%; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 10px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.hint { font-size: 11.5px; color: var(--muted); margin: 0 0 6px; }

.app-footer { text-align: center; font-size: 11px; color: var(--muted); padding: 8px; border-top: 1px solid var(--line); }
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%) translateY(20px); background: #0f1b27; border: 1px solid #2c4a66;
  padding: 10px 16px; border-radius: 10px; box-shadow: 0 10px 30px #000a; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: 90vw;
}
.toast.on { opacity: 1; transform: translateX(-50%); }
.dropmask { position: fixed; inset: 0; background: #06101acc; display: none; place-items: center; z-index: 60; font-size: 22px; font-weight: 700; color: var(--accent); border: 3px dashed var(--accent); }
.dropmask.on { display: grid; }

/* responsive */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 140px 1fr; }
  .settings { grid-column: 1 / -1; position: static; max-height: none; border-left: 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); column-gap: 16px; }
  .settings .panel-title { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .layout { display: flex; flex-direction: column; flex: none; }
  .pages { position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .page-list { flex-direction: row; overflow-x: auto; }
  .page-item { min-width: 92px; width: 92px; }
  .views { grid-template-columns: 1fr; }
  .stage { height: 62vh; min-height: 320px; }
  .features { grid-template-columns: 1fr; }
  .header-actions .btn { padding: 7px 10px; font-size: 13px; }
}
