/*
 * Правая панель просмотра: файлы диалога, просмотр файла (видео, аудио, картинки, PDF, страницы)
 * и встроенный браузер.
 * Подключается после hermes-shell.css, цвета только из токенов, светлая и тёмная темы.
 */

/* Чат и панель результатов в одной строке; без панели чат занимает всю ширину как раньше. */
.hermes-dashboard .results-layout {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
}

.hermes-dashboard .results-layout > .panel--chat {
    flex: 1 1 0;
    min-width: 0;
}

/* ---------- панель ---------- */

.hermes-dashboard .results-panel {
    position: relative;
    display: flex;
    flex: 0 0 var(--results-panel-width, 26rem);
    flex-direction: column;
    width: var(--results-panel-width, 26rem);
    min-width: 0;
    min-height: 0;
    border-left: 1px solid var(--hermes-line);
    background: var(--hermes-panel);
    color: var(--hermes-text);
}

/* Ручка ширины на левом краю: тонкая, видна при наведении. */
.hermes-dashboard .results-panel__resize {
    position: absolute;
    z-index: 4;
    top: 0;
    bottom: 0;
    left: -4px;
    width: 8px;
    cursor: col-resize;
    touch-action: none;
}

.hermes-dashboard .results-panel__resize::after {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 3px;
    width: 2px;
    background: transparent;
    content: "";
    transition: background-color 120ms ease;
}

.hermes-dashboard .results-panel__resize:hover::after,
.hermes-dashboard .results-panel--resizing .results-panel__resize::after {
    background: var(--hermes-accent);
}

/* Пока тянут ширину, рамки не перехватывают мышь и текст не выделяется. */
.hermes-dashboard .results-panel--resizing {
    user-select: none;
}

.hermes-dashboard .results-panel--resizing iframe {
    pointer-events: none;
}

.hermes-dashboard .results-panel__header {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.5rem 0.5rem 0.75rem;
    border-bottom: 1px solid var(--hermes-line);
}

.hermes-dashboard .results-tabs {
    display: flex;
    gap: 0.125rem;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}

.hermes-dashboard .results-tabs__tab {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.625rem;
    border: 0;
    border-radius: 0.5rem;
    background: transparent;
    color: var(--hermes-dim);
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
}

.hermes-dashboard .results-tabs__tab:hover:not(:disabled),
.hermes-dashboard .results-tabs__tab[aria-selected="true"] {
    background: var(--hermes-hover);
    color: var(--hermes-text);
}

.hermes-dashboard .results-tabs__tab:disabled {
    opacity: 0.45;
    cursor: default;
}

.hermes-dashboard .results-tabs__tab:focus-visible {
    outline: 2px solid var(--hermes-accent);
    outline-offset: -2px;
}

.hermes-dashboard .results-panel__count {
    min-width: 1.35rem;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    background: var(--hermes-hover);
    color: var(--hermes-soft);
    font-size: 0.75rem;
    font-weight: 600;
    text-align: center;
}

.hermes-dashboard .results-panel__empty {
    margin: 0;
    padding: 1.5rem 1rem;
    color: var(--hermes-soft);
    font-size: 0.875rem;
    line-height: 1.55;
}

.hermes-dashboard .results-panel__body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 0.5rem 0.5rem 1.5rem;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.hermes-dashboard .results-group + .results-group {
    margin-top: 0.75rem;
}

.hermes-dashboard .results-group__title {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
    margin: 0;
    padding: 0.5rem 0.5rem 0.25rem;
    color: var(--hermes-soft);
    font-size: 0.75rem;
    font-weight: 600;
}

.hermes-dashboard .results-group__title time {
    color: var(--hermes-dim);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.hermes-dashboard .results-list {
    display: grid;
    gap: 0.125rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.hermes-dashboard .results-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    border-radius: 0.625rem;
}

.hermes-dashboard .results-item:hover,
.hermes-dashboard .results-item:focus-within,
.hermes-dashboard .results-item--active {
    background: var(--hermes-hover);
}

.hermes-dashboard .results-item__main {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    gap: 0.625rem;
    min-width: 0;
    padding: 0.5rem;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.hermes-dashboard .results-item__main:focus-visible,
.hermes-dashboard .file-preview__nav:focus-visible,
.hermes-dashboard .results-menu :is(button, a):focus-visible {
    outline: 2px solid var(--hermes-accent);
    outline-offset: -2px;
}

.hermes-dashboard .results-item__icon {
    display: inline-grid;
    flex: 0 0 auto;
    place-items: center;
    min-width: 2.25rem;
    height: 2.25rem;
    padding: 0 0.25rem;
    border-radius: 0.5rem;
    background: var(--hermes-hover);
    color: var(--hermes-soft);
    font-size: 0.625rem;
    font-weight: 750;
    letter-spacing: 0.02em;
}

.hermes-dashboard .results-item__icon--image { background: color-mix(in srgb, #8b5cf6 18%, transparent); color: #8b5cf6; }
.hermes-dashboard .results-item__icon--pdf { background: color-mix(in srgb, #ef4444 16%, transparent); color: #ef4444; }
.hermes-dashboard .results-item__icon--table { background: color-mix(in srgb, #22a55a 16%, transparent); color: #22a55a; }
.hermes-dashboard .results-item__icon--doc { background: color-mix(in srgb, #3b82f6 16%, transparent); color: #3b82f6; }
.hermes-dashboard .results-item__icon--slides { background: color-mix(in srgb, #f59e0b 18%, transparent); color: #d98a06; }
.hermes-dashboard .results-item__icon--archive { background: color-mix(in srgb, #a16207 16%, transparent); color: #a16207; }
.hermes-dashboard .results-item__icon--video { background: color-mix(in srgb, #e11d74 16%, transparent); color: #e11d74; }
.hermes-dashboard .results-item__icon--audio { background: color-mix(in srgb, #0ea5a4 16%, transparent); color: #0b9493; }

.hermes-dashboard .results-item__text {
    display: grid;
    min-width: 0;
}

.hermes-dashboard .results-item__name {
    overflow: hidden;
    font-size: 0.875rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hermes-dashboard .results-item__meta {
    color: var(--hermes-dim);
    font-size: 0.75rem;
}

.hermes-dashboard .results-item__menu-anchor {
    position: relative;
    flex: 0 0 auto;
}

.hermes-dashboard .results-menu {
    position: absolute;
    z-index: 5;
    top: calc(100% + 0.125rem);
    right: 0;
    display: grid;
    min-width: 12rem;
    padding: 0.25rem;
    border: 1px solid var(--hermes-line-strong, var(--hermes-line));
    border-radius: 0.625rem;
    background: var(--hermes-panel-raised, var(--hermes-panel));
    box-shadow: 0 12px 32px rgb(0 0 0 / 0.22);
}

.hermes-dashboard .results-menu :is(button, a) {
    display: block;
    padding: 0.5rem 0.625rem;
    border: 0;
    border-radius: 0.5rem;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 0.8125rem;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.hermes-dashboard .results-menu :is(button, a):hover {
    background: var(--hermes-hover);
}

/* ---------- предпросмотр ---------- */

.hermes-dashboard .file-preview {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    outline: none;
}

.hermes-dashboard .file-preview__header {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.5rem 0.5rem 0.25rem;
    border-bottom: 1px solid var(--hermes-line);
}

.hermes-dashboard .file-preview__header .results-item__icon {
    min-width: 2rem;
    height: 2rem;
}

.hermes-dashboard .file-preview__title {
    display: grid;
    flex: 1 1 auto;
    min-width: 0;
}

.hermes-dashboard .file-preview__title strong {
    overflow: hidden;
    font-size: 0.875rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hermes-dashboard .file-preview__title span {
    color: var(--hermes-dim);
    font-size: 0.75rem;
}

.hermes-dashboard .file-preview__actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 0.375rem;
}

.hermes-dashboard .file-preview__actions .icon-button {
    text-decoration: none;
}

.hermes-dashboard .file-preview__stage {
    position: relative;
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    background: var(--hermes-image-bg, var(--hermes-bg-2, var(--hermes-panel)));
}

.hermes-dashboard .file-preview__state {
    display: grid;
    gap: 0.75rem;
    justify-items: center;
    margin: auto;
    padding: 2rem;
    color: var(--hermes-soft);
    font-size: 0.9375rem;
    text-align: center;
}

.hermes-dashboard .file-preview__state p {
    margin: 0;
}

.hermes-dashboard .file-preview__state--error {
    color: var(--hermes-danger-ink, var(--hermes-danger));
}

.hermes-dashboard .file-preview__image-wrap {
    display: grid;
    flex: 1 1 auto;
    place-items: center;
    min-height: 0;
    overflow: hidden;
}

.hermes-dashboard .file-preview__image-wrap--zoomed {
    place-items: start center;
    overflow: auto;
}

.hermes-dashboard .file-preview__image {
    display: block;
}

.hermes-dashboard .file-preview__image--fit {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    cursor: zoom-in;
}

.hermes-dashboard .file-preview__image--actual {
    max-width: none;
    cursor: zoom-out;
}

.hermes-dashboard .file-preview__nav {
    position: absolute;
    z-index: 2;
    top: 50%;
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    border: 1px solid var(--hermes-line);
    border-radius: 999px;
    background: var(--hermes-panel);
    color: var(--hermes-text);
    cursor: pointer;
    transform: translateY(-50%);
}

.hermes-dashboard .file-preview__nav:hover {
    background: var(--hermes-panel-raised, var(--hermes-hover));
}

.hermes-dashboard .file-preview__nav--prev { left: 0.75rem; }
.hermes-dashboard .file-preview__nav--next { right: 0.75rem; }

.hermes-dashboard .file-preview__nav svg {
    width: 1.25rem;
    height: 1.25rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Видео и аудио: плеер по центру, ролик вписан в панель любой ширины. */
.hermes-dashboard .file-preview__media {
    position: relative;
    display: grid;
    flex: 1 1 auto;
    place-items: center;
    min-height: 0;
    background: #000;
}

/* Рамка задаётся абсолютно: вертикальный рилс и горизонтальный ролик вписываются целиком. */
.hermes-dashboard .file-preview__video {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

.hermes-dashboard .file-preview__media--audio {
    align-content: center;
    gap: 1.25rem;
    padding: 1rem;
    background: var(--hermes-image-bg, var(--hermes-bg-2, var(--hermes-panel)));
}

.hermes-dashboard .file-preview__audio-badge {
    display: grid;
    place-items: center;
    width: 5rem;
    height: 5rem;
    border-radius: 1.25rem;
    background: color-mix(in srgb, #0ea5a4 16%, transparent);
    color: #0b9493;
}

.hermes-dashboard .file-preview__audio-badge svg {
    width: 2.25rem;
    height: 2.25rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.hermes-dashboard .file-preview__audio {
    width: min(100%, 28rem);
}

.hermes-dashboard .file-preview__frame {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    border: 0;
    background: #fff;
}

.hermes-dashboard .file-preview__text {
    flex: 1 1 auto;
    min-height: 0;
    margin: 0;
    padding: 1rem 1.25rem;
    overflow: auto;
    background: var(--hermes-code-bg, var(--hermes-panel));
    color: var(--hermes-code-ink, var(--hermes-text));
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 0.8125rem;
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.hermes-dashboard .file-preview__table-wrap {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    background: var(--hermes-panel);
}

.hermes-dashboard .file-preview__table {
    min-width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.hermes-dashboard .file-preview__table th,
.hermes-dashboard .file-preview__table td {
    max-width: 24rem;
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid var(--hermes-line);
    border-right: 1px solid var(--hermes-line);
    overflow-wrap: anywhere;
    text-align: left;
    vertical-align: top;
}

.hermes-dashboard .file-preview__table th {
    position: sticky;
    top: 0;
    background: var(--hermes-panel-raised, var(--hermes-panel));
    font-weight: 650;
    white-space: nowrap;
}

.hermes-dashboard .file-preview__note {
    flex: 0 0 auto;
    margin: 0;
    padding: 0.5rem 1rem;
    border-top: 1px solid var(--hermes-line);
    background: var(--hermes-panel);
    color: var(--hermes-soft);
    font-size: 0.75rem;
}

/* ---------- экран агента ---------- */

.hermes-dashboard .agent-screen {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
}

.hermes-dashboard .agent-screen__bar {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    padding: 0.375rem 0.5rem 0.375rem 0.875rem;
    border-bottom: 1px solid var(--hermes-line);
}

.hermes-dashboard .agent-screen__bar .icon-button {
    flex: 0 0 auto;
    margin-left: auto;
    text-decoration: none;
}

.hermes-dashboard .agent-screen__dot {
    flex: 0 0 auto;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--hermes-dim);
}

.hermes-dashboard .agent-screen__dot--live {
    background: rgb(var(--hermes-success-rgb, 46 160 67));
    animation: hermes-breathe 1.4s ease-in-out infinite;
}

.hermes-dashboard .agent-screen__status {
    min-width: 0;
    overflow: hidden;
    color: var(--hermes-text);
    font-size: 0.8125rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hermes-dashboard .agent-screen__address {
    flex: 0 0 auto;
    margin: 0;
    padding: 0.25rem 0.875rem;
    overflow: hidden;
    border-bottom: 1px solid var(--hermes-line);
    color: var(--hermes-soft);
    font-size: 0.75rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hermes-dashboard .agent-screen__view {
    display: flex;
    flex: 1 1 auto;
    align-items: flex-start;
    justify-content: center;
    min-height: 0;
    padding: 0.5rem;
    overflow: auto;
    background: var(--hermes-bg-2, var(--hermes-panel));
}

.hermes-dashboard .agent-screen__frame {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 0.375rem;
    box-shadow: 0 0 0 1px var(--hermes-line);
    background: #fff;
}

.hermes-dashboard .agent-screen__frame:not([src]),
.hermes-dashboard .agent-screen__view--empty .agent-screen__frame {
    display: none;
}

.hermes-dashboard .agent-screen__view--empty {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
}

.hermes-dashboard .agent-screen__empty {
    max-width: 22rem;
    margin: 0;
    padding: 1rem;
    color: var(--hermes-soft);
    font-size: 0.8125rem;
    line-height: 1.55;
    text-align: center;
}

.hermes-dashboard .agent-screen__hint {
    flex: 0 0 auto;
    margin: 0;
    padding: 0.375rem 0.875rem;
    border-top: 1px solid var(--hermes-line);
    color: var(--hermes-dim);
    font-size: 0.6875rem;
    line-height: 1.4;
}

@media (prefers-reduced-motion: reduce) {
    .hermes-dashboard .agent-screen__dot--live {
        animation: none;
    }
}

/* ---------- встроенный браузер ---------- */

.hermes-dashboard .preview-browser {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
}

.hermes-dashboard .preview-browser__bar {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 0.25rem;
    padding: 0.375rem 0.5rem;
    border-bottom: 1px solid var(--hermes-line);
}

.hermes-dashboard .preview-browser__bar .icon-button {
    flex: 0 0 auto;
    text-decoration: none;
}

.hermes-dashboard .preview-browser__address {
    flex: 1 1 auto;
    min-width: 0;
    height: 2rem;
    padding: 0 0.75rem;
    border: 1px solid var(--hermes-line);
    border-radius: 999px;
    background: var(--hermes-bg-2, var(--hermes-panel));
    color: var(--hermes-text);
    font: inherit;
    font-size: 0.8125rem;
}

.hermes-dashboard .preview-browser__address:focus {
    border-color: var(--hermes-accent);
    outline: none;
}

.hermes-dashboard .preview-browser__error {
    margin: 0;
    padding: 0.375rem 0.875rem;
    color: var(--hermes-danger-ink, var(--hermes-danger));
    font-size: 0.75rem;
}

.hermes-dashboard .preview-browser__frame {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    border: 0;
    background: #fff;
}

.hermes-dashboard .preview-browser__hint {
    flex: 0 0 auto;
    margin: 0;
    padding: 0.375rem 0.875rem;
    border-top: 1px solid var(--hermes-line);
    color: var(--hermes-dim);
    font-size: 0.6875rem;
    line-height: 1.4;
}

.hermes-dashboard .preview-browser__home {
    flex: 1 1 auto;
    min-height: 0;
    padding: 1rem 0.75rem;
    overflow-y: auto;
}

.hermes-dashboard .preview-browser__home h3 {
    margin: 0 0 0.5rem;
    padding: 0 0.25rem;
    color: var(--hermes-soft);
    font-size: 0.75rem;
    font-weight: 600;
}

.hermes-dashboard .preview-browser__empty {
    margin: 0.5rem 0 0;
    padding: 0 0.25rem;
    color: var(--hermes-soft);
    font-size: 0.8125rem;
    line-height: 1.55;
}

.hermes-dashboard .preview-browser__sites {
    display: grid;
    gap: 0.125rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.hermes-dashboard .preview-browser__site {
    display: grid;
    width: 100%;
    padding: 0.5rem 0.625rem;
    border: 0;
    border-radius: 0.625rem;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.hermes-dashboard .preview-browser__site:hover {
    background: var(--hermes-hover);
}

.hermes-dashboard .preview-browser__site:focus-visible {
    outline: 2px solid var(--hermes-accent);
    outline-offset: -2px;
}

.hermes-dashboard .preview-browser__site strong {
    overflow: hidden;
    font-size: 0.875rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hermes-dashboard .preview-browser__site span {
    overflow: hidden;
    color: var(--hermes-dim);
    font-size: 0.75rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- телефон: панель на весь экран ---------- */

@media (max-width: 760px) {
    .hermes-dashboard .results-panel {
        position: fixed;
        z-index: 50;
        inset: 0;
        flex-basis: auto;
        width: auto;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        border-left: 0;
    }

    .hermes-dashboard .results-panel__resize {
        display: none;
    }

    .hermes-dashboard .file-preview__nav--prev { left: 0.375rem; }
    .hermes-dashboard .file-preview__nav--next { right: 0.375rem; }
}

/* Кнопка «Файлы диалога» над лентой чата. */
.hermes-dashboard .chat-results-toggle {
    position: absolute;
    top: 0.75rem;
    right: 1rem;
    z-index: 3;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--hermes-line);
    border-radius: 999px;
    background: var(--hermes-panel);
    color: var(--hermes-dim);
    font: inherit;
    font-size: 0.8125rem;
    cursor: pointer;
}

.hermes-dashboard .chat-results-toggle:hover {
    background: var(--hermes-hover);
    color: var(--hermes-text);
}

.hermes-dashboard .chat-results-toggle svg {
    width: 1rem;
    height: 1rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linejoin: round;
}

.hermes-dashboard .chat-results-toggle__count::before { content: "("; }
.hermes-dashboard .chat-results-toggle__count::after { content: ")"; }

/* На телефоне плашка с подписью закрывала правый край первых строк ленты: остаётся круглая иконка со счётчиком. */
@media (max-width: 760px) {
    .hermes-dashboard .chat-results-toggle {
        top: 0.5rem;
        right: 0.5rem;
        justify-content: center;
        width: 2.25rem;
        height: 2.25rem;
        padding: 0;
        box-shadow: 0 2px 10px rgb(var(--hermes-shadow-rgb) / calc(0.18 * var(--hermes-shadow-a)));
    }

    .hermes-dashboard .chat-results-toggle__label {
        display: none;
    }

    .hermes-dashboard .chat-results-toggle__count {
        position: absolute;
        top: -0.25rem;
        right: -0.25rem;
        min-width: 1.125rem;
        height: 1.125rem;
        padding: 0 0.25rem;
        border-radius: 999px;
        color: var(--hermes-bg);
        background: var(--hermes-text);
        font-size: 0.6875rem;
        font-weight: 700;
        line-height: 1.125rem;
        text-align: center;
    }

    .hermes-dashboard .chat-results-toggle__count::before,
    .hermes-dashboard .chat-results-toggle__count::after {
        content: none;
    }
}
