:root {
    --bg: #e9e2d8;
    --panel: #f7f5ef;
    --panel-strong: rgba(255, 255, 255, 0.92);
    --sidebar: #0f2d25;
    --sidebar-soft: #173a31;
    --accent: #25d366;
    --accent-dark: #128c7e;
    --accent-pale: #e8fff1;
    --text: #1f2c34;
    --muted: #6b7c85;
    --border: rgba(17, 27, 33, 0.12);
    --incoming: #ffffff;
    --outgoing: #d9fdd3;
    --danger: #b42318;
    --shadow: 0 24px 60px rgba(7, 24, 21, 0.18);
    --font: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: var(--font);
    color: var(--text);
    background:
        radial-gradient(circle at top right, rgba(37, 211, 102, 0.18), transparent 30%),
        linear-gradient(180deg, #e5ddd5 0%, #f4efe8 100%);
}

body {
    min-height: 100vh;
}

.app-body {
    overflow: hidden;
}

.login-body {
    display: grid;
    place-items: center;
    padding: 32px;
}

.login-shell {
    width: min(100%, 460px);
}

.login-panel {
    background: rgba(255, 255, 255, 0.92);
    border-radius: 30px;
    padding: 36px;
    box-shadow: var(--shadow);
}

.brand-kicker,
.sidebar-label {
    display: inline-block;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--accent-dark);
}

.brand-lockup h1,
.sidebar-top h1,
.chat-header h2,
.empty-state h3 {
    margin: 0;
}

.sidebar-top h1 {
    font-size: 26px;
    line-height: 1.1;
}

.brand-lockup p,
.sidebar-subtext,
.chat-meta,
.empty-state p,
.composer-notice,
.selected-file {
    color: var(--muted);
}

.login-form {
    display: grid;
    gap: 18px;
    margin-top: 28px;
}

.login-form label,
.search-box {
    display: grid;
    gap: 8px;
}

.login-form span {
    font-size: 14px;
    font-weight: 600;
}

input,
textarea {
    width: 100%;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 16px;
    padding: 14px 16px;
    font: inherit;
    background: #fff;
}

textarea {
    min-height: 56px;
    resize: vertical;
}

.primary-button,
.secondary-button,
.ghost-button {
    border: 0;
    border-radius: 14px;
    font: inherit;
    cursor: pointer;
    transition: transform 0.18s ease, opacity 0.18s ease;
}

.primary-button {
    background: linear-gradient(135deg, var(--accent-dark), var(--accent));
    color: #fff;
    padding: 14px 18px;
    font-weight: 700;
}

.secondary-button,
.ghost-button {
    background: rgba(255, 255, 255, 0.12);
    color: inherit;
    padding: 12px 16px;
}

.secondary-button {
    background: #eef7f1;
    color: var(--accent-dark);
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.chat-list-item:hover {
    transform: translateY(-1px);
}

.alert {
    margin-top: 18px;
    padding: 14px 16px;
    border-radius: 16px;
}

.alert-error {
    background: rgba(180, 35, 24, 0.08);
    color: var(--danger);
}

.app-shell {
    display: grid;
    grid-template-columns: 380px minmax(0, 1fr);
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 20px 18px;
    min-height: 0;
    overflow: hidden;
    background:
        radial-gradient(circle at top left, rgba(37, 211, 102, 0.14), transparent 24%),
        linear-gradient(180deg, rgba(10, 31, 26, 0.98), rgba(18, 50, 42, 0.98));
    color: #fff;
}

.sidebar-top {
    display: grid;
    gap: 10px;
    flex: 0 0 auto;
}

.sidebar-hero {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.chat-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding-right: 4px;
}

.chat-list-item {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    align-items: start;
    gap: 14px;
    text-align: left;
    border: 0;
    border-radius: 18px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    cursor: pointer;
    transition: transform 0.18s ease, background 0.18s ease, outline 0.18s ease;
}

.chat-list-item.active {
    background: rgba(37, 211, 102, 0.2);
    outline: 1px solid rgba(37, 211, 102, 0.42);
}

.chat-list-main {
    min-width: 0;
}

.chat-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    font-size: 14px;
    font-weight: 700;
    color: #e8fff1;
    background: linear-gradient(135deg, rgba(37, 211, 102, 0.4), rgba(18, 140, 126, 0.7));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.chat-list-heading,
.chat-list-meta,
.toggle-block {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.chat-list-preview {
    margin-top: 6px;
    color: rgba(255, 255, 255, 0.78);
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-list-meta {
    margin-top: 10px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.72);
}

.status-badge,
.mini-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 11px;
    font-weight: 700;
}

.badge-ai-on,
.mini-badge-ai {
    background: rgba(37, 211, 102, 0.18);
    color: #d8ffe6;
}

.badge-ai-off,
.mini-badge-manual {
    background: rgba(255, 182, 24, 0.18);
    color: #ffe2a8;
}

.mini-badge-user {
    background: rgba(17, 27, 33, 0.08);
    color: var(--muted);
}

.mini-badge-auto {
    background: rgba(176, 124, 15, 0.12);
    color: #946200;
}

.chat-panel {
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background:
        radial-gradient(circle at top right, rgba(18, 140, 126, 0.07), transparent 20%),
        linear-gradient(180deg, rgba(244, 239, 232, 0.96), rgba(239, 234, 226, 0.98));
}

.chat-header,
.composer-shell {
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.84);
    backdrop-filter: blur(10px);
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    border-bottom: 1px solid var(--border);
}

.chat-contact {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.chat-contact-copy {
    min-width: 0;
}

.chat-contact-copy h2 {
    font-size: 16px;
    line-height: 1.1;
}

.chat-contact-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #8ed6c7, #2ca58d);
}

.chat-meta {
    margin-top: 2px;
    font-size: 12px;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 0;
    flex: 0 0 auto;
}

.toggle-pill {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 999px;
    background: rgba(17, 27, 33, 0.05);
}

.toggle-pill span {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.toggle-pill input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-pill .switch-slider {
    position: relative;
    inset: auto;
    width: 38px;
    height: 22px;
    flex: 0 0 auto;
    background: #d0d5dd;
    border-radius: 999px;
    transition: background 0.2s ease, opacity 0.2s ease;
}

.toggle-pill .switch-slider::before {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s ease;
}

.toggle-pill input:checked + .switch-slider {
    background: var(--accent);
}

.toggle-pill input:checked + .switch-slider::before {
    transform: translateX(16px);
}

.toggle-pill input:disabled + .switch-slider {
    opacity: 0.7;
}

.messages-pane {
    min-height: 0;
    overflow: auto;
    padding: 16px 16px 12px;
    background:
        linear-gradient(rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.08)),
        radial-gradient(circle at 1px 1px, rgba(17, 27, 33, 0.05) 1px, transparent 0);
    background-size: auto, 18px 18px;
}

.message-row {
    display: flex;
    margin-bottom: 14px;
}

.message-row.incoming {
    justify-content: flex-start;
}

.message-row.outgoing {
    justify-content: flex-end;
}

.message-bubble {
    max-width: min(72%, 680px);
    border-radius: 20px;
    padding: 10px 12px 8px;
    box-shadow: 0 10px 30px rgba(17, 27, 33, 0.08);
    border: 1px solid rgba(17, 27, 33, 0.05);
}

.incoming .message-bubble {
    background: var(--incoming);
    border-top-left-radius: 6px;
}

.outgoing .message-bubble {
    background: var(--outgoing);
    border-top-right-radius: 6px;
}

.message-bubble p {
    margin: 8px 0 0;
    line-height: 1.48;
}

.message-time {
    margin-top: 6px;
    text-align: right;
    font-size: 12px;
    color: var(--muted);
}

.chat-image {
    display: block;
    width: min(100%, 340px);
    border-radius: 14px;
}

.composer-shell {
    position: sticky;
    bottom: 0;
    z-index: 5;
    border-top: 1px solid var(--border);
    box-shadow: 0 -10px 35px rgba(17, 27, 33, 0.06);
}

.composer {
    display: grid;
    gap: 6px;
}

.composer-disabled {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 4px 12px;
    border-radius: 999px;
    background: rgba(17, 27, 33, 0.05);
    color: var(--muted);
    font-size: 12px;
    width: fit-content;
    max-width: 100%;
}

.composer-bar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: end;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 16px;
    background: var(--panel-strong);
    border: 1px solid rgba(17, 27, 33, 0.08);
    box-shadow: 0 8px 24px rgba(17, 27, 33, 0.06);
}

.composer textarea {
    min-height: 24px;
    max-height: 120px;
    padding: 9px 2px 8px;
    border: 0;
    border-radius: 0;
    resize: none;
    background: transparent;
    box-shadow: none;
    font-size: 15px;
    line-height: 1.4;
}

.composer textarea:focus {
    outline: none;
}

.composer-icon,
.send-button,
.preview-clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    cursor: pointer;
    font: inherit;
}

.composer-icon {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: transparent;
    color: #54656f;
}

.composer-icon:hover,
.preview-clear:hover {
    background: rgba(17, 27, 33, 0.06);
}

.send-button {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-dark), var(--accent));
    color: #fff;
    font-size: 14px;
    transform: rotate(-10deg);
}

.composer-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid rgba(17, 27, 33, 0.08);
}

.composer-preview-image {
    width: 52px;
    height: 52px;
    object-fit: cover;
    border-radius: 12px;
}

.composer-preview-copy {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.selected-file {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.preview-clear {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: transparent;
    color: #44525a;
    flex: 0 0 auto;
}

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

.messages-pane::-webkit-scrollbar,
.chat-list::-webkit-scrollbar {
    width: 10px;
}

.messages-pane::-webkit-scrollbar-thumb,
.chat-list::-webkit-scrollbar-thumb {
    background: rgba(31, 44, 52, 0.16);
    border-radius: 999px;
}

.toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    padding: 14px 18px;
    border-radius: 14px;
    background: #11211a;
    color: #fff;
    box-shadow: var(--shadow);
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 999;
}

.toast-error {
    background: #7a271a;
}

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

@media (max-width: 980px) {
    .app-shell {
        grid-template-columns: 1fr;
        height: 100vh;
    }

    .sidebar {
        max-height: 38vh;
    }

    .chat-header,
    .composer-shell,
    .messages-pane {
        padding-left: 12px;
        padding-right: 12px;
    }

    .chat-header {
        align-items: center;
        flex-direction: row;
        gap: 10px;
    }

    .chat-header-actions {
        width: auto;
        margin-left: auto;
    }

    .chat-contact {
        gap: 8px;
    }

    .chat-contact-avatar {
        width: 32px;
        height: 32px;
        font-size: 11px;
    }

    .chat-contact-copy h2 {
        font-size: 15px;
    }

    .chat-meta {
        display: none;
    }

    .sidebar-top h1 {
        font-size: 20px;
    }

    .sidebar-hero {
        align-items: center;
    }

    .message-bubble {
        max-width: 88%;
    }
}
