:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1d2330;
  --muted: #6b7280;
  --line: #e3e7ee;
  --accent: #2563eb;
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
  --skip: #9ca3af;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  font-size: 14px; line-height: 1.6;
}
.hidden { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; cursor: pointer; }
.brand .tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; margin-left: 6px; }
.mainnav button { margin-left: 8px; }

button {
  background: var(--accent); color: #fff; border: 0; border-radius: 7px;
  padding: 7px 12px; cursor: pointer; font-size: 13px;
}
button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
button.subtle { background: #eef2f7; color: var(--ink); }
button.danger { background: var(--err); }
button:disabled { opacity: .5; cursor: not-allowed; }

main { max-width: 1180px; margin: 0 auto; padding: 18px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 18px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 16px; }
h1 { font-size: 20px; margin: 0 0 12px; }
h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }

/* dropzone */
.dropzone {
  border: 2px dashed var(--line); border-radius: 12px; padding: 34px; text-align: center;
  color: var(--muted); transition: .15s; background: #fbfcfe;
}
.dropzone.drag { border-color: var(--accent); background: #eff5ff; color: var(--accent); }

/* whole-screen drag & drop overlay */
.drop-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: none; align-items: center; justify-content: center;
  background: rgba(37, 99, 235, 0.12);
  backdrop-filter: blur(2px);
  pointer-events: none;  /* let drag events reach the window for depth counting */
}
.drop-overlay.show { display: flex; }
.drop-overlay-card {
  border: 3px dashed var(--accent); border-radius: 18px;
  padding: 44px 64px; text-align: center;
  background: var(--panel); color: var(--accent);
  font-size: 20px; font-weight: 700;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.18);
}
.drop-overlay-icon { font-size: 52px; margin-bottom: 8px; }
.toggle-group { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.toggle-group button { background: #fff; color: var(--ink); border-radius: 0; }
.toggle-group button.active { background: var(--accent); color: #fff; }
label.opt { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }

.filelist { margin-top: 14px; max-height: 230px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.filelist table { width: 100%; border-collapse: collapse; }
.filelist td, .filelist th { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: 12px; }

/* status badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.s-queued { background: #eef2f7; color: var(--muted); }
.s-processing { background: #e0edff; color: var(--accent); }
.s-succeeded { background: #dcfce7; color: var(--ok); }
.s-failed { background: #fee2e2; color: var(--err); }
.s-skipped { background: #f1f3f5; color: var(--skip); }
.s-admin { background: #e0edff; color: var(--accent); }
.s-member { background: #eef2f7; color: var(--muted); }
.s-active { background: #dcfce7; color: var(--ok); }
.s-disabled { background: #fee2e2; color: var(--err); }
.user-label { margin-left: 12px; font-size: 12px; color: var(--muted); }

/* progress bars */
.bar { height: 10px; background: #eef2f7; border-radius: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .3s; }

/* result viewer */
.viewer { display: grid; grid-template-columns: 240px 1fr 360px; gap: 14px; align-items: start; }
.nav { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; max-height: 78vh; overflow: auto; }
.nav .doc { font-weight: 600; margin: 8px 4px 4px; font-size: 13px; }
.nav .pg { padding: 5px 8px; border-radius: 6px; cursor: pointer; font-size: 12px; color: var(--ink); }
.nav .pg:hover { background: #eef2f7; }
.nav .pg.active { background: var(--accent); color: #fff; }
.content { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; min-height: 300px; max-height: 78vh; overflow: auto; }
.side { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; max-height: 78vh; overflow: auto; }
.side pre { white-space: pre-wrap; word-break: break-word; font-size: 11px; background: #0f172a; color: #e2e8f0; padding: 10px; border-radius: 8px; }

/* The result viewer breaks out of main's 1180px cap: it grows with the window
   (up to 2000px) and shrinks fluidly on smaller windows, staying centered. */
.viewer-page {
  width: min(96vw, 2000px);
  margin-left: calc(50% - min(48vw, 1000px));
}

/* source-vs-output compare layout: page nav | original document | LLM Markdown */
.viewer.compare { grid-template-columns: 210px 1fr 1fr; }
@media (max-width: 900px) { .viewer.compare { grid-template-columns: 150px 1fr 1fr; } }
.orig { background: #f3f6fb; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; height: 78vh; min-width: 0; }
.origframe { width: 100%; height: 100%; border: 0; display: block; }
.origimg { width: 100%; height: 100%; object-fit: contain; display: block; }
/* file tree (folder uploads) */
.tree-dir { font-size: 12px; font-weight: 600; padding: 4px 6px; cursor: pointer; user-select: none; white-space: nowrap; }
.tree-dir .tw { display: inline-block; width: 10px; color: var(--muted); }
.tree-dir.collapsed .tw { transform: rotate(-90deg); }
.tree-file { font-size: 12px; padding: 4px 6px; border-radius: 6px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.tree-file:hover { background: #eef2f7; }
.tree-file.active { background: var(--accent); color: #fff; }
.tree-sep { border-top: 1px solid var(--line); margin: 8px 0; }

.mdwrap { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.mdview { position: relative; height: 78vh; scroll-behavior: smooth; }
.mdview h1 { font-size: 17px; margin: 4px 0 8px; }
.mdview h2 { font-size: 14px; color: var(--accent); border-top: 1px solid var(--line); padding-top: 10px; margin: 16px 0 6px; }
.mdview .pagemark { font-weight: 700; color: var(--accent); border-top: 2px solid var(--line); padding-top: 12px; margin-top: 18px; }
.mdview pre code { font-size: 11px; }
.mdview pre { background: #0f172a; color: #e2e8f0; padding: 10px; border-radius: 8px; overflow: auto; }
.mdview pre { white-space: pre-wrap; word-break: break-word; }

.content :where(h1,h2,h3) { line-height: 1.3; }
.content table { border-collapse: collapse; margin: 10px 0; width: 100%; }
.content th, .content td { border: 1px solid var(--line); padding: 6px 9px; font-size: 13px; }
.content th { background: #f3f6fb; }
.raw { white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, monospace; font-size: 12px; }

.chart-card { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 12px 0; background: #fcfdff; }
.chart-badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 8px; margin-bottom: 8px; }
.cb-exact { background: #dcfce7; color: var(--ok); }
.cb-totals_only { background: #fef3c7; color: var(--warn); }
.cb-approximate { background: #fef3c7; color: var(--warn); }
.cb-trend_only { background: #fee2e2; color: var(--err); }
.cb-none { background: #f1f3f5; color: var(--muted); }
.chart-note { font-size: 12px; color: var(--muted); margin-top: 8px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs button { background: #eef2f7; color: var(--ink); }
.tabs button.active { background: var(--accent); color: #fff; }

table.jobs { width: 100%; border-collapse: collapse; }
table.jobs td, table.jobs th { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; font-size: 13px; }
table.jobs tr.clickable { cursor: pointer; }
table.jobs tr.clickable:hover { background: #f8fafc; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; opacity: 0; transition: .25s; }
.toast.show { opacity: 1; }
.login { max-width: 360px; margin: 60px auto; }
.login input { width: 100%; padding: 9px; border: 1px solid var(--line); border-radius: 8px; margin: 8px 0; }

/* ---- projects (folders) & sharing ---- */
.small { font-size: 12px; }
select, input[type="text"], input[type="email"] {
  border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; font-size: 13px; background: #fff; color: var(--ink);
}
input[type="text"], input[type="email"] { min-width: 220px; }
.dash { display: grid; grid-template-columns: 220px 1fr; gap: 16px; align-items: start; }
@media (max-width: 800px) { .dash { grid-template-columns: 1fr; } }
.dash-main { min-width: 0; overflow-x: auto; }
.rail { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; position: sticky; top: 64px; }
.rail-head { display: flex; align-items: center; font-size: 12px; font-weight: 700; color: var(--muted); padding: 2px 6px 6px; }
.rail-item { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.rail-item:hover { background: #eef2f7; }
.rail-item.active { background: #e0edff; color: var(--accent); font-weight: 600; }
.rail-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-item .count { font-size: 11px; color: var(--muted); }
.rail-toggle { font-size: 12px; color: var(--muted); padding: 8px 8px 4px; cursor: pointer; user-select: none; }
button.icon { background: transparent; color: var(--muted); padding: 0 6px; font-size: 15px; line-height: 1.4; }
button.icon:hover { color: var(--accent); background: #eef2f7; }
.rail-item button.more { visibility: hidden; }
.rail-item:hover button.more, .rail-item.active button.more { visibility: visible; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.pill { display: inline-block; font-size: 10px; font-weight: 600; padding: 0 6px; border-radius: 8px; background: #fef3c7; color: #92400e; white-space: nowrap; }
.chipwrap { display: inline-flex; align-items: center; gap: 5px; }
select.chip { font-size: 12px; padding: 3px 6px; max-width: 160px; }
.empty { text-align: center; padding: 28px 10px; }
.empty p { margin: 6px 0 12px; }

.modal-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .35); z-index: 900; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 12px; overflow: auto; }
.modal { background: var(--panel); border-radius: 14px; width: min(560px, 100%); padding: 18px 20px; box-shadow: 0 18px 50px rgba(15, 23, 42, .25); }
.modal-head { display: flex; align-items: center; margin-bottom: 8px; }
.modal-head h2 { margin: 0; }
.modal h3 { font-size: 15px; margin: 2px 0 4px; }
.modal-foot { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; gap: 8px; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; }
.palette { display: flex; gap: 8px; margin-top: 4px; }
.pal { width: 24px; height: 24px; border-radius: 6px; padding: 0; border: 2px solid transparent; }
.pal.on { border-color: var(--ink); box-shadow: 0 0 0 2px #fff inset; }
.section-label { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .04em; }
.share-section { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.share-section p { margin: 4px 0 8px; }
.member-list { margin-top: 10px; display: flex; flex-direction: column; }
.member-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.member-row:last-child { border-bottom: 0; }
.person { min-width: 0; overflow: hidden; }
.role-cell { text-align: right; }
.linkfield { flex: 1; min-width: 0; font-family: ui-monospace, monospace; font-size: 12px; }
table.jobs th { white-space: nowrap; }
table.jobs .ops { gap: 6px; flex-wrap: nowrap; }
table.jobs .ops button { white-space: nowrap; }
