/* ============================================================
   TownSuite.Chat — app.css (2026 redesign)
   Global layout + shared chrome. Selectors are unchanged from
   the previous version; only the visual treatment is new.
   Requires: theme/tokens.css + theme/theme-(dark|light).css
   loaded BEFORE this file.
   ============================================================ */

html, body, #app {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    background-color: var(--bg);
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.55;
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

:root {
    --sidebar-open-width: 288px;
    --sidebar-rail-width: 60px;
}

html, body {
    scrollbar-color: var(--line2) transparent;
    scrollbar-width: thin;
}

::selection {
    background: var(--ts-blue);
    color: #fff;
}

a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
}

button, input, select, textarea {
    font-family: var(--font-ui);
}

input::placeholder, textarea::placeholder {
    color: var(--ink3);
}

.container {
    display: grid;
    grid-template-columns: var(--sidebar-open-width) auto;
    grid-template-rows: 100%;
    height: 100%;
}

/* ---------------- sidebar shell ---------------- */

.side-panel {
    grid-column: 1;
    grid-row: 1;
    background-color: var(--bg2);
    padding: 15px 20px;
    position: relative;
    overflow-x: hidden;
    overflow-y: auto;
    scroll-behavior: smooth;
    border-right: 1px solid var(--line);
    margin-top: 0;
    width: var(--sidebar-open-width);
    z-index: 2002;
}

    .side-panel::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        width: 50px;
        height: 100%;
        pointer-events: none;
    }

.three-dot-button {
    background: none;
    border: none;
    border-radius: 8px;
    color: var(--ink3);
    font-size: 15px;
    cursor: pointer;
    padding: 2px 8px;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity .2s ease, background-color .15s ease, color .15s ease;
}

    .three-dot-button:hover {
        background: var(--surface);
        color: var(--ink);
    }

.side-panel-item:hover .three-dot-button {
    opacity: 1;
}

/* ---------------- sidebar search popup ---------------- */

.ts-search-dim {
    position: fixed;
    inset: 0;
    background: var(--backdrop);
    backdrop-filter: blur(2px);
    z-index: 2001;
    pointer-events: all;
}

/* Results panel — centered command-palette style over the dim backdrop. */
.ts-search-popup {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: min(560px, 94vw) !important;
    max-height: 340px !important;
    background: var(--surface) !important;
    border: 1px solid var(--line2) !important;
    border-radius: 14px !important;
    box-shadow: var(--shadow-3) !important;
    overflow-y: auto !important;
    font-family: var(--font-ui);
    color: var(--ink);
}

    /* Telerik renders the popup-settings class on the k-animation-container
       (the element these .ts-search-popup rules style). The actual popup —
       div.k-popup.k-list-container — renders inside it, and the Kendo theme
       paints it as an opaque white card that hides the dark surface above.
       Flatten the inner layers so the themed container shows through.
       !important: the Kendo theme stylesheet loads after this file. */
    .ts-search-popup .k-child-animation-container,
    .ts-search-popup .k-popup {
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        color: inherit !important;
    }

    /* strip Kendo list chrome — the item template styles itself. */
    .ts-search-popup .k-list,
    .ts-search-popup .k-list-content,
    .ts-search-popup .k-table,
    .ts-search-popup .k-list-ul {
        background: transparent !important;
        border: none !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    .ts-search-popup .k-list-item,
    .ts-search-popup .k-list-item.k-selected,
    .ts-search-popup .k-list-item.k-focus,
    .ts-search-popup .k-list-item:hover {
        padding: 0 !important;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        color: inherit !important;
    }

    .ts-search-popup .k-nodata {
        background: transparent !important;
        color: var(--ink3) !important;
    }

/* the popup and the sidebar must sit above the search backdrop (z 2001).
   The popup-settings class is ON the animation container, not inside it,
   so match it directly (:has() only matches descendants). */
.k-animation-container.ts-search-popup {
    z-index: 2002 !important;
}

.container.search-overlay-open .side-panel {
    position: relative;
    z-index: 2002;
}

/* Telerik FileSelect — theme the Kendo chrome to the design tokens.
   !important: the Kendo theme stylesheet loads after this file. */
.kb-file-select .k-upload {
    background: transparent !important;
    border: none !important;
    color: var(--ink) !important;
    font-family: var(--font-ui) !important;
}

.kb-file-select .k-dropzone {
    background: var(--bg) !important;
    border: 1.5px dashed var(--line2) !important;
    border-radius: 16px !important;
    color: var(--ink2) !important;
    padding: 16px 18px !important;
    transition: border-color .15s ease;
}

    .kb-file-select .k-dropzone:hover {
        border-color: var(--accent) !important;
    }

    .kb-file-select .k-dropzone .k-dropzone-hint {
        color: var(--ink3) !important;
    }

.kb-file-select .k-upload-button {
    background: var(--surface) !important;
    border: 1.5px solid var(--line2) !important;
    border-radius: 11px !important;
    color: var(--ink) !important;
    font-weight: 700 !important;
    box-shadow: none !important;
}

    .kb-file-select .k-upload-button:hover {
        border-color: var(--accent) !important;
        color: var(--accent) !important;
    }

.kb-file-select .k-upload-files {
    background: transparent !important;
    border: none !important;
}

.kb-file-select .k-file {
    background: var(--surface) !important;
    border: 1px solid var(--line) !important;
    border-radius: 12px !important;
    color: var(--ink) !important;
}

.kb-file-select .k-file-name {
    color: var(--ink) !important;
}

.kb-file-select .k-file-size,
.kb-file-select .k-file-validation-message {
    color: var(--ink3) !important;
}

.kb-file-select ul.k-upload-files.k-reset {
    overflow-y: auto !important;
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
}

    .kb-file-select ul.k-upload-files.k-reset::-webkit-scrollbar {
        width: 0 !important;
        height: 0 !important;
        display: none !important;
    }

.top-right {
    position: fixed;
    top: 10px;
    right: 10px;
    transform: translateX(-10px);
    z-index: 9999;
    gap: 10px;
}

/* ---------------- chat thread ---------------- */

.chat {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    scroll-behavior: smooth;
}

.chat-title {
    display: inline-block;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

    .chat-title:hover {
        color: var(--accent-strong);
    }

.assistant-message {
    padding: 1rem;
}

    .assistant-message .message-container {
        background: var(--surface);
        border: 1px solid var(--line);
        border-radius: 16px;
        padding: 20px 24px;
        box-shadow: var(--shadow-1);
        line-height: 1.65;
    }

        .assistant-message .message-container .chat-message-content {
            margin-top: 0;
        }

/* markdown output: don't let the first/last element's own margin pad the
   bubble beyond its padding (e.g. a response opening with an H2) */
.chat-message-content > :first-child {
    margin-top: 0;
}

.chat-message-content > :last-child {
    margin-bottom: 0;
}

.user-message {
    justify-content: flex-end;
    padding-right: 1rem;
}

    .user-message .message-container {
        background-color: var(--accent);
        color: var(--accent-ink);
        border-radius: 18px 18px 5px 18px;
        padding: 12px 18px;
        margin-left: 6rem;
        max-width: 72%;
        box-shadow: var(--shadow-1);
    }

        .user-message .chat-message-author {
            display: none;
        }

        .user-message .message-container .chat-message-content {
            margin: 0;
        }

.message-wrapper {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user-message .message-wrapper {
    align-items: flex-end;
}

.user-feedback {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    padding-right: 8px;
}

.copy-btn.copied {
    color: var(--success);
    border-color: var(--success);
    background-color: var(--success-tint);
}

.user-text {
    justify-content: flex-end;
    padding-right: 1rem;
}

    .user-text .user-message-container {
        background-color: var(--surface);
        border: 1.5px solid var(--line2);
        border-radius: 18px;
        padding: 12px 16px;
        margin-left: 6rem;
        max-width: 80%;
        width: 100%;
    }

.edit-message-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.edit-message-textarea {
    width: 100%;
    min-height: 70px;
    resize: vertical;
    border: none;
    outline: none;
    background: transparent;
    color: inherit;
    font: inherit;
}

.edit-message-action {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.edit-message-action-btn {
    background: transparent;
    color: var(--ink);
    border: 1.5px solid var(--line2);
    padding: 8px 16px;
    border-radius: 11px;
    cursor: pointer;
    font-weight: 700;
    font-size: 13.5px;
    transition: border-color .15s ease, color .15s ease, transform .08s ease;
}

    .edit-message-action-btn:hover {
        border-color: var(--accent);
        color: var(--accent);
        background-color: transparent;
    }

.branch-nav {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-left: 0.5rem;
}

.branch-nav-btn {
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0 0.25rem;
    font-size: 0.8rem;
    color: var(--accent);
}

    .branch-nav-btn:disabled {
        opacity: 0.25;
        cursor: default;
    }

.branch-nav-label {
    font-size: 0.8rem;
    min-width: 2.5rem;
    text-align: center;
    color: var(--ink3);
}

.conversation-name {
    font-size: 1.1rem;
    color: var(--ink);
    margin: 0;
    padding: 0 10px;
    text-align: center;
    font-weight: 700;
    letter-spacing: -.01em;
}

.chat-message {
    display: flex;
    margin-bottom: 26px;
    color: var(--ink);
    margin-left: 30px;
}

.chat-header {
    flex-shrink: 0;
    background-color: var(--bg);
    border-bottom: 1px solid var(--line);
    z-index: 10;
    position: relative;
}

.chat-message-header {
    font-weight: 600;
    width: 100%;
    margin: 0 auto;
}

.chat-message p {
    margin: 0;
}

.chat-message pre {
    border: 1px solid var(--line);
    padding: 1em;
    margin: 15px 0;
    width: 100%;
    box-sizing: border-box;
    overflow-x: auto;
    border-radius: 12px;
    background-color: var(--code-bg);
    color: var(--code-text);
    font-family: var(--font-mono);
    font-size: 13px;
}

.chat-message-error {
    border: 1px solid var(--danger);
    padding: 12px 16px;
    margin: 0 auto;
    width: 48rem;
    max-width: 100%;
    border-radius: 12px;
    background-color: var(--danger-tint);
    color: var(--danger);
}

.chat-message-info {
    border: 1px solid var(--success);
    padding: 12px 16px;
    margin: 0 auto;
    border-radius: 12px;
    background-color: var(--success-tint);
    color: var(--success);
}

.chat-message-author {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 700;
    font-size: 13px;
    color: var(--ink2);
    margin-bottom: 8px;
}

.chat-author-emblem {
    width: 20px;
    height: 20px;
    flex: none;
}

.chat-message-content {
    margin-top: 5px;
}


h1:focus {
    outline: none;
}

/* ---------------- brand dots loader ---------------- */

.ts-dots {
    display: inline-flex;
    gap: 6px;
    align-items: center;
}

    .ts-dots i {
        display: block;
        width: var(--ts-dot-size, 9px);
        height: var(--ts-dot-size, 9px);
        transform: rotate(45deg);
        border-radius: 1.5px;
    }

    .ts-dots i:nth-child(1) { background: var(--ts-orange, #E48D1A); }
    .ts-dots i:nth-child(2) { background: var(--ts-green, #2DA343); }
    .ts-dots i:nth-child(3) { background: var(--ts-red, #E03A3E); }

/* larger variant — full-screen app loader */
.ts-dots--lg {
    gap: 10px;
    --ts-dot-size: 15px;
    --ts-dot-rise: -5px;
}

@keyframes tsblink {
    0%, 70%, 100% { opacity: .25; transform: translateY(0) rotate(45deg); }
    35%           { opacity: 1;   transform: translateY(var(--ts-dot-rise, -3px)) rotate(45deg); }
}

@media (prefers-reduced-motion: no-preference) {
    .ts-dots i { animation: tsblink 1.1s infinite; }
    .ts-dots i:nth-child(2) { animation-delay: .18s; }
    .ts-dots i:nth-child(3) { animation-delay: .36s; }
}
.hamburger,
.sidebar-close,
.sidebar-rail-btn {
    border: none;
    border-radius: 11px;
    background: transparent;
    color: var(--ink3);
    cursor: pointer;
    display: grid;
    place-items: center;
    padding: 0;
    margin: 0;
    transition: background-color .15s ease, color .15s ease;
    -webkit-appearance: none;
    appearance: none;
}

    .hamburger:hover,
    .sidebar-close:hover,
    .sidebar-rail-btn:hover {
        background: var(--surface2);
        color: var(--ink);
    }

    .hamburger i,
    .sidebar-close i,
    .sidebar-rail-btn i {
        line-height: 1;
    }

.hamburger {
    display: none;
    width: 44px;
    height: 44px;
    font-size: 18px;
    color: var(--ink);
}

/* ---------------- feedback buttons ---------------- */

.message-feedback {
    display: flex;
    align-items: center;
    gap: 4px;
}

.feedback-btn {
    background: none;
    border: none;
    border-radius: 8px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--ink3);
    padding: 0;
    margin: 0;
    font-size: 13px;
}

    .feedback-btn:hover {
        background-color: var(--surface2);
        color: var(--ink);
    }

    .feedback-btn.selected.like-btn {
        background-color: var(--success-tint);
        border-color: var(--success);
        color: var(--success);
    }

    .feedback-btn.selected.dislike-btn {
        background-color: var(--danger-tint);
        border-color: var(--danger);
        color: var(--danger);
    }

.feedback-thanks {
    font-size: 12px;
    color: var(--success);
    opacity: 0;
    animation: feedbackFadeIn 0.5s forwards;
}

.feedback-submitted .feedback-btn:not(.selected) {
    opacity: 0.5;
}

@keyframes feedbackFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ---------------- model picker ---------------- */

.model-float-button {
    position: fixed;
    top: 10px;
    left: 270px;
    z-index: 999;
    background-color: transparent;
    padding: 0;
    box-shadow: none;
    opacity: 1;
    border-radius: var(--r-pill);
}

    .model-float-button:hover {
        opacity: 1.0;
    }

.model-switch-dropdown {
    appearance: none;
    -webkit-appearance: none;
    background-color: var(--surface);
    color: var(--ink);
    border: 1.5px solid var(--line2);
    border-radius: var(--r-pill);
    padding: 8px 18px;
    font-size: 13.5px;
    font-weight: 600;
    text-align: center;
    text-align-last: center;
    cursor: pointer;
    outline: none;
    transition: border-color .15s ease;
}

    .model-switch-dropdown:hover,
    .model-switch-dropdown:focus {
        border-color: var(--accent);
    }

.sidebar-close {
    display: none;
    width: 44px;
    height: 44px;
    font-size: 18px;
}

.desktop-only {
    display: flex;
}

.mobile-only {
    display: none;
}

/* ===== Desktop only ===== */
@media (min-width: 769px) {

    .sidebar-overlay {
        display: none !important;
    }

    .sidebar-header-logo {
        display: none;
    }

    .container.sidebar-open {
        grid-template-columns: var(--sidebar-open-width) auto;
    }

    .container.sidebar-collapsed {
        grid-template-columns: var(--sidebar-rail-width) auto;
    }

    .side-panel {
        display: flex;
        flex-direction: row;
        padding: 0;
        width: 100%;
        overflow-y: auto;
        overflow-x: hidden;
    }

        .side-panel.open {
            flex-direction: column;
            overflow: hidden;
        }

    .sidebar-rail-desktop {
        width: var(--sidebar-rail-width);
        flex: 0 0 var(--sidebar-rail-width);
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .sidebar-rail-btn {
        width: 38px;
        height: 38px;
    }

        .sidebar-rail-btn:hover {
            background: var(--surface2);
            color: var(--ink);
        }

    .sidebar-body {
        flex: 1 1 auto;
        min-width: 0;
        overflow: visible;
        padding: 14px;
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    .side-panel:not(.open) .sidebar-body {
        padding: 0;
        opacity: 0;
        transform: translateX(-6px);
        pointer-events: none;
        overflow: hidden;
    }

    .side-panel.open .sidebar-body {
        opacity: 1;
        transform: translateX(0);
        pointer-events: auto;
        padding: 14px;
    }

    .container {
        transition: grid-template-columns 220ms ease;
    }

    .side-panel {
        transition: width 220ms ease;
        will-change: width;
    }

    .sidebar-body {
        transition: opacity 160ms ease, transform 220ms ease;
        will-change: opacity, transform;
    }

    .side-panel:not(.open) .sidebar-body {
        opacity: 0;
        transform: translateX(-6px);
        pointer-events: none;
    }

    .side-panel.open .sidebar-body {
        opacity: 1;
        transform: translateX(0);
        pointer-events: auto;
    }

    .side-panel.open .sidebar-rail-desktop {
        width: auto;
        align-self: stretch;
        box-sizing: border-box;
        flex: none;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        gap: 10px;
        padding: 14px 14px 0;
    }

    .model-float-button {
        left: 0 !important;
        transform: none !important;
        margin-left: calc(var(--sidebar-open-width) + 18px);
        transition: margin-left 220ms ease, transform 220ms ease;
        will-change: margin-left, transform;
    }

    .container.sidebar-collapsed .model-float-button {
        margin-left: calc(var(--sidebar-rail-width) + 18px);
    }

    .container.sidebar-open .model-float-button {
        margin-left: calc(var(--sidebar-open-width) + 18px);
    }

    .sidebar-rail-desktop {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding-top: 10px;
        padding-bottom: 0;
        position: relative;
    }

    .rail-user-chip {
        width: 44px;
        height: 44px;
        border: none;
        background: transparent;
        border-radius: 12px;
        display: grid;
        place-items: center;
        cursor: pointer;
        margin-bottom: 8px;
        transition: transform 180ms ease, background-color 180ms ease;
    }

        .rail-user-chip:hover {
            background: var(--surface2);
            transform: translateY(-1px);
        }

    .user-dropdown.rail-user-dropdown {
        position: fixed;
        left: calc(var(--sidebar-rail-width) + 12px);
        bottom: 12px;
        right: auto;
        width: 220px;
    }

    .sidebar-rail-desktop {
        position: relative;
    }

        .sidebar-rail-desktop .rail-logo {
            height: 30px;
            width: auto;
            object-fit: contain;
            margin-left: 4px;
            pointer-events: none;
        }

    .user-dropdown.rail-user-dropdown {
        position: fixed !important;
        width: 180px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .container, .side-panel, .sidebar-body, .sidebar-rail-btn i {
        transition: none !important;
    }
}

/* ===== Mobile / tablet ===== */
@media (max-width: 768px) {

    .container {
        display: block;
    }

    .model-float-button {
        position: absolute;
        top: 10px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 1001;
        padding: 0;
    }

    .top-right {
        position: fixed;
        top: 10px;
        right: 10px;
        display: flex;
        gap: 8px;
        padding: 6px 12px;
        font-size: 14px;
        border-radius: 10px;
        display: none;
    }

    .side-panel {
        grid-column: 1;
        grid-row: 1 / span 2;
        position: fixed;
        top: 0;
        left: 0;
        width: 290px;
        height: 100%;
        box-sizing: border-box;
        background-color: var(--bg2);
        padding: 0 16px 16px 16px;
        overflow-x: hidden;
        overflow-y: auto;
        scroll-behavior: smooth;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        z-index: 2100;
        box-shadow: var(--shadow-3);
    }

        .side-panel.open {
            transform: translateX(0);
        }

    .hamburger {
        display: grid;
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 2001;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }

    .sidebar-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 54px;
        padding: 0 16px;
        background-color: var(--bg2);
        border-bottom: 1px solid var(--line);
        position: sticky;
        top: 0;
        z-index: 2101;
    }

    .sidebar-header-logo {
        height: 30px;
        width: auto;
        object-fit: contain;
        margin-left: 4px;
        pointer-events: none;
    }

    .sidebar-close {
        display: grid;
        color: var(--ink);
    }

    .content {
        grid-column: 2;
        grid-row: 1;
        height: 100vh;
        height: 100dvh;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .conversation-name {
        margin-left: 45px;
        font-size: 1.05em;
        padding: 0;
    }

    .model-switch-dropdown {
        text-align: center;
        text-align-last: center;
    }

    .desktop-only {
        display: none;
    }

    .chat-message {
        margin-left: 3px;
    }

    .mobile-only {
        display: flex;
        position: fixed;
        top: 10px;
        right: 10px;
        z-index: 2201;
    }

    .feedback-overlay {
        z-index: 2503;
    }

    .chat-title {
        white-space: normal;
        overflow: visible;
        text-overflow: unset;
        max-width: none;
        display: block;
    }

    .user-message .message-container {
        margin-left: 2rem;
    }

}

@media (max-width: 768px) {
    .sidebar-rail-desktop {
        display: none;
    }

    .sidebar-body {
        padding: 0;
    }
}

@media (max-width: 768px) {

    .sidebar-body {
        display: flex;
        flex-direction: column;
        height: 100%;
        min-height: 100%;
        padding: 0;
    }

    .side-panel-flexer {
        flex: 1 1 auto;
        min-height: 0;
    }

    .side-panel-footer {
        margin-top: auto;
        position: sticky;
        bottom: 0;
        z-index: 2102;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .side-panel {
        padding-bottom: 20px;
    }
}
