:root {
    --bg: #f4f6f5;
    --surface: #ffffff;
    --surface-2: #eef2f0;
    --ink: #17211d;
    --ink-2: #40504a;
    --ink-3: #5f6e68;
    --line: #e2e8e4;
    --line-strong: #ccd6d1;
    --accent: #1f6f5c;
    --accent-ink: #ffffff;
    --accent-hover: #195c4c;
    --accent-soft: #e7f1ed;
    --danger: #b3261e;
    --danger-soft: #fdeceb;
    --warn: #8a5300;
    --warn-soft: #fdf3e1;
    /* Внутренние комментарии: тот же тёплый тон, что у предупреждений, но тише. */
    --note-ink: #6f4a06;
    --note-soft: #fdf4d4;
    --note-line: #ecd9a4;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(19, 34, 28, 0.06);
    --shadow-pop: 0 14px 36px rgba(19, 34, 28, 0.16);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { height: 100%; overflow: hidden; background: var(--surface); }
body { height: 100%; overflow: hidden; touch-action: pan-x pan-y; }

/* Закрашиваем safe-area сверху сплошным цветом: на iPhone это убирает
   просвечивающий блюр статус-бара, который исчезал при открытии панели клиента. */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: env(safe-area-inset-top, 0px);
    background: var(--surface);
    z-index: 1;
    pointer-events: none;
}

/* iOS приближает страницу при фокусе на поле, если шрифт меньше 16px:
   в мобильной консоли (PWA) это лишний зум, поэтому держим 16px. */
@media (max-width: 900px) {
    input, select, textarea { font-size: 16px !important; }
}

body {
    margin: 0;
    padding-top: env(safe-area-inset-top, 0px);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.45;
    color: var(--ink);
    /* Сплошной фон под статус-баром: на iPhone в PWA не должно быть блюра контента. */
    background: var(--surface);
    -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }

h1, h2, h3, p { margin: 0; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Кнопки */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 36px;
    padding: 0 12px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    font-weight: 550;
    font-size: 13px;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: var(--accent-ink);
    border-color: var(--accent);
}

.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.55; cursor: default; }

.btn-quiet {
    border-color: var(--line);
    background: var(--surface);
    color: var(--ink-2);
}

.btn-quiet:hover { border-color: var(--line-strong); color: var(--ink); }

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.btn-danger:hover { filter: brightness(0.94); }

.btn-small { min-height: 30px; padding: 0 9px; font-size: 12px; }

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--ink-3);
}

.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.is-complete { color: var(--accent); }

.link-btn {
    padding: 0;
    border: 0;
    background: none;
    color: var(--accent);
    font-size: 13px;
    font-weight: 550;
}

.link-btn:hover { text-decoration: underline; }

/* Вход */
.login-view,
.loading-view {
    display: grid;
    place-items: center;
    min-height: calc(var(--app-height, 100dvh) - env(safe-area-inset-top, 0px));
    padding: 24px;
    background: var(--bg);
}

.loading-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    color: var(--ink-3);
    font-size: 13px;
    text-align: center;
}

.loading-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: loading-spin 0.8s linear infinite;
}

/* Страховка от старого закэшированного app.js: как только показан экран
   входа или кабинет, загрузочная плашка не должна оставаться на странице. */
body:has(#login-view:not([hidden])) .loading-view,
body:has(#shell:not([hidden])) .loading-view { display: none !important; }

@keyframes loading-spin { to { transform: rotate(360deg); } }

.login-card {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: min(380px, 100%);
    padding: 28px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.login-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }

.login-mark, .rail-logo {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 11px;
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 700;
    font-size: 19px;
    letter-spacing: -0.02em;
}

.login-head h1 { font-size: 19px; letter-spacing: -0.01em; }
.login-head p { color: var(--ink-3); font-size: 13px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-2); }

.field-control { position: relative; display: flex; align-items: center; width: 100%; }
.field .field-control input { width: 100%; padding-right: 42px; }
.field-eye {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--ink-3);
    cursor: pointer;
}
.field-eye:hover { background: var(--surface-2); color: var(--ink); }
.field-eye svg { width: 17px; height: 17px; }

.field input, .field select, .field textarea {
    width: 100%;
    min-height: 40px;
    padding: 8px 11px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
    font-size: 14px;
    outline: none;
}

.field input:focus, .field select:focus, .field textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.field textarea { resize: vertical; min-height: 76px; }

/* Родной color-input заполняет всю ширину — держим его образцом цвета, а не полосой. */
.field input[type="color"] { width: 88px; min-height: 36px; padding: 3px; cursor: pointer; }

.form-error {
    margin: 0;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    background: var(--danger-soft);
    color: var(--danger);
    font-size: 13px;
}

.login-foot { margin-top: 4px; color: var(--ink-3); font-size: 12px; text-align: center; }

/* Каркас */
.shell { display: flex; height: calc(var(--app-height, 100dvh) - env(safe-area-inset-top, 0px)); overflow: hidden; }

.rail {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 68px;
    flex: 0 0 68px;
    padding: 14px 0 calc(14px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-right: 1px solid var(--line);
}

.rail-nav { display: flex; flex-direction: column; gap: 4px; margin-top: 22px; }

.rail-btn {
    position: relative;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--ink-3);
}

.rail-btn:hover { background: var(--surface-2); color: var(--ink); }

.rail-btn.is-active { background: var(--accent-soft); color: var(--accent); }

.rail-btn.is-active::before {
    content: "";
    position: absolute;
    left: -12px;
    top: 10px;
    bottom: 10px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--accent);
}

.rail-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
}

.rail-foot { margin-top: auto; }

.rail-avatar {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    overflow: hidden;
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 650;
    font-size: 13px;
}

.rail-avatar img { display: block; width: 100%; height: 100%; object-fit: cover; }

.workspace {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: grid;
    /* Ряд фиксирован по высоте окна: иначе лента сообщений растягивает его и композер уезжает под край. */
    grid-template-rows: minmax(0, 1fr);
    grid-template-columns: 320px minmax(0, 1fr) 320px;
    background: var(--surface);
}

/* Левая колонка */
.list-pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    border-right: 1px solid var(--line);
    background: var(--surface);
}

.pane-head { padding: 16px 16px 10px; border-bottom: 1px solid var(--line); }

.pane-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.pane-title-row h1 { font-size: 17px; letter-spacing: -0.01em; }

.pane-actions { display: flex; gap: 2px; }

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 38px;
    margin-top: 12px;
    padding: 0 11px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg);
    color: var(--ink-3);
}

.search-box:focus-within { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }

.search-box input {
    flex: 1;
    min-width: 0;
    border: 0;
    background: transparent;
    outline: none;
    font-size: 13px;
}

.segmented { display: flex; gap: 18px; margin-top: 10px; }

.seg {
    padding: 4px 0 7px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--ink-3);
    font-size: 13px;
    font-weight: 550;
}

.seg:hover { color: var(--ink); }
.seg.is-active { color: var(--accent); border-bottom-color: var(--accent); }

.list-status { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.list-count { color: var(--ink-3); font-size: 12px; }

.conv-list { flex: 1; overflow-y: auto; overscroll-behavior: contain; }

.conv-item {
    position: relative;
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 10px;
    width: 100%;
    padding: 12px 14px;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: transparent;
    text-align: left;
}

.conv-item:hover { background: var(--bg); }
.conv-item.is-active { background: var(--accent-soft); }

.conv-item.is-active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent);
}

.avatar {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--surface-2);
    color: var(--ink-2);
    font-weight: 650;
    font-size: 13px;
    flex: 0 0 auto;
}

.avatar img { display: block; width: 100%; height: 100%; object-fit: cover; }

.conv-main { min-width: 0; }

.conv-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }

.conv-name {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    overflow: hidden;
    font-weight: 600;
    font-size: 13.5px;
}

.conv-name-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conv-channel {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    color: var(--accent);
}

.conv-channel svg { width: 14px; height: 14px; }
.conv-channel.is-badge {
    width: auto;
    height: 16px;
    padding: 0 5px;
    border-radius: 4px;
    background: var(--accent);
    color: var(--accent-ink);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .2px;
    line-height: 1;
}

.conv-time { flex: 0 0 auto; color: var(--ink-3); font-size: 11px; }

.conv-preview {
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--ink-3);
    font-size: 12.5px;
}

.conv-meta { display: flex; align-items: center; gap: 8px; min-width: 0; margin-top: 5px; }

.conv-meta-text {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--ink-3);
    font-size: 11px;
}


.unread {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    margin-left: auto;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--accent);
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
}

.list-empty { padding: 36px 20px; text-align: center; color: var(--ink-3); font-size: 13px; }

.skeleton { padding: 14px; border-bottom: 1px solid var(--line); }
.skeleton-line { height: 10px; margin-bottom: 8px; border-radius: 5px; background: var(--surface-2); }
.skeleton-line:last-child { margin-bottom: 0; width: 60%; }

/* Чат */
.chat-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; background: var(--bg); }

.chat-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 32px; text-align: center; color: var(--ink-3); }
.chat-empty h2 { font-size: 16px; color: var(--ink-2); }
.chat-empty p { max-width: 280px; font-size: 13px; }
.empty-mark { display: grid; place-items: center; width: 56px; height: 56px; margin-bottom: 6px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); color: var(--accent); }

.chat-active { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-head {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 64px;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.chat-person { min-width: 0; flex: 1; }
.chat-person h2 { font-size: 14.5px; letter-spacing: -0.005em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-person p { color: var(--ink-3); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-actions { display: flex; align-items: center; gap: 6px; }

.status-dot { display: inline-block; width: 7px; height: 7px; margin-right: 4px; border-radius: 50%; background: var(--line-strong); }
.status-dot.online { background: #2e9e63; }

.menu-wrap { position: relative; }

.menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 30;
    min-width: 230px;
    max-height: 320px;
    overflow-y: auto;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-pop);
}

.menu-label { padding: 8px 10px 4px; color: var(--ink-3); font-size: 11px; font-weight: 600; text-transform: none; }

.menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 36px;
    padding: 6px 10px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    text-align: left;
    font-size: 13px;
}

.menu-item:hover { background: var(--surface-2); }
.menu-item.is-current { color: var(--accent); font-weight: 600; }
.menu-item.is-current::after { content: '✓'; margin-left: auto; color: var(--accent); font-size: 14px; font-weight: 700; line-height: 1; }

.messages { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; }

.msg-row { display: flex; flex-direction: column; min-width: 0; max-width: min(560px, 82%); }
.msg-row.in { align-self: flex-start; }
.msg-row.out { align-self: flex-end; align-items: flex-end; }

.msg-bubble { min-width: 0; max-width: 100%; padding: 8px 12px; border-radius: 14px; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; overflow: hidden; }
.msg-row.in .msg-bubble { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.msg-row.out .msg-bubble { background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 5px; }

.msg-meta { display: flex; align-items: center; gap: 6px; max-width: 100%; margin-top: 3px; }
.msg-time { color: var(--ink-3); font-size: 10.5px; white-space: nowrap; }
.tool-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.msg-ticks { opacity: .55; display: inline-block; width: 16px; height: 11px; margin-left: 4px; vertical-align: -1px; background-color: currentColor; -webkit-mask: var(--tick-one) center / contain no-repeat; mask: var(--tick-one) center / contain no-repeat; --tick-one: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 12'%3E%3Cpath d='M5 6.5l3.5 3.5L16 2.5' fill='none' stroke='black' stroke-width='1.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); --tick-two: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 21 12'%3E%3Cpath d='M1.5 6.5L4.8 9.8L11 2.5M9.5 6.5L12.8 9.8L19 2.5' fill='none' stroke='black' stroke-width='1.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.msg-ticks.is-seen { width: 20px; opacity: .7; color: var(--accent); -webkit-mask-image: var(--tick-two); mask-image: var(--tick-two); }
.msg-author { min-width: 0; overflow: hidden; color: var(--ink-3); font-size: 11px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.msg-meta-sep { color: var(--ink-3); font-size: 11px; line-height: 1; }

.msg-system { align-self: center; max-width: 80%; margin: 6px 0; color: var(--ink-3); font-size: 11.5px; text-align: center; }

/* Комментарий видят только сотрудники: реплика с той же подсветкой, что и поле ввода. */
.msg-row.internal { align-self: flex-end; align-items: flex-end; max-width: min(560px, 82%); }
.msg-row.internal .msg-bubble { background: var(--note-soft); color: var(--ink); border: 1px solid var(--note-line); border-bottom-right-radius: 5px; }
.msg-row.internal .msg-author { color: var(--ink-3); }

.day-divider { align-self: center; margin: 10px 0 2px; padding: 2px 10px; border-radius: 10px; background: var(--surface-2); color: var(--ink-3); font-size: 11px; }

.composer { flex: 0 0 auto; padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); }

.composer-mode { display: flex; gap: 2px; margin-bottom: 7px; }

.mode-btn {
    padding: 4px 9px;
    min-height: 30px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: none;
    color: var(--ink-3);
    font-size: 12px;
    font-weight: 550;
}

.mode-btn:hover { background: var(--surface-2); color: var(--ink); }
.mode-btn.is-active { background: var(--surface-2); color: var(--ink); }

/* Режим комментария красит только само поле ввода. */
.composer { position: relative; }
.composer-box { border: 1px solid var(--line-strong); border-radius: 16px; background: var(--surface); }
.composer-box:focus-within { border-color: var(--accent); }
.composer.is-internal .composer-box { background: var(--note-soft); border-color: var(--note-line); }
.composer.is-internal .composer-box:focus-within { border-color: var(--note-ink); }

.composer textarea {
    display: block;
    width: 100%;
    min-height: 44px;
    max-height: 140px;
    padding: 12px 14px 4px;
    border: 0;
    border-radius: 16px 16px 0 0;
    background: transparent;
    resize: none;
    outline: none;
    font-size: 14px;
    line-height: 1.4;
}

.composer-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 8px 8px; }
.composer-tools { display: flex; align-items: center; gap: 2px; min-width: 0; }
.tool-btn, .send-round { display: grid; place-items: center; width: 40px; height: 40px; flex: none; border: 0; border-radius: 50%; cursor: pointer; }
.tool-btn { background: none; color: var(--ink-3); }
.tool-btn:hover { background: var(--surface-2); color: var(--ink); }
.tool-btn.is-active { background: var(--note-line); color: var(--note-ink); }
.send-round { background: var(--accent); color: var(--accent-ink); }
.send-round:disabled { background: var(--line-strong); cursor: default; }
.tool-btn:focus-visible, .send-round:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.composer-attached { display: flex; align-items: center; gap: 8px; margin: 0 14px; padding: 4px 0; color: var(--ink-2); font-size: 12px; }
.composer-attached button { border: 0; background: none; color: var(--ink-3); cursor: pointer; font-size: 16px; line-height: 1; }
.composer-pop { position: absolute; left: 14px; right: 14px; bottom: calc(100% - 6px); z-index: 20; max-height: 260px; overflow-y: auto; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-pop); }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 2px; }
.emoji-grid button { height: 36px; border: 0; border-radius: 8px; background: none; font-size: 20px; cursor: pointer; }
.emoji-grid button:hover, .tpl-item:hover { background: var(--surface-2); }
.tpl-item { display: block; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px; background: none; text-align: left; cursor: pointer; }
.tpl-item strong { display: block; font-size: 13px; }
.tpl-item span { display: block; color: var(--ink-3); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer-pop.is-picker { display: flex; flex-direction: column; gap: 10px; max-height: 360px; padding: 12px 14px; overflow: hidden; }
.pick-search-wrap input { width: 100%; height: 38px; padding: 0 12px; border: 0; border-radius: 8px; background: var(--surface-2); font-size: 14px; outline: none; }
.pick-search-wrap input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.pick-tabs { display: flex; align-items: center; gap: 4px; }
.pick-tab { min-height: 32px; padding: 6px 10px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--ink-2); font-size: 13px; cursor: pointer; }
.pick-tab.is-active { border-bottom-color: var(--accent); color: var(--ink); }
.pick-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.pick-keys { display: flex; gap: 4px; margin-left: auto; }
.pick-keys kbd { padding: 1px 6px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--ink-3); font-family: inherit; font-size: 11px; line-height: 1.5; }
.pick-list { flex: 1; min-height: 0; overflow-y: auto; border-top: 1px solid var(--line); }
.pick-item { display: block; width: 100%; padding: 10px 4px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--ink); font-size: 13px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.pick-item.is-active, .pick-item:hover { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.tpl-manage { display: grid; gap: 6px; margin-bottom: 12px; }
.tpl-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.tpl-row span { flex: 1 1 auto; min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.tpl-actions { display: flex; flex: 0 0 auto; gap: 6px; }
.tpl-drag {
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--ink-3);
    cursor: grab;
    touch-action: none;
    font-size: 16px;
    line-height: 1;
}
.tpl-drag:hover { background: var(--surface-2); color: var(--ink); }
.tpl-row.is-dragging { opacity: .45; pointer-events: none; }
.tpl-favorite { min-width: 32px; padding-left: 8px; padding-right: 8px; color: var(--ink-3); }
.tpl-favorite.is-active { color: var(--warn); background: var(--warn-soft); border-color: var(--note-line); }
.msg-link { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.msg-file { display: block; margin-top: 6px; }
.msg-file img { display: block; max-width: 100%; max-height: 220px; border-radius: 8px; }
.msg-file.is-document {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin-top: 6px;
    overflow: hidden;
    color: inherit;
    text-decoration: none;
}
.msg-file.is-document:hover .msg-file-name { text-decoration: underline; }
.msg-file-ext {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    min-width: 30px;
    height: 22px;
    padding: 0 4px;
    border: 0;
    border-radius: 4px;
    background: #fff;
    color: var(--accent);
    font-size: 8px;
    font-weight: 700;
    letter-spacing: .2px;
}
.msg-file-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: inherit;
    font-size: inherit;
}
.msg-file-size { flex: 0 0 auto; color: inherit; opacity: .65; font-size: 10.5px; }

/* Правая колонка */
.details { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); border-left: 1px solid var(--line); }

.details-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px 0 14px; border-bottom: 1px solid var(--line); }

.tabs { display: flex; gap: 16px; }

.tab {
    position: relative;
    padding: 10px 0;
    border: 0;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--ink-3);
    font-size: 13px;
    font-weight: 550;
}

.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--ink); border-bottom-color: var(--accent); }

.tab-count { display: inline-grid; place-items: center; min-width: 17px; height: 17px; margin-left: 3px; padding: 0 4px; border-radius: 9px; background: var(--surface-2); color: var(--ink-3); font-size: 10px; }

.details-close { display: none; }

.details-body { flex: 1; overflow-y: auto; padding: 16px; }

.person { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.person .avatar { width: 46px; height: 46px; font-size: 15px; }
.person-main { min-width: 0; line-height: 1.3; }
.person-name { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.person h2 { font-size: 15px; line-height: 1.3; overflow-wrap: anywhere; }
.person p { color: var(--ink-3); font-size: 12px; line-height: 1.3; overflow-wrap: anywhere; }
.channel-profile-link { display: inline-block; margin-top: 2px; line-height: 1.3; color: var(--accent); font-size: 12px; font-weight: 600; text-decoration: none; }
.channel-profile-link:hover { text-decoration: underline; }

.person-id {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    height: 19px;
    padding: 0 8px;
    border-radius: 10px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 10.5px;
    font-weight: 650;
    line-height: 19px;
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.person-id.is-link:hover { text-decoration: underline; }

.person-blocked { display: inline-flex; align-items: center; height: 19px; padding: 0 8px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); font-size: 10.5px; font-weight: 650; white-space: nowrap; }

.section { margin-bottom: 18px; }
.section h3 { margin-bottom: 8px; color: var(--ink-3); font-size: 11px; font-weight: 650; letter-spacing: 0.02em; }

.kv { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; margin: 0; min-width: 0; }
.kv div { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.kv > div:last-child { border-bottom: 0; }
.kv dt { flex: 0 0 auto; color: var(--ink-3); }
.kv dd { margin: 0; min-width: 0; text-align: right; overflow-wrap: anywhere; }
.kv div { min-width: 0; }
.kv dd.is-clip { flex: 1 1 0; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; overflow-wrap: normal; }
.kv dd.is-clip a { white-space: nowrap; }

.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); font-size: 11.5px; }
.chip b { font-weight: 600; }

.history-item { display: flex; justify-content: space-between; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 12px; }

.note-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.note-meta { display: flex; justify-content: space-between; gap: 8px; color: var(--ink-3); font-size: 11px; }
.note-body { margin-top: 4px; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }

.note-form { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

.note-form textarea {
    width: 100%;
    min-height: 84px;
    padding: 10px 11px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
    resize: vertical;
    outline: none;
    font-size: 13.5px;
    line-height: 1.45;
}

.note-form textarea::placeholder { color: var(--ink-3); }
.note-form textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.note-form .btn { align-self: flex-end; }

.link-out { color: var(--accent); text-decoration: none; }
.link-out:hover { text-decoration: underline; }

/* Настройки */
.settings-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }

.settings-head { display: flex; align-items: flex-end; gap: 16px; padding: 20px 24px 12px; background: var(--surface); }
.settings-head-main { display: flex; flex-direction: column-reverse; align-items: flex-start; gap: 2px; min-width: 0; }
.settings-head h1 { margin-top: 0; font-size: 20px; letter-spacing: -0.01em; }

.back-link { font-size: 12px; }

.tabs-line { display: flex; gap: 22px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--line); }

.settings-body { flex: 1; overflow-y: auto; padding: 22px 24px calc(24px + env(safe-area-inset-bottom)); }

.panel { max-width: 760px; margin-bottom: 20px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-head:last-child { margin-bottom: 0; }
.sites-actions { display: flex; justify-content: flex-start; margin-bottom: 16px; }
.settings-actions { display: flex; justify-content: flex-start; margin-bottom: 14px; }
.settings-add-channel { position: relative; display: inline-block; }
.settings-add-channel > summary { list-style: none; cursor: pointer; }
.settings-add-channel > summary::-webkit-details-marker { display: none; }
.settings-add-channel > summary::after { content: '▾'; margin-left: 8px; }
.settings-add-channel .menu { top: calc(100% + 6px); right: auto; left: 0; min-width: 200px; }
.panel h2 { font-size: 15px; }
.panel p.hint { margin-top: 2px; color: var(--ink-3); font-size: 12px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }

.check-row { display: flex; align-items: center; gap: 8px; min-height: 32px; font-size: 13px; }
.check-row input { width: 16px; height: 16px; accent-color: var(--accent); }
.site-members { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 8px; }
.site-member-col { display: grid; align-content: start; gap: 2px; }
.site-member-col h3 { margin: 0 0 4px; color: var(--ink-3); font-size: 11px; font-weight: 650; letter-spacing: 0.02em; }
.site-member-col .hint { margin: 0; }
@media (max-width: 720px) { .site-members { grid-template-columns: 1fr; } }

.inline-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.code-box { position: relative; margin-top: 8px; padding: 11px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
.code-box .copy { position: absolute; top: 6px; right: 6px; }
/* Сниппет в <pre>: браузерное white-space: pre не дает строкам переноситься и они вылезают за карточку. */
pre.code-box { margin: 8px 0 0; max-width: 100%; white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: auto; line-height: 1.5; }

.code-details { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.code-details summary { cursor: pointer; color: var(--accent); font-size: 12.5px; font-weight: 550; }
.code-details pre.code-box { margin-bottom: 0; white-space: pre-wrap; line-height: 1.5; }

#ticket-btn.has-ticket { background: var(--accent-soft); color: var(--accent); }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { padding: 8px 10px; border-bottom: 1px solid var(--line); color: var(--ink-3); font-size: 11px; font-weight: 650; text-align: left; }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }

.user-cell { display: flex; align-items: center; gap: 10px; }

.status-pill { display: inline-flex; align-items: center; gap: 5px; color: var(--ink-3); font-size: 11.5px; }
.status-pill.active { color: var(--accent); }

/* Служебные слои */
.toasts { position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 100; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }

.toast { max-width: 340px; padding: 10px 14px; border-radius: 10px; background: #22312b; color: #fff; font-size: 13px; box-shadow: var(--shadow-pop); animation: toast-in 160ms ease-out; }
.toast.error { background: #7f1d1a; }

@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.modal { position: fixed; inset: 0; z-index: 110; display: grid; place-items: center; padding: 20px; background: rgba(20, 33, 28, 0.38); overscroll-behavior: contain; }

/* Пока открыто модальное окно, фон не прокручивается и не принимает клики. */
body.modal-open .shell { pointer-events: none; }
body.modal-open .messages,
body.modal-open .conv-list,
body.modal-open .details-body,
body.modal-open .settings-body,
body.modal-open .tabs-line { overflow: hidden !important; overscroll-behavior: none; }
.modal-card { position: relative; width: min(420px, 100%); padding: 20px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-pop); }
.modal-close { position: absolute; top: 10px; right: 10px; display: grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--ink-3); font-size: 20px; line-height: 1; cursor: pointer; }
.modal-close:hover { background: var(--surface-2); color: var(--ink); }
.modal-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.modal-card h2 { font-size: 16px; }
.modal-card p { margin-top: 8px; color: var(--ink-2); font-size: 13px; }

.loading-card { display: flex; flex-direction: column; align-items: center; gap: 12px; width: auto; min-width: 210px; padding: 28px 32px; text-align: center; }
.loading-card p { margin: 0; }
.spinner { display: block; flex: none; width: 28px; height: 28px; border: 2.5px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: mc-spin 0.8s linear infinite; }
@keyframes mc-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 1.6s; } }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal-actions.split { justify-content: space-between; }

.profile-head { display: flex; align-items: center; gap: 14px; padding-right: 30px; }
.profile-head .avatar { width: 56px; height: 56px; font-size: 18px; }
.profile-name { font-weight: 600; }
.profile-mail { color: var(--ink-3); font-size: 12px; overflow-wrap: anywhere; }

.avatar-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

.mobile-only { display: none; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-width: 1180px) {
    .workspace { grid-template-columns: 300px minmax(0, 1fr); }
    .details {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        z-index: 60;
        width: min(360px, 92vw);
        transform: translateX(100%);
        transition: transform 180ms ease;
        border-left: 1px solid var(--line);
        box-shadow: var(--shadow-pop);
    }
    .details.open { transform: none; }
    .details-close { display: grid; }
    .details-toggle { display: grid; }
    .details-head { padding-left: 16px; }
}

@media (min-width: 1181px) {
    .details-toggle { display: none; }

    /* Без выбранного диалога колонка клиента не нужна. */
    .workspace.no-details { grid-template-columns: 320px minmax(0, 1fr); }
    .workspace.no-details .details { display: none; }
}

@media (max-width: 900px) {
    .rail { display: none; }
    .mobile-only { display: grid; }
    .workspace { grid-template-columns: 1fr; }
    .list-pane, .chat-pane { min-height: 0; }
    .shell:not(.mobile-chat) .chat-pane { display: none; }
    .shell.mobile-chat .list-pane { display: none; }
    .shell.mobile-chat .chat-pane { display: flex; }
    .chat-empty { display: none; }
    .settings-head { padding: 16px 16px 10px; }
    .settings-head-main { flex-direction: row; align-items: center; justify-content: space-between; width: 100%; gap: 12px; }
    .tabs-line { gap: 16px; padding: 0 16px; overflow-x: auto; }
    .settings-body { padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); }
    .form-grid { grid-template-columns: 1fr; }
    .chat-head { padding: 8px 10px; }
    .messages { padding: 14px; }
    .msg-row { max-width: 88%; }
    .composer { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
    .composer-hint { display: none; }
    .composer-foot { justify-content: flex-end; }
    .table { min-width: 520px; }
    .settings-body .table-wrap { overflow-x: auto; }
}

@media (max-width: 380px) {
    .pane-head { padding: 12px 12px 8px; }
    .conv-item { padding: 10px 12px; }
    .segmented { gap: 12px; }
}

/* Статусы сотрудников */
.status-dot.invisible { background: #9aa0ab; }
.status-dot.offline { background: #d64545; }
.rail-avatar { position: relative; }
.rail-avatar::after { content: ''; position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; border: 2px solid var(--surface, #fff); border-radius: 50%; background: #2e9e63; }
.rail-avatar[data-status='invisible']::after { background: #9aa0ab; }
.rail-avatar[data-status='offline']::after { background: #d64545; }
.presence h3 { margin: 14px 0 6px; font-size: 13px; }
.presence-status { display: flex; flex-wrap: wrap; gap: 6px; }
.presence-btn { display: inline-flex; align-items: center; gap: 4px; min-height: 36px; padding: 6px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); font-size: 13px; cursor: pointer; }
.presence-btn.is-active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.schedule-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; font-size: 13px; }
.schedule-day { display: flex; align-items: center; gap: 6px; width: 54px; }
.schedule-row input[type='time'] { min-height: 34px; padding: 4px 6px; border: 1px solid var(--line); border-radius: var(--radius-sm); font: inherit; }
.schedule-row input[type='time']:disabled { opacity: 0.45; }

/* Меню аватара и модалка настроек */
.user-menu { position: fixed; z-index: 120; min-width: 210px; max-height: none; }
.menu-sep { height: 1px; margin: 6px 4px; background: var(--line); }
.rail-avatar { overflow: visible; cursor: pointer; }
.rail-avatar img { border-radius: 50%; }
.rail-avatar::after { right: -2px; bottom: -2px; width: 8px; height: 8px; border-width: 1.5px; }
.modal-card { max-height: calc(100dvh - 40px); overflow-y: auto; }
.modal-tabs { display: flex; gap: 18px; margin-top: 14px; border-bottom: 1px solid var(--line); }
.modal-tab { margin-bottom: -1px; padding: 8px 0; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--ink-3); font-size: 13px; cursor: pointer; }
.modal-tab.is-active { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }
.tab-pane { padding-top: 4px; }
.presence-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.schedule-tz { margin: 8px 0 6px; font-size: 13px; }

/* Аватар в модалке настроек, подсветка статуса, вкладка тикетов */
.avatar-pick { position: relative; flex: none; }
.avatar-pick-btn { display: block; padding: 0; border: 0; border-radius: 50%; background: none; cursor: pointer; }
.avatar-pick-btn:hover .avatar { filter: brightness(0.94); }
.avatar-pick-btn:focus-visible, .avatar-remove:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.avatar-remove { position: absolute; top: -6px; right: -6px; display: grid; place-items: center; width: 22px; height: 22px; padding: 0; border: 2px solid var(--surface); border-radius: 50%; background: var(--ink-2); color: #fff; font-size: 14px; line-height: 1; cursor: pointer; }
.avatar-remove[hidden] { display: none; }
.ticket-form { display: grid; gap: 8px; }
.ticket-form textarea { width: 100%; min-height: 96px; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); font: inherit; font-size: 13px; resize: vertical; }
.ticket-actions { display: flex; justify-content: flex-end; }
.ticket-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.ticket-list li { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.ticket-meta { color: var(--ink-3); font-size: 12px; }

/* Меню назначения: статус слева, имя, галочка справа */
.menu-item .menu-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-item .status-dot { flex: none; margin: 0; }

/* Отступы между полями форм и аккордеон */
.panel > .field, .modal-card > .field { margin-top: 14px; }
.panel > .field .hint, .field .hint { margin-top: 2px; color: var(--ink-3); font-size: 12px; }
.panel > .inline-actions { margin-top: 16px; }
.panel > .field-row, .modal-card > .field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; margin-top: 14px; }
.panel > h3 { margin-top: 28px; }
.panel > p.hint { margin-top: 4px; }
@media (max-width: 720px) { .panel > .field-row, .modal-card > .field-row { grid-template-columns: 1fr; } }
.form-grid { row-gap: 14px; column-gap: 16px; }
.accordion { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.accordion summary { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; font-size: 13px; font-weight: 600; cursor: pointer; list-style: none; }
.accordion summary::-webkit-details-marker { display: none; }
.accordion summary::after { content: ''; width: 7px; height: 7px; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); transform: rotate(45deg); transition: transform 160ms ease; }
.accordion[open] summary::after { transform: rotate(-135deg); }
.accordion summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.accordion[open] summary { border-bottom: 1px solid var(--line); }
.accordion > :not(summary) { margin: 12px 14px; }
.accordion p.hint { margin-top: 10px; }
.stats-scroll { overflow-x: auto; }
.stats-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stats-table th, .stats-table td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.stats-table th { color: var(--ink-3); font-weight: 400; }
.stats-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stats-unanswered { margin-bottom: 12px; font-size: 13px; }
.stats-unanswered strong { font-size: 20px; margin-right: 4px; }

.triggers-list { display: grid; gap: 14px; margin-top: 14px; }
.trigger-row { display: grid; gap: 14px; padding-top: 14px; border-top: 1px solid rgba(128, 128, 128, .25); }
.trigger-row:first-child { border-top: 0; padding-top: 0; }
.trigger-row [hidden] { display: none !important; }
.trigger-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.trigger-foot .btn { flex: 0 0 auto; }
.triggers-editor > .btn { margin-top: 14px; }

.conv-item.is-active .avatar { box-shadow: 0 0 0 1.5px var(--line-strong); }
