/* Document surfaces only. Ordinary message bubbles retain the existing Chats theme. */
.chats-final-stage {
  --doc-paper: #e5f0e9;
  --doc-ink: #294638;
  --doc-muted: #5f7a69;
  --doc-line: #c8dccf;
  --doc-accent: #3f6c52;
  --doc-field: #f5faf6;
}
.chats-final-stage .row-wrap:has(.idoc-document,.idoc-editor) { padding: 5px 0; }
.chats-final-stage .msg-row:has(.idoc-document,.idoc-editor) { width: 100%; min-width: 0; }
.chats-final-stage .msg-col-wrap:has(.idoc-document,.idoc-editor) {
  display: block; position: relative; flex: 1; width: 100%; max-width: 100%; min-width: 0; padding-bottom: 34px;
}
.chats-final-stage .msg-col:has(.idoc-document,.idoc-editor) { width: 100%; min-width: 0; max-width: 100%; gap: 0; }
.chats-final-stage .msg-col-wrap:has(.idoc-document,.idoc-editor) > .message-menu-controls { position: absolute; right: 4px; bottom: 0; height: 32px; gap: 6px; }
.chats-final-stage .msg-row .bubble:has(.idoc-document,.idoc-editor) {
  display: flex; box-sizing: border-box; width: 100%; min-width: 0; padding: 18px 18px 12px;
  border: 1px solid var(--doc-line); border-radius: 22px; background: var(--doc-paper); color: var(--doc-ink);
  box-shadow: 0 2px 3px rgba(41,70,56,.035); font-size: 16px; line-height: 1.65;
}
.chats-final-stage .msg-row.right .bubble:has(.idoc-document,.idoc-editor) { border-top-right-radius: 10px; }
.chats-final-stage .msg-row.left .bubble:has(.idoc-document,.idoc-editor) { border-top-left-radius: 10px; }
.chats-final-stage .msg-row .bubble:has(.idoc-document,.idoc-editor) .bubble-time { color: var(--doc-muted); opacity: 1; margin-top: 12px; font-size: 11px; }
.chats-final-stage .msg-row .bubble:has(.idoc-document,.idoc-editor) .reply-quote { padding: 10px 12px; margin: 0 0 14px; background: rgba(255,255,255,.38); border-left: 2px solid #90b79e; color: var(--doc-muted); border-radius: 9px; }
.chats-final-stage .msg-row .bubble:has(.idoc-document,.idoc-editor) .reply-quote b { color: var(--doc-accent); }
.chats-final-stage .idoc-message-action { align-self: flex-start; border: 0; background: transparent; color: var(--doc-muted); font: inherit; font-size: 12px; line-height: 1.25; padding: 8px 2px; cursor: pointer; }
.chats-final-stage .msg-col-wrap:has(.idoc-document) .idoc-message-action { position: absolute; left: 10px; bottom: 0; max-width: calc(100% - 90px); min-height: 32px; }
.idoc-document { font: inherit; line-height: 1.65; min-width: 0; overflow-wrap: anywhere; text-align: left; }
.idoc-document::before { content: 'ДОКУМЕНТ'; display: block; margin: 0 0 14px; color: var(--doc-muted); font-size: 10px; font-weight: 650; letter-spacing: .11em; }
.idoc-document .idoc-text { white-space: pre-wrap; margin: 10px 0; }
.idoc-document h3.idoc-text { font-size: 1.2em; font-weight: 650; line-height: 1.4; letter-spacing: -.02em; margin-top: 18px; }
.idoc-document ul { padding-left: 22px; margin: 12px 0; }
.idoc-document li + li { margin-top: 5px; }
.idoc-document .idoc-list { padding-left: 14px; border-left: 2px solid #91b69e; }
.idoc-table-scroll { max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; margin: 16px 0; border: 1px solid var(--doc-line); border-radius: 12px; background: #f3f8f4; scrollbar-width: thin; scrollbar-color: #aec8b8 transparent; }
.idoc-document table { border-collapse: separate; border-spacing: 0; table-layout: fixed; width: 100%; min-width: 220px; font-size: 14px; color: inherit; line-height: 1.55; }
.idoc-document th,.idoc-document td { padding: 12px; border-bottom: 1px solid #dbe8df; text-align: left; vertical-align: top; white-space: pre-wrap; overflow-wrap: anywhere; }
.idoc-document th { font-weight: 650; color: #365b46; background: #d7e7dd; border-bottom-color: #bdd5c6; }
.idoc-document td + td,.idoc-document th + th { border-left: 1px solid rgba(190,215,199,.36); }
.idoc-document tr:last-child td,.idoc-document tr:last-child th { border-bottom: 0; }
.idoc-editor { min-width: 0; width: 100%; font-size: 15px; color: var(--doc-ink,#294638); text-align: left; }
.idoc-caption { display: flex; align-items: center; gap: 8px; color: var(--doc-muted); font-size: 12px; font-weight: 600; line-height: 1.4; margin-bottom: 14px; }
.idoc-caption svg { width: 18px; height: 18px; }
.idoc-toolbar { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 4px; padding: 5px; border: 1px solid rgba(157,190,168,.3); border-radius: 14px; background: rgba(255,255,255,.45); }
.idoc-editor button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; box-sizing: border-box; font: inherit; font-size: 12px; line-height: 1.25; border: 1px solid var(--doc-line); border-radius: 10px; color: var(--doc-accent); background: #f7fbf8; padding: 9px 11px; min-height: 40px; cursor: pointer; transition: background-color .15s,border-color .15s; }
.idoc-editor button svg { width: 18px; height: 18px; flex: none; }
.idoc-toolbar button { min-width: 0; min-height: 56px; padding: 7px 3px; flex-direction: column; gap: 5px; border-color: transparent; background: transparent; font-size: 11px; }
.idoc-toolbar button[aria-pressed="true"] { background: #cfe3d5; border-color: #c5ddcd; color: #315c41; }
.idoc-editor button:disabled { opacity: .45; cursor: default; }
.idoc-editor button:focus-visible,.idoc-dialog button:focus-visible { outline: 2px solid #709e7e; outline-offset: 3px; }
.idoc-content { max-height: min(44dvh,440px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; margin: 16px 0 10px; padding: 1px; }
.idoc-editor .idoc-document::before { display: none; }
.idoc-block { border: 1px solid transparent; border-radius: 10px; padding: 4px 6px; }
.idoc-block.selected { border-color: #b7d2bf; background: rgba(255,255,255,.22); }
.idoc-editor .idoc-table-scroll { margin: 5px 0; }
.idoc-editor .idoc-table-scroll table { table-layout: auto; }
.idoc-field { display: block; min-width: 68px; min-height: 1.65em; outline: none; white-space: pre-wrap; color: var(--doc-ink); border-radius: 3px; }
.idoc-field:focus { box-shadow: 0 2px 0 -1px #6e9a7b; }
.idoc-field:empty::before { content: 'Текст…'; color: #819e8b; pointer-events: none; }
.idoc-table-tools { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; padding: 10px 0; border-top: 1px solid var(--doc-line); }
.idoc-context-label { width: 100%; color: var(--doc-muted); font-size: 11px; margin-bottom: 3px; }
.idoc-table-tools button { flex: 1 1 calc(50% - 5px); min-height: 38px; padding: 8px; background: rgba(255,255,255,.45); }
.idoc-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; padding: 12px; border: 1px solid var(--doc-line); border-radius: 12px; background: #f0f7f2; }
.idoc-picker label { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 12px; color: var(--doc-muted); }
.idoc-picker input { box-sizing: border-box; width: 52px; padding: 8px; border: 1px solid #c1d9c9; border-radius: 8px; background: #fff; color: var(--doc-ink); font: inherit; font-size: 16px; }
.idoc-picker [data-doc-action="insert-table"] { background: #d7e9dd; }
.idoc-block-tools { margin-top: 2px; }
.idoc-block-tools button { padding: 7px 0; min-height: 34px; font-size: 11px; border: 0; background: transparent; color: var(--doc-muted); }
.idoc-footer { position: sticky; bottom: 0; z-index: 3; display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 12px; padding: 10px 0 2px; border-top: 1px solid var(--doc-line); background: var(--doc-paper); box-shadow: 0 -8px 12px -12px #345c40; }
.idoc-footer button { min-height: 44px; padding: 11px 17px; font-size: 13px; }
.idoc-footer [data-doc-action="cancel"] { background: transparent; border-color: transparent; }
.idoc-footer [data-doc-action="save"] { background: var(--doc-accent); border-color: var(--doc-accent); color: #fff; }
.idoc-status { font-size: 12px; line-height: 1.5; color: #8c4935; background: #faf1e9; border-radius: 9px; padding: 10px 12px; margin-top: 10px; white-space: normal; }
.idoc-status:empty { display: none; }
.idoc-editor[aria-busy="true"] .idoc-status { color: var(--doc-accent); background: #d7e8dc; }
.idoc-editor[aria-busy="true"] .idoc-status::before { content: ''; display: inline-block; width: 10px; height: 10px; margin-right: 8px; border: 1.5px solid #adc8b6; border-top-color: #426f52; border-radius: 50%; animation: idoc-spin .8s linear infinite; }
.idoc-editor [hidden] { display: none !important; }
.idoc-composer { margin: 4px 0 2px; padding: 16px; border: 1px solid var(--doc-line); border-radius: 22px; background: var(--doc-paper); min-width: 0; }
.chats-final-stage.chat-stage:has(.idoc-editor) .composer-wrap { position: relative; }
.chats-final-stage.chat-stage:has(.idoc-editor) .chat-feed { padding-bottom: 14px; }
.chats-final-stage.chat-stage:has(.idoc-editor) .down-jump { display: none; }
.chats-final-stage .composer-wrap:has(.idoc-composer) { max-height: 74%; overflow-y: auto; overscroll-behavior: contain; padding-top: 4px; }
.idoc-dialog-backdrop { position: absolute; inset: 0; z-index: 200; display: flex; align-items: flex-end; justify-content: center; padding: 12px; background: rgba(30,51,39,.25); }
.idoc-dialog { box-sizing: border-box; width: 100%; max-width: 420px; padding: 24px; border-radius: 24px; border: 1px solid #d9e7de; background: #f3f8f4; color: #294638; box-shadow: 0 16px 48px rgba(30,51,39,.12); font-family: inherit; }
.idoc-dialog-icon { display: flex; width: 40px; height: 40px; align-items: center; justify-content: center; border-radius: 12px; background: #e0eee4; color: #64846f; }
.idoc-dialog-icon svg { width: 22px; height: 22px; }
.idoc-dialog h3 { margin: 16px 0 8px; font-size: 19px; line-height: 1.35; font-weight: 650; letter-spacing: -.02em; }
.idoc-dialog p { margin: 0; color: #657b6c; font-size: 14px; line-height: 1.6; }
.idoc-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.idoc-dialog button { min-height: 44px; border: 1px solid #cadfd1; border-radius: 12px; padding: 11px 15px; background: transparent; color: #45644e; font: inherit; font-size: 13px; cursor: pointer; }
.idoc-dialog button.primary { background: #426d51; color: #fff; border-color: #426d51; }
.idoc-dialog button.danger { background: #f5e7df; color: #8b4c3b; border-color: #e9cbbc; }
@keyframes idoc-spin { to { transform: rotate(360deg); } }
@media (hover:hover) { .idoc-editor button:not(:disabled):hover { background: #e0eee4; } .idoc-footer [data-doc-action="save"]:not(:disabled):hover { background: #33593f; } }
@media (max-width:480px) { .idoc-editor .idoc-field { font-size: 16px; } .idoc-document th,.idoc-document td { padding: 10px; } .idoc-table-tools { gap: 4px; } .idoc-table-tools button { flex: 1 1 calc(25% - 4px); font-size: 10px; padding: 8px 3px; } }
@media (min-width:600px) { .idoc-toolbar button { flex-direction: row; font-size: 12px; min-height: 44px; } .idoc-table-tools button { flex: 0 1 auto; } .idoc-context-label { width: auto; margin: 0 6px 0 0; } .idoc-dialog-backdrop { align-items: center; } }
@media (prefers-reduced-motion:reduce) { .idoc-editor button { transition: none; } .idoc-editor[aria-busy="true"] .idoc-status::before { animation: none; } }
