:root {
  --bg: #f6f7f9; --panel: #fff; --line: #e3e6ea; --text: #1f2933; --muted: #6b7280;
  --accent: #2563eb; --accent-soft: #dbeafe; --hl: rgba(255, 210, 0, .45); --hl-active: rgba(255, 120, 0, .5);
  --danger: #dc2626;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif; color: var(--text); background: var(--bg); display: flex; flex-direction: column; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 4px 10px; }
button:hover { background: #f0f2f5; }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.danger:hover { color: var(--danger); }
button#send { background: var(--accent); color: #fff; border-color: var(--accent); }
input, textarea { font: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }

header { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--text); text-decoration: none; font-size: 18px; }
.sub { color: var(--muted); font-size: 13px; }
.ptitle { font-size: 14px; color: var(--muted); max-width: 50vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-btn { background: var(--accent); color: #fff; padding: 6px 14px; border-radius: 6px; cursor: pointer; font-size: 14px; }

.home { max-width: 900px; width: 100%; margin: 24px auto; padding: 0 16px; }
.dropzone { border: 2px dashed #c7cdd4; border-radius: 12px; padding: 36px; text-align: center; background: #fff; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.paper-list { list-style: none; padding: 0; margin: 0; }
.paper-list li { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; margin-bottom: 8px; display: flex; gap: 12px; align-items: center; cursor: pointer; }
.paper-list li:hover { border-color: var(--accent); }
.paper-list .t { font-weight: 600; flex: 1; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: #eef0f3; color: var(--muted); }
.badge.done { background: #dcfce7; color: #166534; }
.badge.analyzing { background: #fef9c3; color: #854d0e; }
.badge.error { background: #fee2e2; color: #991b1b; }

.viewer { flex: 1; display: grid; grid-template-columns: minmax(380px, 1fr) minmax(420px, 1fr); min-height: 0; }
.pdf-pane { display: flex; flex-direction: column; border-right: 1px solid var(--line); min-height: 0; }
.pdf-toolbar { display: flex; gap: 6px; align-items: center; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); font-size: 13px; }
.pdf-toolbar input { width: 54px; padding: 2px 4px; }
.pdf-scroll { flex: 1; overflow: auto; background: #9aa1a9; padding: 12px; }
.page-wrap { position: relative; margin: 0 auto; box-shadow: 0 2px 8px rgba(0,0,0,.3); width: fit-content; }
.page-wrap canvas { display: block; }
.hl-layer { position: absolute; inset: 0; pointer-events: none; }
.hl { position: absolute; background: var(--hl); border-radius: 2px; mix-blend-mode: multiply; }
.hl.active { background: var(--hl-active); }

.side-pane { display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.tabs { display: flex; gap: 4px; padding: 6px 10px; border-bottom: 1px solid var(--line); align-items: center; }
.tabs button[data-tab] { border-color: transparent; background: transparent; padding: 6px 12px; color: var(--muted); }
.tabs button.active { color: var(--accent); border-bottom: 2px solid var(--accent); border-radius: 0; }
.tab { flex: 1; overflow: auto; padding: 12px 16px; min-height: 0; display: flex; flex-direction: column; }
.status { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.status.err { color: var(--danger); }

.meta { margin-bottom: 12px; }
.meta h1 { font-size: 17px; margin: 0 0 2px; }
.meta .ja { color: var(--muted); font-size: 14px; }
.sec { margin-bottom: 14px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.sec > h2 { margin: 0; font-size: 14px; padding: 8px 12px; background: #f3f4f6; }
.item { padding: 8px 12px; border-top: 1px solid var(--line); }
.item h3 { margin: 0 0 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.item p { margin: 0; font-size: 14px; line-height: 1.6; }
.item.has-ev p { cursor: pointer; }
.item.has-ev:hover { background: #fafbfc; }
.ev-chips { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--accent-soft); color: #1e40af; cursor: pointer; border: 1px solid transparent; }
.chip:hover { border-color: var(--accent); }
.chip.nf { background: #f3f4f6; color: var(--muted); }

.popover { position: fixed; z-index: 50; max-width: 460px; background: #1f2933; color: #fff; padding: 10px 12px; border-radius: 8px; font-size: 13px; line-height: 1.5; box-shadow: 0 6px 20px rgba(0,0,0,.3); pointer-events: none; }
.popover .pg { color: #fcd34d; font-weight: 600; margin-right: 6px; }

.chat-log { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }
.msg { max-width: 92%; padding: 8px 12px; border-radius: 10px; font-size: 14px; line-height: 1.6; }
.msg.user { align-self: flex-end; background: var(--accent-soft); }
.msg.assistant { align-self: flex-start; background: #f3f4f6; border: 1px solid var(--line); }
.msg .who { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.msg p { margin: 0 0 6px; } .msg p:last-child { margin-bottom: 0; }
.msg .pref { color: var(--accent); cursor: pointer; font-weight: 600; }
.msg.pending { color: var(--muted); font-style: italic; }
.chat-form { border-top: 1px solid var(--line); padding-top: 8px; display: grid; grid-template-columns: 110px 1fr; gap: 6px; }
.chat-form textarea { resize: vertical; }
.chat-actions { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; font-size: 13px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1f2933; color: #fff; padding: 8px 16px; border-radius: 8px; font-size: 14px; z-index: 60; }
.msg h1, .msg h2, .msg h3, .msg h4 { font-size: 14px; margin: 8px 0 4px; }
.msg ul, .msg ol { margin: 4px 0; padding-left: 20px; }
.msg code { background: #e5e7eb; padding: 0 4px; border-radius: 3px; font-size: 13px; }
