/* ============================================
   AIQYN Chat Interface Styles v2 — Modern
   ============================================ */

/* ── Layout ── */
.chat-app {
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    position: relative;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    height: 100dvh;
    background: var(--color-sidebar-bg);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--color-sidebar-border);
    transition: transform var(--transition-base), background-color var(--transition-base);
    z-index: 100;
}

.sidebar-header {
    padding: var(--space-lg) var(--space-lg);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.sidebar-logo {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}

.sidebar-logo img,
.sidebar-logo svg {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.sidebar-brand {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 3px;
    color: var(--color-sidebar-text);
}

/* ── New Chat Button ── */
.new-chat-btn {
    margin: var(--space-sm) var(--space-md) 0;
    padding: 11px var(--space-md);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    background: var(--color-primary);
    color: var(--color-primary-text);
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition-base);
    box-shadow: var(--shadow-sm);
}

.new-chat-btn:hover {
    background: var(--color-primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.new-chat-btn:active {
    transform: translateY(0) scale(0.98);
}

.new-chat-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

/* ── Chat List ── */
.chat-list-container {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-sm);
    margin-top: var(--space-sm);
}

.chat-list-label {
    padding: var(--space-sm) var(--space-sm);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--color-sidebar-text-muted);
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--color-sidebar-text);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition-fast);
    gap: var(--space-sm);
    position: relative;
}

.chat-item:hover {
    background: var(--color-sidebar-hover);
}

.chat-item.active {
    background: var(--color-sidebar-hover);
    font-weight: 500;
}

.chat-item-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.5;
}

.chat-item-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-item-delete {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    opacity: 0;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.chat-item:hover .chat-item-delete {
    opacity: 0.5;
}

.chat-item-delete:hover {
    opacity: 1 !important;
    background: rgba(192, 57, 43, 0.1);
    color: var(--color-error);
}

.chat-item-delete svg {
    width: 13px;
    height: 13px;
}

/* ── Sidebar Footer ── */
.sidebar-footer {
    padding: var(--space-md);
    border-top: 1px solid var(--color-sidebar-border);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-footer-btn {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--color-sidebar-text-muted);
    font-size: 13px;
    transition: all var(--transition-fast);
}

.sidebar-footer-btn:hover {
    background: var(--color-sidebar-hover);
    color: var(--color-sidebar-text);
}

.sidebar-footer-btn svg {
    width: 16px;
    height: 16px;
    opacity: 0.6;
}

/* ── Mobile Sidebar Toggle ── */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: var(--space-md);
    left: var(--space-md);
    z-index: 200;
    width: 40px;
    height: 40px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-base);
    -webkit-tap-highlight-color: transparent;
}

.sidebar-toggle svg {
    width: 18px;
    height: 18px;
    stroke: var(--color-text);
    fill: none;
    stroke-width: 2;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 90;
    opacity: 0;
    transition: opacity var(--transition-base);
}

.sidebar-overlay.visible {
    display: block;
    opacity: 1;
}

/* ── Main Content ── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
    background: var(--color-bg);
}

/* ── SPA Views ── */
.active-view {
    display: flex !important;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.hidden-view {
    display: none !important;
}

/* ── Chat Header ── */
.chat-header {
    display: none;
    /* Hidden on desktop */
    padding: var(--space-md) var(--space-lg);
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg);
    min-height: 52px;
}

.chat-header-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-muted);
    letter-spacing: 0.5px;
}

/* ── Messages Area ── */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg) 0;
    scroll-behavior: smooth;
    position: relative;
    -webkit-overflow-scrolling: touch;
}

.messages-container {
    max-width: 720px;
    margin: 0 auto;
    padding: 0 var(--space-lg);
}

/* ── Welcome Screen ── */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--space-2xl) var(--space-lg);
    animation: fadeIn 0.5s ease;
    min-height: 50vh;
}

.welcome-logo {
    width: 56px;
    height: 56px;
    margin-bottom: var(--space-lg);
    opacity: 0.5;
}

.welcome-logo img,
.welcome-logo svg {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.welcome-title {
    font-size: 26px;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: var(--space-sm);
    letter-spacing: 0.5px;
}

.welcome-subtitle {
    font-size: 15px;
    color: var(--color-text-muted);
    max-width: 440px;
    line-height: 1.6;
}

.welcome-suggestions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
    margin-top: var(--space-xl);
    width: 100%;
    max-width: 520px;
}

.suggestion-card {
    padding: var(--space-md);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    text-align: left;
    cursor: pointer;
    transition: all var(--transition-base);
    font-size: 13px;
    color: var(--color-text-secondary);
    line-height: 1.5;
}

.suggestion-card:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-border-strong);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.suggestion-card:active {
    transform: translateY(0) scale(0.98);
}

.suggestion-card .suggestion-icon {
    font-size: 18px;
    margin-bottom: 6px;
    display: block;
}

/* ── Message Bubbles ── */
.message {
    display: flex;
    gap: var(--space-md);
    padding: var(--space-sm) 0;
    animation: messageIn 0.3s ease;
}

.message+.message {
    padding-top: var(--space-md);
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-avatar {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 12px;
    font-weight: 600;
}

.message.user .message-avatar {
    background: var(--color-user-bubble);
    color: var(--color-user-bubble-text);
    border-radius: var(--radius-full);
}

.message.ai .message-avatar {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
}

.message.ai .message-avatar img,
.message.ai .message-avatar svg {
    width: 18px;
    height: 18px;
    object-fit: contain;
}

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

.message-author {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--color-text);
}

.message-text {
    font-size: 14px;
    line-height: 1.7;
    color: var(--color-text);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message-text p {
    margin-bottom: var(--space-sm);
}

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

.message-text code {
    background: var(--color-bg-secondary);
    padding: 2px 6px;
    border-radius: 5px;
    font-family: var(--font-mono);
    font-size: 13px;
}

.message-text pre {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: var(--space-md);
    overflow-x: auto;
    margin: var(--space-sm) 0;
}

.message-text pre code {
    background: none;
    padding: 0;
    font-size: 13px;
    line-height: 1.5;
}

.message-text ul,
.message-text ol {
    margin: var(--space-sm) 0;
    padding-left: var(--space-lg);
}

.message-text li {
    margin-bottom: 3px;
}

/* ── Markdown Elements ── */
.message-text h1,
.message-text h2,
.message-text h3,
.message-text h4,
.message-text h5,
.message-text h6 {
    margin: var(--space-md) 0 var(--space-sm);
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.3;
}

.message-text h1:first-child,
.message-text h2:first-child,
.message-text h3:first-child {
    margin-top: 0;
}

.message-text h1 {
    font-size: 1.4em;
}

.message-text h2 {
    font-size: 1.25em;
}

.message-text h3 {
    font-size: 1.1em;
}

.message-text h4 {
    font-size: 1.05em;
}

.message-text strong {
    font-weight: 600;
}

.message-text em {
    font-style: italic;
}

.message-text blockquote {
    border-left: 3px solid var(--color-primary);
    padding-left: var(--space-md);
    margin: var(--space-sm) 0;
    color: var(--color-text-secondary);
}

.message-text hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: var(--space-lg) 0;
}

.table-wrapper {
    width: 100%;
    overflow-x: auto;
    margin: var(--space-sm) 0;
    border-radius: var(--radius-sm);
}

.message-text table {
    width: 100%;
    border-collapse: collapse;
    min-width: 500px; /* Ensures table requires scroll on small screens */
}

.message-text th,
.message-text td {
    border: 1px solid var(--color-border);
    padding: 6px 10px;
    text-align: left;
}

.message-text th {
    background: var(--color-surface);
}

/* ── Typing Indicator ── */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 0;
}

.typing-dot {
    width: 7px;
    height: 7px;
    background: var(--color-primary);
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}

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

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

@keyframes typingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.3;
    }

    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* ── Input Area ── */
.input-area {
    padding: var(--space-sm) var(--space-lg) var(--space-md);
    background: var(--color-bg);
}

.input-wrapper {
    max-width: 720px;
    margin: 0 auto;
    position: relative;
}

.input-container {
    display: flex;
    align-items: flex-end;
    background: var(--color-input-bg);
    border: 1.5px solid var(--color-input-border);
    border-radius: var(--radius-lg);
    padding: 6px 6px 6px 4px;
    transition: all var(--transition-base);
    box-shadow: var(--shadow-input);
}

.input-container:focus-within {
    border-color: var(--color-input-focus-border);
    box-shadow: 0 0 0 3px var(--color-accent-soft), var(--shadow-md);
}

#message-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 12px;
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    outline: none;
    min-height: 24px;
    max-height: 120px;
    color: var(--color-text);
    font-family: var(--font-primary);
}

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

.send-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-primary);
    color: var(--color-primary-text);
    border-radius: var(--radius-md);
    transition: all var(--transition-base);
    flex-shrink: 0;
}

.send-btn:hover {
    background: var(--color-primary-hover);
    transform: scale(1.05);
}

.send-btn:active {
    transform: scale(0.93);
}

.send-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none;
}

.send-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.input-footer {
    text-align: center;
    margin-top: 6px;
    font-size: 11px;
    color: var(--color-text-muted);
}

/* ── Background Ornaments for Chat ── */
.chat-bg-ornaments {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.chat-orn {
    position: absolute;
    opacity: 0.03;
    /* Very subtle in the background */
    pointer-events: none;
    animation: chatFloatAnim 20s ease-in-out infinite alternate;
}

.character-1 {
    width: 180px;
    height: 180px;
    top: 5%;
    right: -4%;
    animation-delay: 0s;
}

.character-2 {
    width: 130px;
    height: 130px;
    bottom: 10%;
    left: -2%;
    animation-delay: 2s;
}

.character-3 {
    width: 90px;
    height: 90px;
    top: 40%;
    left: 15%;
    animation-delay: 4s;
}

.character-4 {
    width: 220px;
    height: 220px;
    bottom: -5%;
    right: 15%;
    animation-delay: 1s;
    opacity: 0.02;
}

.character-5 {
    width: 110px;
    height: 110px;
    top: 20%;
    left: 45%;
    animation-delay: 5s;
}

.character-6 {
    width: 70px;
    height: 70px;
    top: 60%;
    right: 5%;
    animation-delay: 3s;
}

.character-7 {
    width: 150px;
    height: 150px;
    bottom: 30%;
    left: 35%;
    animation-delay: 6s;
    opacity: 0.02;
}

@keyframes chatFloatAnim {
    0% {
        transform: translateY(0) rotate(0deg);
    }

    50% {
        transform: translateY(-15px) rotate(10deg);
    }

    100% {
        transform: translateY(10px) rotate(-5deg);
    }
}

/* ── Mobile Responsive ── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        box-shadow: var(--shadow-xl);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: flex;
    }

    .chat-header {
        display: flex;
        padding-left: 56px;
    }

    .welcome-suggestions {
        grid-template-columns: 1fr;
    }

    .welcome-title {
        font-size: 22px;
    }

    .welcome-subtitle {
        font-size: 14px;
    }

    .messages-container {
        padding: 0 var(--space-md);
    }

    .input-area {
        padding: var(--space-sm) var(--space-md) var(--space-sm);
    }

    .input-container {
        border-radius: var(--radius-md);
    }

    #message-input {
        font-size: 16px;
        padding: 8px 10px;
    }

    .message {
        gap: var(--space-sm);
    }

    .message-avatar {
        width: 28px;
        height: 28px;
    }

    .message-text {
        font-size: 14px;
    }

    .suggestion-card {
        padding: 12px;
    }
}

@media (max-width: 380px) {
    .welcome-title {
        font-size: 20px;
    }

    .input-area {
        padding: var(--space-xs) var(--space-sm) var(--space-sm);
    }
}

/* ── Safe area for notched phones ── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .input-area {
        padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom));
    }

    .sidebar-footer {
        padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom));
    }
}