:root {
  --bg: #f7f6f2; --panel: #ffffff; --ink: #1c2b3a; --muted: #5c6b7c; --line: #dcdad3;
  --forest: #0d3b26; --forest-mid: #1a5c3a; --spark: #c8f04d; --bad: #b3261e;
  --mark: rgba(255, 214, 0, .45); --mark-line: #d9a400;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); }
body { display: flex; flex-direction: column; overflow: hidden; }
.grow { flex: 1; }
[hidden] { display: none !important; }
.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
.btn:hover { border-color: var(--forest-mid); }
.btn.primary { background: var(--forest); border-color: var(--forest); color: #fff; }
.btn.primary:disabled { background: #9aa6a0; border-color: #9aa6a0; cursor: not-allowed; }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.top { display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--forest); color: #fff; flex: none; }
.top .btn.ghost { color: #fff; border-color: rgba(255,255,255,.35); }
.brand { font-size: 17px; } .brand b { color: var(--spark); }
.layout { flex: 1; display: grid; grid-template-columns: 360px minmax(0, 1fr); min-height: 0; }
.side { display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--panel); min-height: 0; }
.doc { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.drop { margin: 10px 12px 0; border: 2px dashed var(--line); border-radius: 8px; padding: 12px; cursor: pointer; flex: none; }
.drop.over { border-color: var(--forest-mid); background: #eef5f0; }
.drop-h { font-weight: 600; } .drop-s { color: var(--muted); font-size: 12px; margin-top: 2px; }
.drop .drop-line { display: none; align-items: center; gap: 8px; }
.drop.filled { border-style: solid; padding: 7px 10px; cursor: default; }
.drop.filled .drop-full { display: none; } .drop.filled .drop-line { display: flex; }
.drop-line .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.drop-line a { font-size: 12px; color: var(--forest-mid); }
.x { border: 0; background: none; font-size: 18px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 2px; }
.drop-err { color: var(--bad); font-size: 12px; margin-top: 4px; } .drop-err:empty { display: none; }
.chat { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.msg { max-width: 92%; padding: 7px 10px; border-radius: 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.ai { background: #f1f0eb; align-self: flex-start; }
.msg.user { background: var(--forest); color: #fff; align-self: flex-end; }
.msg.q { border: 1px solid var(--mark-line); }
.msg.flash { animation: flash 1.2s; }
@keyframes flash { 0% { background: #fff1a8; } 100% { background: #f1f0eb; } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { font: inherit; font-size: 13px; border: 1px solid var(--forest-mid); color: var(--forest-mid); background: #fff; border-radius: 14px; padding: 3px 10px; cursor: pointer; }
.chip:hover { background: #eef5f0; }
.typing { color: var(--muted); font-size: 13px; align-self: flex-start; }
.chat-in { display: flex; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--line); flex: none; }
.chat-in textarea { flex: 1; font: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 7px 8px; resize: none; max-height: 120px; }
.chat-in textarea:disabled { background: #f4f3ef; }
.doc-bar { display: flex; align-items: center; gap: 12px; padding: 8px 16px; flex: none; position: sticky; top: 0; z-index: 5; background: var(--bg); }
.doc-bar a { color: var(--forest-mid); font-size: 13px; }
.openq { color: var(--muted); font-size: 12px; }
.progress { height: 3px; background: #e2e0d8; overflow: hidden; flex: none; }
.progress div { width: 30%; height: 100%; background: var(--forest-mid); animation: slide 1.2s infinite ease-in-out; }
@keyframes slide { 0% { margin-left: -30%; } 100% { margin-left: 100%; } }
.pages { flex: 1; overflow-y: auto; padding: 8px 16px 24px; }
.pages.dim { opacity: .8; }
.placeholder { margin: 40px auto; max-width: 520px; padding: 80px 20px; text-align: center; color: var(--muted); background: #eeede7; border-radius: 8px; }
.page { position: relative; margin: 0 auto 14px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.18); max-width: 900px; }
.page img { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
.tl { position: absolute; inset: 0; line-height: 1; }
.tl span { position: absolute; color: transparent; white-space: pre; cursor: text; transform-origin: 0 0; }
.tl span::selection { background: rgba(26, 92, 58, .25); }
.mk { position: absolute; border-radius: 2px; cursor: pointer; z-index: 2; }
.mk.swap { background: var(--mark); }
.mk.ask { border: 2px solid var(--mark-line); background: transparent; }
.mk.off { background: transparent; }
.mk.off:hover { outline: 1px dotted var(--muted); }
.mk.red { border: 2px solid var(--bad); background: transparent; cursor: default; }
.mk.pulse { animation: pulse .3s; }
@keyframes pulse { 0% { transform: scale(1.06); } 100% { transform: scale(1); } }
.tip { position: fixed; z-index: 30; background: var(--ink); color: #fff; font-size: 13px; padding: 4px 8px; border-radius: 5px; pointer-events: none; max-width: 320px; overflow-wrap: anywhere; }
.pop { position: fixed; z-index: 31; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.18); padding: 6px; width: 260px; max-width: calc(100vw - 32px); }
.pop button.act { display: block; width: 100%; text-align: left; font: inherit; border: 0; background: none; padding: 7px 8px; border-radius: 5px; cursor: pointer; }
.pop button.act:hover { background: #f1f0eb; }
.pop input { width: 100%; font: inherit; padding: 6px; border: 1px solid var(--forest-mid); border-radius: 5px; margin: 4px 0; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box { background: #fff; border-radius: 10px; padding: 16px; width: min(560px, 100%); max-height: 80vh; overflow: auto; }
.modal-box ul { padding-left: 18px; } .modal-box li { margin: 4px 0; overflow-wrap: anywhere; }
.jobs-panel { position: fixed; top: 48px; right: 16px; z-index: 35; width: min(420px, calc(100vw - 32px)); max-height: 70vh; overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.18); padding: 10px; }
.jobs-head { display: flex; justify-content: space-between; align-items: center; }
#jobsList { list-style: none; padding: 0; margin: 8px 0 0; }
#jobsList li { padding: 6px; border-bottom: 1px solid var(--line); cursor: pointer; overflow-wrap: anywhere; } #jobsList li:hover { background: #f1f0eb; }
.small { font-size: 12px; } .muted { color: var(--muted); }
.seg, .bottombar { display: none; }
@media (max-width: 899px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .seg { display: flex; margin: 8px 16px 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex: none; }
  .seg button { flex: 1; font: inherit; border: 0; background: #fff; padding: 7px; position: relative; }
  .seg button.on { background: var(--forest); color: #fff; }
  .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--mark-line); margin-left: 6px; vertical-align: middle; }
  body.v-doc .side .chat, body.v-doc .side .chat-in { display: none; }
  body.v-chat .doc { display: none; }
  body.v-doc .side { border-right: 0; flex: none; }
  .side .drop { display: inline-block; }
  .drops-row { display: flex; }
  .pages { padding: 8px 16px 80px; }
  .doc-bar #btnSwap { display: none !important; }
  .bottombar { display: block; position: fixed; bottom: 0; left: 0; right: 0; padding: 10px 16px; background: var(--bg); border-top: 1px solid var(--line); z-index: 20; }
  .bottombar .btn { width: 100%; padding: 10px; }
  body.v-chat .chat-in { margin-bottom: 64px; }
  .pop { left: 16px !important; right: 16px; bottom: 70px; top: auto !important; width: auto; }
}
/* sign-in page (only when SWAP_AUTH=on) */
.login-body { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; overflow: auto; }
.login-card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 24px; width: min(380px, 100%); }
.login-card h1 { margin: 0 0 6px; font-size: 22px; color: var(--forest); }
.login-card label { display: block; margin: 10px 0; } .login-card input { display: block; width: 100%; padding: 8px; font: inherit; border: 1px solid var(--line); border-radius: 6px; margin-top: 4px; }
.err { color: var(--bad); min-height: 1.2em; }
