/* Раздел «Документы»: список, мастер, редактор с листом как в Word. */

/* ---------- Общее ---------- */

.doc-page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
}

.doc-page-head h1 {
    margin: 4px 0 8px;
    font-size: 28px;
    line-height: 1.2;
}

.doc-back {
    color: #93c5fd;
    text-decoration: none;
    font-size: 14px;
}

.doc-back:hover {
    text-decoration: underline;
}

button.doc-back {
    border: 0;
    padding: 0;
    background: none;
    font: inherit;
    font-size: 14px;
    cursor: pointer;
}

/* Куда ляжет новый документ (каталог, открытый из «Файлов»). */
.doc-place {
    margin: 0;
    color: #94a3b8;
    font-size: 14px;
}

.doc-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 36px;
    box-sizing: border-box;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 8px 14px;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.1;
    white-space: nowrap;
    color: #fff;
    text-decoration: none;
    cursor: pointer;
}

.doc-btn:disabled {
    opacity: .6;
    cursor: not-allowed;
}

.doc-btn-primary {
    background: #2563eb;
    border-color: #2563eb;
}

.doc-btn-primary:hover:not(:disabled) {
    background: #1d4ed8;
}

.doc-btn-secondary {
    background: #334155;
    border-color: #334155;
}

.doc-btn-secondary:hover:not(:disabled),
.doc-btn-secondary.is-active {
    background: #475569;
}

.doc-btn-ghost {
    background: transparent;
    border-color: #475569;
    color: #cbd5e1;
}

.doc-btn-ghost:hover:not(:disabled) {
    border-color: #94a3b8;
    color: #fff;
}

/* «Удалить» в строке списка — тихая кнопка: не ярче названия документа. */
.doc-btn-ghost.is-danger {
    border-color: transparent;
    color: #fca5a5;
}

.doc-btn-ghost.is-danger:hover:not(:disabled) {
    border-color: rgba(248, 113, 113, .5);
    color: #fecaca;
}

.doc-btn-sm {
    min-height: 30px;
    padding: 5px 10px;
    font-size: 13px;
}

.doc-btn-lg {
    min-height: 42px;
    padding: 10px 20px;
    font-size: 15px;
}

.doc-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 0;
    background: transparent;
    color: #94a3b8;
    padding: 4px 6px;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
}

.doc-icon-btn:hover:not(:disabled) {
    color: #fff;
}

.doc-panel {
    border: 1px solid #334155;
    border-radius: 12px;
    background: #0f172a;
    padding: 18px;
    margin-bottom: 18px;
}

.doc-empty {
    color: #cbd5e1;
    line-height: 1.55;
}

.doc-alert {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    border-radius: 10px;
    padding: 10px 14px;
    margin-bottom: 14px;
    font-weight: 600;
}

.doc-alert-error {
    background: rgba(220, 38, 38, .15);
    border: 1px solid rgba(220, 38, 38, .45);
    color: #fecaca;
}

.doc-alert-info {
    background: rgba(37, 99, 235, .15);
    border: 1px solid rgba(37, 99, 235, .45);
    color: #bfdbfe;
}

.doc-hint {
    color: #94a3b8;
    font-size: 13px;
    line-height: 1.45;
}

.doc-note {
    border: 1px solid rgba(245, 158, 11, .5);
    background: rgba(245, 158, 11, .1);
    color: #fde68a;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
}

/* ---------- Список ---------- */

.doc-filter {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.doc-filter input,
.doc-search input {
    flex: 1 1 auto;
    width: 100%;
    max-width: 560px;
    box-sizing: border-box;
    border-color: #334155;
}

.doc-list {
    list-style: none;
    margin: 0;
    padding: 0;
    border: 1px solid #334155;
    border-radius: 12px;
    overflow: hidden;
}

.doc-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
    background: #0f172a;
    border-bottom: 1px solid #263449;
}

.doc-item:last-child {
    border-bottom: 0;
}

.doc-item:hover {
    background: #111c30;
}

.doc-item-main {
    min-width: 0;
}

.doc-item-title {
    color: #c4b5fd;
    font-weight: 700;
    font-size: 15px;
    text-decoration: none;
}

.doc-item-title:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.doc-item-meta {
    margin-top: 4px;
    color: #94a3b8;
    font-size: 13px;
}

.doc-item-meta span + span::before {
    content: " · ";
}

.doc-item-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* ---------- Мастер ---------- */

.doc-search {
    margin-bottom: 18px;
}

.doc-type-group {
    margin-bottom: 18px;
}

.doc-type-group h2 {
    margin: 0 0 10px;
    font-size: 16px;
    color: #cbd5e1;
}

.doc-type-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.doc-type-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    box-sizing: border-box;
    text-align: left;
    background: #111827;
    border: 1px solid #334155;
    border-radius: 12px;
    padding: 14px 16px;
    color: #e5e7eb;
    font: inherit;
    cursor: pointer;
}

.doc-type-card b {
    font-size: 15px;
    line-height: 1.3;
}

.doc-type-card span {
    color: #94a3b8;
    font-size: 13px;
    line-height: 1.45;
}

.doc-type-card:hover,
.doc-type-card:focus-visible {
    border-color: #7c3aed;
    background: #161f35;
}

.doc-type-card:disabled {
    cursor: default;
    opacity: .6;
}

.doc-type-card.is-busy {
    opacity: 1;
    border-color: #7c3aed;
}

.doc-head-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.doc-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    color: #b8c7dc;
}

.doc-field > span {
    font-weight: 600;
}

.doc-field small {
    color: #8193ab;
    font-size: 12px;
}

.doc-field input,
.doc-field select,
.doc-field textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #475569;
    background: #020617;
    color: #fff;
    font: inherit;
    font-size: 14px;
}

.doc-field textarea {
    resize: vertical;
    line-height: 1.45;
}

.doc-field input:focus,
.doc-field select:focus,
.doc-field textarea:focus {
    outline: none;
    border-color: #7c3aed;
}

.doc-form-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

/* ---------- Редактор ---------- */

.doc-editor-page {
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: calc(100vh - 56px);
    min-height: 520px;
    min-width: 0;
}

.doc-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.doc-title-input {
    flex: 1 1 280px;
    min-width: 200px;
    font-size: 18px;
    font-weight: 700;
    border-color: transparent;
    background: transparent;
    color: #f8fafc;
}

.doc-title-input:hover {
    border-color: #334155;
}

.doc-title-input:focus {
    outline: none;
    border-color: #7c3aed;
    background: #020617;
}

.doc-save-state {
    color: #94a3b8;
    font-size: 13px;
    white-space: nowrap;
}

.doc-save-state.is-error {
    color: #fca5a5;
    white-space: normal;
}

/* Только просмотр: название — текстом, рядом тихая пометка. */
.doc-title-text {
    flex: 1 1 280px;
    min-width: 200px;
    margin: 0;
    padding: 8px 0;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
    color: #f8fafc;
    overflow-wrap: anywhere;
}

.doc-readonly-badge {
    color: #94a3b8;
    font-size: 13px;
    white-space: nowrap;
}

.doc-top-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.doc-details {
    flex-shrink: 0;
    border: 1px solid #263449;
    border-radius: 12px;
    background: #0f172a;
    padding: 10px 14px;
}

.doc-details summary {
    cursor: pointer;
    font-weight: 600;
    color: #cbd5e1;
}

.doc-details summary span {
    color: #94a3b8;
    font-weight: 400;
}

.doc-details[open] summary {
    margin-bottom: 12px;
}

/* Раскрытые данные не вытесняют лист: на ноутбуке поля прокручиваются внутри блока. */
.doc-details-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    max-height: 40vh;
    overflow-y: auto;
    padding-right: 4px;
}

.doc-field-wide {
    grid-column: 1 / -1;
}

.doc-readonly {
    color: #e5e7eb;
    font-size: 14px;
}

.doc-readonly.is-text {
    white-space: pre-line;
    line-height: 1.45;
}

/* Лист не сжимается до полоски: если сверху много всего, прокручивается страница. */
.doc-workspace {
    flex: 1;
    min-height: 360px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 14px;
}

.doc-editor-page.is-readonly .doc-workspace {
    grid-template-columns: minmax(0, 1fr);
}

.doc-paper-column {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    border: 1px solid #263449;
    border-radius: 16px;
    background: #0b1220;
    overflow: hidden;
}

.doc-chat-column {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border: 1px solid #263449;
    border-radius: 16px;
    background: #0f172a;
    padding: 14px;
}

/* В узкой колонке кнопки заголовка чата («Очистить историю», «Скрыть») переносятся, а не вылезают за край. */
.doc-chat-column .agent-head,
.doc-chat-column .agent-head-actions {
    flex-wrap: wrap;
    row-gap: 6px;
}

.doc-notice {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    flex-shrink: 0;
    padding: 9px 14px;
    border-bottom: 1px solid #263449;
    background: rgba(124, 58, 237, .14);
    color: #ddd6fe;
    font-size: 14px;
}

.doc-notice > span:first-child {
    flex: 1 1 260px;
}

.doc-notice-warn {
    background: rgba(245, 158, 11, .12);
    color: #fde68a;
}

.doc-notice-progress {
    background: rgba(37, 99, 235, .14);
    color: #bfdbfe;
}

.doc-notice-progress > span:first-child {
    flex: 0 0 auto;
}

.doc-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(191, 219, 254, .35);
    border-top-color: #bfdbfe;
    border-radius: 50%;
    animation: doc-spin .9s linear infinite;
}

@keyframes doc-spin {
    to { transform: rotate(360deg); }
}

.doc-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-wrap: wrap;
    flex-shrink: 0;
    padding: 6px 10px;
    border-bottom: 1px solid #263449;
    background: #111827;
}

.doc-tool {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 6px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: #cbd5e1;
    font: inherit;
    font-size: 15px;
    cursor: pointer;
}

.doc-tool:hover {
    background: #1f2937;
    color: #fff;
}

.doc-tool.is-on {
    background: #312e81;
    border-color: #4f46e5;
    color: #fff;
}

.doc-tool-b {
    font-weight: 800;
}

.doc-tool-i {
    font-style: italic;
    font-family: Georgia, "Times New Roman", serif;
}

.doc-tool-u {
    text-decoration: underline;
}

.doc-tool-text {
    font-size: 13px;
    font-weight: 600;
    padding: 0 10px;
}

.doc-tool-sep {
    width: 1px;
    height: 20px;
    margin: 0 6px;
    background: #334155;
}

.doc-paper-scroll {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 24px 20px 48px;
    background: #1e293b;
    scroll-behavior: auto;
}

/* Лист прячется, пока редактор не встанет на сохранённое место в тексте, — без прокрутки на глазах. */
.doc-paper-scroll:not([data-ready]) .doc-paper {
    visibility: hidden;
}

/* Лист: A4, Times New Roman 14, поля как в Word — классы те же, что в выгрузке (DocumentCatalog.FormatRules). */
.doc-paper {
    box-sizing: border-box;
    width: 100%;
    max-width: 21cm;
    min-height: 29.7cm;
    margin: 0 auto;
    padding: 2cm clamp(14px, 4%, 1.5cm) 2cm clamp(18px, 7%, 3cm);
    background: #fff;
    color: #111;
    box-shadow: 0 4px 24px rgba(0, 0, 0, .45);
    font-family: "Times New Roman", Times, serif;
    font-size: 14pt;
    line-height: 1.15;
    overflow-wrap: break-word;
    outline: none;
    cursor: text;
}

.doc-paper.is-readonly {
    cursor: default;
}

.doc-paper p {
    margin: 0;
    text-align: justify;
    text-indent: 1.25cm;
}

.doc-paper p.header {
    margin-left: 50%;
    text-align: left;
    text-indent: 0;
}

.doc-paper p.title {
    margin-top: 12pt;
    text-align: center;
    text-indent: 0;
    font-weight: bold;
}

.doc-paper p.subtitle {
    margin-bottom: 12pt;
    text-align: center;
    text-indent: 0;
}

.doc-paper p.right {
    text-align: right;
    text-indent: 0;
}

.doc-paper p.center {
    text-align: center;
    text-indent: 0;
}

.doc-paper p.left {
    text-align: left;
    text-indent: 0;
}

.doc-paper p.noindent {
    text-indent: 0;
}

.doc-paper ol,
.doc-paper ul {
    margin: 0;
    padding-left: 1.25cm;
}

.doc-paper li {
    text-align: justify;
}

.doc-paper table {
    width: 100%;
    margin: 6pt 0;
    border-collapse: collapse;
}

.doc-paper td,
.doc-paper th {
    border: 1px solid #000;
    padding: 2pt 5pt;
    text-align: left;
    vertical-align: top;
    color: #111;
}

.doc-paper td p,
.doc-paper th p {
    text-indent: 0;
    text-align: left;
}

/* ---------- Версии ---------- */

.doc-versions {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 1500;
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: min(420px, 100vw);
    box-sizing: border-box;
    padding: 18px;
    overflow-y: auto;
    background: #0f172a;
    border-left: 1px solid #334155;
    box-shadow: -20px 0 50px rgba(0, 0, 0, .45);
}

.doc-versions-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.doc-versions-head h3 {
    margin: 0;
}

.doc-versions:focus,
.doc-preview:focus {
    outline: none;
}

.doc-versions > .doc-btn {
    align-self: flex-start;
}

.doc-version-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.doc-version {
    border: 1px solid #263449;
    border-radius: 10px;
    padding: 10px 12px;
    background: #111827;
}

.doc-version.by-assistant {
    border-left: 3px solid #7c3aed;
}

.doc-version-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 14px;
}

.doc-version-head span {
    color: #a5b4fc;
}

.doc-version-note {
    margin-top: 4px;
    color: #94a3b8;
    font-size: 13px;
}

.doc-version-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.doc-preview-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1600;
    display: flex;
    justify-content: center;
    padding: 24px;
    background: rgba(2, 6, 23, .78);
}

.doc-preview {
    display: flex;
    flex-direction: column;
    width: min(22.5cm, 100%);
    max-height: 100%;
    border: 1px solid #334155;
    border-radius: 14px;
    background: #0f172a;
    overflow: hidden;
}

.doc-preview-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 16px;
    border-bottom: 1px solid #263449;
}

.doc-preview-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.doc-preview-title span {
    color: #94a3b8;
    font-size: 13px;
}

.doc-preview-actions {
    display: flex;
    gap: 8px;
}

.doc-preview-scroll {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 20px;
    background: #1e293b;
}

/* Затемнение под выдвижным чатом на узком экране: щелчок по нему закрывает чат. */
.doc-chat-backdrop {
    display: none;
}

/* Ноутбук: чат ассистента — выдвижной справа, лист — во всю ширину. Выдвигает его кнопка «Ассистент» в верхней строке. */
@media (max-width: 1200px) {
    .doc-workspace {
        grid-template-columns: minmax(0, 1fr);
    }

    .doc-chat-column {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        z-index: 1400;
        width: min(420px, 92vw);
        box-sizing: border-box;
        border-radius: 0;
        box-shadow: -20px 0 50px rgba(0, 0, 0, .45);
        transform: translateX(105%);
        transition: transform .2s ease;
    }

    .doc-editor-page.chat-open .doc-chat-column {
        transform: none;
    }

    .doc-editor-page.chat-open .doc-chat-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1390;
        background: rgba(2, 6, 23, .45);
    }

    .doc-editor-page .doc-only-wide {
        display: none;
    }

    .doc-details-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Широкий экран: чат — колонкой справа; скрытый чат возвращает кнопка «Ассистент» в верхней строке. */
@media (min-width: 1201px) {
    .doc-editor-page .doc-only-narrow,
    .doc-editor-page:not(.chat-hidden) .doc-chat-show {
        display: none;
    }

    .doc-editor-page.chat-hidden .doc-workspace {
        grid-template-columns: minmax(0, 1fr);
    }

    .doc-editor-page.chat-hidden .doc-chat-column {
        display: none;
    }
}

@media (max-width: 720px) {
    .doc-page-head,
    .doc-item {
        flex-direction: column;
        align-items: stretch;
    }

    .doc-details-grid {
        grid-template-columns: 1fr;
    }
}

/* ---------- Карточка данных и чат «Другого документа» ---------- */

/* Пока текст — нетронутая заготовка, лист скрыт (редактор на странице работает): вместо него карточка данных или чат. */
.doc-editor-page.is-setup .doc-paper-scroll,
.doc-editor-page.is-pending .doc-paper-scroll {
    display: none;
}

.doc-editor-page.is-setup .doc-workspace {
    grid-template-columns: minmax(0, 1fr) 420px;
}

.doc-setup {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 22px 24px 28px;
    background: #0f172a;
}

.doc-setup-loading {
    padding: 22px 24px;
}

.doc-setup-head {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-bottom: 14px;
    border-bottom: 1px solid #263449;
}

.doc-setup-kicker {
    color: #a78bfa;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.doc-setup-head h2 {
    margin: 0;
    font-size: 20px;
    line-height: 1.3;
    color: #f8fafc;
}

.doc-setup-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    max-width: 860px;
}

.doc-setup .doc-hint,
.doc-setup .doc-note,
.doc-setup .doc-form-actions {
    max-width: 860px;
}

/* Подсказка у главной кнопки карточки данных: «Опишите документ» после щелчка без описания — заметнее. */
.doc-form-actions .doc-action-hint {
    flex-basis: 100%;
    color: #94a3b8;
    font-size: 13px;
}

.doc-form-actions .doc-action-hint.is-warn {
    color: #fde68a;
}

/* «Другой документ» с ассистентом: ни формы, ни листа — чат во всю рабочую область, по центру. */
.doc-editor-page.is-ai .doc-workspace {
    grid-template-columns: minmax(0, 1fr);
}

.doc-editor-page.is-ai .doc-paper-column {
    display: none;
}

.doc-editor-page.is-ai .doc-chat-column {
    width: 100%;
    max-width: 900px;
    justify-self: center;
    box-sizing: border-box;
    padding: 18px 22px;
}

.doc-editor-page.is-ai .agent-input textarea {
    min-height: 84px;
}

.doc-ai-intro {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px 12px;
    flex-wrap: wrap;
    flex-shrink: 0;
    padding-bottom: 12px;
    margin-bottom: 12px;
    border-bottom: 1px solid #263449;
}

.doc-ai-picked {
    flex: 1 1 240px;
    color: #c4b5fd;
    font-size: 13px;
}

.doc-ai-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-left: auto;
}

/* Ноутбук и телефон: пока документ не составлен, чат не выдвижной — он на странице, под карточкой данных. */
@media (max-width: 1200px) {
    .doc-editor-page.is-setup,
    .doc-editor-page.is-pending {
        height: auto;
    }

    .doc-editor-page.is-setup .doc-workspace {
        grid-template-columns: minmax(0, 1fr);
    }

    .doc-editor-page.is-setup .doc-chat-column,
    .doc-editor-page.is-pending .doc-chat-column,
    .doc-editor-page.is-ai .doc-chat-column {
        position: static;
        width: auto;
        transform: none;
        transition: none;
        box-shadow: none;
        border-radius: 16px;
        z-index: auto;
    }

    .doc-editor-page.is-ai .doc-chat-column {
        width: 100%;
    }

    .doc-editor-page.is-setup .doc-chat-column,
    .doc-editor-page.is-pending .doc-chat-column {
        height: min(560px, 80vh);
    }

    .doc-setup {
        overflow: visible;
    }
}

@media (max-width: 720px) {
    .doc-setup {
        padding: 16px 14px 20px;
    }

    .doc-setup-fields {
        grid-template-columns: 1fr;
    }

    .doc-editor-page.is-ai .doc-chat-column {
        padding: 14px;
    }

    .doc-head-actions .doc-btn {
        flex: 1 1 auto;
        justify-content: center;
    }
}
