:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #697386;
  --line: #e5e9f1;
  --accent: #3559e0;
  --accent-soft: #eef2ff;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --good: #067647;
  --good-soft: #ecfdf3;
  --warn: #b54708;
  --warn-soft: #fffaeb;
  --shadow: 0 10px 30px rgba(16,24,40,.06);
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font: 14px/1.55 -apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",Arial,sans-serif; }
body.reader-mode { overflow: hidden; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
.boot { min-height: 100vh; display: grid; place-items: center; color: var(--muted); }
.shell { --sidebar-width:224px; --sidebar-rail:16px; min-height:100vh; display:grid; grid-template-columns:var(--sidebar-width) minmax(0,1fr); transition:grid-template-columns .18s ease; }
.shell.sidebar-auto { grid-template-columns:var(--sidebar-rail) minmax(0,1fr); }
.sidebar { position:sticky; top:0; z-index:40; width:var(--sidebar-width); height:100vh; padding:24px 16px; background:#111827; color:#d9e0ee; transform:translateX(0); transition:transform .18s ease, box-shadow .18s ease; }
.shell.sidebar-auto .sidebar { transform:translateX(calc(-1 * (var(--sidebar-width) - var(--sidebar-rail)))); }
.shell.sidebar-auto .sidebar:hover, .shell.sidebar-auto .sidebar:focus-within { transform:translateX(0); box-shadow:12px 0 30px rgba(15,23,42,.18); }
.brand { display:flex; gap:10px; align-items:center; justify-content:space-between; padding:0 4px 24px 10px; font-size:18px; font-weight:700; color:#fff; }
.brand-main { display:flex; gap:10px; align-items:center; min-width:0; }
.sidebar-mode-btn { width:30px; height:30px; flex:0 0 30px; display:grid; place-items:center; border:1px solid #344054; border-radius:8px; background:#1f2937; color:#d9e0ee; font-size:14px; line-height:1; }
.sidebar-mode-btn:hover, .sidebar-mode-btn:focus-visible { background:#2b3648; color:#fff; outline:none; border-color:#526078; }
.sidebar-peek { display:none; position:absolute; right:0; top:50%; width:var(--sidebar-rail); height:44px; transform:translateY(-50%); align-items:center; justify-content:center; border-radius:8px 0 0 8px; background:#263244; color:#cbd5e1; font-size:18px; pointer-events:none; }
.shell.sidebar-auto .sidebar-peek { display:flex; }
.shell.sidebar-auto .sidebar:hover .sidebar-peek, .shell.sidebar-auto .sidebar:focus-within .sidebar-peek { opacity:0; }

.brand-mark { width:32px; height:32px; border-radius:9px; display:grid; place-items:center; background:#fff; color:#111827; font-weight:800; }
.nav { display:grid; gap:6px; }
.nav a { padding:10px 12px; border-radius:10px; color:#aeb8ca; }
.nav a:hover, .nav a.active { background:#202b3d; color:#fff; }
.sidebar-foot { position:absolute; bottom:18px; left:16px; right:16px; }
.main { min-width:0; min-height:100vh; display:flex; flex-direction:column; }
.topbar { height:64px; background:rgba(255,255,255,.92); border-bottom:1px solid var(--line); display:flex; align-items:center; justify-content:space-between; padding:0 28px; position:sticky; top:0; z-index:20; backdrop-filter: blur(10px); }
.topbar h1 { margin:0; font-size:18px; }
.content { padding:28px; max-width:1500px; margin:0 auto; width:100%; flex:1 1 auto; min-height:0; }
.content.reader-content { max-width:none; overflow:hidden; padding:10px 16px 16px; }
.page-head { display:flex; justify-content:space-between; gap:16px; align-items:flex-start; margin-bottom:20px; }
.page-head h2 { margin:0 0 4px; font-size:24px; }
.page-head p { margin:0; color:var(--muted); }
.grid { display:grid; gap:16px; }
.stats { grid-template-columns: repeat(4,minmax(0,1fr)); }
.card { background:var(--panel); border:1px solid var(--line); border-radius:var(--radius); box-shadow:var(--shadow); }
.card-pad { padding:20px; }
.stat .label { color:var(--muted); font-size:13px; }
.stat .value { font-size:28px; font-weight:750; margin-top:6px; letter-spacing:-.5px; }
.section-title { margin:0 0 14px; font-size:16px; }
.two-col { grid-template-columns: minmax(0,1.25fr) minmax(300px,.75fr); align-items:start; }
.table-wrap { overflow:auto; }
table { width:100%; border-collapse:collapse; }
th, td { text-align:left; padding:11px 12px; border-bottom:1px solid var(--line); vertical-align:top; }
th { color:var(--muted); font-size:12px; font-weight:650; background:#fafbfc; position:sticky; top:0; }
tr:last-child td { border-bottom:0; }
.muted { color:var(--muted); }
.small { font-size:12px; }
.btn { border:1px solid var(--line); background:#fff; color:var(--text); padding:8px 12px; border-radius:9px; display:inline-flex; align-items:center; justify-content:center; gap:7px; }
.btn:hover { background:#f8fafc; }
.btn.primary { background:var(--accent); color:#fff; border-color:var(--accent); }
.btn.danger { color:var(--danger); background:var(--danger-soft); border-color:#fecdca; }
.btn.ghost { border-color:transparent; background:transparent; }
.btn:disabled { opacity:.55; cursor:not-allowed; }
.actions { display:flex; flex-wrap:wrap; gap:8px; align-items:center; }
.input, .textarea, .select { width:100%; border:1px solid #d7dce5; border-radius:9px; padding:9px 11px; background:#fff; color:var(--text); outline:none; }
.input:focus, .textarea:focus, .select:focus { border-color:#89a0ff; box-shadow:0 0 0 3px rgba(53,89,224,.1); }
.textarea { min-height:110px; resize:vertical; }
.field { display:grid; gap:6px; }
.field label { font-weight:650; font-size:13px; }
.form-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:14px; }
.span-2 { grid-column:1 / -1; }
.filters { display:grid; grid-template-columns:minmax(220px,1fr) 150px auto; gap:10px; margin-bottom:16px; }
.paper-grid { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:14px; }
.paper-card { padding:17px; display:grid; gap:10px; min-height:190px; transition:.15s ease; }
.paper-card:hover { transform:translateY(-1px); border-color:#cbd4ff; }
.paper-title { font-size:16px; font-weight:700; line-height:1.4; }
.paper-meta { display:flex; flex-wrap:wrap; gap:8px; color:var(--muted); font-size:12px; }
.tag { display:inline-flex; align-items:center; padding:3px 8px; border-radius:999px; background:#f2f4f7; color:#475467; font-size:12px; }
.tag.q1 { background:#ecfdf3; color:#067647; }
.tag.q2 { background:#eef4ff; color:#3538cd; }
.tag.q3 { background:#fffaeb; color:#b54708; }
.tag.q4 { background:#fff1f3; color:#c01048; }
.tag.status-completed { background:var(--good-soft); color:var(--good); }
.tag.status-error { background:var(--danger-soft); color:var(--danger); }
.tag.status-analyzing { background:var(--warn-soft); color:var(--warn); }
.upload-zone { border:1.5px dashed #b8c1d4; border-radius:12px; padding:18px; background:#fbfcff; }
.upload-row { display:grid; grid-template-columns:1fr 1fr; gap:14px; }
.file-box { border:1px solid var(--line); border-radius:10px; padding:14px; background:#fff; }
.file-box input { width:100%; }
.progress { height:8px; background:#e9edf5; border-radius:999px; overflow:hidden; }
.progress > div { height:100%; width:0; background:var(--accent); transition:width .25s ease; }
.progress-log { max-height:190px; overflow:auto; background:#111827; color:#d8e0ef; border-radius:10px; padding:12px; font:12px/1.6 ui-monospace,SFMono-Regular,Consolas,monospace; white-space:pre-wrap; }
.login-wrap { min-height:100vh; display:grid; place-items:center; padding:20px; background:radial-gradient(circle at top left,#eef2ff,transparent 40%),var(--bg); }
.login-card { width:min(420px,100%); padding:28px; }
.login-card h1 { margin:0 0 4px; }
.login-card p { color:var(--muted); margin:0 0 22px; }
.reader-topbar { width:100%; display:flex; justify-content:space-between; align-items:flex-start; gap:16px; }
.reader-topbar-main { min-width:0; flex:1 1 auto; }
.reader-topbar-title { font-size:18px; font-weight:700; line-height:1.35; word-break:break-word; }
.reader-topbar-meta { margin-top:4px; color:var(--muted); font-size:13px; }
.reader-topbar-tags { margin-top:8px; }
.reader-topbar-actions { flex:0 0 auto; justify-content:flex-end; }
.topbar.topbar-reader { height:auto; min-height:64px; padding:12px 18px; align-items:flex-start; }
.reader-workspace { height:100%; min-height:0; display:grid; grid-template-rows:auto minmax(0,1fr); gap:10px; }
.reader-notice { margin:0; }
.reader-layout { display:grid; grid-template-columns:minmax(0,1.55fr) minmax(380px,.75fr); gap:14px; align-items:stretch; min-height:0; }
.reader-layout-full { height:100%; min-height:0; }
.pdf-panel { overflow:hidden; display:flex; flex-direction:column; min-height:0; }
.pdf-toolbar { padding:8px 10px; display:flex; align-items:center; justify-content:space-between; gap:10px; border-bottom:1px solid var(--line); background:#fafbfc; flex-wrap:wrap; }
.pdf-toolbar-actions { justify-content:flex-end; }
.pdf-stage { flex:1; min-height:0; overflow:auto; background:#e8ebf0; display:block; padding:14px; scroll-behavior:smooth; }
.pdf-page-wrap { width:fit-content; max-width:100%; margin:0 auto 18px; display:grid; gap:8px; justify-items:center; }
.pdf-page-wrap:last-child { margin-bottom:0; }
.pdf-stage canvas { display:block; background:#fff; box-shadow:0 4px 18px rgba(0,0,0,.16); max-width:100%; height:auto; border-radius:2px; }
.pdf-page-caption { font-size:12px; color:var(--muted); }
.analysis-panel { min-height:0; overflow:auto; height:100%; }
.analysis-section { padding:15px 17px; border-bottom:1px solid var(--line); }
.analysis-section:last-child { border-bottom:0; }
.analysis-section h3 { margin:0 0 8px; font-size:13px; color:#344054; }
.analysis-section p { margin:0; white-space:pre-wrap; }
.tabs { display:flex; gap:6px; }
.tabs button.active { background:var(--accent); color:#fff; border-color:var(--accent); }
.notice { border-radius:10px; padding:11px 13px; background:var(--accent-soft); color:#3646a7; }
.notice.warn { background:var(--warn-soft); color:var(--warn); }
.notice.danger { background:var(--danger-soft); color:var(--danger); }
.empty { text-align:center; padding:48px 20px; color:var(--muted); }
.pagination { display:flex; align-items:center; justify-content:center; gap:8px; margin-top:18px; }
.toast { position:fixed; right:20px; bottom:20px; max-width:420px; background:#101828; color:#fff; padding:11px 14px; border-radius:10px; box-shadow:var(--shadow); opacity:0; transform:translateY(8px); pointer-events:none; transition:.2s; z-index:100; }
.toast.show { opacity:1; transform:none; }
.code { background:#f2f4f7; border-radius:7px; padding:2px 6px; font-family:ui-monospace,SFMono-Regular,Consolas,monospace; }
.kv { display:grid; grid-template-columns:160px 1fr; gap:8px 16px; }
.kv > div:nth-child(odd) { color:var(--muted); }
.modal-backdrop { position:fixed; inset:0; background:rgba(15,23,42,.45); display:grid; place-items:center; z-index:60; padding:24px; }
.modal { width:min(920px,100%); max-height:90vh; overflow:auto; padding:20px; }
@media (max-width:1100px) { .stats{grid-template-columns:repeat(2,1fr)} .paper-grid{grid-template-columns:repeat(2,1fr)} .reader-topbar{display:grid} .reader-topbar-actions{justify-content:flex-start} .reader-layout,.two-col{grid-template-columns:1fr} .reader-layout{height:auto; min-height:0} .analysis-panel{height:auto; min-height:320px} }
@media (max-width:760px) { .shell,.shell.sidebar-auto,.shell.sidebar-fixed{grid-template-columns:1fr}.sidebar,.shell.sidebar-auto .sidebar{position:static;width:auto;height:auto;transform:none;box-shadow:none}.sidebar-mode-btn,.sidebar-peek{display:none!important}.nav{grid-template-columns:repeat(4,1fr);overflow:auto}.sidebar-foot{display:none}.topbar{padding:0 16px}.topbar.topbar-reader{padding:10px 12px}.content,.content.reader-content{padding:12px;height:auto;overflow:visible}.stats,.paper-grid,.form-grid,.upload-row{grid-template-columns:1fr}.span-2{grid-column:auto}.filters{grid-template-columns:1fr}.reader-topbar{display:grid}.reader-topbar-actions{justify-content:flex-start}.reader-layout{display:block;height:auto;min-height:0}.pdf-stage{min-height:420px;max-height:none}.analysis-panel{height:auto}.kv{grid-template-columns:1fr}.nav a{white-space:nowrap;text-align:center}.brand{padding-bottom:14px} body.reader-mode{overflow:auto} }

/* Multi-provider AI settings */
.settings-grid { grid-template-columns:minmax(0,1.2fr) minmax(340px,.8fr); align-items:start; }
.model-url { max-width:420px; overflow-wrap:anywhere; margin-top:5px; }
.secret-ok { color:var(--good); margin-top:5px; }
.secret-missing { color:var(--warn); margin-top:5px; }
.check-row { display:flex; gap:8px; align-items:center; font-size:13px; }
.secret-guide ol { margin:0 0 16px 20px; padding:0; display:grid; gap:10px; line-height:1.55; }
.model-picker { width:min(620px,100%); }
@media (max-width:1100px) { .settings-grid{grid-template-columns:1fr} }


/* ===== Final desktop reader workspace ===== */
body.reader-mode,
body.reader-mode #app {
  width: 100%;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}
body.reader-mode .shell {
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}
body.reader-mode .main {
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}
body.reader-mode .topbar.topbar-reader {
  position: relative;
  top: auto;
  flex: 0 0 auto;
  min-height: 62px;
  height: auto;
  padding: 10px 16px;
  z-index: 20;
}
body.reader-mode .content.reader-content {
  flex: 1 1 0;
  width: 100%;
  height: 0;
  min-height: 0;
  max-width: none;
  margin: 0;
  padding: 10px 14px 14px;
  overflow: hidden;
}
.reader-topbar {
  min-width: 0;
  align-items: center;
}
.reader-topbar-main {
  min-width: 0;
}
.reader-topbar-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
}
.reader-topbar-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}
.reader-topbar-tags {
  margin-top: 5px;
  flex-wrap: nowrap;
  overflow: hidden;
}
.reader-topbar-actions {
  flex-wrap: nowrap;
  white-space: nowrap;
}
.reader-workspace {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
.reader-layout,
.reader-layout-full {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  grid-template-columns: minmax(0, 2.1fr) minmax(340px, 1fr);
  gap: 12px;
}
.pdf-panel,
.analysis-panel {
  height: 100%;
  min-height: 0;
}
.pdf-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.pdf-toolbar {
  flex: 0 0 auto;
  position: relative;
  z-index: 2;
  padding: 7px 9px;
}
.pdf-stage {
  flex: 1 1 0;
  width: 100%;
  height: 0;
  min-height: 0;
  max-height: none;
  overflow-x: auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 14px 16px 24px;
}
.pdf-page-wrap {
  width: max-content;
  max-width: 100%;
  margin: 0 auto 18px;
}
.pdf-stage canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  object-fit: contain;
}
.analysis-panel {
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
.analysis-section {
  padding: 13px 15px;
}

/* Tablet / narrow-window fallback: unlock outer page so stacked panels remain reachable. */
@media (max-width: 980px) {
  body.reader-mode,
  body.reader-mode #app {
    height: auto;
    min-height: 100%;
    overflow: auto;
  }
  body.reader-mode .shell,
  body.reader-mode .main {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
  body.reader-mode .content.reader-content {
    height: auto;
    overflow: visible;
  }
  .reader-topbar {
    display: grid;
  }
  .reader-topbar-title,
  .reader-topbar-meta {
    white-space: normal;
  }
  .reader-topbar-tags,
  .reader-topbar-actions {
    flex-wrap: wrap;
    overflow: visible;
    justify-content: flex-start;
  }
  .reader-workspace,
  .reader-layout,
  .reader-layout-full {
    height: auto;
    overflow: visible;
  }
  .reader-layout,
  .reader-layout-full {
    grid-template-columns: 1fr;
  }
  .pdf-panel {
    height: 72vh;
    min-height: 520px;
  }
  .analysis-panel {
    height: 55vh;
    min-height: 360px;
  }
}
