/* ===== TOP HEADER ===== */




.top-header {
    margin-bottom: 25px;
}

/* FIRST ROW */

.top-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;

    padding-bottom: 12px;
    margin-bottom: 12px;

    border-bottom: 2px solid #c3ccd8;
}

.project-title {
    font-size: 28px;
    font-weight: bold;
    color: #2b3a4a;
}

.top-user-info {
    display: flex;
    align-items: center;
    gap: 12px;

    font-size: 14px;
    color: #444;
}

/* SECOND ROW */

.top-menu-row {
    display: flex;
    justify-content: space-between;
    align-items: center;

    padding-bottom: 10px;
    border-bottom: 1px solid #ccd3dd;
}

/* MENU */

.main-menu {
    display: flex;
    gap: 6px;
}

.main-menu .btn.active {
    opacity: 0.5;
}

/* SERVER STATUS */

.server-status {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 14px;
    color: #444;
}

.server-metric {
    padding-left: 10px;
    border-left: 1px solid #c3ccd8;
    color: #444;
}

.status-online {
    color: #1a7f37;
    font-weight: bold;
}

.status-warning {
    color: #b26a00;
    font-weight: bold;
}

.status-offline {
    color: #c0392b;
    font-weight: bold;
}

/* ===== LOGOUT LINK ===== */

.logout-link {
    color: #005fcc;
    text-decoration: none;
    font-weight: bold;
    font-size: 14px;
}

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

/* ===== BASE ===== */

body {
    font-family: Arial, sans-serif;
    background: #e6ebf1;
    margin: 0;
    padding: 0;
    color: #222;
}

h1,
h2,
h3 {
    margin-top: 0;
    color: #2b3a4a;
}

/* ===== MAIN CONTAINER ===== */

.admin-container {
    max-width: 1400px;
    margin: 40px auto;
    background: #ffffff;
    padding: 30px;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,.12);
}

/* ===== BUTTONS ===== */

.btn {
    display: inline-block;
    padding: 6px 12px;
    font-size: 13px;
    border-radius: 4px;
    border: none;
    background: #005fcc;
    color: #fff;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    text-align: center;
    transition: background .15s ease;
}

.btn:hover {
    background: #004ea8;
}

.btn:disabled {
    opacity: 0.5;
}

.btn-danger {
    background: #c0392b;
}

.btn-danger:hover {
    background: #a93226;
}

/* ===== TABLE ===== */

.admin-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
    font-size: 14px;
    background: #ffffff;
}

/* HEADERS */

.admin-table th {
    background: #dce3ea;
    border-bottom: 2px solid #b9c2cf;
    padding: 10px 12px;
    text-align: center;
    color: #2b3a4a;
}

/* CELLS */

.admin-table td {
    padding: 10px 12px;
    text-align: center;
    vertical-align: middle;
    border-bottom: 1px solid #ccd3dd;
}

/* FIRST COLUMN LEFT */

.admin-table td:nth-child(2) {
    text-align: left;
}

/* ROW COLORS */

.admin-table tr:nth-child(odd) {
    background: #f0f4fa;
}

.admin-table tr:nth-child(even) {
    background: #e4ebf5;
}

.admin-table tr:hover {
    background: #dce3ea;
}

/* ===== CHECKBOXES ===== */

input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* ===== ACTIONS ===== */

.actions {
    white-space: nowrap;
}

/* ===== USER STATISTICS ===== */

.stats-container {
    max-width: 1040px;
}

.stats-user-card {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1.4fr;
    gap: 14px;
    margin: 0 0 22px;
    padding: 16px;
    border: 1px solid #ccd3dd;
    border-radius: 6px;
    background: #f0f4fa;
}

.stats-label {
    margin-bottom: 5px;
    font-size: 12px;
    font-weight: bold;
    color: #5a6775;
    text-transform: uppercase;
}

.stats-user-name {
    font-size: 18px;
    font-weight: bold;
    color: #2b3a4a;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 26px;
}

.stats-metric {
    padding: 16px;
    border: 1px solid #ccd3dd;
    border-radius: 6px;
    background: #ffffff;
}

.stats-value {
    font-size: 28px;
    font-weight: bold;
    color: #2b3a4a;
}

.stats-table {
    margin-bottom: 26px;
}

.stats-table td:first-child {
    text-align: left;
}

.stats-table td:nth-child(2) {
    text-align: left;
}

@media (max-width: 800px) {

    .stats-user-card,
    .stats-grid {
        grid-template-columns: 1fr;
    }

}
/* ===== PAGINATION ===== */

.pagination {
    margin-top: 25px;
    text-align: center;
}

.pagination a,
.pagination span {
    display: inline-block;
    padding: 6px 10px;
    margin: 2px;
    text-decoration: none;
    border-radius: 6px;
    border: 1px solid #bcc7d4;
    color: #333;
    background: #fff;
    font-size: 13px;
}

.pagination a:hover {
    background: #eef2f7;
}

.page-info {
    background: #dce3ea;
    border-color: #b9c2cf;
    font-weight: bold;
}

/* ===== FORM ELEMENTS ===== */

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
    padding: 6px 10px;
    border: 1px solid #9fb0c5;
    border-radius: 4px;
    font-size: 14px;
    background: #ffffff;
    box-sizing: border-box;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: #4c83ff;
    box-shadow: 0 0 0 2px rgba(76,131,255,.2);
}

/* ===== STATUS LABELS ===== */

.status-active {
    color: #1a7f37;
    font-weight: bold;
}

.status-disabled {
    color: #c0392b;
    font-weight: bold;
}

/* ===== TOP TOOLBAR SPACING ===== */

.admin-container > .btn,
.admin-container > button {
    margin-bottom: 10px;
}

/* ===== MOBILE ===== */

@media (max-width: 1100px) {

    .admin-container {
        padding: 20px;
        margin: 20px;
    }

    .admin-table {
        font-size: 13px;
    }

    .admin-table th,
    .admin-table td {
        padding: 8px;
    }

}

@media (max-width: 800px) {

    .admin-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

}

/* ===== LOGIN PAGE ===== */

.login-container {
    max-width: 420px;
    margin: 80px auto;
    background: #ffffff;
    padding: 30px;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,.12);
}

.login-container h2 {
    margin-bottom: 25px;
    text-align: center;
    color: #2b3a4a;
}

.login-container form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.login-container input[type="text"],
.login-container input[type="password"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #9fb0c5;
    border-radius: 4px;
    font-size: 14px;
    box-sizing: border-box;
    background: #fff;
}

.login-container input:focus {
    outline: none;
    border-color: #4c83ff;
    box-shadow: 0 0 0 2px rgba(76,131,255,.2);
}

.login-container button {
    padding: 10px 12px;
    border: none;
    border-radius: 4px;
    background: #005fcc;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    transition: background .15s ease;
}

.login-container button:hover {
    background: #004ea8;
}

/* ===== ERROR MESSAGE ===== */

.error {
    background: #ffe5e5;
    color: #a00;
    padding: 10px;
    margin-bottom: 15px;
    border-radius: 4px;
    font-size: 14px;
}


/* ===== CREATE / EDIT USER FORM ===== */

.form-container {
    max-width: 620px;
    margin: 40px auto;
    background: #ffffff;
    padding: 30px;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,.12);
}

.form-container h2 {
    margin-bottom: 20px;
    color: #2b3a4a;
}

/* BACK BUTTON */

.btn-back {
    margin-bottom: 25px;
    background: #6c7a89;
}

.btn-back:hover {
    background: #5a6775;
}

.btn-back-admin {
    background: #6c7a89;
}

.btn-back-admin:hover {
    background: #5a6775;
}

/* FORM GROUPS */

.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    margin-bottom: 7px;
    font-weight: bold;
    color: #2b3a4a;
}

/* REQUIRED STAR */

.required {
    color: #c0392b;
}

/* INPUTS */

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="email"],
.form-group input[type="number"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #9fb0c5;
    border-radius: 4px;
    font-size: 14px;
    background: #ffffff;
    box-sizing: border-box;
    transition:
        border-color .15s ease,
        box-shadow .15s ease;
}

/* FOCUS */

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #4c83ff;
    box-shadow: 0 0 0 2px rgba(76,131,255,.2);
}

/* SUBMIT BUTTON */

.form-container button[type="submit"] {
    margin-top: 10px;
    min-width: 140px;
}

/* ===== PAGINATION ===== */


.pagination a.btn {
    background: #005fcc;
    color: #fff;
    border: none;
}

.pagination a.btn:hover {
    background: #004ea8;
}

/* ===== DISABLED BULK BUTTONS ===== */

.bulk-btn:disabled {
    cursor: not-allowed;
}

/* ===== NOTIFICATIONS ===== */

.notice {
    margin-bottom: 20px;
    padding: 14px 18px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid transparent;
}

/* SUCCESS */

.notice-green {
    background: #e6f4ea;
    color: #1a7f37;
    border-color: #a8dbb5;
}

/* WARNING */

.notice-yellow {
    background: #fff4db;
    color: #7a5a00;
    border-color: #f1d38a;
}

/* ERROR */

.notice-pink {
    background: #fde6ec;
    color: #7a1e3a;
    border-color: #f1b4c4;
}

/* ===== SETTINGS ===== */

.settings-section {
    margin-top: 18px;
    padding: 20px;
    border: 1px solid #d6dee8;
    border-radius: 6px;
    background: #ffffff;
}

.settings-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 10px;
}

.settings-section-header h3 {
    margin: 0;
    color: #24364a;
}

.settings-status {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: bold;
    white-space: nowrap;
}

.settings-status-ready {
    background: #e6f4ea;
    color: #1a7f37;
}

.settings-status-missing {
    background: #fff4db;
    color: #7a5a00;
}

.settings-help {
    max-width: 820px;
    margin: 0 0 18px;
    color: #566579;
    line-height: 1.45;
}

.settings-form {
    max-width: 860px;
}

.settings-section .settings-form {
    padding: 16px;
    border: 1px solid #d6dee8;
    background: #f7f9fc;
    box-shadow: none;
}

.form-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 18px;
}

.form-group-port {
    max-width: 180px;
}

.settings-muted {
    color: #6b7788;
    font-weight: normal;
}

.settings-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 18px;
    color: #2b3a4a;
    font-weight: bold;
}

.settings-checkbox-list {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    margin: 0 0 18px;
}

.settings-checkbox-list .settings-checkbox {
    margin: 0;
}

.settings-radio-group {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    margin: 0 0 18px;
    padding: 0;
    border: 0;
}

.settings-radio-group legend {
    width: 100%;
    margin: 0 0 8px;
    padding: 0;
    color: #2b3a4a;
    font-weight: bold;
}

.settings-radio-group label {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: #2b3a4a;
    font-weight: bold;
}

.settings-help-icon {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin-left: 4px;
    border-radius: 50%;
    background: #eef3f8;
    color: #4e6075;
    font-size: 12px;
    font-weight: bold;
    cursor: help;
}

.settings-help-icon:hover::after,
.settings-help-icon:focus::after {
    content: attr(aria-label);
    position: absolute;
    left: 50%;
    bottom: calc(100% + 8px);
    z-index: 5;
    width: 260px;
    padding: 9px 10px;
    border-radius: 4px;
    background: #24364a;
    color: #ffffff;
    font-size: 12px;
    font-weight: normal;
    line-height: 1.35;
    transform: translateX(-50%);
    box-shadow: 0 8px 22px rgba(18, 33, 52, .18);
}

.field-help {
    margin: 7px 0 0;
    color: #6b7788;
    font-size: 13px;
    line-height: 1.4;
}

.field-help a {
    color: #315fbd;
    font-weight: bold;
}

.settings-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.settings-actions button {
    margin-top: 0;
}

.settings-form .settings-actions button,
.settings-form .settings-actions button[type="submit"] {
    margin-top: 0;
}

.instance-transfer-grid {
    display: grid;
    grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
    gap: 18px;
    max-width: 860px;
    margin: 0 auto;
}

.transfer-panel {
    max-width: none;
    margin: 0;
}

.transfer-panel h4 {
    margin: 0 0 14px;
    color: #2b3a4a;
}

.transfer-checkboxes {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 14px;
}

.transfer-checkboxes .settings-checkbox:last-child {
    grid-column: 1 / -1;
}

.smtp-test-result {
    display: block;
    min-height: 20px;
    margin-top: 8px;
    color: #6b7788;
    font-size: 13px;
    font-weight: bold;
    line-height: 1.35;
}

.smtp-test-result.is-success {
    color: #1a7f37;
}

.smtp-test-result.is-error {
    color: #b4233a;
}

.smtp-test-result.is-pending,
.smtp-test-result.is-muted {
    color: #6b7788;
}

.invite-copy-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
}

.invite-copy-row input {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid #a8dbb5;
    border-radius: 4px;
    font-size: 13px;
}

.invite-copy-row .btn {
    margin-top: 0;
}

.forgot-password-link {
    display: block;
    margin-top: 16px;
    text-align: center;
    color: #005fcc;
    text-decoration: none;
    font-size: 14px;
}

.forgot-password-link:hover {
    text-decoration: underline;
}

.forgot-password-note {
    margin: 16px 0 0;
    padding: 10px 12px;
    border: 1px solid #f1d38a;
    border-radius: 4px;
    background: #fff4db;
    color: #7a5a00;
    font-size: 13px;
    line-height: 1.4;
}

.success-message {
    margin: 0 0 14px;
    padding: 10px 12px;
    border: 1px solid #a8dbb5;
    border-radius: 4px;
    background: #e6f4ea;
    color: #1a7f37;
    font-size: 13px;
    line-height: 1.4;
}

.invite-user-name {
    margin: -4px 0 16px;
    color: #566579;
    text-align: center;
    font-size: 14px;
}

.password-criteria,
.password-errors {
    margin: 0;
    padding: 10px 12px 10px 28px;
    border-radius: 4px;
    font-size: 13px;
    line-height: 1.45;
}

.password-criteria {
    background: #f3f6fa;
    color: #566579;
}

.password-criteria li.is-met {
    color: #1a7f37;
    font-weight: bold;
}

.password-errors {
    background: #ffe5e5;
    color: #a00;
}

.password-actions {
    display: flex;
    gap: 10px;
}

.password-actions button {
    flex: 1;
    margin-top: 0;
}

.password-copy-status {
    min-height: 18px;
    margin-top: -8px;
    color: #1a7f37;
    font-size: 13px;
    line-height: 1.35;
}

@media (max-width: 760px) {
    .settings-section-header,
    .form-row,
    .instance-transfer-grid {
        display: block;
    }

    .settings-status {
        margin-top: 10px;
    }

    .form-group-port {
        max-width: none;
    }

    .settings-radio-group {
        align-items: flex-start;
        flex-direction: column;
        gap: 10px;
    }

    .transfer-panel + .transfer-panel {
        margin-top: 14px;
    }

    .transfer-checkboxes {
        grid-template-columns: 1fr;
    }

    .settings-help-icon:hover::after,
    .settings-help-icon:focus::after {
        left: 0;
        width: min(260px, 76vw);
        transform: none;
    }
}

/* ===== CHAT ===== */

.chat-page {
    max-width: 1380px;
    margin: 40px auto;
    height: calc(100vh - 130px);
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 18px;
}

.chat-sidebar {
    height: 100%;
    min-height: 0;
    box-sizing: border-box;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    border: 1px solid #ccd3dd;
    border-radius: 6px;
    background: #f7f9fc;
}

.chat-new-btn {
    width: 100%;
}

.chat-session-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    scrollbar-gutter: stable;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-session-item {
    position: relative;
    flex: 0 0 auto;
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #c3ccd8;
    border-radius: 6px;
    background: #ffffff;
    color: #2b3a4a;
    overflow: hidden;
}

.chat-session-item:hover,
.chat-session-item.active {
    background: #e7f0ff;
    border-color: #8fb0df;
}

.chat-session-open {
    display: block;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    min-height: 52px;
    padding: 9px 34px 9px 10px;
    border: 0;
    background: transparent;
    color: inherit;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
}

.chat-session-open span,
.chat-session-open small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-session-open span {
    line-height: 1.25;
    font-size: 13px;
    font-weight: bold;
}

.chat-session-open small {
    margin-top: 4px;
    line-height: 1.25;
    font-size: 11px;
    color: #66758a;
}

.chat-session-delete {
    position: absolute;
    top: 50%;
    right: 6px;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 1px solid #d7b8b2;
    border-radius: 4px;
    background: #fff7f5;
    color: #a93226;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    font-family: inherit;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-50%);
    transition: opacity .12s ease, background .12s ease;
}

.chat-session-delete:hover,
.chat-session-delete:focus {
    background: #ffe0da;
    color: #8f241c;
}


.chat-session-item:hover .chat-session-delete,
.chat-session-item:focus-within .chat-session-delete {
    opacity: 1;
    pointer-events: auto;
}

.chat-container {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#chat {
    flex: 1;
    overflow-y: auto;

    display: flex;
    flex-direction: column;
    gap: 14px;

    padding: 16px;

    border: 1px solid #ccd3dd;
    border-radius: 6px;

    background: #f7f9fc;
}

/* TOP BAR */

/* ===== CHAT TOPBAR ===== */

.chat-topbar {
    display: flex;
    flex-direction: column;
    gap: 12px;

    padding-bottom: 15px;
    margin-bottom: 15px;

    border-bottom: 2px solid #c3ccd8;
}

.chat-title-row {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

/* RIGHT SIDE */

.chat-topbar-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.chat-topbar h2 {
    margin: 0;
    font-size: 26px;
    line-height: 1;
    color: #2b3a4a;
}

/* AI SELECT */

.chat-controls {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.ai-select {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 320px;
}

.ai-model-select {
    width: 380px;
}

.ai-select label {
    flex-shrink: 0;
    font-size: 14px;
    font-weight: bold;
    color: #2b3a4a;
    white-space: nowrap;
}

.ai-select select,
.ai-select input {
    width: 100%;
    min-width: 0;
}

/* CHAT WINDOW */

#chat {
    flex: 1;

    overflow-y: auto;

    padding: 16px;

    border: 1px solid #ccd3dd;
    border-radius: 6px;

    background: #f7f9fc;
}

/* MESSAGE WRAPPER */

.chat-message {
    display: flex;
    flex-direction: column;

    width: 100%;
    margin-bottom: 0px;
}

/* BASE MESSAGE */

.msg {
    width: 90%;
    max-width: 90%;
    padding: 10px 14px;

    border-radius: 10px;

    line-height: 1.5;
    white-space: pre-wrap;

    font-size: 14px;

    box-shadow: 0 1px 2px rgba(0,0,0,.05);
} 



.msg-images {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 280px));
    gap: 10px;
    margin-top: 10px;
}

.msg-images a {
    display: block;
}

.msg-images img {
    display: block;
    width: 100%;
    max-height: 360px;
    object-fit: contain;
    border-radius: 6px;
    border: 1px solid rgba(0,0,0,.12);
    background: #fff;
}

/*.msg {
    display: block;

    width: 90%;

    box-sizing: border-box;
}*/

/* USER */

.msg.user {
    align-self: flex-end;

    margin-left: 18%;

    /*background: #d9e9ff;*/
    background: #d6ebff;

    border: 1px solid #b7cdea;
}

/* AI */

.msg.ai {
    align-self: flex-start;

    margin-right: 18%;

    /*background: #eef4fb;*/
    background: #e7ffe7;
    border: 1px solid #ccd8e6;
}

.msg-meta {
    display: inline-flex;
    align-items: center;
    align-self: flex-start;
    gap: 5px;
    max-width: 90%;
    margin: 4px 0 8px;
    padding: 3px 7px;
    border: 1px solid #f1b4c4;
    border-radius: 4px;
    background: #fff1f4;
    color: #9b2444;
    font-size: 11px;
    font-weight: normal;
    line-height: 1.25;
}

.msg.user + .msg-meta {
    align-self: flex-end;
    margin-left: 18%;
}

.msg.ai + .msg-meta {
    margin-right: 18%;
}

.msg-meta-icon {
    position: relative;
    flex: 0 0 auto;
    width: 10px;
    height: 8px;
    margin-top: 2px;
    border: 1.5px solid currentColor;
    border-radius: 2px;
}

.msg-meta-icon::before {
    content: "";
    position: absolute;
    left: 1.5px;
    top: -6px;
    width: 5px;
    height: 6px;
    border: 1.5px solid currentColor;
    border-bottom: 0;
    border-radius: 6px 6px 0 0;
}

.msg-meta-label {
    font-weight: bold;
}

.msg-meta-values {
    overflow-wrap: anywhere;
}

/* INPUT AREA */

.input-area {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    align-items: center;
}

.input-area .btn {
    height: 28px;   /* фикс */
    flex-shrink: 0;
}

/* INPUT */

.chat-input {
    flex: 1;

    resize: none;

    /*height: 20px;*/
    /*min-height: 20px;*/

    max-height: 160px;

    padding: 4px 10px;

    border: 1px solid #9fb0c5;
    border-radius: 6px;

    font-size: 14px;
    font-family: inherit;

    /*line-height: 20px;*/

    overflow-y: auto;

    box-sizing: border-box;
}

.chat-message {
    width: 100%;
}

/* SECURITY */

#security {
    margin-top: 12px;
}

/* SECURITY TITLE */

.sec-title {
    font-weight: bold;

    margin-bottom: 8px;

    color: #7a5a00;
}

/* SECURITY ITEM */

.sec-item {
    background: #fff4db;

    border: 1px solid #f1d38a;

    color: #7a5a00;

    margin-bottom: 6px;

    padding: 8px 10px;

    border-radius: 4px;

    font-size: 12px;
}

/* MOBILE */

@media (max-width: 800px) {

    .chat-page {
        margin: 10px;
        height: calc(100vh - 20px);
        grid-template-columns: 1fr;
    }

    .chat-sidebar {
        max-height: 180px;
    }

    .chat-container {
        min-height: 0;
    }

    .msg {
        max-width: 92%;
    }

    .chat-title-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .chat-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .ai-select,
    .ai-model-select {
        width: 100%;
    }

}

/* READONLY FIELDS */
input[type="text"][readonly],
input[type="url"][readonly],
input[type="email"][readonly],
input[type="password"][readonly],
input[type="number"][readonly],
textarea[readonly],
textarea:read-only,
select:disabled {
    background-color: #e6ebf1 !important;
    color: #555555 !important;
    cursor: not-allowed !important;
    border-color: #b8c5d9;
}

input[type="text"][readonly]:hover,
input[type="url"][readonly]:hover,
input[type="email"][readonly]:hover,
input[type="password"][readonly]:hover,
input[type="number"][readonly]:hover,
select:disabled:hover {
    background-color: #f1f4f9 !important;
}

input[type="text"][readonly]:focus,
input[type="url"][readonly]:focus,
input[type="email"][readonly]:focus,
input[type="password"][readonly]:focus,
input[type="number"][readonly]:focus,
select:disabled:focus {
    border-color: #b8c5d9 !important;
    box-shadow: none !important;
    outline: none;
}

/* ===== CHAT RICH CONTENT ===== */

.msg-text + .code-block,
.code-block + .msg-text,
.code-block + .code-block {
    margin-top: 10px;
}

.msg-text:empty {
    display: none;
}

.code-block {
    overflow: hidden;
    border: 1px solid #b7c6d8;
    border-radius: 6px;
    background: #17202a;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.05);
}

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 34px;
    padding: 6px 8px 6px 12px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    background: #202c38;
}

.code-lang {
    overflow: hidden;
    color: #b9c7d6;
    font-size: 12px;
    font-weight: bold;
    text-transform: uppercase;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.code-copy-btn,
.preview-btn {
    padding: 4px 9px;
    border: 1px solid #8fa2b8;
    border-radius: 4px;
    background: #ffffff;
    color: #2b3a4a;
    font-size: 12px;
    cursor: pointer;
}

.code-copy-btn:hover,
.preview-btn:hover {
    background: #eef2f7;
}

.image-preview-actions a.preview-btn {
    text-decoration: none;
}

.code-copy-btn:disabled,
.preview-btn:disabled {
    cursor: default;
    opacity: .7;
}

.code-block pre {
    max-width: 100%;
    margin: 0;
    padding: 12px;
    overflow-x: auto;
    white-space: pre;
}

.code-block code {
    color: #edf4ff;
    font-family: Consolas, "Courier New", monospace;
    font-size: 13px;
    line-height: 1.45;
}

.code-block .tok-keyword {
    color: #77b7ff;
    font-weight: bold;
}

.code-block .tok-string {
    color: #9de59d;
}

.code-block .tok-number {
    color: #ffd37a;
}

.code-block .tok-builtin {
    color: #d7a7ff;
}

.code-block .tok-comment {
    color: #94a3b8;
    font-style: italic;
}

.code-block .tok-tag {
    color: #7dd3fc;
}

.code-block .tok-attr {
    color: #f9a8d4;
}

.code-block .tok-variable {
    color: #fca5a5;
}

.msg-image-link {
    position: relative;
    cursor: zoom-in;
}

.msg-image-link::after {
    content: "Preview";
    position: absolute;
    right: 3px;
    bottom: 8px;
    padding: 3px 7px;
    border-radius: 4px;
    background: rgba(23,32,42,.78);
    color: #fff;
    font-size: 11px;
    opacity: 0;
    transition: opacity .15s ease;
}

.msg-image-link:hover::after,
.msg-image-link.is-opening::after {
    opacity: 1;
}

.msg-image-link.is-opening::after {
    content: "Opening preview...";
}

.image-preview {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(14,23,34,.72);
}

.image-preview-panel {
    display: flex;
    flex-direction: column;
    max-width: min(1100px, 96vw);
    max-height: 94vh;
    overflow: hidden;
    border-radius: 6px;
    background: #ffffff;
    box-shadow: 0 18px 60px rgba(0,0,0,.35);
}

.image-preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-bottom: 1px solid #ccd3dd;
    background: #f7f9fc;
}

.image-preview-title-wrap {
    min-width: 0;
}

.image-preview-title {
    overflow: hidden;
    color: #2b3a4a;
    font-size: 14px;
    font-weight: bold;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-preview-meta {
    margin-top: 2px;
    color: #667789;
    font-size: 12px;
}

.image-preview-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.image-preview-body {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: min(720px, 92vw);
    min-height: min(420px, 70vh);
    background: #fff;
}

.image-preview-panel:not(.is-loading) .image-preview-body {
    min-width: 0;
    min-height: 0;
}

.image-preview-loading {
    padding: 34px 42px;
    color: #4d5f72;
    font-size: 14px;
    font-style: italic;
}

.image-preview-loading::after {
    content: "";
    display: inline-block;
    width: 18px;
    overflow: hidden;
    vertical-align: bottom;
    animation: thinkingDots 1.2s steps(4, end) infinite;
}

.image-preview-loading.error {
    color: #7a1e3a;
    font-style: normal;
}

.image-preview-loading.error::after {
    content: none;
    animation: none;
}

.image-preview-img.is-hidden {
    display: none !important;
}

.image-preview img {
    display: block;
    max-width: 100%;
    max-height: calc(94vh - 55px);
    object-fit: contain;
    background: #fff;
}

@media (max-width: 800px) {
    .image-preview {
        padding: 10px;
    }

    .image-preview-toolbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .image-preview-actions {
        width: 100%;
    }

    .preview-btn {
        flex: 1;
    }
}




.msg.thinking {
    color: #4d5f72;
    font-style: italic;
}

.msg.thinking .msg-text::after {
    content: "";
    display: inline-block;
    width: 18px;
    overflow: hidden;
    vertical-align: bottom;
    animation: thinkingDots 1.2s steps(4, end) infinite;
}

.msg.error {
    background: #fde6ec;
    border-color: #f1b4c4;
    color: #7a1e3a;
}

@keyframes thinkingDots {
    0% { content: ""; }
    25% { content: "."; }
    50% { content: ".."; }
    75%, 100% { content: "..."; }
}





/* ===== CHAT MARKDOWN ===== */

.msg-text p,
.msg-text ul,
.msg-text ol,
.msg-text blockquote,
.msg-text h3,
.msg-text h4,
.msg-text h5 {
    margin: 0 0 8px;
}

.msg-text p:last-child,
.msg-text ul:last-child,
.msg-text ol:last-child,
.msg-text blockquote:last-child,
.msg-text h3:last-child,
.msg-text h4:last-child,
.msg-text h5:last-child {
    margin-bottom: 0;
}

.msg-text h3,
.msg-text h4,
.msg-text h5 {
    color: inherit;
    font-size: 15px;
    line-height: 1.35;
}

.msg-text ul,
.msg-text ol {
    padding-left: 22px;
}

.msg-text li + li {
    margin-top: 3px;
}

.msg-text blockquote {
    padding: 6px 10px;
    border-left: 3px solid #8fa2b8;
    background: rgba(255,255,255,.45);
    color: #405061;
}

.msg-text a {
    color: #005fcc;
    text-decoration: underline;
    overflow-wrap: anywhere;
}

.msg-text code {
    padding: 1px 4px;
    border: 1px solid rgba(0,0,0,.12);
    border-radius: 4px;
    background: rgba(255,255,255,.65);
    font-family: Consolas, "Courier New", monospace;
    font-size: 13px;
}

.markdown-table-wrap {
    max-width: 100%;
    margin: 8px 0;
}

.markdown-table-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 4px;
}

.table-copy-btn {
    padding: 4px 9px;
    border: 1px solid #8fa2b8;
    border-radius: 4px;
    background: #ffffff;
    color: #2b3a4a;
    font-size: 12px;
    cursor: pointer;
}

.table-copy-btn:hover {
    background: #eef2f7;
}

.table-copy-btn:disabled {
    cursor: default;
    opacity: .7;
}

.markdown-table-scroller {
    max-width: 100%;
    overflow-x: auto;
}

.markdown-table {
    width: 100%;
    border-collapse: collapse;
    background: rgba(255,255,255,.55);
    font-size: 13px;
}

.markdown-table th,
.markdown-table td {
    padding: 7px 9px;
    border: 1px solid rgba(143,162,184,.75);
    vertical-align: top;
}

.markdown-table th {
    background: rgba(220,227,234,.85);
    color: #2b3a4a;
    font-weight: bold;
}

.markdown-table tbody tr:nth-child(even) {
    background: rgba(255,255,255,.35);
}


/* ===== MESSAGE COPY ===== */

.msg {
    position: relative;
}

.message-copy-btn {
    position: absolute;
    top: 2px;
    right: 3px;
    padding: 3px 7px;
    border: 1px solid #8fa2b8;
    border-radius: 4px;
    background: rgba(255,255,255,.92);
    color: #2b3a4a;
    font-size: 11px;
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s ease, background .15s ease;
    z-index: 2;
}

.msg:hover .message-copy-btn,
.message-copy-btn:focus {
    opacity: 1;
}

.message-copy-btn:hover {
    background: #eef2f7;
}

.message-copy-btn:disabled {
    cursor: default;
    opacity: .8;
}





/* ===== COPY BUTTON ALIGNMENT ===== */

.code-copy-btn,
.table-copy-btn {
    transform: translateY(2px);
}



/* ===== CHAT SIDEBAR OVERRIDES ===== */
.chat-page > .chat-sidebar {
    height: 100%;
    min-height: 0;
    box-sizing: border-box;
    overflow: hidden;
}

.chat-page > .chat-sidebar > .chat-session-list {
    flex: 1 1 auto;
    min-height: 0;
    max-height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
}

.chat-page > .chat-sidebar > .chat-session-list > .chat-session-item {
    flex: 0 0 auto;
    min-height: 54px;
    box-sizing: border-box;
}

.chat-page .chat-session-open {
    display: block;
    width: 100%;
    min-height: 52px;
    box-sizing: border-box;
    padding: 9px 34px 9px 10px;
    line-height: normal;
}

.chat-page .chat-session-open span,
.chat-page .chat-session-open small {
    display: block;
    line-height: 1.25;
}
