/* Система заявок, дизайн "Переписка" (утверждён 2026-10-18, образец mockups/v3-inbox). Все стили, без CSS-библиотек.
   Шрифт Inter и значки Bootstrap Icons подключаются отдельными файлами из assets/vendor. */

:root {
    --bg: #fff;
    --page: #fafafb;
    --side: #f6f6f7;
    --text: #1d1f24;
    --muted: #6e727b;
    --line: #e6e7ea;
    --hover: #f1f2f4;
    --sel: #eef3fd;
    --primary: #2f6fde;
    --primary-dark: #255fc4;
    --danger: #c9483f;
    --ok: #3f9265;
    --warn: #b7791f;
    --st-new: #2f6fde;
    --st-work: #d08a1d;
    --st-passed: #8a63c9;
    --st-wait: #8b8f99;
    --st-closed: #3f9265;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 "Inter", "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
h1, h2, h3 { margin: 0; }

/* ---------- Каркас ---------- */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); height: 100vh; }
.app.inbox { grid-template-columns: 236px 360px minmax(0, 1fr); }

.side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 10px; min-height: 0; }
.side-top { display: flex; align-items: center; padding: 0 6px 12px; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; color: var(--text); text-decoration: none; }
.logo i { color: var(--primary); font-size: 20px; }
.side-hide { display: none; margin-left: auto; }
.btn-wide { width: 100%; padding: 8px; margin-bottom: 12px; }
.folders { display: flex; flex-direction: column; gap: 1px; overflow-y: auto; flex: 1; }
.folders a {
    display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: #3a3d45; text-decoration: none; font-weight: 500;
}
.folders a:hover { background: var(--hover); }
.folders a.active { background: #e6edfb; color: var(--primary); font-weight: 600; }
.folders a i { width: 16px; text-align: center; color: var(--muted); }
.folders a.active i { color: var(--primary); }
.folders .badge { margin-left: auto; background: var(--primary); color: #fff; font-size: 11px; border-radius: 9px; padding: 0 6px; line-height: 17px; }
.folders-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 14px 10px 4px; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 10px 6px 0; border-top: 1px solid var(--line); margin-top: 8px; }
.side-user-name { display: flex; flex-direction: column; min-width: 0; flex: 1; font-size: 13px; }
.side-user-name b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user-name span { color: var(--muted); font-size: 12px; }
.side-shade { display: none; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--page); overflow-y: auto; }
.page-head { display: flex; align-items: center; gap: 10px; padding: 14px 20px; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.page-head h1 { font-size: 17px; font-weight: 700; }
.page-head .head-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.page-body { padding: 20px; }
.narrow { max-width: 780px; }
.menu-btn { display: none; }

/* ---------- Кнопки ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 8px; border: 1px solid var(--line);
    background: #fff; padding: 5px 11px; cursor: pointer; font-weight: 600; font-size: 13px; white-space: nowrap; text-decoration: none; color: var(--text);
}
.btn:hover { background: var(--hover); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b23c34; }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent; cursor: pointer; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.link-btn { border: 0; background: none; color: var(--primary); cursor: pointer; padding: 0; }
.copy { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 3px; }
.copy:hover { color: var(--text); }

/* ---------- Блоки, сообщения ---------- */
.box { background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.box + .box { margin-top: 14px; }
.box-head { padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 700; display: flex; align-items: center; gap: 8px; }
.box-body { padding: 16px; }
.box-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.alert { border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; border: 1px solid; }
.alert-ok { background: #f2f8f4; border-color: #cfe5d7; }
.alert-err { background: #fbf2f1; border-color: #efd0cd; }
.alert-warn { background: #fbf6ee; border-color: #ecdcbf; }
.after-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- Формы ---------- */
.field { margin-bottom: 14px; }
.field-label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.req::after { content: " *"; color: var(--danger); }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.err-text { color: var(--danger); font-size: 12px; margin-top: 4px; display: none; }
.has-error .err-text { display: block; }
.input {
    width: 100%; border: 1px solid #d9dbe0; border-radius: 8px; padding: 7px 10px; background: #fff; outline: 0;
}
.input:focus { border-color: #a9c1ee; box-shadow: 0 0 0 3px #e6eefc; }
.has-error .input, .input.is-error { border-color: var(--danger); }
textarea.input { resize: vertical; min-height: 80px; }
select.input { padding-right: 6px; }
.field-x { position: relative; }
.field-x .input { padding-right: 30px; }
.field-x .x-btn {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: none; color: #a3a7af;
    padding: 0 4px; cursor: pointer; display: none; line-height: 1;
}
.field-x textarea ~ .x-btn { top: 16px; }
.field-x.has-value .x-btn { display: block; }
.field-x .x-btn:hover { color: var(--text); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 3px 0; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { appearance: none; width: 36px; height: 20px; border-radius: 10px; background: #cfd2d8; position: relative; cursor: pointer; margin: 0; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { left: 18px; }

.chip-check { position: absolute; opacity: 0; pointer-events: none; }
.chip {
    display: inline-flex; align-items: center; gap: 6px; border: 1px solid #d9dbe0; border-radius: 16px; padding: 4px 12px;
    margin: 0 6px 6px 0; cursor: pointer; background: #fff; user-select: none;
}
.chip-check:checked + .chip { border-color: var(--primary); background: var(--sel); color: var(--primary-dark); }
.chip-check:disabled + .chip { opacity: .45; cursor: default; }
.chip-user { border-color: var(--primary); background: var(--sel); color: var(--primary-dark); }
.chip-user .bi-x { cursor: pointer; }

.drop-zone { border: 1px dashed #c4c7cd; border-radius: 10px; padding: 14px; text-align: center; color: var(--muted); background: #fbfbfc; }
.drop-zone.over { border-color: var(--primary); background: var(--sel); }
.drop-buttons { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.files { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.file { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px; font-size: 12px; background: #fff; max-width: 100%; color: var(--text); text-decoration: none; }
.file span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file i { color: var(--muted); font-size: 16px; }
.file .bi-file-earmark-pdf { color: var(--danger); }
.file .file-del { border: 0; background: none; color: var(--danger); cursor: pointer; padding: 0 0 0 4px; }
.file-thumb { width: 22px; height: 22px; border-radius: 4px; background: center / cover no-repeat #eef0f3; flex: none; }

/* ---------- Выпадающие меню ---------- */
.dd { position: relative; display: inline-block; }
.dd-menu {
    position: absolute; top: calc(100% + 4px); left: 0; z-index: 60; min-width: 200px; background: #fff; border: 1px solid var(--line);
    border-radius: 10px; box-shadow: 0 10px 28px rgba(20, 24, 33, .14); padding: 5px; display: none;
}
.dd.open .dd-menu { display: block; }
.dd-menu.right { left: auto; right: 0; }
.dd-menu.up { top: auto; bottom: calc(100% + 4px); }
.dd-item { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; text-align: left; padding: 7px 10px; border-radius: 7px; cursor: pointer; color: var(--text); text-decoration: none; white-space: nowrap; }
.dd-item:hover { background: var(--hover); }
.dd-item i { color: var(--muted); width: 16px; }
.dd-item.danger, .dd-item.danger i { color: var(--danger); }
.dd-sep { height: 1px; background: var(--line); margin: 5px 2px; }
.dd-title { font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--muted); padding: 6px 10px 2px; }
.ms-label { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Окна (dialog) ---------- */
dialog.win { border: 0; border-radius: 14px; padding: 0; width: 520px; max-width: calc(100% - 24px); box-shadow: 0 20px 50px rgba(20, 24, 33, .25); color: var(--text); }
dialog.win::backdrop { background: rgba(20, 24, 33, .4); }
.win-head { display: flex; align-items: center; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 700; }
.win-head .icon-btn { margin-left: auto; }
.win-body { padding: 16px 18px; max-height: 70vh; overflow-y: auto; }
.win-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); }

/* ---------- Статусы, аватары ---------- */
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; margin: 0 4px; flex: none; display: inline-block; }
.st-new { color: var(--st-new); }
.st-work { color: var(--st-work); }
.st-passed { color: var(--st-passed); }
.st-wait { color: var(--st-wait); }
.st-closed { color: var(--st-closed); }
.st { display: inline-flex; align-items: center; gap: 2px; white-space: nowrap; font-weight: 600; }
.st > span:last-child { color: var(--text); }
.ava {
    width: 32px; height: 32px; border-radius: 50%; color: #fff; font-size: 12px; font-weight: 600;
    display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.ava.sm { width: 24px; height: 24px; font-size: 10px; }
.ava.is-empty { background: #fff; color: var(--muted); border: 1px dashed #c4c7cd; }

/* ---------- Таблицы и списки ---------- */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 9px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fbfbfc; }
.tbl td { padding: 9px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: #fbfbfc; }
.tbl .num { text-align: right; }
.tbl tfoot td { font-weight: 700; border-top: 1px solid var(--line); background: #fbfbfc; }
.tbl .cell-actions { text-align: right; width: 1%; }
.person { display: flex; align-items: center; gap: 8px; }
.list-foot { display: flex; align-items: center; gap: 10px; padding: 10px 16px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.list-foot select { width: auto; padding: 3px 6px; }
.pager { margin-left: auto; display: flex; gap: 4px; }
.pager .btn { padding: 3px 9px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 0; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 9px 14px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button { border: 0; background: #fff; padding: 5px 11px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted); border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--sel); color: var(--primary); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }

/* ---------- Заявки: список ---------- */
.list-pane { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; min-width: 0; background: #fff; }
.list-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 10px; }
.list-head h1 { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.refresh { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.search { display: flex; align-items: center; gap: 6px; margin: 0 16px 10px; border: 1px solid var(--line); border-radius: 8px; padding: 0 4px 0 10px; }
.search > i { color: var(--muted); }
.search .field-x { flex: 1; min-width: 0; }
.search .field-x input { border: 0; outline: 0; padding: 7px 24px 7px 0; width: 100%; background: transparent; }
.search select { border: 0; border-left: 1px solid var(--line); background: transparent; padding: 6px 4px; color: var(--muted); outline: 0; }
.list { overflow-y: auto; flex: 1; }
.row { padding: 11px 16px; border-bottom: 1px solid var(--line); cursor: pointer; position: relative; }
.row:hover { background: var(--hover); }
.row.selected { background: var(--sel); }
.row.unread::before { content: ""; position: absolute; left: 5px; top: 17px; width: 7px; height: 7px; border-radius: 50%; background: var(--st-new); }
.row-top { display: flex; gap: 8px; align-items: baseline; }
.row-login { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.unread .row-login { font-weight: 700; }
.row-time { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.row-text { color: #4b4f58; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 2px 0 6px; }
.row-foot { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.row-foot .st { font-weight: 500; }
.row-foot .st > span:last-child { color: var(--muted); }
.row-foot .who { margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-empty { padding: 30px 16px; text-align: center; color: var(--muted); }
.list-pane .list-foot { border-top: 1px solid var(--line); padding: 8px 16px; }

/* ---------- Заявки: диалог ---------- */
.conv { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--page); }
.conv-empty { margin: auto; color: var(--muted); text-align: center; }
.conv-head { background: #fff; border-bottom: 1px solid var(--line); padding: 12px 20px; }
.conv-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.back-btn { display: none; }
.conv-title { font-size: 18px; font-weight: 700; }
.conv-title a { color: inherit; text-decoration: none; }
.conv-id { color: var(--muted); }
.conv-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.conv-actions-m { display: none; }
.facts { display: flex; gap: 4px 20px; flex-wrap: wrap; margin-top: 8px; font-size: 13px; color: var(--muted); }
.facts b { color: var(--text); font-weight: 600; }
.conv-msg { margin: 12px 20px 0; }
.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 10px; max-width: 720px; }
.msg-body { min-width: 0; }
.msg-head { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.msg-head b { color: var(--text); font-weight: 600; }
.bubble { background: #fff; border: 1px solid var(--line); border-radius: 4px 12px 12px 12px; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.mine { margin-left: auto; flex-direction: row-reverse; }
.msg.mine .msg-head { text-align: right; }
.msg.mine .bubble { border-radius: 12px 4px 12px 12px; background: #f0f4fb; border-color: #dbe4f3; }
.msg.first .bubble { border-left: 3px solid var(--st-new); }
.msg.transfer .bubble { border-left: 3px solid var(--st-passed); }
.msg.report .bubble { border-left: 3px solid var(--st-closed); }
.msg.wait .bubble { border-left: 3px solid var(--st-wait); }
.bubble-label { font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; letter-spacing: .03em; white-space: normal; }
.sys { align-self: center; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; text-align: center; }
.sys b { color: #44474f; font-weight: 600; }
.composer { background: #fff; border-top: 1px solid var(--line); padding: 12px 20px; }
.composer textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; resize: vertical; min-height: 64px; outline: 0; }
.composer textarea:focus { border-color: #a9c1ee; }
.composer-row { display: flex; gap: 6px; margin-top: 8px; align-items: center; flex-wrap: wrap; }
.composer-row .btn-primary { margin-left: auto; }
.camera-btn { display: none; }

/* ---------- Дерево прав ---------- */
.rights { border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.rights-tools { padding: 10px; border-bottom: 1px solid var(--line); background: #fbfbfc; border-radius: 10px 10px 0 0; }
.rights-tools .toolbar { margin: 8px 0 0; }
.rights-count { margin-left: auto; color: var(--muted); }
.rights-tree { max-height: 440px; overflow-y: auto; padding: 8px 12px; }
.rights-tree ul { list-style: none; margin: 0; padding-left: 24px; }
.rights-tree > ul { padding-left: 0; }
.rights-tree li { padding: 2px 0; }
.rights-tree label { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; }
.rights-tree input { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; }
.rights-tree .r-branch > label { font-weight: 600; }
.rights-tree .r-quick { font-size: 12px; margin-left: 8px; }
.rights-tree .r-quick a { text-decoration: none; }
.rights-tree .r-id { color: #a3a7af; font-size: 12px; }
.rights-tree li.filtered { display: none; }

/* ---------- Оповещения о новых заявках ---------- */
.notify-stack { position: fixed; right: 16px; bottom: 16px; z-index: 90; display: flex; flex-direction: column; gap: 8px; width: 360px; max-width: calc(100% - 32px); }
.notify {
    background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; gap: 12px;
    box-shadow: 0 12px 32px rgba(20, 24, 33, .16); animation: pop .25s ease-out;
}
.notify-icon { width: 34px; height: 34px; border-radius: 50%; background: var(--sel); color: var(--primary); display: flex; align-items: center; justify-content: center; flex: none; }
.notify-body { min-width: 0; }
.notify-title { font-weight: 700; }
.notify-text { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notify-open { margin-top: 6px; }
.notify-close { border: 0; background: none; color: var(--muted); cursor: pointer; align-self: flex-start; margin-left: auto; }
@keyframes pop { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Состояния страницы ---------- */
.view { display: contents; }
.page-state { padding: 40px 16px; text-align: center; color: var(--muted); }
.page-state i { font-size: 28px; display: block; margin-bottom: 6px; }
.boot { min-height: 100vh; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.is-loading { opacity: .6; pointer-events: none; }
.file-link img { display: block; }
.tree-locked { color: var(--muted); font-size: 12px; margin-left: 8px; }

/* ---------- Вход ---------- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--side); padding: 16px; }
.login-box { width: 100%; max-width: 360px; }
.login-logo { text-align: center; margin-bottom: 18px; }
.login-logo i { font-size: 34px; color: var(--primary); }
.login-logo h1 { font-size: 20px; margin-top: 4px; }

/* ---------- Адаптив ---------- */
@media (max-width: 1180px) {
    .app, .app.inbox { grid-template-columns: minmax(0, 1fr); }
    .app.inbox { grid-template-columns: 320px minmax(0, 1fr); }
    .side { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 70; transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 20px rgba(0, 0, 0, .1); }
    .app.side-open .side { transform: none; }
    .app.side-open .side-shade { display: block; position: fixed; inset: 0; z-index: 69; background: rgba(20, 24, 33, .3); }
    .side-hide, .menu-btn { display: inline-block; }
}
@media (max-width: 760px) {
    .app.inbox { grid-template-columns: minmax(0, 1fr); }
    .app.inbox .conv { display: none; }
    .app.inbox.conv-open .list-pane { display: none; }
    .app.inbox.conv-open .conv { display: flex; }
    .back-btn { display: inline-block; }
    .conv-head { padding: 10px 12px; }
    .conv-actions { display: none; }
    .conv-actions-m { display: flex; gap: 6px; width: 100%; }
    .conv-actions-m > .btn { flex: 1; }
    .conv-msg { margin: 10px 12px 0; }
    .messages { padding: 14px 12px; }
    .composer { padding: 10px 12px 52px; }
    .camera-btn { display: inline-flex; }
    .drop-text { display: none; }
    .page-head { padding: 10px 12px; }
    .page-body { padding: 12px 12px 60px; }
    .row2 { grid-template-columns: 1fr; }
    .tbl th, .tbl td { padding: 8px 10px; }
    .list-foot .pager { margin-left: 0; }
}
