/**
 * Общие стили: кнопки, select, checkbox.
 * Кнопки — сплошной заливка, лёгкая граница, без градиентов и лишнего свечения.
 */
:root {
    --u-radius: 9px;
    --u-radius-sm: 8px;
    --u-accent: #16a34a;
    --u-accent-hover: #22c55e;
    --u-accent-active: #166534;
    --u-border: #3f3f46;
    --u-border-strong: #52525b;
    --u-bg-field: #141414;
    --u-bg-field-hover: #18181b;
    --u-btn-secondary-bg: #27272a;
    --u-btn-secondary-hover: #3f3f46;
    --u-danger: #b91c1c;
    --u-danger-hover: #991b1b;
    --u-danger-active: #7f1d1d;
    --u-text: #e5e5e5;
    --u-muted: #a1a1aa;
    --u-font: "Inter", system-ui, -apple-system, sans-serif;
    --u-focus-ring: 0 0 0 2px #141414, 0 0 0 4px rgba(37, 99, 235, 0.45);
}

/* ——— Выпадающие списки ——— */
select,
.ui-select {
    font-family: var(--u-font);
    font-size: 13px;
    color: var(--u-text);
    background-color: var(--u-bg-field);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    border: 1px solid var(--u-border);
    border-radius: var(--u-radius);
    padding: 10px 40px 10px 14px;
    min-height: 42px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    transition: border-color 0.15s ease, background-color 0.15s ease;
    width: 100%;
    box-sizing: border-box;
}

select:hover,
.ui-select:hover {
    border-color: var(--u-border-strong);
    background-color: var(--u-bg-field-hover);
}

select:focus,
.ui-select:focus {
    outline: none;
    border-color: var(--u-accent);
    box-shadow: var(--u-focus-ring);
}

select:disabled,
.ui-select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

select option {
    background: #18181b;
    color: var(--u-text);
}

/* ——— Чекбоксы (единый вид, без «тонкого» системного чекбокса) ——— */
input[type="checkbox"]:not(.perm-cb) {
    -webkit-appearance: none;
    appearance: none;
    width: 1.25rem;
    height: 1.25rem;
    min-width: 1.25rem;
    min-height: 1.25rem;
    margin: 0;
    border: 2px solid var(--u-border);
    border-radius: 6px;
    background: var(--u-bg-field);
    cursor: pointer;
    vertical-align: middle;
    flex-shrink: 0;
    transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
    box-sizing: border-box;
    position: relative;
}

input[type="checkbox"]:not(.perm-cb):hover:not(:disabled) {
    border-color: var(--u-border-strong);
    background: var(--u-bg-field-hover);
}

input[type="checkbox"]:not(.perm-cb):checked {
    background-color: var(--u-accent);
    border-color: rgba(255, 255, 255, 0.22);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M3.5 8L6.5 11L12.5 5' stroke='%23f8fafc' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-size: 12px 12px;
    background-position: center;
    background-repeat: no-repeat;
}

input[type="checkbox"]:not(.perm-cb):focus-visible {
    outline: none;
    box-shadow: var(--u-focus-ring);
}

input[type="checkbox"]:not(.perm-cb):disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ——— Кнопки (унифицированная система) ——— */
.u-btn,
.btn-primary,
.btn-secondary,
.action,
.new-chat-btn,
.ui-nav-btn,
.kb-save-desc,
.btn-save-perms,
.send-btn,
button.action,
form#settingsForm button[type="submit"].action,
form#f button[type="submit"] {
    font-family: var(--u-font);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.25;
    border-radius: 10px;
    padding: 10px 18px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    box-sizing: border-box;
    transition: all 0.12s ease;
    border: 1px solid transparent;
    user-select: none;
    white-space: nowrap;
}

/* Расстояние между соседними кнопками */
.u-btn + .u-btn,
.action + .action,
input + .action,
.action + input,
.ui-nav-btn + .ui-nav-btn {
    margin-left: 8px;
}

/* Эффект нажатия для всех кнопок */
.u-btn:active, .action:active, .new-chat-btn:active, .ui-nav-btn:active, .send-btn:active {
    transform: scale(0.97);
    filter: brightness(0.9);
}

.u-btn:disabled, .action:disabled, .new-chat-btn:disabled {
    opacity: 0.45 !important;
    cursor: not-allowed;
    transform: none !important;
}

.u-btn:focus-visible, .action:focus-visible, .new-chat-btn:focus-visible {
    outline: none;
    box-shadow: var(--u-focus-ring);
}

/* Основная (акцентная) */
.u-btn--primary,
.new-chat-btn,
.send-btn,
.kb-save-desc,
.btn-save-perms,
#confirmModalOk,
button.action:not(.secondary):not(.danger),
form#settingsForm button[type="submit"].action,
form#f button[type="submit"] {
    background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.u-btn--primary:hover,
.new-chat-btn:hover,
.send-btn:hover,
.kb-save-desc:hover,
.btn-save-perms:hover,
#confirmModalOk:hover,
button.action:not(.secondary):not(.danger):hover {
    background: linear-gradient(180deg, #60a5fa 0%, #2563eb 100%);
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 8px rgba(37, 99, 235, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* Вторичная (нейтральная) */
.u-btn--secondary,
.btn-secondary,
.source-open-tab-btn,
button.action.secondary {
    background: #27272a;
    color: #e4e4e7;
    border: 1px solid #3f3f46;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.u-btn--secondary:hover,
.btn-secondary:hover:not(:disabled),
.source-open-tab-btn:hover:not(:disabled),
button.action.secondary:hover {
    background: #3f3f46;
    border-color: #52525b;
    color: #ffffff;
}

/* Опасное действие */
.u-btn--danger,
button.action.danger {
    background: linear-gradient(180deg, #ef4444 0%, #b91c1c 100%);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.2);
}

.u-btn--danger:hover,
button.action.danger:hover {
    background: linear-gradient(180deg, #f87171 0%, #b91c1c 100%);
    box-shadow: 0 4px 8px rgba(239, 68, 68, 0.3);
}

/* ——— Переходы между разделами: топбар, «назад», вкладки админки ——— */
.ui-nav-btn {
    font-family: var(--u-font);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    min-height: 34px;
    box-sizing: border-box;
    border-radius: var(--u-radius-sm);
    border: 1px solid var(--u-border);
    background: var(--u-bg-field);
    color: var(--u-muted);
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
    box-shadow: none;
}

button.ui-nav-btn {
    font: inherit;
    appearance: none;
}

.ui-nav-btn:hover {
    border-color: var(--u-border-strong);
    color: var(--u-text);
    background: var(--u-bg-field-hover);
    text-decoration: none;
}

.ui-nav-btn:focus-visible {
    outline: none;
    box-shadow: var(--u-focus-ring);
}

.ui-nav-btn.active {
    background: var(--u-accent);
    border-color: rgba(255, 255, 255, 0.14);
    color: #fafafa;
}

.ui-nav-btn.active:hover {
    background: var(--u-accent-hover);
    color: #fafafa;
}

.send-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: var(--u-radius);
}

form#f button[type="submit"] {
    width: 100%;
    padding: 11px 18px;
    font-size: 14px;
    font-weight: 600;
    margin-top: 4px;
}

input.ui-input-inline,
.ui-input-inline {
    width: 100%;
    margin-bottom: 6px;
    padding: 8px 12px;
    font-size: 12px;
    border-radius: var(--u-radius);
    border: 1px solid var(--u-border);
    background: var(--u-bg-field);
    color: var(--u-text);
    font-family: var(--u-font);
    box-sizing: border-box;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input.ui-input-inline:last-of-type,
#uploadParentKb.ui-input-inline {
    margin-bottom: 0;
}

input.ui-input-inline:focus {
    outline: none;
    border-color: var(--u-accent);
    box-shadow: var(--u-focus-ring);
}

/* ——— Модальные окна ——— */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: u-modalBackdropIn 0.2s ease;
}
@keyframes u-modalBackdropIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.modal-overlay.open { display: flex; }

.modal-panel {
    background: linear-gradient(165deg, #1f1f23 0%, #171718 100%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 18px;
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.4),
        0 24px 64px rgba(0, 0, 0, 0.65),
        0 8px 24px rgba(0, 0, 0, 0.35);
    animation: u-modalPanelIn 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes u-modalPanelIn {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to   { opacity: 1; transform: none; }
}

.modal-panel--confirm {
    max-width: 400px;
    border-radius: 20px;
    border-top: 3px solid rgba(239, 68, 68, 0.65);
}

.modal-head {
    padding: 18px 22px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-head h2 { font-size: 16px; font-weight: 600; color: #fafafa; margin: 0; }

.modal-head--confirm {
    padding: 22px 24px 16px;
    border-bottom: none;
    align-items: flex-start;
}
.modal-head--confirm h2 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.3;
    color: #fafafa;
    padding-right: 12px;
}

.modal-close {
    flex-shrink: 0;
    height: 32px;
    padding: 0 12px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid #2a2a2a;
    color: #71717a;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    line-height: 1;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    font-family: var(--u-font);
    white-space: nowrap;
}
.modal-close:hover {
    color: #e4e4e7;
    background: rgba(255, 255, 255, 0.06);
}
.modal-close:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px #171718, 0 0 0 4px rgba(59, 130, 246, 0.45);
}

.modal-body {
    padding: 18px 22px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    color: #e5e5e5;
    font-family: var(--u-font);
    font-size: 14px;
}
.modal-body--confirm {
    padding: 0 24px 8px;
    gap: 0;
}

.confirm-modal-text {
    margin: 0;
    font-size: 14px;
    line-height: 1.6;
    color: #a39f9a;
}

.modal-actions {
    padding: 14px 22px 18px;
    border-top: 1px solid #262626;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
}
.modal-actions .btn-secondary,
.modal-actions .btn-primary,
.modal-actions #confirmModalOk {
    padding: 10px 18px;
    font-weight: 600;
    border-radius: 10px;
}
.modal-actions--confirm {
    margin-top: 0;
    padding: 20px 24px 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(0, 0, 0, 0.22);
    justify-content: flex-end;
    gap: 12px;
}
.modal-actions--confirm .btn-secondary {
    min-width: 108px;
    order: 1;
}
.modal-actions--confirm #confirmModalOk {
    min-width: 108px;
    order: 2;
}

/* ——— Тост-уведомления ——— */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 13px;
    font-family: var(--u-font);
    color: #fff;
    animation: u-toastIn 0.25s ease;
    max-width: 380px;
    pointer-events: auto;
}
.toast.error   { background: #ef4444; }
.toast.success { background: #10b981; }
@keyframes u-toastIn {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: none; opacity: 1; }
}
