:root {
    --bg-primary: #000000;
    --bg-secondary: #080a0f;
    --bg-tertiary: #0d1020;
    --bg-elevated: #111526;
    --bg-hover: #151928;
    --bg-input: #0a0d18;
    --text-primary: #f5f5f7;
    --text-secondary: #a0a0ab;
    --text-muted: #6e6e73;
    --text-dim: #3a3a3f;
    --blue: #1468F0;
    --blue-b: #3d8bff;
    --blue-s: #85b7eb;
    --accent-dim: rgba(20, 104, 240, 0.1);
    --accent-border: rgba(20, 104, 240, 0.28);
    --border: rgba(255, 255, 255, 0.05);
    --border-light: rgba(255, 255, 255, 0.08);
    --border-medium: rgba(255, 255, 255, 0.12);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.7);
    --shadow-glow: 0 0 24px rgba(20, 104, 240, 0.22);
    --code-bg: #0d1020;
    --font-d: 'Playfair Display', Georgia, serif;
    --font-b: 'Epilogue', 'Helvetica Neue', sans-serif;
    --font-m: 'JetBrains Mono', monospace;
    --ease: cubic-bezier(0.16, 1, 0.3, 1);
    --sidebar-width: 236px;
    --r-xs: 6px;
    --r-sm: 10px;
    --r-md: 14px;
    --r-lg: 18px;
    --r-xl: 24px;
    --r-full: 9999px;
    --green: #22c55e;
    --warn: #f59e0b;
    --danger: #f87171
}

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

html,
body {
    height: 100%;
    height: 100dvh;
    font-family: var(--font-b);
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased
}

/* AUTH */
#auth-screen {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200
}

#auth-screen::before {
    content: '';
    position: fixed;
    top: -30%;
    left: 50%;
    transform: translateX(-50%);
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(20, 104, 240, 0.07), transparent 70%);
    pointer-events: none
}

.auth-card {
    width: 400px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--r-lg);
    padding: 40px;
    box-shadow: var(--shadow-lg)
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px
}

.auth-icon {
    width: 40px;
    height: 40px;
    background: var(--blue);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(20, 104, 240, 0.4);
    flex-shrink: 0
}

.auth-wordmark {
    font-family: var(--font-b);
    font-size: 20px;
    font-weight: 300;
    letter-spacing: 4px;
    color: var(--text-primary)
}

.auth-wordmark b {
    color: var(--blue-b);
    font-weight: 400
}

.auth-sub {
    font-size: 12.5px;
    color: var(--text-muted);
    font-weight: 300;
    margin-bottom: 28px;
    line-height: 1.5
}

.auth-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 22px
}

.auth-tab {
    padding: 9px 16px;
    font-size: 12px;
    font-weight: 300;
    letter-spacing: .5px;
    cursor: pointer;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all .2s var(--ease)
}

.auth-tab.active {
    color: var(--blue-b);
    border-bottom-color: var(--blue)
}

.form-group {
    margin-bottom: 13px
}

.form-label {
    display: block;
    font-size: 10px;
    font-weight: 300;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 5px
}

.form-input {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: var(--r-sm);
    padding: 10px 13px;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 300;
    font-family: var(--font-b);
    outline: none;
    transition: border-color .2s
}

.form-input:focus {
    border-color: rgba(20, 104, 240, 0.5);
    box-shadow: 0 0 0 3px rgba(20, 104, 240, 0.08)
}

.form-input::placeholder {
    color: var(--text-dim)
}

.form-select {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: var(--r-sm);
    padding: 10px 13px;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 300;
    font-family: var(--font-b);
    outline: none;
    cursor: pointer
}

.btn-blue {
    width: 100%;
    padding: 11px;
    background: var(--blue);
    border: none;
    border-radius: var(--r-sm);
    color: #fff;
    font-size: 13px;
    font-weight: 300;
    font-family: var(--font-b);
    letter-spacing: .5px;
    cursor: pointer;
    transition: all .2s var(--ease);
    box-shadow: 0 2px 12px rgba(20, 104, 240, 0.3);
    margin-top: 4px
}

.btn-blue:hover {
    background: #1d7cf5;
    box-shadow: 0 4px 18px rgba(20, 104, 240, 0.45);
    transform: translateY(-1px)
}

.btn-blue:disabled {
    background: var(--bg-elevated);
    color: var(--text-dim);
    box-shadow: none;
    cursor: not-allowed;
    transform: none
}

.auth-error {
    color: var(--danger);
    font-size: 11px;
    margin-top: 10px;
    display: none;
    font-weight: 300
}

/* LAYOUT */
.app {
    display: flex;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    position: relative
}

.app::before {
    content: '';
    position: fixed;
    top: -30%;
    left: 50%;
    transform: translateX(-50%);
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(20, 104, 240, 0.05), transparent 70%);
    pointer-events: none;
    z-index: 0
}

/* SIDEBAR */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    position: relative;
    flex-shrink: 0;
    transition: transform .3s var(--ease)
}

.sidebar::after {
    content: '';
    position: absolute;
    top: 0;
    right: -1px;
    width: 1px;
    height: 100%;
    background: linear-gradient(180deg, transparent, var(--accent-border), transparent);
    opacity: .25
}

.sidebar-head {
    display: flex;
    align-items: center;
    padding: 15px 13px;
    border-bottom: 1px solid var(--border);
    gap: 7px
}

.logo {
    display: flex;
    align-items: center;
    gap: 9px;
    text-decoration: none;
    flex: 1;
    min-width: 0
}

.logo-box {
    width: 30px;
    height: 30px;
    background: var(--blue);
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(20, 104, 240, 0.35);
    flex-shrink: 0
}

.logo-name {
    font-family: var(--font-b);
    font-size: 14px;
    font-weight: 300;
    letter-spacing: 3.5px;
    color: var(--text-primary);
    white-space: nowrap
}

.logo-name b {
    color: var(--blue-b);
    font-weight: 400
}

.sb-btn {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: var(--r-sm);
    color: var(--text-muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: all .2s var(--ease);
    text-decoration: none
}

.sb-btn:hover {
    background: var(--blue);
    color: #fff;
    border-color: var(--blue);
    box-shadow: var(--shadow-glow);
    transform: scale(1.07)
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 10px 7px
}

.nav-sec {
    padding: 8px 9px 4px;
    font-size: 9px;
    font-weight: 300;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--text-dim)
}

.nav-it {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border-radius: var(--r-sm);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 300;
    transition: all .15s var(--ease);
    border-left: 2px solid transparent;
    margin-bottom: 1px;
    user-select: none
}

.nav-it:hover {
    background: var(--bg-hover);
    color: var(--text-primary)
}

.nav-it.active {
    background: var(--accent-dim);
    color: var(--text-primary);
    border-left-color: var(--blue)
}

.nav-it svg {
    flex-shrink: 0;
    opacity: .65
}

.nav-it.active svg {
    opacity: 1
}

.sidebar-foot {
    padding: 11px 13px;
    border-top: 1px solid var(--border)
}

.user-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: var(--r-sm)
}

.u-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-m);
    font-size: 10px;
    font-weight: 500;
    color: #fff;
    flex-shrink: 0
}

.u-info {
    flex: 1;
    min-width: 0
}

.u-email {
    font-size: 11px;
    color: var(--text-primary);
    font-weight: 300;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis
}

.u-role {
    font-size: 9px;
    color: var(--text-muted);
    font-weight: 300;
    letter-spacing: .5px
}

.logout-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 3px;
    border-radius: var(--r-xs);
    transition: color .15s;
    display: flex
}

.logout-btn:hover {
    color: var(--danger)
}

/* MAIN */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    position: relative;
    z-index: 1
}

.topbar {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 11px 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(20px) saturate(1.5);
    z-index: 10;
    flex-shrink: 0
}

.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 5px;
    border-radius: var(--r-xs);
    transition: all .15s
}

.menu-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary)
}

.topbar-title {

    font-size: 12px;
    font-weight: 300;
    letter-spacing: 3px;
    color: var(--text-primary);
    flex: 1
}

.topbar-right {
    display: flex;
    gap: 7px;
    align-items: center
}

.tb-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: var(--r-full);
    font-size: 10px;
    font-weight: 300;
    color: var(--text-muted);
    letter-spacing: .5px
}

.pulse-dot {
    width: 6px;
    height: 6px;
    background: var(--green);
    border-radius: 50%;
    position: relative;
    flex-shrink: 0
}

.pulse-dot::after {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 1.5px solid var(--green);
    animation: pulseRing 2s ease-in-out infinite
}

@keyframes pulseRing {

    0%,
    100% {
        transform: scale(1);
        opacity: .6
    }

    50% {
        transform: scale(1.5);
        opacity: 0
    }
}

/* PAGES */
.page {
    display: none;
    flex: 1;
    overflow: hidden;
    flex-direction: column;
    position: relative
}

.page.active {
    display: flex
}

.pg {
    padding: 22px 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    flex: 1;
    overflow-y: auto;
    min-height: 0
}

/* Snippets page: row layout on desktop, column on mobile */
.snip-pg {
    flex-direction: row;
    gap: 14px;
    overflow: hidden
}

/* QUERY PAGE */
#page-query {
    overflow: hidden
}

.chat-area {
    flex: 1;
    overflow-y: auto;
    position: relative
}

.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 56px 24px;
    text-align: center
}

.welcome.hidden {
    display: none
}

.welcome-icon {
    width: 68px;
    height: 68px;
    background: var(--blue);
    border-radius: 17px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 24px rgba(20, 104, 240, 0.4);
    margin-bottom: 22px;
    position: relative
}

.welcome-icon::after {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: 18px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.12), transparent);
    pointer-events: none
}

.welcome-title {
    font-family: var(--font-d);
    font-size: 29px;
    font-weight: 300;
    margin-bottom: 9px;
    letter-spacing: -.3px
}

.welcome-sub {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 300;
    margin-bottom: 34px;
    line-height: 1.6;
    max-width: 340px
}

.sug-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 9px;
    max-width: 500px;
    width: 100%
}

.sug-card {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 13px 15px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--r-md);
    cursor: pointer;
    text-align: left;
    transition: all .2s var(--ease);
    font-family: var(--font-b)
}

.sug-card:hover {
    background: var(--bg-hover);
    border-color: var(--border-medium);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md)
}

.sug-icon {
    font-size: 15px;
    flex-shrink: 0
}

.sug-text {
    font-size: 12px;
    font-weight: 300;
    color: var(--text-secondary);
    line-height: 1.4
}

/* MESSAGES */
.msgs {
    width: 100%;
    max-width: 740px;
    margin: 0 auto;
    padding: 18px 0 24px;
    display: flex;
    flex-direction: column;
    gap: 2px
}

.msg {
    padding: 4px 15px;
    animation: msgIn .3s var(--ease) forwards
}

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

    to {
        opacity: 1;
        transform: none
    }
}

.msg-inner {
    display: flex;
    gap: 11px;
    padding: 12px 14px;
    border-radius: var(--r-md);
    transition: background .15s
}

.msg.user .msg-inner {
    background: var(--bg-secondary);
    border: 1px solid var(--border)
}

.msg.bot .msg-inner {
    background: transparent
}

.msg:hover .msg-inner {
    background: var(--bg-hover)
}

.msg.user:hover .msg-inner {
    background: var(--bg-elevated)
}

.msg-av {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 400
}

.msg.user .msg-av {
    background: var(--bg-elevated);
    border: 1px solid var(--border-medium);
    color: var(--text-muted)
}

.msg.bot .msg-av {
    background: var(--blue);
    box-shadow: 0 2px 8px rgba(20, 104, 240, 0.3)
}

.msg-body {
    flex: 1;
    min-width: 0
}

.msg-role {
    font-size: 9px;
    font-weight: 300;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 6px
}

.msg.bot .msg-role {
    color: var(--blue-b);
    opacity: .7
}

.msg-text {
    font-size: 13.5px;
    color: var(--text-primary);
    line-height: 1.78;
    font-weight: 300
}

.msg-text p {
    margin-bottom: 10px
}

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

.msg-text ul,
.msg-text ol {
    padding-left: 18px;
    margin-bottom: 10px
}

.msg-text li {
    margin-bottom: 4px;
    color: var(--text-secondary)
}

.msg-text strong {
    font-weight: 500;
    color: var(--text-primary)
}

.msg-text h1,
.msg-text h2,
.msg-text h3 {
    font-family: var(--font-d);
    font-weight: 300;
    margin: 14px 0 7px
}

.msg-text h3 {
    font-size: 15px
}

.msg-text h2 {
    font-size: 17px
}

.msg-text h1 {
    font-size: 20px
}

.msg-text pre {
    background: var(--code-bg) !important;
    border: 1px solid var(--border-light);
    border-radius: var(--r-md);
    padding: 14px 16px;
    overflow-x: auto;
    margin: 10px 0
}

.msg-text code {
    font-family: var(--font-m);
    font-size: 12px;
    color: var(--blue-s)
}

.msg-text :not(pre)>code {
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 5px;
    font-size: 11.5px;
    color: var(--blue-b);
    border: 1px solid var(--border-light)
}

.msg-text table {
    border-collapse: collapse;
    width: 100%;
    margin: 12px 0;
    font-size: 12.5px
}

.msg-text th,
.msg-text td {
    padding: 9px 12px;
    border: 1px solid var(--border-medium);
    text-align: left
}

.msg-text th {
    background: var(--bg-tertiary);
    font-weight: 300;
    font-size: 10px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-muted)
}

.sources {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 8px
}

.source-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 9px;
    background: var(--accent-dim);
    border: 1px solid var(--accent-border);
    border-radius: var(--r-full);
    font-size: 9px;
    font-weight: 300;
    color: var(--blue-b);
    letter-spacing: .3px;
    font-family: var(--font-m)
}

.t-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: var(--r-full);
    font-size: 9px;
    font-family: var(--font-m);
    font-weight: 400
}

.t-cached {
    background: rgba(34, 197, 94, 0.1);
    color: var(--green)
}

.t-fast {
    background: var(--accent-dim);
    color: var(--blue-b)
}

.t-heavy {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warn)
}

.t-sql {
    background: var(--accent-dim);
    color: var(--blue-b)
}

.t-none {
    background: var(--bg-elevated);
    color: var(--text-muted)
}

/* TYPING */
.typing {
    display: flex;
    gap: 5px;
    padding: 3px 0
}

.typing span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--text-dim);
    animation: dot 1.4s ease-in-out infinite
}

.typing span:nth-child(2) {
    animation-delay: .2s
}

.typing span:nth-child(3) {
    animation-delay: .4s
}

@keyframes dot {

    0%,
    60%,
    100% {
        opacity: .3;
        transform: scale(1)
    }

    30% {
        opacity: 1;
        transform: scale(1.25)
    }
}

/* INPUT */
.input-area {
    padding: 0 15px 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    flex-shrink: 0
}

.input-wrap {
    width: 100%;
    max-width: 740px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 9px;
    padding: 9px 9px 9px 15px;
    background: var(--bg-input);
    border: 1px solid var(--border-medium);
    border-radius: var(--r-xl);
    transition: border-color .2s, box-shadow .2s
}

.input-wrap:focus-within {
    border-color: rgba(20, 104, 240, 0.4);
    box-shadow: 0 0 0 3px rgba(20, 104, 240, 0.08)
}

.input-wrap textarea {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    resize: none;
    font-family: var(--font-b);
    font-size: 13.5px;
    font-weight: 300;
    line-height: 1.6;
    color: var(--text-primary);
    max-height: 180px;
    padding: 0;
    scrollbar-width: none
}

.input-wrap textarea::placeholder {
    color: var(--text-muted)
}

.input-ctrls {
    display: flex;
    gap: 6px;
    align-items: center
}

.lang-sel {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: var(--r-sm);
    padding: 6px 9px;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 300;
    font-family: var(--font-m);
    outline: none;
    cursor: pointer
}

.send-btn {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--blue);
    border: none;
    border-radius: var(--r-full);
    color: #fff;
    cursor: pointer;
    transition: all .2s var(--ease);
    box-shadow: 0 2px 8px rgba(20, 104, 240, 0.3)
}

.send-btn:hover:not(:disabled) {
    background: #1d7cf5;
    transform: scale(1.08);
    box-shadow: 0 4px 14px rgba(20, 104, 240, 0.45)
}

.send-btn:active:not(:disabled) {
    transform: scale(0.94)
}

.send-btn:disabled {
    background: var(--bg-elevated);
    color: var(--text-dim);
    box-shadow: none;
    cursor: not-allowed
}

.disclaimer {
    text-align: center;
    font-size: 10px;
    color: var(--text-dim);
    margin-top: 7px;
    font-weight: 300;
    letter-spacing: .2px;
    max-width: 740px;
    margin-left: auto;
    margin-right: auto
}

/* CARDS */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--r-md);
    padding: 16px 18px
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 13px
}

.card-title {
    font-family: var(--font-d);
    font-size: 15px;
    font-weight: 300
}

/* STATS */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 13px
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--r-md);
    padding: 16px 18px
}

.stat-lbl {
    font-size: 9px;
    font-weight: 300;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 8px
}

.stat-val {
    font-family: var(--font-d);
    font-size: 26px;
    font-weight: 300;
    color: var(--text-primary)
}

.stat-sub {
    font-size: 10px;
    color: var(--text-dim);
    margin-top: 4px;
    font-weight: 300
}

/* TABLE */
.tbl-wrap {
    overflow-x: auto
}

table {
    width: 100%;
    border-collapse: collapse
}

th {
    text-align: left;
    padding: 8px 12px;
    font-size: 9px;
    font-weight: 300;
    font-family: var(--font-m);
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border)
}

td {
    padding: 10px 12px;
    font-size: 12.5px;
    font-weight: 300;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary)
}

tr:last-child td {
    border-bottom: none
}

tr:hover td {
    background: var(--bg-hover);
    color: var(--text-primary)
}

/* BADGES */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: var(--r-xs);
    font-size: 9px;
    font-family: var(--font-m);
    font-weight: 400
}

.b-green {
    background: rgba(34, 197, 94, 0.1);
    color: var(--green)
}

.b-blue {
    background: var(--accent-dim);
    border: 1px solid var(--accent-border);
    color: var(--blue-b)
}

.b-yellow {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warn)
}

.b-red {
    background: rgba(248, 113, 113, 0.1);
    color: var(--danger)
}

.b-gray {
    background: var(--bg-elevated);
    color: var(--text-muted)
}

.mth {
    display: inline-flex;
    padding: 2px 8px;
    border-radius: var(--r-xs);
    font-size: 9px;
    font-family: var(--font-m);
    font-weight: 500;
    min-width: 48px;
    justify-content: center
}

.mth-GET {
    background: rgba(34, 197, 94, 0.1);
    color: var(--green)
}

.mth-POST {
    background: var(--accent-dim);
    color: var(--blue-b)
}

.mth-PUT {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warn)
}

.mth-DELETE {
    background: rgba(248, 113, 113, 0.1);
    color: var(--danger)
}

.mth-PATCH {
    background: rgba(56, 189, 248, 0.1);
    color: #38bdf8
}

/* UPLOAD */
.upload-zone {
    border: 1px dashed var(--border-medium);
    border-radius: var(--r-md);
    padding: 44px 24px;
    text-align: center;
    cursor: pointer;
    transition: all .2s var(--ease);
    background: var(--bg-secondary)
}

.upload-zone:hover,
.upload-zone.drag {
    border-color: rgba(20, 104, 240, 0.5);
    background: var(--accent-dim)
}

.up-icon {
    font-size: 34px;
    margin-bottom: 11px
}

.up-title {
    font-family: var(--font-d);
    font-size: 17px;
    font-weight: 300;
    margin-bottom: 6px
}

.up-sub {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 300
}

.up-types {
    margin-top: 11px;
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap
}

.prog-bar {
    height: 2px;
    background: var(--border);
    border-radius: var(--r-full);
    overflow: hidden;
    margin-top: 7px
}

.prog-fill {
    height: 100%;
    background: var(--blue);
    border-radius: var(--r-full);
    transition: width .3s
}

/* SNIPPETS */
.snip-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--r-md);
    overflow: hidden
}

.snip-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary)
}

.snip-path {
    font-family: var(--font-m);
    font-size: 12px;
    color: var(--text-primary)
}

.lang-tabs {
    display: flex;
    gap: 3px
}

.l-tab {
    padding: 4px 9px;
    border-radius: var(--r-xs);
    font-size: 9px;
    font-family: var(--font-m);
    cursor: pointer;
    color: var(--text-muted);
    transition: all .15s;
    border: 1px solid transparent
}

.l-tab:hover {
    color: var(--text-secondary);
    background: var(--bg-elevated)
}

.l-tab.active {
    color: var(--blue-b);
    background: var(--accent-dim);
    border-color: var(--accent-border)
}

.snip-code {
    padding: 16px 18px
}

.snip-code pre {
    margin: 0;
    border: none !important;
    padding: 0 !important;
    background: transparent !important;
    font-family: var(--font-m);
    font-size: 11.5px;
    line-height: 1.6;
    color: var(--blue-s)
}

/* FILTERS */
.filters {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap
}

.f-input {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--r-sm);
    padding: 7px 12px;
    color: var(--text-primary);
    font-size: 12.5px;
    font-weight: 300;
    font-family: var(--font-b);
    outline: none;
    transition: border-color .2s
}

.f-input:focus {
    border-color: rgba(20, 104, 240, 0.4)
}

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

.f-sel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--r-sm);
    padding: 7px 12px;
    color: var(--text-secondary);
    font-size: 12.5px;
    font-weight: 300;
    font-family: var(--font-b);
    outline: none;
    cursor: pointer
}

.btn-act {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 14px;
    background: var(--blue);
    border: none;
    border-radius: var(--r-sm);
    color: #fff;
    font-size: 11.5px;
    font-weight: 300;
    font-family: var(--font-b);
    cursor: pointer;
    transition: all .2s var(--ease);
    box-shadow: 0 2px 8px rgba(20, 104, 240, 0.25);
    white-space: nowrap
}

.btn-act:hover {
    background: #1d7cf5;
    box-shadow: 0 4px 14px rgba(20, 104, 240, 0.4)
}

.btn-out {
    display: inline-flex;
    align-items: center;
    padding: 5px 10px;
    background: transparent;
    border: 1px solid var(--border-medium);
    border-radius: var(--r-sm);
    color: var(--text-muted);
    font-size: 10.5px;
    font-weight: 300;
    font-family: var(--font-b);
    cursor: pointer;
    transition: all .15s
}

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

.btn-del {
    display: inline-flex;
    padding: 4px 9px;
    background: transparent;
    border: 1px solid rgba(248, 113, 113, 0.2);
    border-radius: var(--r-sm);
    color: var(--danger);
    font-size: 10.5px;
    font-family: var(--font-b);
    cursor: pointer;
    transition: all .15s
}

.btn-del:hover {
    background: rgba(248, 113, 113, 0.07)
}

/* TOAST */
.toast-wrap {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 7px
}

.toast {
    background: var(--bg-elevated);
    border: 1px solid var(--border-medium);
    border-radius: var(--r-md);
    padding: 10px 15px;
    font-size: 12px;
    font-weight: 300;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    animation: tIn .2s var(--ease);
    max-width: 280px;
    box-shadow: var(--shadow-md)
}

.toast.ok {
    border-color: rgba(34, 197, 94, 0.3)
}

.toast.err {
    border-color: rgba(248, 113, 113, 0.3)
}

@keyframes tIn {
    from {
        transform: translateX(14px);
        opacity: 0
    }

    to {
        transform: none;
        opacity: 1
    }
}

.spinner {
    width: 13px;
    height: 13px;
    border: 1.5px solid var(--border-medium);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin .6s linear infinite
}

@keyframes spin {
    to {
        transform: rotate(360deg)
    }
}

.empty-st {
    text-align: center;
    padding: 44px 24px;
    color: var(--text-muted)
}

.empty-ic {
    font-size: 36px;
    margin-bottom: 11px
}

.empty-title {
    font-family: var(--font-d);
    font-size: 15px;
    font-weight: 300;
    color: var(--text-secondary);
    margin-bottom: 5px
}

.empty-st p {
    font-size: 12px;
    font-weight: 300
}

.snip-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary);
    gap: 10px;
    flex-wrap: wrap
}

.snip-layout {
    display: flex;
    gap: 12px;
    flex: 1;
    min-height: 0;
    overflow: hidden
}

.snip-list-col {
    width: 260px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 10px
}

.adm-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px
}

::-webkit-scrollbar {
    width: 3px;
    height: 3px
}

::-webkit-scrollbar-track {
    background: transparent
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.07);
    border-radius: var(--r-full)
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.12)
}

::selection {
    background: rgba(20, 104, 240, 0.3);
    color: white
}

/* ═══ RESPONSIVE — TABLET ═══ */
@media(max-width:1024px) {
    :root {
        --sidebar-width: 220px
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr)
    }

    .msgs {
        max-width: 100%
    }
}

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

    /* Sidebar: full-height overlay */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        height: 100%;
        height: 100dvh;
        width: 272px;
        transform: translateX(-100%);
        z-index: 200;
        box-shadow: none;
        transition: transform .3s var(--ease), box-shadow .3s;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 16px 0 48px rgba(0, 0, 0, 0.85);
    }

    .sidebar-foot {
        display: flex
    }

    .menu-toggle {
        display: flex
    }

    /* App layout */
    .app {
        flex-direction: column;
        height: 100vh;
        height: 100dvh;
        overflow: hidden
    }

    .topbar {
        height: 50px;
        padding: 0 12px;
        gap: 8px
    }

    .topbar-title {
        font-size: 11px;
        letter-spacing: 2px
    }

    .main {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden
    }

    .page {
        display: none;
        flex: 1;
        min-height: 0;
        overflow: hidden;
        flex-direction: column
    }

    .page.active {
        display: flex
    }

    .pg {
        padding: 10px;
        gap: 10px;
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch
    }

    /* Chat page — fix correct class names */
    #page-query.active {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
        overflow: hidden
    }

    .chat-area {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch
    }

    /* Welcome screen — correct class names */
    .welcome {
        padding: 20px 14px 10px;
        min-height: unset
    }

    .welcome-icon {
        width: 48px;
        height: 48px;
        border-radius: 11px;
        margin-bottom: 14px
    }

    .welcome-title {
        font-size: 18px;
        margin-bottom: 6px
    }

    .welcome-sub {
        font-size: 12px;
        margin-bottom: 20px;
        max-width: 100%
    }

    /* Suggestion grid */
    .sug-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        max-width: 100%
    }

    .sug-card {
        padding: 11px 12px;
        gap: 8px
    }

    .sug-icon {
        font-size: 15px
    }

    .sug-text {
        font-size: 11.5px
    }

    /* Messages */
    .msgs {
        max-width: 100%;
        padding: 10px 0 14px
    }

    .msg {
        padding: 2px 8px
    }

    .msg-inner {
        padding: 10px 11px;
        gap: 9px;
        border-radius: var(--r-sm)
    }

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

    .msg-role {
        font-size: 9.5px;
        margin-bottom: 5px;
        letter-spacing: 1px
    }

    .msg-text {
        font-size: 13px;
        line-height: 1.68
    }

    .msg-text pre {
        padding: 10px 12px;
        font-size: 11.5px;
        overflow-x: auto
    }

    .msg-text h1 {
        font-size: 17px
    }

    .msg-text h2 {
        font-size: 15px
    }

    .msg-text h3 {
        font-size: 13.5px
    }

    .msg-text table {
        font-size: 12px;
        display: block;
        overflow-x: auto
    }

    .msg-text th,
    .msg-text td {
        padding: 7px 10px
    }

    .sources {
        margin-left: 35px;
        gap: 4px;
        margin-top: 7px
    }

    .source-chip {
        font-size: 9.5px;
        padding: 2px 7px
    }

    .t-badge {
        font-size: 9px;
        padding: 2px 6px
    }

    /* Input — correct class names */
    .input-area {
        padding: 7px 10px;
        padding-bottom: calc(7px + env(safe-area-inset-bottom, 0px));
        flex-shrink: 0;
    }

    .input-wrap {
        padding: 8px 10px 8px 13px;
        border-radius: 14px;
        gap: 7px;
        max-width: 100%;
    }

    .input-wrap textarea {
        font-size: 16px;
        min-height: 20px
    }

    .disclaimer {
        font-size: 9.5px;
        margin-top: 5px
    }

    .lang-sel {
        font-size: 10px;
        padding: 5px 8px
    }

    .send-btn {
        width: 32px;
        height: 32px
    }

    .input-ctrls {
        gap: 6px
    }

    /* Documents & Endpoints — filters stack */
    .filters {
        flex-direction: column;
        align-items: stretch;
        gap: 7px
    }

    .filters input,
    .filters select,
    .f-input,
    .f-sel {
        width: 100% !important;
        max-width: 100% !important
    }

    .filters .btn-act,
    .filters button {
        width: 100%;
        justify-content: center;
        text-align: center
    }

    /* Tables */
    .tbl-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch
    }

    table {
        min-width: 480px;
        font-size: 12px
    }

    th {
        padding: 8px 10px;
        font-size: 9.5px
    }

    td {
        padding: 9px 10px;
        font-size: 12px
    }

    .col-hide-mobile {
        display: none
    }

    /* Upload */
    .upload-zone {
        padding: 28px 14px
    }

    .up-title {
        font-size: 15px
    }

    .up-sub {
        font-size: 12px
    }

    /* Snippets — stack vertically */
    .snip-pg {
        flex-direction: column !important;
        overflow-y: auto;
        overflow-x: hidden
    }

    .snip-list-col {
        width: 100% !important;
        flex-shrink: 0
    }

    .snip-ep-list {
        max-height: 200px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch
    }

    #snip-out {
        min-height: 280px;
        overflow-y: auto
    }

    .snip-head {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 11px 13px
    }

    .lang-tabs {
        flex-wrap: wrap;
        gap: 4px
    }

    .l-tab {
        padding: 4px 9px;
        font-size: 10px
    }

    .snip-code {
        padding: 12px
    }

    .snip-code pre {
        font-size: 11.5px;
        white-space: pre-wrap;
        word-break: break-word
    }

    /* Admin */
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px
    }

    .stat-card {
        padding: 12px
    }

    .stat-val {
        font-size: 22px
    }

    .stat-lbl {
        font-size: 9px
    }

    .stat-sub {
        font-size: 10px
    }

    .adm-grid {
        grid-template-columns: 1fr !important;
        gap: 10px
    }

    .card {
        padding: 12px;
        border-radius: var(--r-sm)
    }

    .card-title {
        font-size: 13px;
        margin-bottom: 10px
    }

    /* Auth */
    .auth-card {
        padding: 26px 20px;
        width: calc(100vw - 32px);
        max-width: 400px
    }

    .auth-wordmark {
        font-size: 17px;
        letter-spacing: 3px
    }

    .auth-sub {
        font-size: 12px
    }

    /* Topbar badge — hide on very small */
    .tb-badge {
        display: none
    }

    /* Toast */
    .toast-wrap {
        top: auto !important;
        bottom: 16px;
        left: 10px;
        right: 10px
    }

    .toast {
        max-width: 100%;
        width: 100%
    }
}

/* ═══ RESPONSIVE — SMALL PHONES ═══ */
@media(max-width:480px) {
    .sug-grid {
        grid-template-columns: 1fr
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr
    }

    .stat-val {
        font-size: 20px
    }

    .welcome-title {
        font-size: 16px
    }

    .welcome-sub {
        font-size: 11.5px
    }

    .msg-text {
        font-size: 12.5px
    }

    .pg {
        padding: 8px
    }

    .auth-card {
        padding: 22px 16px
    }

    .input-wrap {
        padding: 7px 8px 7px 12px
    }

    table {
        min-width: 400px
    }

    .snip-ep-list {
        max-height: 160px
    }

    .topbar {
        height: 46px;
        padding: 0 10px
    }

    .topbar-title {
        font-size: 10px;
        letter-spacing: 1.5px
    }

    .nav-sec {
        font-size: 8px
    }

    .nav-it {
        font-size: 11px;
        padding: 7px 9px
    }
}

/* ═══ iOS SAFE AREA ═══ */
@supports(padding:env(safe-area-inset-bottom)) {
    .input-area {
        padding-bottom: calc(7px + env(safe-area-inset-bottom))
    }

    .sidebar {
        padding-bottom: env(safe-area-inset-bottom)
    }
}

.sb-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    z-index: 99;
    animation: fadeIn .25s ease
}

.sb-backdrop.vis {
    display: block
}

@keyframes fadeIn {
    from {
        opacity: 0
    }

    to {
        opacity: 1
    }
}

#feedback-tb td {
    word-break: break-word;
    vertical-align: top;
    font-size: 12px;
}

#feedback-tb tr:hover {
    background: var(--bg-hover);
}

#answer-modal pre {
    color: #eee;
    line-height: 1.5;
}
/* ── New Chat Button ─────────────────────────────────────────── */
.new-chat-btn {
    position: absolute;
    top: 10px;
    right: 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--r-full);
    color: var(--text-muted);
    font-family: var(--font-b);
    font-size: 11px;
    font-weight: 300;
    letter-spacing: .4px;
    padding: 5px 12px;
    cursor: pointer;
    transition: all .2s var(--ease);
    z-index: 10;
}
.new-chat-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-medium);
    color: var(--text-primary);
}

/* Make chat area position:relative so button can be absolute inside */
.page#page-query {
    position: relative;
}