/* ══════════════════════════════════════════════════════════════
   Nyx — Sleek Dark Theme
   ══════════════════════════════════════════════════════════════ */

:root {
    --bg-0: #050509;
    --bg-1: #0b0b13;
    --bg-2: #111119;
    --bg-3: #181824;
    --bg-4: #1f1f30;
    --surface: rgba(255, 255, 255, 0.025);
    --hover: rgba(255, 255, 255, 0.045);
    --border: rgba(255, 255, 255, 0.06);
    --border-s: rgba(255, 255, 255, 0.10);

    --t1: #eaeaf2;
    --t2: #8e8ea8;
    --t3: #55556e;

    --accent: #8b5cf6;
    --accent-h: #a78bfa;
    --accent-d: rgba(139, 92, 246, 0.10);
    --accent-g: rgba(139, 92, 246, 0.18);
    --grad: linear-gradient(135deg, #8b5cf6, #6366f1, #38bdf8);

    --green: #34d399;
    --amber: #fbbf24;
    --red: #ef4444;
    --blue: #38bdf8;

    --sb-w: 260px;
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 16px;
    --r-xl: 22px;
    --r-full: 9999px;

    --ease: cubic-bezier(.4, 0, .2, 1);
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-0);
    color: var(--t1);
    overflow: hidden;
    height: 100vh;
}

/* ── App ────────────────────────────────────────────────── */
.app {
    display: flex;
    height: 100vh;
    width: 100vw;
    position: relative
}

/* ══════════════════════════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════════════════════════ */
.sidebar {
    width: var(--sb-w);
    min-width: var(--sb-w);
    height: 100vh;
    background: var(--bg-1);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform .3s var(--ease), opacity .25s var(--ease);
    z-index: 100;
    overflow: hidden;
}

.sidebar.collapsed {
    transform: translateX(-100%);
    position: absolute;
    opacity: 0;
    pointer-events: none
}

.sidebar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 16px 14px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 9px
}

.logo-glyph {
    width: 32px;
    height: 32px;
    border-radius: var(--r-md);
    background: var(--grad);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: .9rem;
    font-weight: 800;
    box-shadow: 0 0 18px var(--accent-g);
}

.logo-text {
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: .02em;
    background: var(--grad);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.icon-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--t2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .15s;
    flex-shrink: 0;
}

.icon-btn:hover {
    background: var(--hover);
    color: var(--t1)
}

/* New Chat */
.new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    margin: 2px 14px 10px;
    padding: 9px;
    border: 1px solid var(--border-s);
    border-radius: var(--r-md);
    background: transparent;
    color: var(--t2);
    font-family: inherit;
    font-size: .82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all .2s var(--ease);
}

.new-chat-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-d)
}

/* Usage */
.usage-section {
    padding: 0 14px 8px
}

.usage-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 5px
}

.usage-dot {
    font-size: .55rem;
    color: var(--green)
}

.usage-text {
    font-size: .68rem;
    color: var(--t3);
    font-family: 'JetBrains Mono', monospace
}

.usage-track {
    height: 3px;
    border-radius: 2px;
    background: var(--bg-4);
    overflow: hidden
}

.usage-fill {
    height: 100%;
    border-radius: 2px;
    background: var(--green);
    width: 0;
    transition: width .5s var(--ease), background .3s
}

.usage-fill.warn {
    background: var(--amber)
}

.usage-fill.crit {
    background: var(--red)
}

/* History */
.history-section {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--border);
    margin-top: 4px
}

.history-head {
    font-size: .62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--t3);
    padding: 12px 16px 6px
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 8px
}

.hist-empty {
    padding: 10px 16px;
    font-size: .76rem;
    color: var(--t3)
}

.hist-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: .78rem;
    color: var(--t2);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
    transition: background .12s, color .12s;
}

.hist-item:hover {
    background: var(--hover);
    color: var(--t1)
}

.hist-item.active {
    background: var(--accent-d);
    color: var(--accent)
}

.hist-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis
}

.hist-del {
    opacity: 0;
    background: none;
    border: none;
    color: var(--t3);
    cursor: pointer;
    padding: 2px;
    display: flex;
    transition: opacity .12s, color .12s;
}

.hist-item:hover .hist-del {
    opacity: 1
}

.hist-del:hover {
    color: var(--red)
}

/* Sidebar Bottom */
.sidebar-bottom {
    display: flex;
    gap: 2px;
    padding: 8px 10px;
    border-top: 1px solid var(--border)
}

.sb-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 7px 4px;
    border: none;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--t3);
    font-family: inherit;
    font-size: .62rem;
    cursor: pointer;
    transition: all .12s;
}

.sb-btn:hover {
    background: var(--hover);
    color: var(--t1)
}

/* ══════════════════════════════════════════════════════════
   MAIN
   ══════════════════════════════════════════════════════════ */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-0);
    position: relative
}

.topbar {
    height: 46px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    border-bottom: 1px solid var(--border);
    background: rgba(5, 5, 9, .8);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    flex-shrink: 0;
}

.topbar-label {
    font-size: .82rem;
    font-weight: 600;
    color: var(--t2)
}

/* ══════════════════════════════════════════════════════════
   MESSAGES
   ══════════════════════════════════════════════════════════ */
.msgs-wrap {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth
}

.msgs {
    max-width: 740px;
    margin: 0 auto;
    padding: 28px 20px 120px
}

/* Welcome */
.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 70px 20px 40px;
    animation: fadeUp .7s var(--ease);
}

.w-glyph {
    font-size: 3rem;
    margin-bottom: 14px;
    background: var(--grad);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 24px var(--accent-g));
    animation: float 5s ease-in-out infinite;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0)
    }

    50% {
        transform: translateY(-6px)
    }
}

.w-title {
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: -.03em;
    background: var(--grad);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 6px;
}

.w-sub {
    color: var(--t3);
    font-size: .92rem;
    margin-bottom: 36px;
    line-height: 1.5
}

.w-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    max-width: 500px
}

.w-chip {
    padding: 9px 15px;
    border: 1px solid var(--border-s);
    border-radius: var(--r-lg);
    background: var(--surface);
    color: var(--t2);
    font-family: inherit;
    font-size: .8rem;
    cursor: pointer;
    transition: all .2s var(--ease);
}

.w-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-d);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, .3)
}

/* ── Message ────────────────────────────────────────────── */
.message {
    display: flex;
    gap: 10px;
    margin-bottom: 22px;
    animation: fadeUp .25s var(--ease)
}

.message.user {
    justify-content: flex-end
}

.message.assistant {
    justify-content: flex-start
}

.msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: var(--r-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .75rem;
    flex-shrink: 0;
    font-weight: 700;
}

.message.user .msg-avatar {
    background: var(--grad);
    color: #fff;
    order: 2
}

.message.assistant .msg-avatar {
    background: var(--bg-3);
    color: var(--accent);
    border: 1px solid var(--border)
}

.msg-body {
    max-width: 72%;
    min-width: 50px
}

.msg-content {
    padding: 10px 14px;
    border-radius: var(--r-lg);
    font-size: .88rem;
    line-height: 1.7;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message.user .msg-content {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px
}

.message.assistant .msg-content {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px
}

.msg-badge {
    display: inline-block;
    font-size: .6rem;
    color: var(--t3);
    margin-top: 3px;
    padding: 1px 7px;
    border: 1px solid var(--border);
    border-radius: var(--r-full);
}

.message-image {
    max-width: 300px;
    max-height: 220px;
    border-radius: var(--r-md);
    margin-top: 6px;
    cursor: pointer;
    object-fit: contain;
    transition: transform .2s
}

.message-image:hover {
    transform: scale(1.03)
}

.message-actions {
    display: flex;
    gap: 3px;
    margin-top: 5px;
    opacity: 0;
    transition: opacity .12s
}

.message:hover .message-actions {
    opacity: 1
}

.msg-action-btn {
    padding: 2px 7px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--t3);
    font-family: inherit;
    font-size: .68rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 3px;
    transition: all .12s;
}

.msg-action-btn:hover {
    background: var(--hover);
    color: var(--t1)
}

/* Collapsed */
.collapsed-response {
    margin-bottom: 6px
}

.collapsed-toggle {
    font-size: .72rem;
    color: var(--t3);
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 2px 8px;
    cursor: pointer;
    font-family: inherit;
    transition: all .12s
}

.collapsed-toggle:hover {
    border-color: var(--accent);
    color: var(--accent)
}

.collapsed-content {
    display: none;
    padding: 6px 10px;
    margin-top: 4px;
    border-left: 2px solid var(--border);
    font-size: .8rem;
    color: var(--t2)
}

.collapsed-content.show {
    display: block
}

/* Typing */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 0
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    animation: bounce 1.4s infinite ease-in-out
}

.typing-dot:nth-child(2) {
    animation-delay: .2s
}

.typing-dot:nth-child(3) {
    animation-delay: .4s
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(.5);
        opacity: .35
    }

    40% {
        transform: scale(1);
        opacity: 1
    }
}

/* ── Markdown ───────────────────────────────────────────── */
.msg-content h1,
.msg-content h2,
.msg-content h3,
.msg-content h4 {
    margin: 14px 0 6px;
    font-weight: 600;
    line-height: 1.3
}

.msg-content h1 {
    font-size: 1.2rem
}

.msg-content h2 {
    font-size: 1.06rem
}

.msg-content h3 {
    font-size: .96rem
}

.msg-content p {
    margin: 6px 0
}

.msg-content ul,
.msg-content ol {
    margin: 6px 0;
    padding-left: 18px
}

.msg-content li {
    margin: 2px 0
}

.msg-content blockquote {
    border-left: 3px solid var(--accent);
    padding: 3px 10px;
    margin: 6px 0;
    color: var(--t2);
    background: var(--surface);
    border-radius: 0 6px 6px 0
}

.msg-content a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px
}

.msg-content a:hover {
    color: var(--accent-h)
}

.msg-content table {
    border-collapse: collapse;
    margin: 10px 0;
    width: 100%;
    font-size: .82rem
}

.msg-content th,
.msg-content td {
    border: 1px solid var(--border-s);
    padding: 6px 10px;
    text-align: left
}

.msg-content th {
    background: var(--bg-4);
    font-weight: 600
}

.msg-content details {
    margin: 6px 0
}

.msg-content summary {
    cursor: pointer;
    color: var(--accent);
    font-weight: 500
}

/* Code */
.code-block-wrapper {
    position: relative;
    margin: 10px 0;
    border-radius: var(--r-md);
    overflow: hidden;
    border: 1px solid var(--border)
}

.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 10px;
    background: var(--bg-4);
    font-size: .66rem;
    color: var(--t3);
    font-family: 'JetBrains Mono', monospace
}

.code-copy-btn {
    padding: 2px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--t3);
    font-family: inherit;
    font-size: .62rem;
    cursor: pointer;
    transition: all .12s
}

.code-copy-btn:hover {
    border-color: var(--accent);
    color: var(--accent)
}

.code-copy-btn.copied {
    border-color: var(--green);
    color: var(--green)
}

.code-block-wrapper pre {
    margin: 0;
    padding: 12px 14px;
    overflow-x: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: .8rem;
    line-height: 1.55;
    background: var(--bg-1) !important
}

.code-block-wrapper code {
    font-family: 'JetBrains Mono', monospace;
    background: transparent !important
}

.msg-content code:not(pre code) {
    background: var(--bg-4);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: .8em;
    border: 1px solid var(--border)
}

.message.user .msg-content code:not(pre code) {
    background: rgba(255, 255, 255, .14);
    border-color: rgba(255, 255, 255, .18)
}

/* ══════════════════════════════════════════════════════════
   INPUT AREA 
   ══════════════════════════════════════════════════════════ */
.input-area {
    padding: 0 20px 14px;
    max-width: 780px;
    margin: 0 auto;
    width: 100%
}

.input-box {
    display: flex;
    background: var(--bg-2);
    border: 1px solid var(--border-s);
    border-radius: var(--r-xl);
    padding: 8px 8px 8px 14px;
    align-items: flex-end;
    gap: 8px;
    transition: border-color .2s, box-shadow .2s;
}

.input-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-d), 0 4px 20px rgba(0, 0, 0, .4)
}

.chat-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    color: var(--t1);
    font-family: inherit;
    font-size: .88rem;
    line-height: 1.5;
    resize: none;
    max-height: 180px;
    min-height: 22px;
    padding: 4px 0;
}

.chat-input::placeholder {
    color: var(--t3)
}

/* Inside the input on the right */
.input-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 1px
}

.char-count {
    font-size: .62rem;
    color: var(--t3);
    font-family: 'JetBrains Mono', monospace
}

/* Model Dropdown Menu */
.model-dropdown-wrap {
    position: relative
}

.model-select-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    border: none;
    border-radius: var(--r-lg);
    background: var(--bg-3);
    color: var(--t2);
    font-family: inherit;
    font-size: .75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s var(--ease);
}

.model-select-btn:hover {
    color: var(--t1);
    background: var(--hover)
}

.model-menu {
    display: none;
    position: absolute;
    bottom: calc(100% + 8px);
    right: 0;
    background: var(--bg-3);
    border: 1px solid var(--border-s);
    border-radius: var(--r-md);
    padding: 4px;
    z-index: 200;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
    min-width: 110px;
    animation: fadeUp .15s var(--ease);
}

.model-menu.show {
    display: flex;
    flex-direction: column;
    gap: 2px
}

.menu-opt {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border: none;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--t2);
    font-family: inherit;
    font-size: .75rem;
    cursor: pointer;
    text-align: left;
    transition: all .12s;
    white-space: nowrap;
}

.menu-opt:hover {
    background: var(--hover);
    color: var(--t1)
}

.menu-opt.active {
    background: var(--accent-d);
    color: var(--accent)
}

/* Status Dots */
.m-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    transition: background .3s
}

.pro-dot {
    background: var(--accent)
}

.think-dot {
    background: var(--blue)
}

.fast-dot {
    background: var(--green)
}

.send-btn,
.stop-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--r-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all .15s;
    flex-shrink: 0;
}

.send-btn {
    background: var(--accent);
    color: #fff
}

.send-btn:hover {
    background: var(--accent-h);
    box-shadow: 0 0 12px var(--accent-g)
}

.stop-btn {
    background: var(--red);
    color: #fff
}

.stop-btn:hover {
    background: #dc2626
}

.input-disclaimer {
    text-align: center;
    font-size: .62rem;
    color: var(--t3);
    margin-top: 6px
}

/* ══════════════════════════════════════════════════════════
   MODALS
   ══════════════════════════════════════════════════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .65);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn .15s
}

.modal-img-wrap {
    position: relative;
    max-width: 90vw;
    max-height: 90vh
}

.modal-img-wrap img {
    max-width: 90vw;
    max-height: 85vh;
    border-radius: var(--r-md);
    box-shadow: 0 8px 40px rgba(0, 0, 0, .6)
}

.modal-x {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bg-4);
    border: 1px solid var(--border);
    color: var(--t1);
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer
}

.modal-card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 22px;
    min-width: 260px;
    text-align: center;
    box-shadow: 0 8px 36px rgba(0, 0, 0, .5)
}

.modal-card h3 {
    font-size: 1rem;
    margin-bottom: 16px;
    font-weight: 600
}

.export-btn {
    display: block;
    width: 100%;
    padding: 10px;
    margin-bottom: 6px;
    border: 1px solid var(--border-s);
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--t1);
    font-family: inherit;
    font-size: .85rem;
    cursor: pointer;
    transition: all .12s
}

.export-btn:hover {
    border-color: var(--accent);
    background: var(--accent-d)
}

.modal-cancel {
    padding: 7px 18px;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--t3);
    font-family: inherit;
    font-size: .82rem;
    cursor: pointer;
    margin-top: 6px
}

.modal-cancel:hover {
    color: var(--t1)
}

/* Drop */
.drop-zone {
    position: fixed;
    inset: 0;
    background: rgba(139, 92, 246, .05);
    backdrop-filter: blur(4px);
    z-index: 999;
    display: none;
    align-items: center;
    justify-content: center;
    pointer-events: none
}

.drop-zone.show {
    display: flex
}

.drop-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 36px 54px;
    border: 2px dashed var(--accent);
    border-radius: var(--r-xl);
    background: rgba(5, 5, 9, .85);
    color: var(--accent);
    font-size: 1rem;
    font-weight: 600
}

/* Toast */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    padding: 9px 18px;
    border-radius: var(--r-md);
    font-size: .82rem;
    font-weight: 500;
    z-index: 2000;
    transition: transform .3s var(--ease);
    box-shadow: 0 4px 20px rgba(0, 0, 0, .5)
}

.toast.show {
    transform: translateX(-50%) translateY(0)
}

.toast.error {
    background: var(--red);
    color: #fff
}

.toast.success {
    background: var(--green);
    color: #000
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 4px
}

::-webkit-scrollbar-track {
    background: transparent
}

::-webkit-scrollbar-thumb {
    background: var(--border-s);
    border-radius: 2px
}

::-webkit-scrollbar-thumb:hover {
    background: var(--t3)
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0
    }

    to {
        opacity: 1
    }
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(8px)
    }

    to {
        opacity: 1;
        transform: translateY(0)
    }
}

/* ══════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════ */
@media(max-width:768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        box-shadow: 0 0 40px rgba(0, 0, 0, .6)
    }

    .sidebar.collapsed {
        transform: translateX(-100%)
    }

    .msg-body {
        max-width: 86%
    }

    .msgs {
        padding: 16px 12px 100px
    }

    .input-area {
        padding: 0 10px 10px
    }

    .w-title {
        font-size: 2.2rem
    }
}

@media(max-width:480px) {
    .msg-body {
        max-width: 92%
    }
}