* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, sans-serif; color: #1c1c28; background: #f4f4f8; }
header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; background: #1c1c28; color: #fff;
}
header .spacer { flex: 1; }
header .sep { width: 1px; height: 22px; background: #3a3a4d; margin: 0 4px; }
header button {
  background: #2e2e40; color: #fff; border: 0; border-radius: 6px;
  padding: 4px 10px; cursor: pointer;
}
.muted { color: #9aa0b8; } .small { font-size: 12px; }
main { display: flex; height: calc(100vh - 46px); }
#outline { width: 200px; overflow-y: auto; background: #f4f4f8;
  border-right: 1px solid #e2e2ee; padding: 8px; font-size: 13px; }
#outline h4 { margin: 0 0 6px; color: #7c5cff; font-size: 12px; }
#outline .oitem { cursor: pointer; padding: 3px 4px; border-radius: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#outline .oitem:hover { background: #e6e1ff; }
#annoList { width: 200px; overflow-y: auto; background: #f4f4f8;
  border-right: 1px solid #e2e2ee; padding: 8px; font-size: 13px; }
#annoList h4 { margin: 0 0 6px; color: #7c5cff; font-size: 12px; }
#annoList .aitem { cursor: pointer; padding: 3px 4px; border-radius: 4px;
  display: flex; align-items: center; justify-content: space-between; gap: 6px; }
#annoList .aitem:hover { background: #e6e1ff; }
#annoList .aitem span { flex: 1; }
#annoList .adel { border: 0; background: none; cursor: pointer; color: #b3261e;
  font-size: 12px; line-height: 1; padding: 2px 4px; border-radius: 3px; }
#annoList .adel:hover { background: #f3d6d4; }
#annoList .empty { color: #999; }
#thumbs { width: 140px; overflow-y: auto; background: #ececf2;
  border-right: 1px solid #e2e2ee; padding: 8px; display: flex;
  flex-direction: column; gap: 8px; align-items: center; }
#thumbs .thumb { cursor: pointer; border: 2px solid transparent; border-radius: 4px;
  background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.12); line-height: 0; }
#thumbs .thumb.active { border-color: #7c5cff; }
#thumbs .thumb canvas { width: 110px; height: auto; display: block; }
#thumbs .num { font-size: 11px; color: #777; text-align: center; line-height: 1.4; }
#viewer { flex: 1; overflow: auto; display: flex; justify-content: center;
  padding: 20px; }
#canvas { box-shadow: 0 2px 12px rgba(0,0,0,.18); background: #fff; height: max-content; }
#viewer.inverted { background: #2a2a30; }
#viewer.inverted #canvas, #viewer.inverted #pages canvas {
  filter: invert(1) hue-rotate(180deg); }
#stage { position: relative; height: max-content; }
#inkLayer { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
#inkLayer.active { pointer-events: auto; cursor: crosshair; }
#inkLayer path { fill: none; stroke: #e23; stroke-width: 2; stroke-linecap: round;
  stroke-linejoin: round; }
#annoLayer { position: absolute; inset: 0; }
#annoLayer.active { cursor: crosshair; }
#annoLayer .hl { position: absolute; background: rgba(255,235,59,.4);
  border: 1px solid rgba(230,190,0,.7); pointer-events: none; }
#pages { display: flex; flex-direction: column; gap: 16px; align-items: center; }
#pages canvas { box-shadow: 0 2px 12px rgba(0,0,0,.18); background: #fff; }
header button.active { background: #7c5cff; }

/* Режимы-вкладки: «Просмотр» / «Фото → PDF» / «Заявка» (одна страница) */
header .modes { display: inline-flex; gap: 4px; margin-left: 6px; }
header .modes button { background: transparent; border: 1px solid #3a3a4d;
  border-radius: 7px; padding: 5px 12px; font-size: 13px; white-space: nowrap; }
header .modes button:hover { background: #2e2e40; }
header .modes button.on { background: #7c5cff; border-color: #7c5cff; color: #fff; }
/* Группа кнопок активного режима — сохраняет прежнюю инлайн-раскладку тулбара */
header .tb { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
header .tb.hidden { display: none; }
header .tb .muted.small { max-width: 360px; }
#ai { width: 340px; background: #fff; border-left: 1px solid #e2e2ee;
  display: flex; flex-direction: column; padding: 12px; gap: 8px; }
#ai h3 { margin: 0; color: #7c5cff; }
.log { flex: 1; overflow: auto; font-size: 14px; }
.msg { margin: 6px 0; }
.msg.ai b { color: #7c5cff; } .msg.user b { color: #555; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; }
.quick button, #ask {
  background: #f0f0f5; border: 1px solid #d8d8e4; border-radius: 6px;
  padding: 6px 8px; cursor: pointer; font-size: 13px;
}
#ask { background: #7c5cff; color: #fff; border: 0; }
.row { display: flex; gap: 6px; }
.row input { flex: 1; padding: 6px 8px; border: 1px solid #d8d8e4; border-radius: 6px; }
code { background: #f0f0f5; padding: 1px 4px; border-radius: 4px; }
#ai h3 button { background: none; border: 0; cursor: pointer; font-size: 16px; }
/* Утилита скрытия — ДОЛЖНА перебивать display из других правил, иначе
   `.modal{display:flex}` (ниже по файлу) показывал бы `.modal.hidden`. */
.hidden { display: none !important; }
#status { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(40, 40, 48, .92); color: #fff; padding: 12px 18px;
  border-radius: 8px; font: 14px system-ui, sans-serif; z-index: 100;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .3); max-width: 70%; text-align: center; }
#status.error { background: #b3261e; }
.settings { display: flex; flex-direction: column; gap: 6px;
  background: #f7f7fb; border: 1px solid #e2e2ee; border-radius: 8px; padding: 10px; }
.settings label { display: flex; flex-direction: column; font-size: 12px;
  color: #555; gap: 2px; }
.settings input, .settings select {
  padding: 5px 7px; border: 1px solid #d8d8e4; border-radius: 6px; font-size: 13px; }
#saveCfg { background: #7c5cff; color: #fff; border: 0; border-radius: 6px;
  padding: 6px; cursor: pointer; }

/* --- Dark UI theme (chrome only; the PDF page stays white — use ◐ invert for
   dark reading of the document itself). Toggle persists in localStorage. ----- */
body.dark { background: #15151c; color: #e4e4ee; }
body.dark #outline, body.dark #annoList { background: #1c1c28; border-right-color: #2e2e40; }
body.dark #outline .oitem:hover, body.dark #annoList .aitem:hover { background: #2e2e40; }
body.dark #annoList .empty { color: #888; }
body.dark #thumbs { background: #15151c; border-right-color: #2e2e40; }
body.dark #thumbs .num { color: #9aa0b8; }
body.dark #viewer { background: #15151c; }
body.dark #ai { background: #1c1c28; border-left-color: #2e2e40; }
body.dark .msg.user b { color: #aab; }
body.dark .quick button { background: #2e2e40; border-color: #3a3a4d; color: #e4e4ee; }
body.dark .row input,
body.dark .settings input, body.dark .settings select {
  background: #2e2e40; border-color: #3a3a4d; color: #e4e4ee; }
body.dark .settings { background: #1c1c28; border-color: #2e2e40; }
body.dark .settings label { color: #9aa0b8; }
body.dark code { background: #2e2e40; color: #e4e4ee; }

/* «Отправить как заявку» — модальное окно интеграции с тендерной площадкой. */
.modal { position: fixed; inset: 0; background: rgba(20,20,30,.45);
  display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-box { background: #fff; border-radius: 10px; padding: 18px 20px;
  width: 380px; max-width: 92vw; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.modal-box h3 { margin: 0 0 6px; color: #7c5cff; }
.modal-box label { display: flex; flex-direction: column; font-size: 12px;
  color: #555; gap: 3px; margin-bottom: 8px; }
.modal-box input, .modal-box textarea {
  padding: 6px 8px; border: 1px solid #d8d8e4; border-radius: 6px;
  font-size: 14px; font-family: inherit; }
.modal-box .row { margin-top: 10px; }
.modal-box .row button { flex: 1; padding: 8px; border-radius: 6px; border: 0;
  cursor: pointer; font-size: 14px; background: #7c5cff; color: #fff; }
.modal-box .row button.ghost { background: #f0f0f5; color: #333;
  border: 1px solid #d8d8e4; }
#reqResult { font-size: 13px; line-height: 1.5; }
#reqResult .ok { color: #1a9d5a; font-weight: 600; }
#reqResult dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px;
  margin: 8px 0; }
#reqResult dt { color: #888; } #reqResult dd { margin: 0; }
body.dark .modal-box { background: #1c1c28; color: #e4e4ee; }
body.dark .modal-box label { color: #9aa0b8; }
body.dark .modal-box input, body.dark .modal-box textarea {
  background: #2e2e40; border-color: #3a3a4d; color: #e4e4ee; }
body.dark .modal-box .row button.ghost { background: #2e2e40;
  border-color: #3a3a4d; color: #e4e4ee; }

/* «Мои заявки» — список отправленных заявок со статусами. */
.modal-wide { width: 560px; }
#myReqList { max-height: 50vh; overflow: auto; margin: 8px 0; }
#myReqList table { width: 100%; border-collapse: collapse; font-size: 13px; }
#myReqList th, #myReqList td { text-align: left; padding: 6px 8px;
  border-bottom: 1px solid #ececf2; }
#myReqList th { color: #888; font-weight: 600; }
#myReqList .empty { color: #9aa0b8; padding: 12px; text-align: center; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px;
  font-size: 12px; background: #eef0ff; color: #5a4bd0; }
.badge.published { background: #e6f7ee; color: #1a9d5a; }
.badge.closed { background: #f0f0f5; color: #888; }
.badge.new { background: #ffece0; color: #d2691e; }
body.dark #myReqList th, body.dark #myReqList td { border-color: #2e2e40; }
body.dark .badge { background: #2e2e40; color: #b9b0ff; }
body.dark .badge.new { background: #3a2a1e; color: #f0a868; }

/* Phase 4: offer comparison deep-link, expandable offers, deep-link highlight */
#myReqList .cmp { color: #5a4bd0; text-decoration: none; font-weight: 600; }
#myReqList .cmp:hover { text-decoration: underline; }
#myReqList .linklike { background: none; border: 0; color: #7c5cff;
  cursor: pointer; font: inherit; padding: 0; }
#myReqList .linklike:hover { text-decoration: underline; }
#myReqList tr.req-row.hl > td { background: #fff7e6; }
#myReqList .offers { padding: 4px 2px 8px; }
#myReqList .offers-tbl { width: 100%; font-size: 12px; }
#myReqList .offers-tbl th { color: #9aa0b8; }
body.dark #myReqList .cmp { color: #b9b0ff; }
body.dark #myReqList tr.req-row.hl > td { background: #3a3320; }

/* ── «Фото → PDF» (3-шаговая модалка) ─────────────────────────────────── */
.i2p .i2p-steps { display: flex; gap: 6px; margin: 4px 0 12px; }
.i2p-dot { font-size: 12px; color: #9aa0b8; background: #f0f0f5;
  border-radius: 12px; padding: 3px 10px; }
.i2p-dot.on { background: #7c5cff; color: #fff; }
.i2p-step { max-height: 60vh; overflow: auto; }

/* Шаг 1 — сетка выбранных миниатюр */
.i2p-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px; margin: 4px 0 10px; }
.i2p-cell { position: relative; aspect-ratio: 3/4; border-radius: 8px;
  overflow: hidden; background: #f0f0f5; }
.i2p-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.i2p-num { position: absolute; left: 4px; bottom: 4px; min-width: 18px;
  height: 18px; padding: 0 4px; border-radius: 9px; background: rgba(20,20,30,.7);
  color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.i2p-x { position: absolute; top: 3px; right: 3px; width: 20px; height: 20px;
  border: 0; border-radius: 50%; background: rgba(20,20,30,.6); color: #fff;
  font-size: 15px; line-height: 1; cursor: pointer; padding: 0; }
.i2p-x:hover { background: #e2426a; }
.i2p-add { display: flex; align-items: center; justify-content: center;
  border: 1.5px dashed #c8c8d8; border-radius: 8px; padding: 14px;
  color: #7c5cff; cursor: pointer; font-size: 14px; font-weight: 600; }
.i2p-add:hover { background: #f6f4ff; border-color: #7c5cff; }

/* Шаг 2 — карточки с предпросмотром и инструментами */
.i2p-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px; margin: 4px 0; }
.i2p-card { border: 1px solid #ececf2; border-radius: 10px; padding: 8px;
  background: #fafaff; }
.i2p-preview { height: 150px; display: grid; place-items: center;
  overflow: hidden; background: #fff; border-radius: 6px; }
.i2p-preview img { max-width: 130px; max-height: 130px; transition: transform .15s; }
.i2p-tools { display: flex; gap: 2px; justify-content: center; margin-top: 6px; }
.i2p-tools button { flex: 1; border: 1px solid #e0e0ea; background: #fff;
  border-radius: 6px; padding: 4px 0; cursor: pointer; font-size: 14px; }
.i2p-tools button:hover { background: #efeaff; border-color: #7c5cff; }
.i2p-cap { font-size: 11px; color: #888; text-align: center; margin-top: 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Шаг 3 — настройки */
.i2p-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.modal-box select { padding: 6px 8px; border: 1px solid #d8d8e4;
  border-radius: 6px; font-size: 14px; font-family: inherit; background: #fff; }
.i2p-check { flex-direction: row !important; align-items: center; gap: 8px !important;
  font-size: 13px !important; color: #333 !important; cursor: pointer; }
.i2p-check input { width: auto; }
.i2p-err { background: #fdecef; color: #c0334f; border-radius: 6px;
  padding: 8px 10px; font-size: 13px; margin-top: 8px; }

body.dark .i2p-dot { background: #2e2e40; color: #9aa0b8; }
body.dark .i2p-dot.on { background: #7c5cff; color: #fff; }
body.dark .i2p-cell, body.dark .i2p-preview { background: #2a2a3a; }
body.dark .i2p-card { background: #232331; border-color: #34344a; }
body.dark .i2p-add { border-color: #3a3a4d; color: #b9b0ff; }
body.dark .i2p-add:hover { background: #2a2740; }
body.dark .i2p-tools button { background: #2e2e40; border-color: #3a3a4d; color: #e4e4ee; }
body.dark .modal-box select { background: #2e2e40; border-color: #3a3a4d; color: #e4e4ee; }
body.dark .i2p-check { color: #e4e4ee !important; }
body.dark .i2p-err { background: #3a2027; color: #f0939f; }
