:root {
    --surface-bg: #0e1618;
    --surface-app: #131f24;
    --surface-panel: #1b2a31;
    --surface-panel-soft: #21353d;
    --surface-message: #213038;
    --text-main: #e8f0f2;
    --text-muted: #8aa2ad;
    --accent: #3cd1ad;
    --accent-strong: #21b98e;
    --attention: #ffca62;
    --danger: #ff7d74;
    --border-strong: rgba(152, 186, 197, 0.24);
    --border-soft: rgba(152, 186, 197, 0.12);
    --shadow-deep: 0 28px 70px rgba(0, 0, 0, 0.42);
    --font-ui: "Space Grotesk", "Avenir Next", "Segoe UI", sans-serif;
    --font-copy: "IBM Plex Sans", "Trebuchet MS", "Segoe UI", sans-serif;
}

/* Auth Form Styles */
.auth-form {
    width: 100%;
    max-width: 400px;
    margin-inline: auto;
}

.auth-status {
    max-width: 400px;
    margin-inline: auto;
}

.auth-form-element {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 24px;
}

.auth-btn {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-family: var(--font-ui);
    font-weight: 600;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 8px;
}

.auth-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(60, 209, 173, 0.3);
}

.auth-btn:active {
    transform: translateY(0);
}

.auth-switch {
    margin-top: 24px;
    text-align: center;
}

.auth-switch p {
    color: var(--text-muted);
    font-family: var(--font-copy);
    font-size: 14px;
}

.auth-switch a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s ease;
}

.auth-switch a:hover {
    color: var(--accent-strong);
}

.auth-status {
    margin-top: 20px;
    min-height: 60px;
}

.auth-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-muted);
    font-family: var(--font-copy);
    font-size: 14px;
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-soft);
    border-top: 2px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.auth-error {
    background: rgba(255, 125, 116, 0.1);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 12px;
    border-radius: 8px;
    font-family: var(--font-copy);
    font-size: 14px;
    text-align: center;
}

.auth-success {
    background: rgba(60, 209, 173, 0.1);
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 12px;
    border-radius: 8px;
    font-family: var(--font-copy);
    font-size: 14px;
    text-align: center;
}

.hidden {
    display: none !important;
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 8px;
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 500;
    color: white;
    opacity: 0;
    transform: translateY(100%);
    transition: all 0.3s ease;
    z-index: 10000;
    max-width: 300px;
    word-wrap: break-word;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

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

.toast-success {
    background: linear-gradient(135deg, #21b98e, #3cd1ad);
    border-left: 4px solid #21b98e;
}

.toast-error {
    background: linear-gradient(135deg, #ff7d74, #ff9999);
    border-left: 4px solid #ff7d74;
}

.toast-info {
    background: linear-gradient(135deg, #3cd1ad, #5ee3c4);
    border-left: 4px solid #3cd1ad;
}

.toast-warning {
    background: linear-gradient(135deg, #ffca62, #ffd93d);
    color: #333;
    border-left: 4px solid #ffca62;
}

/* Loading States */
.loading {
    opacity: 0.7;
    cursor: not-allowed;
    position: relative;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid transparent;
    border-top: 2px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error States */
.error {
    border-color: var(--danger) !important;
    background: rgba(255, 125, 116, 0.1) !important;
    animation: shake 0.3s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.error:focus {
    outline: 2px solid var(--danger);
    outline-offset: 2px;
}

/* Enhanced Button States */
button {
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

button:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

button:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

/* Pulse Animation for Important Actions */
@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(60, 209, 173, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(60, 209, 173, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(60, 209, 173, 0);
    }
}

.pulse {
    animation: pulse 2s infinite;
}

/* Focus Improvements */
*:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Smooth Scrolling */
html {
    scroll-behavior: smooth;
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Checkbox Styles */
.checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-main);
    margin-bottom: 8px;
}

.checkbox-label input[type="checkbox"] {
    display: none;
}

.checkmark {
    width: 20px;
    height: 20px;
    background: var(--surface-panel-soft);
    border: 2px solid var(--border-strong);
    border-radius: 4px;
    margin-right: 12px;
    position: relative;
    transition: all 0.2s ease;
}

.checkbox-label input[type="checkbox"]:checked + .checkmark {
    background: var(--accent);
    border-color: var(--accent);
}

.checkbox-label input[type="checkbox"]:checked + .checkmark::after {
    content: '';
    position: absolute;
    left: 6px;
    top: 2px;
    width: 6px;
    height: 12px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Group Options */
.group-options {
    display: none;
    margin-top: 16px;
    padding: 16px;
    background: var(--surface-panel-soft);
    border-radius: 8px;
    border: 1px solid var(--border-soft);
}

.group-options .field {
    margin-bottom: 16px;
}

.group-options .field:last-child {
    margin-bottom: 0;
}

.group-options input[type="text"] {
    width: 100px;
    padding: 8px 12px;
    background: var(--surface-panel);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    color: var(--text-main);
    font-size: 14px;
    text-align: center;
}

.group-options input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(60, 209, 173, 0.1);
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface-panel);
    border-radius: 12px;
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-deep);
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px;
    border-bottom: 1px solid var(--border-soft);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--text-main);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-soft);
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

/* Test Chat Styles */
.test-chat-container {
    border: 1px solid var(--border-soft);
    border-radius: 0.5rem;
    background: var(--background);
    overflow: hidden;
}

.test-chat-messages {
    height: 200px;
    overflow-y: auto;
    padding: 1rem;
    background: var(--background);
    border-bottom: 1px solid var(--border-soft);
}

.test-message {
    margin-bottom: 0.75rem;
    display: flex;
    gap: 0.5rem;
}

.test-message:last-child {
    margin-bottom: 0;
}

.user-message {
    justify-content: flex-end;
}

.bot-message {
    justify-content: flex-start;
}

.message-content {
    max-width: 80%;
    padding: 0.5rem 0.75rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    line-height: 1.4;
    word-wrap: break-word;
}

.user-message .message-content {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.bot-message .message-content {
    background: var(--surface);
    color: var(--text-main);
    border: 1px solid var(--border-soft);
    border-bottom-left-radius: 0.25rem;
}

.test-message.error .message-content {
    background: #fee2e2;
    color: #dc2626;
    border-color: #fecaca;
}

.test-message.handoff .message-content {
    background: #d1fae5;
    color: #059669;
    border-color: #a7f3d0;
    font-weight: 500;
}

.test-chat-input-container {
    padding: 1rem;
    display: flex;
    gap: 0.5rem;
    background: var(--surface);
}

.test-chat-input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-soft);
    border-radius: 0.375rem;
    background: var(--background);
    color: var(--text-main);
    font-size: 0.875rem;
}

.test-chat-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.test-chat-input-container .btn-primary {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.config-section {
    margin-bottom: 32px;
}

.config-section h3 {
    margin: 0 0 16px 0;
    font-size: 1.1rem;
    color: var(--text-main);
}

.radio-group {
    display: flex;
    gap: 24px;
    margin-bottom: 24px;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--text-main);
}

.radio-option input[type="radio"] {
    accent-color: var(--accent);
}

.input-group {
    display: flex;
    gap: 8px;
}

.input-group input {
    flex: 1;
}

.btn-primary {
    background: var(--accent);
    color: var(--surface-bg);
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

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

.btn-secondary {
    background: var(--surface-panel-soft);
    color: var(--text-main);
    border: 1px solid var(--border-strong);
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: var(--surface-message);
    border-color: var(--accent);
}

.config-status {
    padding: 12px;
    border-radius: 8px;
    margin-top: 16px;
    display: none;
}

.config-status.success {
    background: rgba(60, 209, 173, 0.1);
    border: 1px solid var(--accent);
    color: var(--accent);
    display: block;
}

.config-status.error {
    background: rgba(255, 125, 116, 0.1);
    border: 1px solid var(--danger);
    color: var(--danger);
    display: block;
}

.field-help {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 4px;
    line-height: 1.4;
}

.field-help a {
    color: var(--accent);
    text-decoration: none;
}

.field-help a:hover {
    text-decoration: underline;
}

/* AI Toggle Button */
.ai-active {
    background: var(--accent) !important;
    color: var(--surface-bg) !important;
}

.ai-active:hover {
    background: var(--accent-strong) !important;
}

.terms-consent {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.5;
}

.terms-consent input {
    margin-top: 3px;
    accent-color: var(--accent);
}

.terms-consent a {
    color: var(--accent);
}

.workspace-nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
    padding: 16px 8px;
    background: #101b20;
    border-right: 1px solid var(--border-soft);
}

.workspace-nav-links {
    display: grid;
    gap: 7px;
    width: 100%;
}

.workspace-nav-btn,
.workspace-logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    min-height: 48px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 9px;
    background: transparent;
    color: var(--text-muted);
    text-align: left;
    cursor: pointer;
    font: inherit;
}

.workspace-nav-btn svg,
.workspace-logout-btn svg {
    flex: 0 0 21px;
    width: 21px;
    height: 21px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.7;
}

.workspace-nav-btn:hover,
.workspace-nav-btn.active {
    color: var(--text-main);
    background: rgba(60, 209, 173, 0.1);
    border-color: var(--border-soft);
}

.workspace-nav-btn.active {
    box-shadow: inset 0 3px var(--accent);
}

.workspace-nav-bottom {
    display: grid;
    margin-top: auto;
}

.workspace-nav-btn:hover,
.workspace-logout-btn:hover {
    transform: none;
    box-shadow: none;
}

.workspace-logout-btn {
    color: var(--text-muted);
}

.workspace-logout-btn:hover {
    color: var(--danger);
}

.notifications-nav-btn {
    position: relative;
}

.notification-unread-count {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    border: 2px solid #171d37;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font: 600 10px/13px var(--font-ui);
    text-align: center;
}

.modal-content.notifications-modal-content {
    width: min(680px, 100%);
    max-width: 680px;
    max-height: min(760px, calc(100vh - 48px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.notifications-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 28px;
    border-bottom: 1px solid var(--border-soft);
}

.notifications-toolbar .btn-secondary {
    flex: 0 0 auto;
}

.notifications-list {
    min-height: 120px;
    padding: 12px 28px 24px;
    overflow-y: auto;
}

.notification-item {
    padding: 16px 0;
    border-bottom: 1px solid var(--border-soft);
    color: var(--text-muted);
}

.notification-item.notification-unread {
    color: var(--text-main);
}

.notification-item-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: var(--text-main);
}

.notification-status {
    flex: 0 0 auto;
    color: var(--attention);
    font-size: 12px;
}

.notification-status-resolved {
    color: var(--accent);
}

.notification-item p {
    margin: 8px 0;
    line-height: 1.5;
}

.notification-item small {
    color: var(--text-muted);
}

.notification-read-btn {
    margin-top: 10px;
    padding: 6px 10px;
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    background: transparent;
    color: var(--accent);
    cursor: pointer;
}

.notifications-empty {
    padding: 28px 0;
    color: var(--text-muted);
    text-align: center;
}

@media (max-width: 560px) {
    .notifications-toolbar {
        align-items: flex-start;
        flex-direction: column;
        padding-inline: 18px;
    }

    .notifications-list {
        padding-inline: 18px;
    }
}

.account-modal-content {
    max-width: 640px;
}

.account-email {
    color: var(--text-main);
    font-weight: 600;
}

.account-form {
    display: grid;
    gap: 14px;
    margin: 20px 0;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-soft);
}

.account-subscription {
    display: grid;
    gap: 8px;
    margin: 20px 0;
    padding: 16px;
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    background: var(--surface-panel-soft);
}

.account-subscription h3 {
    margin: 0;
    font-family: var(--font-ui);
    font-size: 16px;
}

.account-notifications {
    display: grid;
    gap: 10px;
    margin: 20px 0;
}

.account-notifications h3 {
    margin: 0;
    color: #f1f3ff;
    font-family: var(--font-ui);
    font-size: 16px;
}

.account-notifications .field-help {
    margin: 0;
}

.subscription-status-label {
    margin: 0;
    font-weight: 600;
}

.subscription-status-label.is-trial {
    color: var(--attention);
}

.subscription-status-label.is-active {
    color: var(--accent);
}

.subscription-status-label.is-expired {
    color: var(--danger);
}

.subscription-modal-content {
    max-width: 480px;
}

.subscription-price {
    font-weight: 600;
    color: var(--text-main);
}

.pix-checkout {
    display: grid;
    gap: 12px;
    justify-items: center;
}

.pix-checkout.hidden {
    display: none;
}

.pix-qr-image {
    width: 220px;
    height: 220px;
    border-radius: 12px;
    background: #fff;
    padding: 8px;
}

.pix-checkout textarea {
    width: 100%;
    resize: none;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--surface-app);
    color: var(--text-main);
    font-size: 12px;
}

.account-form input,
.account-danger input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--surface-app);
    color: var(--text-main);
}

.account-form h3,
.account-danger h3 {
    margin: 0;
}

.account-danger {
    display: grid;
    gap: 10px;
    color: var(--text-muted);
}

.danger-btn {
    border: 1px solid rgba(255, 125, 116, 0.5);
    border-radius: 8px;
    padding: 10px 14px;
    color: #fff;
    background: #a63d38;
    cursor: pointer;
}

.legal-page {
    position: relative;
    z-index: 1;
    width: min(820px, calc(100% - 32px));
    margin: 36px auto;
    padding: clamp(22px, 5vw, 48px);
    border: 1px solid var(--border-strong);
    border-radius: 18px;
    background: rgba(19, 31, 36, 0.96);
    box-shadow: var(--shadow-deep);
    line-height: 1.65;
}

.legal-page h1,
.legal-page h2 {
    color: var(--text-main);
    font-family: var(--font-ui);
}

.legal-page h1 {
    margin-top: 0;
}

.legal-page a {
    color: var(--accent);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    position: relative;
    color: var(--text-main);
    font-family: var(--font-copy);
    background:
        radial-gradient(
            900px 500px at 12% -12%,
            rgba(60, 209, 173, 0.22),
            transparent 65%
        ),
        radial-gradient(
            820px 540px at 92% 8%,
            rgba(255, 202, 98, 0.14),
            transparent 62%
        ),
        linear-gradient(160deg, #0f1b20 8%, #0b1215 45%, #090d10 100%);
}

.scene-glow {
    position: fixed;
    pointer-events: none;
    border-radius: 50%;
    filter: blur(42px);
    opacity: 0.6;
    z-index: 0;
}

.scene-glow-one {
    width: 320px;
    height: 320px;
    top: 6%;
    right: 7%;
    background: rgba(60, 209, 173, 0.18);
}

.scene-glow-two {
    width: 260px;
    height: 260px;
    bottom: 9%;
    left: 6%;
    background: rgba(255, 202, 98, 0.15);
}

.hidden {
    display: none !important;
}

.eyebrow {
    margin: 0 0 8px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    font-weight: 700;
    font-size: 11px;
    color: var(--accent);
}

.connect-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    position: relative;
    z-index: 1;
    animation: reveal-up 420ms ease-out;
}

.connect-card {
    width: min(640px, 100%);
    border: 1px solid var(--border-strong);
    border-radius: 22px;
    padding: 28px;
    background:
        linear-gradient(140deg, rgba(60, 209, 173, 0.08), transparent 58%),
        linear-gradient(0deg, rgba(16, 33, 39, 0.94), rgba(16, 33, 39, 0.94));
    box-shadow: var(--shadow-deep);
    backdrop-filter: blur(10px);
}

.connect-card h1 {
    margin: 0;
    font-size: clamp(1.5rem, 3.8vw, 2.2rem);
    line-height: 1.08;
    font-family: var(--font-ui);
}

.connect-subtitle {
    margin: 10px 0 22px;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.session-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: end;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field span {
    font-size: 12px;
    color: var(--text-muted);
}

.session-controls input,
.session-controls button,
.chat-search-wrap input,
.message-form input,
.message-form select,
.message-form textarea,
.message-form button {
    border-radius: 12px;
    border: 1px solid transparent;
    font-family: inherit;
    font-size: 0.92rem;
    padding: 11px 13px;
}

.session-controls input,
.chat-search-wrap input,
.message-form input,
.message-form select,
.message-form textarea {
    width: 100%;
    color: var(--text-main);
    background: linear-gradient(
        0deg,
        rgba(32, 50, 58, 0.92),
        rgba(32, 50, 58, 0.92)
    );
    border-color: var(--border-soft);
}

.session-controls input:focus-visible,
.chat-search-wrap input:focus-visible,
.message-form input:focus-visible,
.message-form select:focus-visible,
.message-form textarea:focus-visible {
    outline: none;
    border-color: rgba(60, 209, 173, 0.6);
    box-shadow: 0 0 0 3px rgba(60, 209, 173, 0.14);
}

.session-controls button,
.message-form button {
    cursor: pointer;
    white-space: nowrap;
    color: #03291f;
    background: linear-gradient(
        120deg,
        var(--accent) 0%,
        var(--accent-strong) 100%
    );
    font-weight: 700;
    transition:
        transform 150ms ease,
        filter 150ms ease;
}

.session-controls button:hover,
.message-form button:hover {
    transform: translateY(-1px);
    filter: brightness(1.04);
}

.session-controls button:active,
.message-form button:active {
    transform: translateY(0);
}

.connection-row {
    margin-top: 16px;
    display: flex;
    align-items: center;
    gap: 9px;
}

.connection-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--attention);
    box-shadow: 0 0 0 4px rgba(255, 202, 98, 0.22);
    animation: pulse 1.6s infinite;
}

.connection-dot-connected {
    background: var(--accent);
    box-shadow: 0 0 0 4px rgba(60, 209, 173, 0.2);
}

.connection-dot-closed {
    background: var(--danger);
    box-shadow: 0 0 0 4px rgba(255, 125, 116, 0.22);
}

.connection-status {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.qr-wrapper {
    margin-top: 18px;
    display: grid;
    place-items: center;
    border-radius: 16px;
    padding: 18px;
    background: #f9ffff;
    animation: reveal-up 300ms ease-out;
}

.qr-wrapper img {
    width: 280px;
    max-width: 100%;
    aspect-ratio: 1 / 1;
}

.app-shell {
    width: min(1460px, calc(100vw - 32px));
    height: calc(100vh - 32px);
    margin: 16px auto;
    border-radius: 22px;
    display: grid;
    grid-template-columns: 64px 340px minmax(0, 1fr);
    overflow: hidden;
    position: relative;
    z-index: 1;
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-deep);
    background: var(--surface-app);
    animation: reveal-up 340ms ease-out;
}

.sidebar {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    background: linear-gradient(180deg, var(--surface-panel) 0%, #16262d 100%);
    border-right: 1px solid var(--border-soft);
}

.sidebar-top {
    padding: 20px 18px 18px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--border-soft);
}

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

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border-soft);
    background: rgba(60, 209, 173, 0.08);
    color: var(--accent);
    cursor: pointer;
    transition: all 140ms ease;
}

.icon-btn:hover {
    background: rgba(60, 209, 173, 0.16);
    border-color: rgba(60, 209, 173, 0.3);
    transform: rotate(90deg);
}

.icon-btn:active {
    transform: rotate(90deg) scale(0.95);
}

.sidebar-eyebrow {
    margin-bottom: 5px;
}

.sidebar-top h1 {
    margin: 0;
    font-size: 1.3rem;
    font-family: var(--font-ui);
    letter-spacing: 0.01em;
}

.session-label {
    margin: 8px 0 0;
    color: var(--text-muted);
    font-size: 12px;
}

.connection-pill {
    align-self: start;
    border-radius: 999px;
    padding: 6px 11px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    border: 1px solid transparent;
}

.connection-pill-idle,
.connection-pill-qr {
    color: #f8d58b;
    background: rgba(255, 202, 98, 0.12);
    border-color: rgba(255, 202, 98, 0.24);
}

.connection-pill-connecting {
    color: #a4d9ff;
    background: rgba(119, 194, 245, 0.14);
    border-color: rgba(119, 194, 245, 0.3);
}

.connection-pill-connected {
    color: #8ff0d2;
    background: rgba(60, 209, 173, 0.12);
    border-color: rgba(60, 209, 173, 0.3);
}

.connection-pill-closed {
    color: #ffc2bc;
    background: rgba(255, 125, 116, 0.12);
    border-color: rgba(255, 125, 116, 0.3);
}

.chat-search-wrap {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-soft);
}

.chat-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 10px;
}


.event-panel {
    border-top: 1px solid var(--border-soft);
    background: rgba(15, 26, 31, 0.72);
}

.event-header {
    padding: 10px 14px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-soft);
}

.event-list {
    max-height: 180px;
    overflow: auto;
    padding: 8px 10px 12px;
}

.event-item {
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    padding: 8px 9px;
    background: rgba(24, 40, 47, 0.58);
}

.event-item + .event-item {
    margin-top: 6px;
}

.event-name {
    font-size: 11px;
    color: var(--accent);
    font-weight: 700;
}

.event-summary {
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-main);
}

.event-time {
    margin-top: 5px;
    font-size: 11px;
    color: var(--text-muted);
}

.chat-item {
    width: 100%;
    border: 1px solid transparent;
    border-radius: 12px;
    background: transparent;
    color: var(--text-main);
    text-align: left;
    padding: 12px;
    cursor: pointer;
    transition:
        background-color 140ms ease,
        border-color 140ms ease,
        transform 140ms ease;
}

.chat-item + .chat-item {
    margin-top: 6px;
}

.chat-item:hover {
    background: rgba(60, 209, 173, 0.08);
    border-color: rgba(60, 209, 173, 0.2);
    transform: translateX(1px);
}

.chat-item.active {
    background: rgba(60, 209, 173, 0.12);
    border-color: rgba(60, 209, 173, 0.32);
}

.chat-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.chat-title {
    font-family: var(--font-ui);
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.chat-time {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.chat-subline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    color: var(--text-muted);
    font-size: 12px;
}

.chat-preview {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.badge {
    min-width: 22px;
    padding: 2px 7px;
    border-radius: 999px;
    text-align: center;
    font-weight: 700;
    font-size: 11px;
    color: #03291f;
    background: linear-gradient(
        120deg,
        var(--accent) 0%,
        var(--accent-strong) 100%
    );
    flex-shrink: 0;
}

.empty-state {
    padding: 18px 12px;
    color: var(--text-muted);
    font-size: 0.93rem;
}

.chat-panel {
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-height: 0;
    background:
        radial-gradient(
            420px 260px at 78% -12%,
            rgba(60, 209, 173, 0.14),
            transparent 70%
        ),
        linear-gradient(180deg, #101b20 0%, var(--surface-bg) 100%);
}


.chat-header h2 {
    margin: 0;
    font-size: 1.2rem;
    font-family: var(--font-ui);
    font-weight: 700;
}

.chat-header p {
    margin: 6px 0 0;
    font-size: 12px;
    color: var(--text-muted);
}

.chat-header-presence {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--accent);
    font-weight: 500;
}

.presence-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    animation: pulse 1.2s infinite;
}

.typing-indicator {
    display: flex;
    gap: 3px;
    align-items: center;
    padding: 4px 0;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing-bounce 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-bounce {
    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

.message-list {
    overflow-y: auto;
    min-height: 0;
    padding: 20px 22px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message {
    position: relative;
    max-width: min(72%, 780px);
    padding: 10px 12px;
    border-radius: 12px;
    line-height: 1.45;
    font-size: 14px;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.2);
    word-break: break-word;
    animation: reveal-up 210ms ease;
}

.message.inbound {
    align-self: flex-start;
    background: var(--surface-message);
}

.message.outbound {
    align-self: flex-end;
    background: linear-gradient(160deg, #23c7a3 0%, #1ca788 100%);
    color: #03271d;
}

.message-time {
    text-align: right;
    color: rgba(214, 230, 235, 0.72);
    font-size: 11px;
}

.message.outbound .message-time {
    color: rgba(3, 39, 29, 0.72);
}

.message-empty {
    margin: auto 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.94rem;
    padding: 22px;
    border: 1px dashed rgba(152, 186, 197, 0.24);
    border-radius: 14px;
    background: rgba(20, 33, 39, 0.56);
}

.message-actions {
    position: absolute;
    z-index: 2;
    top: -19px;
    right: 8px;
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 3px;
    border: 1px solid rgba(165, 181, 231, 0.18);
    border-radius: 999px;
    background: #182238;
    box-shadow: 0 5px 16px rgba(0, 0, 0, 0.28);
    opacity: 0;
    pointer-events: none;
    transform: translateY(3px);
    transition: opacity 120ms ease, transform 120ms ease;
}

.message:hover .message-actions,
.message:focus-within .message-actions,
.message-actions-visible .message-actions {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.message-action-btn {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    min-height: 30px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #e8eff5;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
}

.message-action-btn:hover,
.message-action-btn:focus-visible {
    background: rgba(255, 255, 255, 0.14);
    outline: none;
}

.message-reaction-actions {
    display: flex;
    align-items: center;
}

.reply-preview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 10px 18px 0;
    padding: 9px 12px;
    border-left: 3px solid #25d366;
    border-radius: 8px;
    background: rgba(32, 50, 58, 0.92);
}

.reply-preview-copy {
    min-width: 0;
}

.reply-preview-copy span {
    display: block;
    color: #25d366;
    font-size: 12px;
    font-weight: 600;
}

.reply-preview-copy p {
    overflow: hidden;
    margin: 3px 0 0;
    color: var(--text-main);
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reply-preview-close {
    display: grid;
    flex: 0 0 32px;
    place-items: center;
    width: 32px;
    height: 32px;
    min-height: 32px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 24px;
}

.reply-preview-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
}

.message-composer {
    border-top: 1px solid var(--border-soft);
    background: linear-gradient(
        0deg,
        rgba(21, 34, 40, 0.96),
        rgba(21, 34, 40, 0.96)
    );
    position: relative;
}

.composer-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
}

.composer-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 140ms ease;
    flex-shrink: 0;
}

.composer-btn:hover {
    background: rgba(60, 209, 173, 0.1);
    color: var(--accent);
}

.composer-btn:active {
    transform: scale(0.95);
}

.composer-btn.recording {
    background: var(--danger);
    color: white;
    animation: pulse-recording 1.5s infinite;
}

@keyframes pulse-recording {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 125, 116, 0.7);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 8px rgba(255, 125, 116, 0);
    }
}

.composer-btn.send-btn {
    background: var(--accent);
    color: #03291f;
}

.composer-btn.send-btn:hover {
    background: var(--accent-strong);
    filter: brightness(1.1);
}

.input-field-wrapper {
    flex: 1;
    position: relative;
    min-width: 0;
}

.message-input-field {
    width: 100%;
    min-height: 44px;
    max-height: 120px;
    border: none;
    border-radius: 22px;
    background: rgba(32, 50, 58, 0.92);
    color: var(--text-main);
    font-family: inherit;
    font-size: 15px;
    line-height: 20px;
    padding: 12px 16px;
    resize: none;
    outline: none;
    transition: all 140ms ease;
}

.message-input-field:focus {
    background: rgba(32, 50, 58, 0.96);
    box-shadow: 0 0 0 1px rgba(60, 209, 173, 0.3);
}

.message-input-field::placeholder {
    color: var(--text-muted);
}

.composer-typing-indicator {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 3px;
    align-items: center;
}

.composer-typing-indicator .typing-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--accent);
    animation: typing-bounce 1.4s infinite;
}

.composer-typing-indicator .typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.composer-typing-indicator .typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

/* Attach Menu */
.attach-menu {
    position: absolute;
    bottom: 100%;
    left: 16px;
    right: 16px;
    background: var(--surface-panel);
    border: 1px solid var(--border-strong);
    border-radius: 16px;
    box-shadow: var(--shadow-deep);
    z-index: 100;
    animation: slide-up 200ms ease;
}

.attach-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border-soft);
}

.attach-menu-header span {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
}

.close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 125, 116, 0.1);
    color: var(--danger);
    cursor: pointer;
    transition: all 140ms ease;
}

.close-btn:hover {
    background: rgba(255, 125, 116, 0.2);
}

.attach-options {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 16px 20px 20px;
}

.attach-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 8px;
    border: none;
    border-radius: 12px;
    background: transparent;
    color: var(--text-main);
    cursor: pointer;
    transition: all 140ms ease;
    position: relative;
}

.attach-option:hover {
    background: rgba(60, 209, 173, 0.1);
}

.attach-icon {
    font-size: 24px;
    line-height: 1;
}

.attach-option span {
    font-size: 12px;
    text-align: center;
    line-height: 1.2;
}

/* Emoji Picker */
.emoji-picker {
    position: absolute;
    bottom: 100%;
    left: 16px;
    right: 16px;
    max-height: 400px;
    background: var(--surface-panel);
    border: 1px solid var(--border-strong);
    border-radius: 16px;
    box-shadow: var(--shadow-deep);
    z-index: 100;
    animation: slide-up 200ms ease;
    display: flex;
    flex-direction: column;
    min-width: 320px;
}

.emoji-picker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-soft);
}

.emoji-picker-header span {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
}

.emoji-categories {
    display: flex;
    gap: 4px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-soft);
    overflow-x: auto;
    flex-shrink: 0;
}

.emoji-category {
    padding: 6px 12px;
    border: none;
    border-radius: 16px;
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    transition: all 140ms ease;
    white-space: nowrap;
}

.emoji-category:hover {
    background: rgba(60, 209, 173, 0.1);
    color: var(--text-main);
}

.emoji-category.active {
    background: var(--accent);
    color: #03291f;
}

.emoji-grid {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
}

.emoji-item {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: transparent;
    font-size: 20px;
    cursor: pointer;
    transition: all 140ms ease;
}

.emoji-item:hover {
    background: rgba(60, 209, 173, 0.1);
}

/* Voice Recorder */
.voice-recorder {
    position: absolute;
    bottom: 100%;
    left: 16px;
    right: 16px;
    background: var(--surface-panel);
    border: 1px solid var(--border-strong);
    border-radius: 16px;
    box-shadow: var(--shadow-deep);
    z-index: 100;
    animation: slide-up 200ms ease;
}

.voice-recorder-content {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
}

.voice-wave {
    display: flex;
    gap: 3px;
    align-items: center;
}

.wave-dot {
    width: 4px;
    height: 20px;
    border-radius: 2px;
    background: var(--accent);
    animation: wave-animation 1.2s infinite ease-in-out;
}

.wave-dot:nth-child(2) {
    animation-delay: 0.1s;
}

.wave-dot:nth-child(3) {
    animation-delay: 0.2s;
}

.wave-dot:nth-child(4) {
    animation-delay: 0.3s;
}

.wave-dot:nth-child(5) {
    animation-delay: 0.4s;
}

@keyframes wave-animation {
    0%, 60%, 100% {
        transform: scaleY(0.5);
        opacity: 0.5;
    }
    30% {
        transform: scaleY(1);
        opacity: 1;
    }
}

.voice-timer {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-main);
    font-family: monospace;
    flex: 1;
}

.voice-btn-cancel,
.voice-btn-send {
    padding: 8px 16px;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 140ms ease;
}

.voice-btn-cancel {
    background: rgba(255, 125, 116, 0.1);
    color: var(--danger);
}

.voice-btn-cancel:hover {
    background: rgba(255, 125, 116, 0.2);
}

.voice-btn-send {
    background: var(--accent);
    color: #03291f;
}

.voice-btn-send:hover {
    background: var(--accent-strong);
}

/* Business Options */
.business-options {
    position: absolute;
    bottom: 100%;
    right: 16px;
    background: var(--surface-panel);
    border: 1px solid var(--border-strong);
    border-radius: 16px;
    box-shadow: var(--shadow-deep);
    z-index: 100;
    animation: slide-up 200ms ease;
    min-width: 200px;
}

.business-options-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-soft);
}

.business-options-header span {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
}

.business-options-content {
    padding: 8px;
}

.business-option {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-main);
    cursor: pointer;
    transition: all 140ms ease;
}

.business-option:hover {
    background: rgba(60, 209, 173, 0.1);
}

.business-icon {
    font-size: 18px;
    line-height: 1;
}

.business-option span {
    font-size: 14px;
    text-align: left;
}

/* Chat Header Actions */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border-soft);
    background: linear-gradient(
        0deg,
        rgba(20, 34, 39, 0.92),
        rgba(20, 34, 39, 0.92)
    );
}

.chat-header-left {
    flex: 1;
    min-width: 0;
}

.chat-title-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-profile-picture {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--surface-panel-soft);
    display: flex;
    align-items: center;
    justify-content: center;
}

.profile-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.profile-placeholder {
    width: 24px;
    height: 24px;
    opacity: 0.6;
}

.chat-title-content {
    flex: 1;
    min-width: 0;
}

.chat-header-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.header-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border-soft);
    background: rgba(60, 209, 173, 0.08);
    color: var(--accent);
    cursor: pointer;
    transition: all 140ms ease;
}

.header-btn:hover {
    background: rgba(60, 209, 173, 0.16);
    border-color: rgba(60, 209, 173, 0.3);
}

.header-btn:active {
    transform: scale(0.95);
}

.chat-ai-toggle-btn {
    margin-right: 8px;
}

.chat-ai-toggle-btn.ai-active {
    background: var(--accent) !important;
    color: #080f1c !important;
    border-color: var(--accent) !important;
}

.chat-ai-toggle-btn.ai-active:hover {
    background: var(--accent-strong) !important;
}

@keyframes slide-up {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 680px) {
    .attach-options {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .emoji-grid {
        grid-template-columns: repeat(6, 1fr);
    }
    
    .voice-recorder-content {
        padding: 12px 16px;
        gap: 12px;
    }
    
    .business-options {
        right: 8px;
        left: 8px;
        min-width: auto;
    }
}

/* Refined workspace theme */
:root {
    --surface-bg: #090c18;
    --surface-app: #101426;
    --surface-panel: #151b30;
    --surface-panel-soft: #1d2540;
    --surface-message: #202842;
    --text-main: #f3f5ff;
    --text-muted: #9aa5c3;
    --accent: #6de7d2;
    --accent-strong: #38cdb8;
    --attention: #ffca7a;
    --danger: #ff7d9a;
    --border-strong: rgba(165, 181, 231, 0.22);
    --border-soft: rgba(165, 181, 231, 0.12);
    --shadow-deep: 0 32px 90px rgba(2, 4, 14, 0.64);
    --font-ui: "Segoe UI Variable Display", "Aptos Display", "Trebuchet MS", sans-serif;
    --font-copy: "Segoe UI Variable", "Aptos", "Segoe UI", sans-serif;
    color-scheme: dark;
}

html {
    scrollbar-color: #3a4568 #111629;
}

body {
    color: var(--text-main);
    font-family: var(--font-copy);
    background:
        radial-gradient(ellipse at 12% 4%, rgba(84, 111, 255, 0.2), transparent 34%),
        radial-gradient(ellipse at 88% 10%, rgba(35, 223, 195, 0.13), transparent 30%),
        radial-gradient(ellipse at 52% 100%, rgba(135, 71, 255, 0.11), transparent 42%),
        #090c18;
}

::selection {
    color: #080f1c;
    background: var(--accent);
}

button,
input,
select,
textarea {
    font: inherit;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.scene-glow {
    filter: blur(72px);
    opacity: 0.52;
}

.scene-glow-one {
    width: 420px;
    height: 420px;
    background: rgba(74, 108, 255, 0.2);
}

.scene-glow-two {
    width: 360px;
    height: 360px;
    background: rgba(35, 223, 195, 0.15);
}

.eyebrow {
    color: #8c9aff;
    font-size: 10px;
    letter-spacing: 0.19em;
}

.connect-screen {
    padding: 28px;
}

.connect-card {
    width: min(560px, 100%);
    padding: clamp(28px, 5vw, 48px);
    border: 1px solid rgba(171, 187, 255, 0.2);
    border-radius: 28px;
    background:
        radial-gradient(ellipse at 100% 0, rgba(91, 110, 255, 0.16), transparent 48%),
        linear-gradient(145deg, rgba(24, 31, 56, 0.96), rgba(14, 18, 34, 0.97));
    box-shadow: 0 32px 100px rgba(2, 5, 20, 0.58), inset 0 1px rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(24px);
}

.auth-brand-logo {
    display: block;
    width: 144px;
    height: 144px;
    margin: 0 auto 12px;
    object-fit: contain;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.sidebar-brand-logo {
    flex: 0 0 52px;
    width: 52px;
    height: 52px;
    object-fit: contain;
}

.sidebar-brand-copy {
    min-width: 0;
}

.connect-card h1,
.sidebar-top h1,
.chat-header h2,
.modal-header h2,
.legal-page h1,
.legal-page h2 {
    font-family: var(--font-ui);
    letter-spacing: -0.035em;
}

.connect-card h1 {
    font-size: clamp(2rem, 5vw, 3rem);
    line-height: 1.04;
}

.connect-subtitle {
    color: #a3adca;
    line-height: 1.65;
}

.session-controls button,
.auth-btn,
.btn-primary {
    border: 0;
    color: #071519;
    background: linear-gradient(120deg, #72f0d7, #45cfe1 58%, #8f91ff);
    box-shadow: 0 9px 28px rgba(62, 211, 210, 0.2);
    font-weight: 750;
}

.session-controls button {
    min-height: 48px;
    padding-inline: 22px;
    border-radius: 14px;
}

.session-controls button:hover,
.auth-btn:hover,
.btn-primary:hover {
    filter: brightness(1.08);
    box-shadow: 0 12px 32px rgba(62, 211, 210, 0.3);
}

.app-shell {
    width: min(1600px, calc(100vw - 48px));
    height: calc(100vh - 48px);
    margin: 24px auto;
    grid-template-columns: 76px 330px minmax(0, 1fr);
    border: 1px solid rgba(165, 181, 231, 0.17);
    border-radius: 26px;
    background: rgba(15, 20, 39, 0.94);
    box-shadow: 0 30px 110px rgba(2, 5, 20, 0.62), 0 0 0 1px rgba(255, 255, 255, 0.025);
    backdrop-filter: blur(22px);
}

.workspace-nav {
    padding: 18px 12px;
    background: linear-gradient(180deg, #171d37 0%, #111629 100%);
    border-right-color: rgba(165, 181, 231, 0.1);
}

.workspace-nav-links {
    gap: 10px;
}

.workspace-nav-btn,
.workspace-logout-btn {
    width: 50px;
    height: 50px;
    min-height: 50px;
    border-radius: 16px;
    color: #929dbd;
}

.workspace-nav-btn:hover,
.workspace-nav-btn.active {
    color: #e8ebff;
    border-color: rgba(141, 151, 255, 0.2);
    background: linear-gradient(145deg, rgba(109, 119, 255, 0.22), rgba(81, 227, 211, 0.1));
}

.workspace-nav-btn.active {
    box-shadow: inset 3px 0 #72ead8, 0 6px 20px rgba(89, 113, 255, 0.13);
}

.sidebar {
    background: linear-gradient(180deg, rgba(23, 29, 52, 0.98), rgba(18, 23, 42, 0.98));
    border-right-color: rgba(165, 181, 231, 0.1);
}

.sidebar-top {
    padding: 26px 22px 20px;
    border-bottom-color: rgba(165, 181, 231, 0.1);
}

.sidebar-top h1 {
    font-size: 1.65rem;
}

.connection-pill {
    padding: 7px 10px;
    border-radius: 10px;
}

.chat-search-wrap {
    padding: 16px 16px 14px;
    border-bottom-color: rgba(165, 181, 231, 0.1);
}

.chat-search-wrap input,
.session-controls input {
    min-height: 44px;
    padding: 11px 14px;
    color: var(--text-main);
    border: 1px solid rgba(165, 181, 231, 0.13);
    border-radius: 13px;
    background: rgba(8, 12, 27, 0.62);
}

.chat-search-wrap input:focus-visible {
    border-color: rgba(109, 231, 210, 0.58);
    box-shadow: 0 0 0 4px rgba(109, 231, 210, 0.1);
}

.chat-list {
    padding: 12px;
}

.chat-item {
    padding: 14px 13px;
    border-radius: 15px;
}

.chat-item:hover {
    background: rgba(115, 129, 255, 0.1);
    border-color: rgba(141, 151, 255, 0.16);
}

.chat-item.active {
    background: linear-gradient(110deg, rgba(108, 120, 255, 0.18), rgba(55, 207, 190, 0.09));
    border-color: rgba(129, 150, 255, 0.28);
    box-shadow: inset 3px 0 #75e9d8;
}

.chat-title {
    font-size: 14px;
    font-weight: 700;
}

.chat-panel {
    background:
        radial-gradient(ellipse at 75% -8%, rgba(98, 115, 255, 0.13), transparent 38%),
        linear-gradient(160deg, #111629, #0d1120 76%);
}

.chat-header {
    min-height: 88px;
    padding: 18px 28px;
    background: rgba(17, 22, 42, 0.78);
    border-bottom-color: rgba(165, 181, 231, 0.11);
    backdrop-filter: blur(18px);
}

.chat-header h2 {
    font-size: 1.22rem;
}

.chat-profile-picture {
    width: 46px;
    height: 46px;
    border: 2px solid rgba(135, 148, 255, 0.3);
    background: linear-gradient(145deg, #262f55, #172c41);
}

.chat-profile-picture .profile-placeholder circle:first-child {
    fill: #253052;
}

.chat-profile-picture .profile-placeholder circle:nth-child(2),
.chat-profile-picture .profile-placeholder path {
    fill: #8490c0;
}

.header-btn,
.icon-btn {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    color: #9ea9ff;
    border-color: rgba(141, 151, 255, 0.18);
    background: rgba(112, 124, 255, 0.09);
}

.header-btn:hover,
.icon-btn:hover {
    color: #e7eaff;
    border-color: rgba(141, 151, 255, 0.35);
    background: rgba(112, 124, 255, 0.17);
}

.message-list {
    padding: 26px clamp(18px, 4vw, 54px);
    gap: 13px;
}

.message {
    padding: 12px 15px;
    border: 1px solid rgba(165, 181, 231, 0.11);
    border-radius: 17px;
    box-shadow: 0 10px 24px rgba(2, 5, 17, 0.18);
}

.message.inbound {
    background: linear-gradient(145deg, #202842, #1a2239);
    border-bottom-left-radius: 6px;
}

.message.outbound {
    color: #07191b;
    background: linear-gradient(130deg, #6de7d2, #5fcce5);
    border: 0;
    border-bottom-right-radius: 6px;
}

.message-composer {
    background: rgba(17, 22, 42, 0.94);
    border-top-color: rgba(165, 181, 231, 0.1);
}

.composer-input-wrapper {
    gap: 10px;
    padding: 16px 22px;
}

.message-input-field {
    min-height: 48px;
    padding: 14px 18px;
    border: 1px solid rgba(165, 181, 231, 0.12);
    border-radius: 16px;
    background: rgba(8, 12, 27, 0.65);
}

.message-input-field:focus {
    background: rgba(8, 12, 27, 0.85);
    box-shadow: 0 0 0 3px rgba(109, 231, 210, 0.1);
}

.composer-btn.send-btn {
    background: linear-gradient(135deg, #6de7d2, #5fcce5);
    color: #07191b;
}

.composer-btn.send-btn:hover {
    background: linear-gradient(135deg, #91f2e2, #78d9ee);
}

.modal {
    padding: 24px;
    background: rgba(5, 7, 17, 0.76);
    backdrop-filter: blur(14px);
}

.modal-content {
    width: min(620px, 100%);
    max-width: 620px;
    border: 1px solid rgba(165, 181, 231, 0.2);
    border-radius: 24px;
    background: linear-gradient(145deg, #181e36, #111629);
    box-shadow: 0 36px 110px rgba(0, 0, 0, 0.62);
}

.modal-header {
    padding: 24px 28px;
    border-bottom-color: rgba(165, 181, 231, 0.12);
}

.modal-header h2 {
    font-size: 1.55rem;
}

.modal-subtitle {
    margin: 6px 0 0;
    color: var(--text-muted);
    font-size: 13px;
}

.close-btn {
    width: 38px;
    height: 38px;
    border-radius: 13px;
    color: #b6bed6;
    background: rgba(165, 181, 231, 0.08);
}

.close-btn:hover {
    color: #fff;
    background: rgba(255, 125, 154, 0.18);
}

.modal-body {
    padding: 24px 28px;
}

.ai-config-content {
    width: min(1080px, 100%);
    max-width: 1080px;
    max-height: min(900px, calc(100vh - 48px));
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    overflow: hidden;
}

.ai-config-content .modal-header {
    padding: 22px 30px;
}

.ai-config-body {
    min-height: 0;
    padding: 0;
    display: grid;
    grid-template-columns: 210px minmax(0, 1fr);
    overflow: hidden;
}

.config-nav {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 26px 16px;
    border-right: 1px solid rgba(165, 181, 231, 0.1);
    background: rgba(8, 12, 27, 0.3);
}

.config-nav-label {
    padding: 0 12px 10px;
    color: #818cae;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.16em;
}

.config-nav a {
    display: flex;
    align-items: center;
    min-height: 42px;
    padding: 9px 12px;
    border: 1px solid transparent;
    border-radius: 12px;
    color: #a6afcb;
    font-size: 12px;
    font-weight: 650;
    text-decoration: none;
    transition: color 140ms ease, background 140ms ease, border-color 140ms ease;
}

.config-nav a:hover,
.config-nav a:focus-visible {
    color: #f2f4ff;
    border-color: rgba(141, 151, 255, 0.16);
    background: rgba(111, 124, 255, 0.12);
}

.ai-config-sections {
    min-height: 0;
    overflow-y: auto;
    padding: 24px 30px 30px;
    scroll-behavior: smooth;
    scrollbar-gutter: stable;
}

.config-section {
    margin: 0 0 16px;
    padding: 21px 22px;
    border: 1px solid rgba(165, 181, 231, 0.13);
    border-radius: 18px;
    background:
        linear-gradient(135deg, rgba(100, 114, 255, 0.045), transparent 48%),
        rgba(20, 26, 48, 0.78);
    scroll-margin-top: 20px;
}

.config-section:last-of-type {
    margin-bottom: 16px;
}

.config-section-heading {
    display: flex;
    align-items: flex-start;
    gap: 13px;
    margin-bottom: 20px;
}

.config-step {
    display: grid;
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    place-items: center;
    border: 1px solid rgba(120, 226, 218, 0.2);
    border-radius: 11px;
    color: #79e7d8;
    background: rgba(78, 218, 202, 0.09);
    font-family: var(--font-ui);
    font-size: 11px;
    font-weight: 800;
}

.config-section-heading h3 {
    margin: 1px 0 4px;
    color: #f1f3ff;
    font-family: var(--font-ui);
    font-size: 1rem;
    letter-spacing: -0.02em;
}

.config-section-heading p {
    margin: 0;
    color: #98a3c2;
    font-size: 12px;
    line-height: 1.5;
}

.config-section .field {
    gap: 7px;
    margin-bottom: 17px;
}

.config-section .field:last-child {
    margin-bottom: 0;
}

.config-section .field > label,
.account-form .field > label,
.account-danger > label {
    color: #e2e6f8;
    font-size: 12px;
    font-weight: 700;
}

.config-section input:not([type="checkbox"]):not([type="radio"]),
.config-section select,
.config-section textarea,
.account-form input,
.account-danger input,
.test-chat-input {
    width: 100%;
    min-height: 43px;
    padding: 10px 13px;
    border: 1px solid rgba(165, 181, 231, 0.15);
    border-radius: 12px;
    color: #f3f5ff;
    background: rgba(8, 12, 27, 0.62);
    font-size: 13px;
    transition: border-color 140ms ease, box-shadow 140ms ease;
}

.config-section textarea {
    min-height: 88px;
    line-height: 1.55;
    resize: vertical;
}

.config-section input:focus,
.config-section select:focus,
.config-section textarea:focus,
.account-form input:focus,
.account-danger input:focus,
.test-chat-input:focus {
    border-color: rgba(109, 231, 210, 0.55);
    outline: none;
    box-shadow: 0 0 0 3px rgba(109, 231, 210, 0.09);
}

.config-section input::placeholder,
.config-section textarea::placeholder,
.test-chat-input::placeholder {
    color: #7783a4;
}

.field-help {
    margin-top: 1px;
    color: #929dbb;
    font-size: 11px;
    line-height: 1.5;
}

.field-help a,
.terms-consent a {
    color: #7de8d7;
}

.input-group {
    gap: 9px;
}

.input-group .btn-secondary {
    flex: 0 0 auto;
    padding: 10px 17px;
}

.radio-group {
    display: grid;
    margin: 0;
}

.radio-option {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px;
    border: 1px solid rgba(120, 226, 218, 0.2);
    border-radius: 14px;
    background: rgba(69, 218, 201, 0.06);
}

.radio-option input[type="radio"] {
    margin: 3px 0 0;
    accent-color: var(--accent);
}

.radio-option span {
    display: grid;
    gap: 4px;
    font-size: 13px;
}

.radio-option small {
    color: #929dbb;
    font-size: 11px;
}

.checkbox-label {
    position: relative;
    gap: 10px;
    margin: 0;
    color: #e5e9fb;
    font-size: 13px;
    font-weight: 650;
}

.checkbox-label input[type="checkbox"] {
    position: absolute;
    width: 18px;
    height: 18px;
    margin: 0;
    opacity: 0;
}

.checkmark {
    flex: 0 0 19px;
    width: 19px;
    height: 19px;
    margin: 0;
    border: 1px solid rgba(165, 181, 231, 0.28);
    border-radius: 6px;
    background: rgba(8, 12, 27, 0.5);
}

.checkbox-label input[type="checkbox"]:checked + .checkmark {
    border-color: #62ddcf;
    background: linear-gradient(135deg, #6de7d2, #5fcce5);
}

.checkbox-label input[type="checkbox"]:focus-visible + .checkmark {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.group-options {
    margin-top: 15px;
    padding: 16px;
    border-color: rgba(165, 181, 231, 0.1);
    border-radius: 14px;
    background: rgba(8, 12, 27, 0.28);
}

.group-options .field {
    margin-bottom: 14px;
}

.group-options input[type="text"] {
    width: 100%;
    text-align: left;
}

.test-chat-container {
    border-color: rgba(165, 181, 231, 0.14);
    border-radius: 14px;
    background: #10162a;
}

.test-chat-messages {
    height: 180px;
    border-bottom-color: rgba(165, 181, 231, 0.12);
    background:
        radial-gradient(ellipse at 90% 10%, rgba(79, 212, 197, 0.07), transparent 55%),
        #10162a;
}

.test-chat-input-container {
    padding: 12px;
    background: rgba(8, 12, 27, 0.44);
}

.bot-message .message-content {
    color: #e5e9fb;
    background: #202842;
    border-color: rgba(165, 181, 231, 0.12);
}

.user-message .message-content {
    color: #07191b;
    background: linear-gradient(130deg, #6de7d2, #5fcce5);
}

.modal-footer {
    padding: 16px 28px;
    border-top-color: rgba(165, 181, 231, 0.12);
    background: rgba(10, 14, 28, 0.72);
}

.btn-primary,
.btn-secondary {
    min-height: 42px;
    padding: 10px 17px;
    border-radius: 12px;
    font-size: 12px;
}

.btn-secondary {
    color: #e6eaff;
    border: 1px solid rgba(165, 181, 231, 0.17);
    background: rgba(165, 181, 231, 0.08);
}

.btn-secondary:hover {
    border-color: rgba(141, 151, 255, 0.38);
    background: rgba(112, 124, 255, 0.14);
}

.config-status {
    padding: 12px 14px;
    border-radius: 12px;
    font-size: 12px;
}

.account-modal-content .modal-body {
    max-height: calc(100vh - 160px);
    overflow-y: auto;
}

.account-email {
    color: #c9d0ed;
}

.account-form {
    gap: 13px;
    border-bottom-color: rgba(165, 181, 231, 0.12);
}

.account-form h3,
.account-danger h3 {
    color: #f1f3ff;
    font-family: var(--font-ui);
}

.account-danger {
    padding: 17px;
    border: 1px solid rgba(255, 125, 154, 0.18);
    border-radius: 15px;
    background: rgba(255, 125, 154, 0.045);
}

.account-danger p {
    margin: 0;
    font-size: 12px;
    line-height: 1.6;
}

.danger-btn {
    border-radius: 11px;
    background: linear-gradient(120deg, #f36f8b, #d85179);
}

.auth-form-element {
    gap: 14px;
}

.auth-form .field label {
    color: #e2e6f8;
    font-size: 12px;
    font-weight: 700;
}

.auth-form .field input {
    width: 100%;
    min-height: 45px;
    padding: 11px 13px;
    border: 1px solid rgba(165, 181, 231, 0.16);
    border-radius: 12px;
    color: var(--text-main);
    background: rgba(8, 12, 27, 0.62);
}

.auth-btn {
    min-height: 46px;
    border-radius: 13px;
}

.auth-switch {
    margin-top: 20px;
}

.auth-switch p {
    margin: 10px 0;
}

.auth-switch a {
    color: #82e9dc;
}

.legal-page {
    border-color: rgba(165, 181, 231, 0.17);
    border-radius: 24px;
    background: rgba(16, 20, 38, 0.96);
    box-shadow: var(--shadow-deep);
}

.legal-page h1,
.legal-page h2 {
    color: #f3f5ff;
}

.legal-page a {
    color: #82e9dc;
}

.toast {
    border: 1px solid rgba(165, 181, 231, 0.18);
    border-radius: 14px;
    backdrop-filter: blur(16px);
}

@media (max-width: 980px) {
    .app-shell {
        width: 100%;
        height: 100vh;
        margin: 0;
        border: 0;
        border-radius: 0;
        grid-template-columns: 68px minmax(230px, 32vw) minmax(0, 1fr);
    }

    .ai-config-content {
        width: min(940px, 100%);
        max-width: 940px;
    }
}

@media (max-width: 680px) {
    .app-shell {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto minmax(160px, 27vh) minmax(0, 1fr);
    }

    .workspace-nav {
        padding: 8px 12px;
    }

    .workspace-nav-btn,
    .workspace-logout-btn {
        width: 42px;
        height: 42px;
        min-height: 42px;
        border-radius: 13px;
    }

    .sidebar-top {
        padding: 16px 18px 14px;
    }

    .chat-header {
        min-height: 74px;
        padding: 13px 15px;
    }

    .composer-input-wrapper {
        gap: 5px;
        padding: 10px;
    }

    .composer-btn {
        width: 36px;
        height: 40px;
    }

    .modal {
        align-items: stretch;
        padding: 8px;
    }

    .modal-content,
    .ai-config-content {
        width: 100%;
        max-width: none;
        max-height: calc(100dvh - 16px);
        border-radius: 19px;
    }

    .ai-config-content .modal-header {
        padding: 17px 18px;
    }

    .modal-header h2 {
        font-size: 1.25rem;
    }

    .ai-config-body {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto minmax(0, 1fr);
    }

    .config-nav {
        display: flex;
        flex-direction: row;
        gap: 6px;
        overflow-x: auto;
        padding: 10px 12px;
        border-right: 0;
        border-bottom: 1px solid rgba(165, 181, 231, 0.1);
        scrollbar-width: none;
    }

    .config-nav::-webkit-scrollbar {
        display: none;
    }

    .config-nav-label {
        display: none;
    }

    .config-nav a {
        flex: 0 0 auto;
        min-height: 36px;
        padding: 7px 10px;
        font-size: 11px;
    }

    .ai-config-sections {
        padding: 14px 12px 20px;
    }

    .config-section {
        padding: 17px 15px;
        border-radius: 15px;
    }

    .config-section-heading {
        gap: 10px;
        margin-bottom: 16px;
    }

    .config-section-heading p {
        font-size: 11px;
    }

    .modal-footer {
        padding: 12px 14px;
    }

    .modal-footer .btn-primary,
    .modal-footer .btn-secondary {
        flex: 1;
    }

    .input-group {
        flex-wrap: wrap;
    }

    .input-group input {
        flex-basis: 100%;
    }

    .account-modal-content .modal-body {
        max-height: calc(100dvh - 120px);
    }
}

.message-meta {
    margin-top: 6px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
}

.message-flag {
    font-size: 10px;
    text-transform: uppercase;
    color: rgba(214, 230, 235, 0.72);
}

.message-status {
    font-size: 11px;
    font-weight: 700;
}

.message-participant {
    margin-bottom: 5px;
    font-size: 11px;
    color: rgba(214, 230, 235, 0.72);
}

.message-sender {
    margin-bottom: 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
}

.message-sender-me {
    color: rgba(3, 39, 29, 0.85);
}

.message-quote {
    margin: 0 0 7px;
    border-left: 2px solid rgba(60, 209, 173, 0.6);
    padding-left: 8px;
    color: rgba(214, 230, 235, 0.84);
    font-size: 12px;
}

.message-text {
    white-space: pre-wrap;
}

.media-wrap {
    margin-bottom: 6px;
}

.message-media-img {
    max-width: min(280px, 100%);
    border-radius: 10px;
    display: block;
}

.message-media-video {
    width: min(340px, 100%);
    border-radius: 10px;
}

.load-media-btn,
.doc-link {
    display: inline-block;
    border-radius: 8px;
    border: 1px solid var(--border-soft);
    padding: 7px 10px;
    background: rgba(20, 33, 39, 0.72);
    color: var(--text-main);
    text-decoration: none;
    font-size: 12px;
}

.load-media-btn {
    cursor: pointer;
}

.message-reactions {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.message-reactions span {
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 11px;
    background: rgba(60, 209, 173, 0.16);
    border: 1px solid rgba(60, 209, 173, 0.25);
}

.interactive-options {
    margin: 6px 0 0;
    padding-left: 18px;
    font-size: 12px;
}

@keyframes reveal-up {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%,
    100% {
        transform: scale(1);
    }
    50% {
        transform: scale(0.92);
    }
}

@media (max-width: 980px) {
    .app-shell {
        width: 100%;
        height: 100vh;
        margin: 0;
        border-radius: 0;
        border: 0;
        grid-template-columns: 64px minmax(240px, 32vw) minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr);
    }

    .workspace-nav {
        padding: 16px 8px;
    }

    .sidebar {
        border-right: 0;
        border-bottom: 1px solid var(--border-soft);
    }

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

@media (max-width: 680px) {
    .app-shell {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto minmax(160px, 27vh) minmax(0, 1fr);
    }

    .workspace-nav {
        flex-direction: row;
        justify-content: space-between;
        gap: 10px;
        padding: 8px 12px;
        border-right: 0;
        border-bottom: 1px solid var(--border-soft);
    }

    .workspace-nav-links {
        display: flex;
        justify-content: center;
        width: auto;
    }

    .workspace-nav-bottom {
        width: auto;
        margin-top: 0;
    }

    .workspace-nav-btn,
    .workspace-logout-btn {
        width: 40px;
        min-height: 40px;
        padding: 0;
    }

    .workspace-logout-btn {
        border-top: 0;
    }

    .connect-screen {
        padding: 14px;
    }

    .connect-card {
        padding: 22px 18px;
        border-radius: 18px;
    }

    .session-controls {
        grid-template-columns: 1fr;
    }

    .chat-header {
        padding: 16px;
    }

    .message-list {
        padding: 14px;
    }

    .message-form {
        grid-template-columns: 1fr;
        padding: 12px;
    }

    #jid-input,
    #message-type,
    #message-input,
    #send-btn,
    #media-url-input,
    #media-file-input,
    #mime-input,
    #file-name-input,
    #reaction-message-id,
    #reaction-emoji,
    #interactive-json {
        grid-column: auto;
    }
}

/* ===== Responsive optimizations (WhatsApp-style navigation) ===== */

/* Dynamic viewport height support */
.app-shell {
  height: calc(100dvh - 48px);
}
@media (max-width: 980px) {
  .app-shell {
    height: 100dvh;
  }
}

/* Back button hidden on desktop */
.chat-back-btn {
  display: none;
}

/* Compact / portrait single-pane navigation */
@media (max-width: 820px), (orientation: portrait) and (max-width: 1024px) {
  .app-shell {
    width: 100%;
    height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
  }

  .workspace-nav {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--border-soft);
  }

  .workspace-nav-links {
    display: flex;
    justify-content: center;
    width: auto;
    gap: 6px;
  }

  .workspace-nav-bottom {
    width: auto;
    margin-top: 0;
  }

  .workspace-nav-btn,
  .workspace-logout-btn {
    width: 40px;
    height: 40px;
    min-height: 40px;
    border-radius: 12px;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 0;
    min-height: 0;
  }

  /* Default: show chat list, hide chat panel */
  .app-shell:not(.chat-open) .chat-panel {
    display: none;
  }

  /* When a chat is open: hide list, show chat */
  .app-shell.chat-open .sidebar {
    display: none;
  }

  .app-shell.chat-open .chat-panel {
    display: grid;
  }

  .chat-back-btn {
    display: flex;
  }

  .chat-header {
    padding: 10px 12px;
    min-height: 56px;
  }

  .chat-header-left {
    min-width: 0;
  }

  .chat-title-wrapper {
    min-width: 0;
    gap: 8px;
  }

  .chat-header h2 {
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .chat-header p {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .header-btn {
    width: 34px;
    height: 34px;
    min-height: 34px;
    border-radius: 10px;
  }

  .chat-profile-picture {
    width: 34px;
    height: 34px;
  }

  .workspace-nav-btn,
  .workspace-logout-btn {
    width: 36px;
    height: 36px;
    min-height: 36px;
  }

  .composer-btn {
    width: 34px;
    height: 34px;
  }

  .message-list {
    padding: 12px;
  }

  .composer-input-wrapper {
    padding: 8px 10px;
    gap: 6px;
  }

}

/* Landscape / horizontal screens: auth card alignment & sizing */
.connect-screen {
  min-height: 100dvh;
  min-height: 100vh;
  place-items: center;
  padding: clamp(12px, 3vw, 24px);
  padding-top: max(12px, env(safe-area-inset-top));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
}

.connect-card {
  width: min(560px, 100%);
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@media (orientation: landscape) and (max-height: 520px) {
  .auth-brand-logo {
    width: 96px;
    height: 96px;
    margin: 0 auto 8px;
  }

  .connect-card {
    padding: clamp(16px, 3vh, 24px);
  }

  .connect-card h1 {
    font-size: clamp(1.4rem, 4vh, 2rem);
  }

  .connect-subtitle {
    margin: 6px 0 12px;
  }

  .auth-form-element {
    margin-top: 12px;
    gap: 10px;
  }

  .auth-btn {
    min-height: 40px;
    padding: 8px 18px;
  }
}

/* Modal safe areas */
.modal {
  padding-left: max(8px, env(safe-area-inset-left));
  padding-right: max(8px, env(safe-area-inset-right));
}

/* Better touch targets on small devices */
@media (max-width: 680px) {
  button {
    min-height: 40px;
  }

  .composer-btn {
    min-height: 40px;
  }
}

/* Prevent horizontal overflow globally */
html, body {
  overflow-x: hidden;
  max-width: 100%;
}

img, video, canvas, svg {
  max-width: 100%;
  height: auto;
}

@media (hover: none) {
  .message-actions-visible .message-actions {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }
}
