:root {
    --bg: #e7ece9;
    --panel: #ffffff;
    --panel-soft: #f5f7f6;
    --line: #dce3df;
    --text: #17201c;
    --muted: #66736d;
    --green: #128c62;
    --green-dark: #075e54;
    --mint: #dcf8ec;
    --blue: #2b6cb0;
    --amber: #b7791f;
    --red: #c53030;
    --shadow: 0 18px 55px rgba(24, 35, 31, .14);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background:
        linear-gradient(180deg, var(--green-dark) 0 128px, var(--bg) 128px 100%);
    font-family: Tahoma, Arial, sans-serif;
}

button,
input,
textarea {
    font: inherit;
}

button {
    border: 0;
    color: #fff;
    background: var(--green);
    border-radius: 8px;
    padding: 11px 18px;
    cursor: pointer;
    min-height: 42px;
}

button:hover {
    filter: brightness(.96);
}

button:disabled {
    opacity: .55;
    cursor: not-allowed;
}

input,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 13px;
    color: var(--text);
    background: #fff;
    outline: none;
}

input:focus,
textarea:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(18, 140, 98, .12);
}

textarea {
    resize: vertical;
}

.hidden {
    display: none !important;
}

.shell {
    min-height: 100vh;
    padding: 28px;
}

.auth-view {
    min-height: calc(100vh - 56px);
    display: grid;
    place-items: center;
}

.auth-panel {
    width: min(420px, 100%);
    padding: 34px;
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.brand-mark {
    width: 54px;
    height: 54px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(135deg, var(--green), var(--green-dark));
    border-radius: 50%;
    font-weight: 800;
    font-size: 24px;
}

.brand-mark.small {
    width: 36px;
    height: 36px;
    font-size: 17px;
}

.auth-panel h1,
.section-head h2,
.chat-header h2 {
    margin: 18px 0;
    font-size: 24px;
}

.auth-panel label,
.settings-grid label {
    display: grid;
    gap: 8px;
    margin-bottom: 14px;
    color: var(--muted);
}

.auth-panel button {
    width: 100%;
    margin-top: 8px;
}

.notice {
    padding: 12px 14px;
    margin-bottom: 16px;
    border-radius: 8px;
    background: #edf7f2;
    color: var(--green-dark);
}

.notice.danger,
.small-error {
    background: #fff5f5;
    color: var(--red);
}

.small-error {
    padding: 10px;
    border-radius: 8px;
    font-size: 12px;
    overflow-wrap: anywhere;
}

.app-view {
    width: min(1480px, 100%);
    height: calc(100vh - 56px);
    margin: 0 auto;
    display: grid;
    grid-template-columns: 390px minmax(0, 1fr);
    background: var(--panel);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.sidebar {
    min-width: 0;
    border-left: 1px solid var(--line);
    background: var(--panel);
    display: grid;
    grid-template-rows: auto auto auto 1fr;
}

.topbar,
.chat-header,
.section-head {
    min-height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    background: var(--panel-soft);
}

.brand-line {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-line h1,
.chat-header h2,
.section-head h2 {
    margin: 0;
    font-size: 19px;
}

.icon-btn,
.ghost {
    color: var(--green-dark);
    background: transparent;
    border: 1px solid var(--line);
}

.danger {
    color: var(--red);
}

.tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    border-bottom: 1px solid var(--line);
}

.tab {
    min-height: 46px;
    padding: 8px;
    color: var(--muted);
    background: #fff;
    border-radius: 0;
    border-bottom: 2px solid transparent;
}

.tab.active {
    color: var(--green-dark);
    border-bottom-color: var(--green);
}

.search-row {
    display: grid;
    grid-template-columns: 1fr 46px;
    gap: 8px;
    padding: 12px;
    border-bottom: 1px solid var(--line);
}

.search-row button {
    padding: 0;
    font-size: 25px;
}

.conversation-list {
    min-height: 0;
    overflow: auto;
}

.conversation {
    width: 100%;
    min-height: 74px;
    display: grid;
    grid-template-columns: 48px 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 12px 14px;
    background: #fff;
    border-bottom: 1px solid #edf0ee;
    color: var(--text);
    text-align: right;
    border-radius: 0;
}

.conversation.active {
    background: #eef6f2;
}

.avatar {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(135deg, #2f855a, #2b6cb0);
    font-weight: 800;
}

.conversation strong,
.message .body,
.catalog-item strong {
    overflow-wrap: anywhere;
}

.conversation p {
    margin: 6px 0 0;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 210px;
}

.badge {
    min-width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    padding: 0 7px;
    border-radius: 999px;
    color: #fff;
    background: var(--green);
    font-size: 12px;
}

.workspace {
    min-width: 0;
    background:
        radial-gradient(circle at top left, rgba(18, 140, 98, .08), transparent 260px),
        #f4f1ea;
}

.panel-view {
    height: 100%;
    display: none;
}

.panel-view.active {
    display: grid;
    grid-template-rows: auto 1fr auto;
}

#catalogView.active,
#settingsView.active,
#accountView.active {
    grid-template-rows: auto auto 1fr;
    overflow: auto;
    background: #fff;
}

.chat-header span {
    display: block;
    margin-top: 5px;
    color: var(--muted);
    font-size: 13px;
}

.messages {
    min-height: 0;
    overflow: auto;
    padding: 22px;
}

.empty-state {
    height: 100%;
    display: grid;
    place-items: center;
    color: var(--muted);
}

.message {
    max-width: min(560px, 82%);
    margin: 8px 0;
    padding: 10px 12px 7px;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
}

.message.out {
    margin-right: auto;
    background: var(--mint);
}

.message.deleted {
    opacity: .55;
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 9px;
    margin-top: 6px;
    color: var(--muted);
    font-size: 11px;
}

.message-actions {
    display: inline-flex;
    gap: 6px;
}

.message-actions button {
    min-height: 24px;
    padding: 2px 7px;
    border-radius: 6px;
    color: var(--muted);
    background: rgba(255, 255, 255, .62);
    font-size: 11px;
}

.composer {
    display: grid;
    grid-template-columns: 1fr 96px;
    gap: 10px;
    padding: 14px;
    background: var(--panel-soft);
    border-top: 1px solid var(--line);
}

.composer textarea {
    min-height: 44px;
    max-height: 130px;
}

.compact-form,
.settings-grid,
.account-card {
    margin: 22px;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.compact-form {
    display: grid;
    grid-template-columns: repeat(4, 1fr) auto;
    gap: 10px;
    align-items: start;
}

.compact-form textarea {
    min-height: 46px;
}

.catalog-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
    padding: 0 22px 22px;
}

.catalog-item {
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

.catalog-image {
    height: 130px;
    background: linear-gradient(135deg, #e6fffa, #ebf4ff);
    background-size: cover;
    background-position: center;
}

.catalog-body {
    padding: 14px;
}

.catalog-body p {
    min-height: 38px;
    color: var(--muted);
}

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

.settings-grid .actions {
    grid-column: 1 / -1;
}

.connection-result {
    grid-column: 1 / -1;
    padding: 13px 15px;
    border-radius: 8px;
    border: 1px solid #b7ead3;
    color: var(--green-dark);
    background: #effaf5;
    line-height: 1.8;
    overflow-wrap: anywhere;
}

.connection-result.error {
    border-color: #fed7d7;
    color: var(--red);
    background: #fff5f5;
}

.connection-result .report-title {
    margin-bottom: 8px;
    font-weight: 800;
}

.connection-result dl {
    display: grid;
    grid-template-columns: 170px minmax(0, 1fr);
    gap: 6px 12px;
    margin: 0;
}

.connection-result dt {
    color: var(--muted);
}

.connection-result dd {
    margin: 0;
}

.connection-result ul {
    margin: 12px 0 0;
    padding: 0 20px 0 0;
}

.connection-result pre {
    max-height: 180px;
    margin: 12px 0 0;
    padding: 10px;
    overflow: auto;
    direction: ltr;
    text-align: left;
    white-space: pre-wrap;
    border-radius: 8px;
    background: rgba(255, 255, 255, .72);
}

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

.account-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(13, 19, 17, .42);
    z-index: 20;
}

.modal-card {
    width: min(420px, 100%);
    display: grid;
    gap: 12px;
    padding: 22px;
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
}

.modal-card h2 {
    margin: 0 0 4px;
}

.toast {
    position: fixed;
    left: 22px;
    bottom: 22px;
    max-width: min(360px, calc(100vw - 44px));
    padding: 13px 16px;
    border-radius: 8px;
    color: #fff;
    background: var(--green-dark);
    box-shadow: var(--shadow);
    opacity: 0;
    transform: translateY(14px);
    pointer-events: none;
    transition: .22s ease;
    z-index: 30;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.error {
    background: var(--red);
}

@media (max-width: 860px) {
    .shell {
        padding: 0;
    }

    .app-view {
        height: 100vh;
        border-radius: 0;
        grid-template-columns: 1fr;
    }

    .sidebar {
        min-height: 45vh;
        border-left: 0;
        border-bottom: 1px solid var(--line);
    }

    .workspace {
        min-height: 55vh;
    }

    .compact-form,
    .settings-grid {
        grid-template-columns: 1fr;
    }

    .conversation p {
        max-width: 52vw;
    }

    .message {
        max-width: 92%;
    }
}
