:root {
    --bg: #f6f7fb;
    --sidebar: #f3f4f8;
    --card: #ffffff;
    --text: #1b1f2a;
    --muted: #6f7380;
    --border: #e6e8f0;
    --primary: #2d5bff;
    --accent: #ff7e36;
    --radius: 16px;
}

* {
    box-sizing: border-box;
    -ms-overflow-style: none;
    /* IE and Edge */
    scrollbar-width: none;
    /* Firefox */
}

/* Hide scrollbar for Chrome, Safari and Opera */
*::-webkit-scrollbar {
    display: none;
}

body {
    margin: 0;
    font-family: 'Manrope', 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
}

a {
    color: inherit;
    text-decoration: none;
}

.app {
    display: grid;
    grid-template-columns: 280px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--sidebar);
    padding: 20px 18px 16px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    height: 100vh;
    overflow: hidden;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    margin-right: -10px;
    padding-right: 10px;
}

.sidebar-header {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
    position: relative;
}

.sidebar-toggle-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sidebar-toggle-btn:hover {
    background: #eef1f8;
    color: var(--text);
}

.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 10px 0;
}

.logo-container img {
    width: 80px;
    height: auto;
}

.sidebar-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid var(--border);
    cursor: pointer;
    font-weight: 600;
    color: var(--text);
    transition: all 0.2s ease;
}

.sidebar-btn i {
    color: var(--muted);
}

.sidebar-btn:hover {
    background: #eef1f8;
}

.section-title {
    font-size: 12px;
    color: var(--muted);
    margin: 8px 0;
    padding: 0 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-list {
    display: grid;
    gap: 8px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    position: relative;
}

.history-item .delete-btn {
    margin-left: auto;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    opacity: 0;
    pointer-events: none;
}

.history-item .delete-btn:hover {
    color: #ff5a5a;
    border-color: #ffb3b3;
    background: #fff5f5;
}

.history-item:hover .delete-btn {
    opacity: 1;
    pointer-events: auto;
}

.history-item:hover {
    transform: translateX(4px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.04);
}

.history-item .tag {
    font-size: 10px;
    padding: 2px 8px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #f4f5f9;
    color: var(--muted);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.history-item .badge {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    position: absolute;
    right: 10px;
}

.sidebar-footer {
    margin-top: auto;
    padding: 12px 10px;
    border-top: 1px solid var(--border);
    background: var(--sidebar);
    z-index: 10;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--muted);
    font-weight: 700;
    margin: 6px 2px 8px;
}

.section-count {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 12px;
    color: var(--muted);
}

.footer-btn {
    width: 100%;
    text-align: center;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    color: var(--muted);
    font-weight: 600;
}

.user-block {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 14px;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: #101828;
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
}

.user-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.user-name {
    font-weight: 600;
}

.user-tier {
    font-size: 12px;
    color: var(--muted);
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.chat-item:hover {
    transform: translateX(4px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.04);
}

/* Footer Icons */
.footer-icons {
    display: flex;
    justify-content: space-between;
    /* Distribute evenly */
    margin-bottom: 20px;
    padding: 0 5px;
}

.footer-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: #fff;
    border: 1px solid var(--border);
    display: grid;
    place-items: center;
    color: var(--muted);
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
}

.footer-icon-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: #eef1f8;
    transform: translateY(-2px);
}

.footer-popup {
    position: absolute;
    bottom: 48px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: #fff;
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    width: 140px;
    text-align: center;
    opacity: 0;
    visibility: hidden;
    z-index: 1000;
    font-size: 12px;
    color: var(--text);
    transition: all 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    pointer-events: none;
    /* Prevent flickering */
}

.footer-popup::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 10px;
    height: 10px;
    background: #fff;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.footer-icon-btn:hover .footer-popup {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.popup-img {
    width: 100%;
    height: 100px;
    background: #f0f0f0;
    margin-bottom: 8px;
    display: grid;
    place-items: center;
    color: #ccc;
    border-radius: 8px;
}

.chat-item.active {
    border-color: #cdd7ff;
    background: #eef1fb;
}

.chat-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: #eef1fb;
    color: var(--primary);
    display: grid;
    place-items: center;
    font-size: 16px;
}

.chat-content {
    flex: 1;
}

.chat-title {
    font-weight: 700;
}

.chat-preview {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.3;
}

.main {
    display: flex;
    flex-direction: column;
    padding: 20px 24px 32px;
}

.app.sidebar-collapsed {
    grid-template-columns: 72px 1fr;
}

.sidebar.collapsed {
    padding-left: 10px;
    padding-right: 10px;
}

.sidebar.collapsed .logo-container img {
    width: 44px;
    height: auto;
}

.sidebar.collapsed .logo-container {
    justify-content: center;
    position: relative;
}

.sidebar.collapsed .sidebar-toggle-btn {
    top: 50%;
    left: 50%;
    right: auto;
    transform: translate(-50%, -50%);
    opacity: 0;
    pointer-events: none;
}

.sidebar.collapsed .logo-container:hover .sidebar-toggle-btn {
    opacity: 1;
    pointer-events: auto;
}

.sidebar.collapsed .logo-container:hover img {
    opacity: 0;
}

.sidebar.collapsed .sidebar-btn {
    justify-content: center;
    gap: 0;
    padding: 10px;
}

.sidebar.collapsed .sidebar-btn .btn-text {
    display: none;
}

.sidebar.collapsed .history-section,
.sidebar.collapsed .chat-history,
.sidebar.collapsed .sidebar-footer {
    display: none;
}

.top-bar {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    align-items: center;
    margin-bottom: 30px;
}

#rightPanel {
    position: relative;
}

.right-topbar {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 20;
    display: flex;
    justify-content: flex-start;
}

.right-topbar .inner {
    display: flex;
    justify-content: flex-start;
}

.model-switcher {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 12px;
    font-weight: 600;
    opacity: 0.5;
    transition: opacity 0.3s ease;
    color: var(--text);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.04);
}

.model-switcher:hover {
    opacity: 1;
}

.model-switcher label {
    font-size: 13px;
    color: var(--muted);
}

.model-switcher select {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px 8px;
    background: #fff;
    font-weight: 600;
}

.model-switcher .model-note {
    font-size: 12px;
    color: var(--muted);
}

.record-btn.recording {
    background: #111827;
    color: #fff;
    border-color: #111827;
}

.mobile-menu-btn {
    display: none;
    cursor: pointer;
}

.ghost-btn,
.pill-btn {
    border: 1px solid var(--border);
    background: #fff;
    padding: 10px 16px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.pill-btn.primary {
    background: #111827;
    color: #fff;
    border: none;
}

.hero {
    text-align: center;
    margin: 20px auto 26px;
    max-width: 760px;
}

.hero h1 {
    margin: 0 0 12px;
    font-size: clamp(28px, 3vw, 36px);
    font-weight: 700;
}

.input-card {
    background: #fff;
    border-radius: 18px;
    padding: 18px;
    border: 1px solid var(--border);
    box-shadow: 0 16px 60px rgba(0, 0, 0, 0.06);
}

.input-box {
    width: 100%;
    border: none;
    padding: 14px;
    font-size: 16px;
    color: var(--text);
    outline: none;
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 6px;
    gap: 10px;
}

.icon-btn {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid var(--border);
    display: grid;
    place-items: center;
    background: #fff;
    cursor: pointer;
}

.actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.quick-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.actions-left {
    flex: 1;
    min-width: 0;
}

.actions-right {
    flex-shrink: 0;
}

.quick-actions.inline {
    margin-left: 4px;
    flex-wrap: nowrap;
    overflow-x: auto;
    max-width: 420px;
    padding-bottom: 2px;
}

.quick-actions.inline::-webkit-scrollbar {
    height: 4px;
}

.quick-actions.inline::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 999px;
}

.quick-actions.inline .quick-chip {
    white-space: nowrap;
    flex-shrink: 0;
}

.quick-chip {
    padding: 8px 12px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid var(--border);
    color: var(--text);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.15s ease;
}

.quick-chip:hover {
    background: #eef1f8;
    transform: translateY(-1px);
}

.tabs {
    display: none;
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-top: auto;
    padding-bottom: 12px;
    flex-shrink: 0;
}

.feature-card {
    background: #fff;
    border-radius: 16px;
    border: 1px solid var(--border);
    padding: 0 0 16px 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.04);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    overflow: hidden;
}

.feature-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.06);
}

.feature-thumb {
    width: 100%;
    height: 120px;
    border-radius: 0;
    background: linear-gradient(135deg, #e8edff, #f5f7ff);
    display: grid;
    place-items: center;
    overflow: hidden;
}

.feature-thumb img {
    height: 64px;
    width: 64px;
    object-fit: contain;
}

.feature-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: #eef1fb;
    color: var(--primary);
    display: grid;
    place-items: center;
    font-size: 18px;
    margin-left: 16px;
}

.feature-title {
    margin: 0 16px;
    font-size: 16px;
    font-weight: 700;
}

.feature-description {
    margin: 0 16px;
    color: var(--muted);
    line-height: 1.5;
    font-size: 14px;
}

@media (max-width: 1024px) {
    .app {
        grid-template-columns: 240px 1fr;
    }
}

/* Typing Indicator */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    background: #fff;
    border-radius: 12px;
    border: 1px solid var(--border);
    width: fit-content;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--muted);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing {

    0%,
    80%,
    100% {
        transform: scale(0);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

@media (max-width: 768px) {
    .app {
        grid-template-columns: 1fr;
    }

    /* Off-canvas Sidebar */
    .sidebar {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 80%;
        max-width: 300px;
        z-index: 1001;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.1);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 1000;
        backdrop-filter: blur(2px);
        animation: fadeIn 0.3s ease;
    }

    .sidebar-overlay.open {
        display: block;
    }

    .sidebar-toggle-btn {
        display: none;
    }

    /* Top Bar Mobile */
    .top-bar {
        justify-content: space-between;
        padding: 0 4px;
    }

    .right-topbar {
        top: 8px;
        left: 8px;
    }

    .mobile-menu-btn {
        display: flex !important;
        width: 40px;
        height: 40px;
        align-items: center;
        justify-content: center;
        font-size: 20px;
        background: #fff;
        border: 1px solid var(--border);
        border-radius: 10px;
        color: var(--text);
    }

    /* Hero Mobile */
    .hero {
        padding: 0 12px;
        margin-top: 10px;
    }

    .hero h1 {
        font-size: 28px;
    }

    /* Bottom Station Mobile */
    #mainContainer[data-state="chat"] #bottomStation {
        left: 0;
        padding: 10px 12px;
    }

    #mainContainer[data-state="chat"] #innerChatContainer {
        height: 60vh;
        /* Adjust for mobile keyboard */
    }

    .input-card {
        padding: 12px;
        border-radius: 16px;
    }

    .quick-actions {
        flex-wrap: nowrap;
        overflow-x: auto;
        justify-content: flex-start;
        padding-bottom: 4px;
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    .quick-actions::-webkit-scrollbar {
        display: none;
    }

    .quick-chip {
        white-space: nowrap;
        flex-shrink: 0;
        font-size: 13px;
        padding: 6px 10px;
    }

    /* Fix Overlap on Mobile Landing */
    #mainContainer[data-state="landing"] {
        overflow-y: auto !important;
        display: block !important;
        height: 100vh;
    }

    #mainContainer[data-state="landing"] #featuresGrid {
        position: static !important;
        transform: none !important;
        margin-top: 40px !important;
        padding-bottom: 40px !important;
        left: auto !important;
    }

    /* Ensure bottom station doesn't overlap on landing */
    #mainContainer[data-state="landing"] #bottomStation {
        position: static !important;
        /* Let it flow */
        margin-top: 20px;
    }
}

/* Prevent scroll chaining */
.history-section,
#rightPanel,
#innerChatContainer {
    overscroll-behavior: contain;
}

/* --- Layout State: LANDING --- */
#mainContainer[data-state="landing"] #rightPanel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    overflow: hidden;
}

#mainContainer[data-state="landing"] #heroTitle {
    display: block;
    margin-bottom: 40px;
}

#mainContainer[data-state="landing"] #innerChatContainer {
    display: none;
}

#mainContainer[data-state="landing"] #featuresGrid {
    position: absolute;
    bottom: 0;
    width: 100%;
    max-width: 800px;
    padding-bottom: 20px;
}

#mainContainer[data-state="landing"] #bottomStation {
    position: static;
    /* Let flex centering handle it */
    width: 100%;
    max-width: 800px;
    margin-bottom: 160px;
    /* Space for features */
}

/* Landing State Quick Actions Config */
/* Kept centered with input */

/* --- Layout State: CHAT --- */
#mainContainer[data-state="chat"] #rightPanel {
    display: block;
    height: 100%;
    overflow-y: auto;
    /* Outer Page Scroll */
    padding-bottom: 220px;
    /* Space for fixed footer */
}

#mainContainer[data-state="chat"] #heroTitle {
    display: none;
}

#mainContainer[data-state="chat"] #innerChatContainer {
    display: block;
    height: 65vh;
    /* Dedicated height for chat messages */
    overflow-y: auto;
    /* Inner Message Scroll */
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 20px 0;
}

#mainContainer[data-state="chat"] #featuresGrid {
    display: grid;
    /* Pushed down by natural flow or spacer */
    margin-top: 100px;
    width: 100%;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

#mainContainer[data-state="chat"] #bottomStation {
    position: fixed;
    bottom: 0;
    left: 260px;
    /* Sidebar offset */
    right: 0;
    background: var(--bg);
    z-index: 999;
    padding: 20px 24px 20px;
    border-top: 1px solid rgba(0, 0, 0, 0.03);
}

#mainContainer[data-state="chat"] .quick-actions {
    margin-bottom: 0;
}

/* Common Styles */
.features-grid-custom {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

@media (max-width: 768px) {
    .features-grid-custom {
        grid-template-columns: repeat(2, 1fr);
    }

    #mainContainer[data-state="chat"] #bottomStation {
        left: 0;
    }

    /* Mobile Header */
    .mobile-header {
        display: flex !important;
        padding: 12px 16px;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 10px;
    }
}

/* Match quick chips height to icon buttons */
.quick-actions.inline .quick-chip {
    height: 34px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    font-size: 13px;
}