/* ============================================
   OBSIDIAN DARK — Jeski Chat
   Single-container sidebar, mini-to-full
   ============================================ */

:root {
    --bg-primary: #0d0d0d;
    --bg-sidebar: #111111;
    --bg-surface: #1a1a1a;
    --bg-surface-2: #222222;
    --bg-hover: #252525;
    --bg-input: #1c1c1c;

    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-medium: rgba(255, 255, 255, 0.10);

    --text-primary: #ececec;
    --text-secondary: #999999;
    --text-muted: #555555;
    --text-input: #d4d4d4;
    --accent-bright: #a0a0a0;

    --user-bubble-bg: #2a2a2a;
    --user-bubble-border: rgba(255, 255, 255, 0.08);

    /* Sidebar */
    --sb-expanded: 240px;
    --sb-collapsed: 52px;

    --header-height: 52px;
    --input-max-width: 720px;
    --message-max-width: 720px;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

/* ═══════════════════════════════════════════
   LAYOUT
   ═══════════════════════════════════════════ */
.app-layout {
    display: flex;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
}

/* ═══════════════════════════════════════════
   MOBILE HAMBURGER — hidden on desktop
   ═══════════════════════════════════════════ */
.mobile-hamburger {
    display: none;
    /* shown only via media query */
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 1100;
    background: var(--bg-surface);
    border: 1px solid var(--border-medium);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    width: 38px;
    height: 38px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 150ms ease;
}

.mobile-hamburger:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ═══════════════════════════════════════════
   SIDEBAR BACKDROP — mobile overlay
   ═══════════════════════════════════════════ */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 999;
}

.sidebar-backdrop.visible {
    display: block;
}

/* ═══════════════════════════════════════════
   SIDEBAR  — single seamless container
   ═══════════════════════════════════════════ */
.sidebar {
    width: var(--sb-expanded);
    min-width: var(--sb-collapsed);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
    z-index: 1000;
    transition: width 280ms var(--ease);
}

.sidebar.collapsed {
    width: var(--sb-collapsed);
}

/* ---- Label text: hidden when collapsed via overflow ---- */
.sb-label {
    white-space: nowrap;
    overflow: hidden;
    opacity: 1;
    transition: opacity 200ms var(--ease);
}

.sidebar.collapsed .sb-label {
    opacity: 0;
    pointer-events: none;
}

/* ---- Top buttons (toggle + new-chat) ---- */
.sb-top {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 0 6px;
    flex-shrink: 0;
}

.sb-icon-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 150ms ease;
    flex-shrink: 0;
}

.sb-icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ---- New Chat (wide button, hides in collapsed) ---- */
.sb-new-chat-section {
    padding: 4px 8px 8px;
    flex-shrink: 0;
    overflow: hidden;
    transition: opacity 200ms var(--ease);
}

.sidebar.collapsed .sb-new-chat-section {
    opacity: 0;
    height: 0;
    padding: 0;
    pointer-events: none;
}

.sb-new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13.5px;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all 150ms ease;
}

.sb-new-chat-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-medium);
}

/* ---- Nav / History ---- */
.sb-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 8px;
}

.sb-section-title {
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 4px 6px 6px;
}

.sb-history {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sb-history-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 13px;
    overflow: hidden;
    transition: background 150ms ease, color 150ms ease;
}

.sb-history-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sb-history-item.active {
    background: var(--bg-surface-2);
    color: var(--text-primary);
}

.sb-history-item svg {
    flex-shrink: 0;
    opacity: 0.45;
}

.sb-history-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- Footer ---- */
.sb-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
    font-size: 12px;
    color: var(--text-muted);
    overflow: hidden;
}

.sb-footer-dot {
    width: 7px;
    height: 7px;
    min-width: 7px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 6px rgba(74, 222, 128, 0.5);
    animation: pulse-dot 2.5s infinite;
}

@keyframes pulse-dot {

    0%,
    100% {
        opacity: 1
    }

    50% {
        opacity: .45
    }
}

/* ═══════════════════════════════════════════
   CHAT MAIN
   ═══════════════════════════════════════════ */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-primary);
    min-width: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    height: var(--header-height);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.header-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
}

.status-dot.online {
    background: #4ade80;
}

.status-dot.busy {
    background: #facc15;
    animation: blink 1s infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1
    }

    50% {
        opacity: .4
    }
}

/* ═══════════════════════════════════════════
   MESSAGES
   ═══════════════════════════════════════════ */
.messages-container {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.messages-container::-webkit-scrollbar {
    width: 5px;
}

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--bg-surface-2);
    border-radius: 10px;
}

/* Welcome */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 40px 16px;
    text-align: center;
    animation: fade-in 0.5s ease;
}

.welcome-logo {
    font-size: 48px;
    margin-bottom: 20px;
}

.welcome-title {
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.03em;
    margin-bottom: 8px;
}

.welcome-subtitle {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 32px;
}

.suggestion-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    max-width: 600px;
    width: 100%;
}

.suggestion-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    cursor: pointer;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 13.5px;
    font-family: var(--font-sans);
    line-height: 1.5;
    transition: all 150ms ease;
}

.suggestion-card:hover {
    background: var(--bg-surface-2);
    border-color: var(--border-medium);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.suggestion-icon {
    font-size: 18px;
}

/* Messages */
.messages-list {
    display: flex;
    flex-direction: column;
    padding: 24px 0;
    width: 100%;
}

.message-row {
    display: flex;
    padding: 6px 20px;
    width: 100%;
    animation: slide-in 0.2s ease;
    justify-content: center;
}

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

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

.message-inner {
    display: flex;
    gap: 14px;
    max-width: var(--message-max-width);
    width: 100%;
    align-items: flex-start;
}

.message-row.user .message-inner {
    flex-direction: row-reverse;
}

.message-row.user .message-bubble {
    background: var(--user-bubble-bg);
    border: 1px solid var(--user-bubble-border);
    border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
    max-width: 80%;
}

.message-row.assistant .message-bubble {
    background: transparent;
    border: none;
    max-width: 100%;
    line-height: 1.75;
    padding: 2px 0;
}

.avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
    margin-top: 2px;
}

.avatar.user-avatar {
    background: var(--bg-surface-2);
    border: 1px solid var(--border-medium);
    color: var(--text-secondary);
    font-weight: 600;
}

.avatar.ai-avatar {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
}

.message-bubble {
    padding: 10px 16px;
    color: var(--text-primary);
    font-size: 15px;
    overflow-wrap: break-word;
    word-break: break-word;
}

/* Markdown */
.message-bubble p {
    margin: 0 0 0.75em;
}

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

.message-bubble strong {
    color: var(--text-primary);
}

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

.message-bubble ul,
.message-bubble ol {
    padding-left: 1.5em;
    margin: 0.5em 0;
}

.message-bubble li {
    margin-bottom: 0.3em;
}

.message-bubble h1,
.message-bubble h2,
.message-bubble h3 {
    font-weight: 600;
    margin: .8em 0 .4em;
    letter-spacing: -.02em;
}

.message-bubble h1 {
    font-size: 1.25em;
}

.message-bubble h2 {
    font-size: 1.1em;
}

.message-bubble h3 {
    font-size: 1em;
}

.message-bubble code {
    font-family: var(--font-mono);
    background: var(--bg-surface-2);
    padding: .15em .4em;
    border-radius: 4px;
    font-size: .88em;
    color: #e2e2e2;
}

.message-bubble pre {
    background: #161616;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    margin: .75em 0;
    overflow-x: auto;
}

.message-bubble pre code {
    background: transparent;
    padding: 14px 16px;
    display: block;
    font-size: 13px;
    border-radius: 0;
    color: inherit;
    white-space: pre;
    overflow-wrap: normal;
    word-break: normal;
}

.message-bubble blockquote {
    border-left: 3px solid var(--border-medium);
    padding-left: 12px;
    margin: .5em 0;
    color: var(--text-secondary);
}

.message-bubble table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
    margin: .75em 0;
}

.message-bubble th,
.message-bubble td {
    border: 1px solid var(--border-subtle);
    padding: 8px 12px;
    text-align: left;
}

.message-bubble th {
    background: var(--bg-surface);
    font-weight: 500;
}

.message-bubble a {
    color: var(--accent-bright);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.message-bubble a:hover {
    opacity: .8;
}

.message-bubble hr {
    border: none;
    border-top: 1px solid var(--border-subtle);
    margin: 1em 0;
}

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

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

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

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

@keyframes typing-bounce {

    0%,
    80%,
    100% {
        transform: scale(.7);
        opacity: .4
    }

    40% {
        transform: scale(1);
        opacity: 1
    }
}

@keyframes cursor-blink {

    0%,
    100% {
        opacity: 1
    }

    50% {
        opacity: 0
    }
}

.streaming-cursor::after {
    content: '\25CB';
    font-size: .85em;
    animation: cursor-blink .7s step-end infinite;
    color: var(--text-muted);
    margin-left: 2px;
}

/* ═══════════════════════════════════════════
   INPUT AREA
   ═══════════════════════════════════════════ */
.input-area {
    padding: 14px 20px 18px;
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-xl);
    padding: 12px 10px 12px 18px;
    width: 100%;
    max-width: var(--input-max-width);
    transition: border-color 150ms ease, box-shadow 150ms ease;
    position: relative;
}

.input-wrapper:focus-within {
    border-color: rgba(255, 255, 255, 0.18);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    color: var(--text-input);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.6;
    max-height: 200px;
    overflow-y: auto;
    padding: 0;
}

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

.chat-input::-webkit-scrollbar {
    width: 4px;
}

.chat-input::-webkit-scrollbar-thumb {
    background: var(--bg-surface-2);
    border-radius: 4px;
}

/* Model picker */
.model-picker-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    background: var(--bg-surface-2);
    border: 1px solid var(--border-medium);
    border-radius: 20px;
    padding: 6px 10px;
    color: var(--text-secondary);
    font-size: 12px;
    font-family: var(--font-sans);
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 150ms ease;
}

.model-picker-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.15);
}

.model-picker-btn.active-llama {
    color: #fb923c;
    border-color: rgba(249, 115, 22, 0.35);
}

.model-picker-btn.active-qwen {
    color: #60a5fa;
    border-color: rgba(59, 130, 246, 0.35);
}

/* Send */
.send-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    border-radius: 50%;
    background: var(--text-primary);
    border: none;
    color: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 200ms ease;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background: #d4d4d4;
    transform: scale(1.05);
}

.send-btn:disabled {
    background: var(--bg-surface-2);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* Stop mode */
.send-btn.is-stop {
    background: #ef4444;
    color: #fff;
    cursor: pointer;
    animation: stop-pulse 1.8s ease-in-out infinite;
}

.send-btn.is-stop:hover {
    background: #dc2626;
    transform: scale(1.08);
}

@keyframes stop-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45); }
    50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

/* Model popup */
.model-popup {
    position: absolute;
    bottom: calc(100% + 8px);
    right: 0;
    width: 210px;
    background: #1e1e1e;
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
    overflow: hidden;
    display: none;
    z-index: 200;
    animation: popup-in 0.15s ease;
}

.model-popup.visible {
    display: block;
}

@keyframes popup-in {
    from {
        opacity: 0;
        transform: translateY(6px)
    }

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

.model-option {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: var(--font-sans);
    text-align: left;
    transition: background 150ms ease;
    border-bottom: 1px solid var(--border-subtle);
}

.model-option:last-child {
    border-bottom: none;
}

.model-option:hover {
    background: var(--bg-hover);
}

.model-option.active {
    background: var(--bg-surface-2);
}

.model-option-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.model-option-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.model-option-desc {
    font-size: 11.5px;
    color: var(--text-muted);
}

#opt-llama.active .model-option-name {
    color: #fb923c;
}

#opt-qwen.active .model-option-name {
    color: #60a5fa;
}

.model-option-check {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.model-option-check.hidden {
    visibility: hidden;
}

.input-disclaimer {
    font-size: 11.5px;
    color: var(--text-muted);
    text-align: center;
}

/* ═══════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════ */
@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(10px)
    }

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

/* ═══════════════════════════════════════════
   RESPONSIVE — MOBILE  (≤ 768px)
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {

    /* Show mobile hamburger */
    .mobile-hamburger {
        display: flex;
    }

    /* Sidebar: fixed overlay, hidden by default */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        height: 100dvh;
        z-index: 1000;
        width: 0;
        min-width: 0;
        border-right: none;
        transition: width 280ms var(--ease);
    }

    /* Collapsed on mobile = fully hidden */
    .sidebar.collapsed {
        width: 0;
        min-width: 0;
    }

    /* Expanded on mobile = slide out */
    .sidebar.expanded {
        width: 280px;
        min-width: 280px;
        border-right: 1px solid var(--border-subtle);
    }

    .sidebar.collapsed .sb-top,
    .sidebar.collapsed .sb-new-chat-section,
    .sidebar.collapsed .sb-nav,
    .sidebar.collapsed .sb-footer {
        display: none;
    }

    /* Hide the desktop toggle inside sidebar on mobile (we use the fixed hamburger) */
    #sidebar-toggle {
        display: none;
    }

    /* Compact chat header on mobile */
    .chat-header {
        padding: 0 14px 0 52px;
        /* leave space for hamburger */
    }

    .suggestion-grid {
        grid-template-columns: 1fr;
    }

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

    .welcome-logo {
        font-size: 36px;
    }

    .message-row {
        padding: 6px 12px;
    }

    .message-row.user .message-bubble {
        max-width: 90%;
    }

    .message-inner {
        gap: 10px;
    }

    .avatar {
        width: 26px;
        height: 26px;
        font-size: 11px;
    }

    .input-area {
        padding: 10px 12px 14px;
    }

    .input-wrapper {
        padding: 10px 8px 10px 14px;
    }

    .model-popup {
        width: 200px;
    }
}

@media (max-width: 400px) {
    .suggestion-grid {
        gap: 8px;
    }

    .suggestion-card {
        padding: 10px 12px;
        font-size: 12.5px;
    }

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