/* Blazor bridge: совместимость компонентов с buriat-theme.css */

.valid.modified:not([type=checkbox]) {
    outline: 1px solid var(--status-active-text, #22855e);
}

.invalid {
    outline: 1px solid var(--color-sun, #c94a42);
}

.validation-message {
    color: var(--color-sun, #c94a42);
    font-size: 12px;
}

.d-none { display: none !important; }

.form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    margin-top: 12px;
    flex-wrap: wrap;
}

/* Кнопки (legacy class names в admin-секциях) */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius-sm, 8px);
    border: 1px solid var(--chat-border);
    background: transparent;
    color: var(--chat-text, inherit);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.22s ease;
    text-decoration: none;
}

.btn:hover { background: var(--chat-hover); }

.btn-primary {
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text);
    border-color: transparent;
}

.btn-primary:hover { background: var(--btn-primary-hover); }

.btn-ghost, .btn.btn-ghost {
    background: transparent;
    border-color: var(--chat-border);
}

.btn-sm { padding: 6px 12px; font-size: 13px; }

.btn-block { width: 100%; }

.primary-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 11px 18px;
    border: none;
    border-radius: var(--radius-sm, 8px);
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.22s ease;
}

.primary-btn:hover { background: var(--btn-primary-hover); }

.primary-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.secondary-btn {
    padding: 9px 16px;
    border-radius: var(--radius-sm, 8px);
    border: 1px solid var(--chat-border);
    background: transparent;
    color: var(--chat-text);
    cursor: pointer;
}

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

/* Поля форм */
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.field span {
    font-size: 13px;
    font-weight: 500;
    color: var(--chat-text-secondary);
}

.field input,
.field select,
.field textarea,
.form-control,
.compose-input {
    padding: 11px 14px;
    border: 1px solid var(--chat-border);
    border-radius: var(--radius-sm, 8px);
    background: var(--chat-input-bg);
    color: var(--chat-text);
    font-size: 14px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

/* Textarea: только по вертикали, на всю ширину контейнера */
textarea,
.field textarea,
.textarea-fluid,
.admin-panel textarea,
.answer-card textarea {
    resize: vertical;
    min-height: 96px;
    max-width: 100%;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-wrap: break-word;
    word-break: break-word;
    field-sizing: content;
}

.field input:focus,
.form-control:focus,
.compose-input:focus {
    outline: none;
    border-color: var(--chat-accent);
}

.compose-input {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    resize: none;
}

/* Элементы с hidden не должны отображаться даже при display: grid/flex в кастомных классах */
[hidden] {
    display: none !important;
}

/* Диалоги */
.dialog-overlay {
    position: fixed;
    inset: 0;
    background: var(--modal-overlay);
    display: grid;
    place-items: center;
    padding: 16px;
    z-index: 200;
}

.dialog-overlay[hidden] {
    display: none !important;
}

.dialog-card {
    width: min(100%, 520px);
    max-height: 90vh;
    overflow-y: auto;
    border-radius: var(--radius-lg, 16px);
    border: 1px solid var(--chat-border);
    background: var(--modal-bg);
    padding: 24px;
    color: var(--chat-text);
    box-shadow: var(--admin-shadow-lg);
}

.dialog-title {
    margin: 0 0 16px;
    font-size: 18px;
}

/* Алерты */
.alert {
    padding: 12px 14px;
    border-radius: var(--radius-sm, 8px);
    font-size: 14px;
    margin-bottom: 12px;
}

.alert-error {
    background: rgba(201, 74, 66, 0.12);
    color: var(--color-sun);
    border: 1px solid rgba(201, 74, 66, 0.25);
}

.alert-info {
    background: var(--kpi-blue-bg);
    color: var(--kpi-blue-text);
}

.alert-warning {
    background: var(--status-pending-bg);
    color: var(--status-pending-text);
}

/* Toolbar / таблицы в admin */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

/* Горизонтальный ряд: поле и кнопка на одной линии (как StackPanel Horizontal) */
.toolbar-row {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
}

.toolbar-form {
    margin-bottom: 12px;
}

.toolbar-form.toolbar-row {
    align-items: center;
    gap: 14px;
}

.toolbar-form.toolbar-row .field-inline {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    margin-bottom: 0;
    flex: 1 1 280px;
    min-width: 0;
    max-width: 420px;
}

.toolbar-form.toolbar-row .field-inline > span {
    flex-shrink: 0;
    margin-bottom: 0;
    white-space: nowrap;
}

.toolbar-form.toolbar-row .field-inline input {
    flex: 1;
    min-width: 120px;
}

.toolbar-form .field-grow,
.toolbar-form .input-grow {
    flex: 1 1 200px;
    min-width: 140px;
    max-width: 320px;
}

.toolbar-action {
    flex-shrink: 0;
    align-self: center;
    margin-top: 0;
}

.toolbar-tight {
    gap: 10px;
}

.toolbar-no-margin {
    margin-bottom: 0;
}

.dept-header .toolbar-tight.toolbar-no-margin,
.dept-header-card .toolbar-tight.toolbar-no-margin {
    margin-top: 10px;
    align-items: center;
}

.dept-header .toolbar-action,
.dept-header-card .toolbar-action {
    margin-top: 4px;
}

/* Bitrix24: отступ между чекбоксами и кнопками */
.bitrix-check-group {
    margin-bottom: 14px;
}

.bitrix-check-group .check-label {
    margin-bottom: 10px;
}

.bitrix-check-group .check-label:last-child {
    margin-bottom: 0;
}

.bitrix-toolbar {
    margin-top: 24px;
    padding-top: 8px;
}

.panel-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
    align-items: center;
}

.table-wrap {
    overflow-x: auto;
}

.table-wrap table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.table-wrap th,
.table-wrap td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--admin-border);
}

.table-wrap th {
    background: var(--table-head-bg);
    color: var(--admin-text-muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.section { margin-top: 16px; }

.section-title {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--admin-text-secondary);
}

.upload-progress {
    margin-top: 12px;
    height: 8px;
    border-radius: 999px;
    background: var(--chat-border, rgba(255, 255, 255, 0.12));
    overflow: hidden;
}

.upload-progress-bar {
    height: 100%;
    border-radius: inherit;
    background: var(--color-sun, #c9a84c);
    transition: width 0.25s ease;
}

.upload-progress-label {
    margin: 8px 0 0;
    font-size: 13px;
    color: var(--chat-text-muted, #888);
}

.check-list { display: flex; flex-direction: column; gap: 6px; }

.check-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    cursor: pointer;
}

.text-hint {
    color: var(--chat-text-muted);
    font-size: 13px;
}

.text-muted { color: var(--chat-text-muted); }

/* Чат: подзаголовок и сообщения */
.chat-title-sub {
    display: block;
    font-size: 12px;
    color: var(--chat-text-muted);
    margin-top: 2px;
}

.msg-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--chat-text-muted);
    margin-bottom: 4px;
}

.msg-text {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.55;
}

.msg-time {
    display: block;
    margin-top: 8px;
    font-size: 11px;
    color: var(--chat-text-muted);
}

/* Просмотр чатов пользователей (admin) */
.admin-user-pick-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.admin-user-pick-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--admin-border);
    border-radius: var(--radius-md, 12px);
    background: var(--admin-panel);
    cursor: pointer;
    text-align: left;
    overflow: hidden;
    transition: background 0.22s ease, border-color 0.22s ease;
}

.admin-user-pick-card:hover {
    background: var(--admin-hover);
    border-color: var(--chat-accent);
}

.pick-name {
    font-weight: 600;
    color: var(--admin-text);
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pick-email {
    color: var(--admin-text-muted);
    font-size: 12px;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-break: normal;
}

.admin-readonly-badge {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--status-pending-bg);
    color: var(--status-pending-text);
}

.admin-chats-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 16px;
    min-height: 400px;
}

.admin-chats-sidebar {
    display: flex;
    flex-direction: column;
    gap: 4px;
    border: 1px solid var(--admin-border);
    border-radius: var(--radius-md, 12px);
    padding: 8px;
    background: var(--admin-panel);
    max-height: calc(100vh - 220px);
    overflow-y: auto;
}

.admin-chats-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 10px 12px;
    border: none;
    border-radius: var(--radius-sm, 8px);
    background: transparent;
    color: var(--admin-text);
    cursor: pointer;
    text-align: left;
    width: 100%;
}

.admin-chats-item:hover,
.admin-chats-item.active {
    background: var(--admin-hover);
}

.admin-chats-item-title {
    font-size: 13px;
    font-weight: 500;
}

.admin-chats-main {
    border: 1px solid var(--admin-border);
    border-radius: var(--radius-md, 12px);
    padding: 16px;
    background: var(--admin-panel);
    overflow: hidden;
}

.admin-chats-main .chat-feed,
.admin-chats-main .grok-thread {
    max-height: calc(100vh - 240px);
    overflow-y: auto;
}

.chat-list-row {
    display: flex;
    align-items: stretch;
    gap: 2px;
}

.chat-list-row .chat-item {
    flex: 1;
    min-width: 0;
}

.chat-delete-btn {
    flex-shrink: 0;
    width: 28px;
    border: none;
    border-radius: var(--radius-sm, 8px);
    background: transparent;
    color: var(--chat-text-muted);
    cursor: pointer;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.2s ease, background 0.2s ease;
}

.chat-list-row:hover .chat-delete-btn { opacity: 1; }

.chat-delete-btn:hover {
    background: rgba(201, 74, 66, 0.15);
    color: var(--color-sun);
}

.card {
    border: 1px solid var(--admin-border);
    border-radius: var(--radius-md, 12px);
    background: var(--admin-panel);
}

.card-body { padding: 20px; }

/* Сетка полей (Bitrix, настройки) */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 14px;
}

.grid-2 .field {
    min-width: 0;
}

@media (max-width: 768px) {
    .grid-2 {
        grid-template-columns: 1fr;
    }
}

/* Таблицы admin */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th,
.data-table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--admin-border);
    vertical-align: middle;
}

.data-table th {
    background: var(--table-head-bg);
    color: var(--admin-text-muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.data-table tbody tr:hover {
    background: var(--admin-hover);
}

.data-table .col-actions {
    width: 1%;
    white-space: nowrap;
    text-align: right;
}

.dept-section {
    margin-top: 20px;
    padding-top: 4px;
}

.dept-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--admin-text);
}

.dept-header,
.dept-header-card {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.dept-job-table {
    margin-top: 8px;
}

.dept-job-name {
    font-weight: 500;
    color: var(--admin-text);
}

.actions-inline {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
}

.input-width-lg {
    width: min(100%, 20rem);
}

.input-width-md {
    width: min(100%, 16rem);
}

.input-width-sm {
    width: min(100%, 14rem);
}

/* Вопросы без ответа */
.pending-split {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.85fr);
    gap: 20px;
    align-items: start;
}

.pending-split .answer-card {
    min-width: 0;
}

.pending-split .field {
    min-width: 0;
    width: 100%;
}

.data-table tr.selected {
    background: var(--kpi-blue-bg);
}

.data-table .cell-question {
    max-width: 100%;
    white-space: pre-wrap;
    word-break: break-word;
}

.answer-card {
    background: var(--admin-panel);
    border: 1px solid var(--admin-border);
    border-radius: var(--radius-md, 12px);
    padding: 20px;
    min-width: 0;
}

.answer-card.empty {
    border-style: dashed;
}

.answer-card .question-preview {
    padding: 12px 14px;
    background: var(--chat-input-bg);
    border-radius: var(--radius-sm, 8px);
    border-left: 3px solid var(--chat-accent);
    margin-bottom: 16px;
    font-size: 13px;
    white-space: pre-wrap;
    word-break: break-word;
}

.bitrix-status-card {
    margin-bottom: 16px;
    padding: 12px 16px;
    border-radius: var(--radius-sm, 8px);
    border: 1px solid var(--admin-border);
    background: var(--chat-input-bg);
    font-size: 13px;
}

.bitrix-status-card.is-ok {
    border-color: rgba(52, 180, 140, 0.4);
    background: var(--kpi-green-bg);
}

.bitrix-status-card.is-pending {
    border-color: rgba(201, 168, 76, 0.4);
    background: var(--status-pending-bg);
}

@media (max-width: 900px) {
    .pending-split {
        grid-template-columns: 1fr;
    }
}

.auth-loading-screen,
.auth-loading-inline {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 40vh;
    color: var(--text-muted, #888);
    padding: 24px;
}

.auth-loading-inline {
    min-height: auto;
    padding: 16px;
}

#blazor-error-ui {
    background: var(--color-sun);
    color: #fff;
    padding: 8px 16px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: none;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    margin-left: 12px;
}

@media (max-width: 900px) {
    .admin-chats-layout {
        grid-template-columns: 1fr;
    }
}
