/* ═══════════════════════════════════════════
   LUMINA AI — Design System
   ═══════════════════════════════════════════ */

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

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility
}

button {
    font: inherit;
    cursor: pointer;
    border: none;
    background: none
}

input,
textarea {
    font: inherit;
    border: none;
    outline: none;
    background: none
}

a {
    text-decoration: none;
    color: inherit
}

ul,
ol {
    list-style: none
}

/* --- Tokens: Light --- */
:root,
[data-theme="light"] {
    --bg-primary: #FAF9F6;
    --bg-secondary: #F2F0EB;
    --bg-tertiary: #E8E6E0;
    --bg-surface: #FFFFFF;
    --bg-surface-hover: #F7F6F3;
    --text-primary: #1A1814;
    --text-secondary: #6E6A62;
    --text-tertiary: #9B968D;
    --accent: #C2410C;
    --accent-hover: #A93A0B;
    --accent-subtle: #FFF5ED;
    --accent-muted: #FDBA74;
    --border: #E3E0D9;
    --border-subtle: #EEECE7;
    --border-focus: rgba(194, 65, 12, 0.25);
    --success: #15803D;
    --warning: #B45309;
    --error: #DC2626;
    --shadow-rgb: 28, 24, 20;
    --glass-bg: rgba(255, 255, 255, 0.72);
    --glass-border: rgba(255, 255, 255, 0.2);
    --code-bg: #F5F3EE;
    --code-text: #C2410C;
    --scrollbar-thumb: #D1CDC5;
    --scrollbar-track: transparent;
    --user-msg-bg: #FFF5ED;
    --user-msg-border: #FDDCB5;
    --ambient-color: rgba(253, 186, 116, 0.08);
}

/* --- Tokens: Dark --- */
[data-theme="dark"] {
    --bg-primary: #0E0D0B;
    --bg-secondary: #1A1814;
    --bg-tertiary: #252320;
    --bg-surface: #1E1C18;
    --bg-surface-hover: #2A2722;
    --text-primary: #F4F2ED;
    --text-secondary: #9B968D;
    --text-tertiary: #6E6A62;
    --accent: #F97316;
    --accent-hover: #FB923C;
    --accent-subtle: #1C1106;
    --accent-muted: #9A3412;
    --border: #2E2B26;
    --border-subtle: #1E1C18;
    --border-focus: rgba(249, 115, 22, 0.3);
    --shadow-rgb: 0, 0, 0;
    --glass-bg: rgba(30, 28, 24, 0.72);
    --glass-border: rgba(255, 255, 255, 0.06);
    --code-bg: #161412;
    --code-text: #FB923C;
    --scrollbar-thumb: #3D3A34;
    --scrollbar-track: transparent;
    --user-msg-bg: #1C1106;
    --user-msg-border: #3D2A10;
    --ambient-color: rgba(249, 115, 22, 0.05);
}

/* --- Shadows --- */
:root {
    --shadow-1: 0 1px 2px rgba(var(--shadow-rgb), 0.04), 0 1px 3px rgba(var(--shadow-rgb), 0.06);
    --shadow-2: 0 2px 4px rgba(var(--shadow-rgb), 0.04), 0 4px 8px rgba(var(--shadow-rgb), 0.06);
    --shadow-3: 0 4px 8px rgba(var(--shadow-rgb), 0.04), 0 8px 16px rgba(var(--shadow-rgb), 0.08);
    --shadow-4: 0 8px 16px rgba(var(--shadow-rgb), 0.06), 0 16px 32px rgba(var(--shadow-rgb), 0.10);
    --shadow-5: 0 12px 24px rgba(var(--shadow-rgb), 0.08), 0 24px 48px rgba(var(--shadow-rgb), 0.12);
}

/* --- Typography --- */
body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: 15px;
    line-height: 1.65;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    background: var(--bg-primary);
    transition: color .4s ease, background .4s ease;
    overflow: hidden;
    height: 100vh;
}

.text-display {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.03em
}

.text-h1 {
    font-size: 1.5rem;
    font-weight: 650;
    line-height: 1.2;
    letter-spacing: -0.025em
}

.text-h2 {
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.25;
    letter-spacing: -0.02em
}

.text-h3 {
    font-size: 1.0625rem;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.015em
}

.text-body {
    font-size: .9375rem;
    font-weight: 400;
    line-height: 1.65;
    letter-spacing: -0.01em
}

.text-body-medium {
    font-size: .9375rem;
    font-weight: 500;
    line-height: 1.65;
    letter-spacing: -0.01em
}

.text-small {
    font-size: .8125rem;
    font-weight: 400;
    line-height: 1.5;
    letter-spacing: 0
}

.text-caption {
    font-size: .75rem;
    font-weight: 500;
    line-height: 1.4;
    letter-spacing: .01em
}

.text-overline {
    font-size: .6875rem;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: .06em;
    text-transform: uppercase
}

/* --- Grain Overlay --- */
.grain-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    pointer-events: none;
    opacity: .03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 128px 128px;
}

/* --- Ambient Light --- */
.ambient-light {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background: radial-gradient(ellipse 60% 50% at 15% 10%, var(--ambient-color), transparent 70%);
    transition: background .4s ease;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 6px
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-track)
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary)
}

/* ═══════════ LAYOUT ═══════════ */
.app-layout {
    display: flex;
    height: 100vh;
    position: relative;
    z-index: 1
}

/* --- Sidebar --- */
.sidebar {
    width: 280px;
    min-width: 280px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    transition: transform .3s ease, opacity .3s ease, background .4s ease, border-color .4s ease;
    z-index: 10;
}

.sidebar.collapsed {
    transform: translateX(-100%);
    min-width: 0;
    width: 0;
    opacity: 0;
    overflow: hidden
}

.sidebar-header {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-subtle);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px
}

.logo-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

.logo-text {
    font-size: 1.0625rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary)
}

.btn-new-chat {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 8px;
    font-size: .8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    background: var(--bg-surface);
    transition: all .2s ease;
}

.btn-new-chat:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
    box-shadow: var(--shadow-1)
}

.btn-new-chat:active {
    transform: scale(.97)
}

.sidebar-search {
    padding: 12px 16px
}

.sidebar-search input {
    width: 100%;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: .8125rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    transition: all .2s ease;
}

.sidebar-search input::placeholder {
    color: var(--text-tertiary)
}

.sidebar-search input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--border-focus)
}

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

.nav-group-label {
    padding: 8px 12px 6px;
    font-size: .6875rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-tertiary);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    font-size: .8125rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all .2s ease;
    position: relative;
    overflow: hidden;
}

.nav-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 0;
    background: var(--accent);
    border-radius: 0 2px 2px 0;
    transition: height .2s ease;
}

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

.nav-item:hover::before {
    height: 60%
}

.nav-item.active {
    background: var(--bg-surface);
    color: var(--text-primary);
    font-weight: 500
}

.nav-item.active::before {
    height: 60%
}

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

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

.sidebar-footer {
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 9999px;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .75rem;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
}

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

.user-name {
    font-size: .8125rem;
    font-weight: 500;
    color: var(--text-primary)
}

.user-plan {
    font-size: .6875rem;
    color: var(--text-tertiary)
}

/* ═══════════ MAIN AREA ═══════════ */
.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative
}

/* --- Top Bar --- */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--glass-bg);
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    z-index: 5;
    transition: all .4s ease;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 12px
}

.btn-sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    color: var(--text-secondary);
    transition: all .2s ease;
}

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

/* Model Selector */
.model-selector {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 9999px;
    font-size: .8125rem;
    font-weight: 500;
    color: var(--text-primary);
    border: 1px solid var(--border);
    background: var(--bg-surface);
    cursor: pointer;
    transition: all .2s ease;
    position: relative;
}

.model-selector:hover {
    box-shadow: var(--shadow-1);
    border-color: var(--accent)
}

.model-selector .chevron {
    width: 14px;
    height: 14px;
    transition: transform .25s ease;
    color: var(--text-tertiary);
}

.model-selector.open .chevron {
    transform: rotate(180deg)
}

.model-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0
}

.model-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 220px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-3);
    z-index: 20;
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
    overflow: hidden;
}

.model-dropdown.open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto
}

.model-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    font-size: .8125rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all .15s ease;
}

.model-option:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary)
}

.model-option.selected {
    color: var(--accent);
    font-weight: 500
}

.model-option-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0
}

.model-option-info {
    flex: 1
}

.model-option-name {
    font-weight: 500;
    color: var(--text-primary)
}

.model-option-desc {
    font-size: .6875rem;
    color: var(--text-tertiary);
    margin-top: 1px
}

.model-option-check {
    width: 14px;
    height: 14px;
    color: var(--accent);
    opacity: 0
}

.model-option.selected .model-option-check {
    opacity: 1
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 8px
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    color: var(--text-secondary);
    transition: all .2s ease;
}

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

.btn-icon:active {
    transform: scale(.94)
}

/* Theme toggle */
.theme-toggle {
    position: relative;
    overflow: hidden
}

.theme-toggle svg {
    transition: transform .4s ease, opacity .3s ease
}

/* ═══════════ CHAT ═══════════ */
.chat-scroll {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth
}

.chat-container {
    max-width: 768px;
    margin: 0 auto;
    padding: 32px 24px 120px
}

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 48px 24px;
    text-align: center;
}

.empty-logo {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    margin-bottom: 24px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-3);
}

.empty-title {
    font-size: 1.5rem;
    font-weight: 650;
    letter-spacing: -0.025em;
    margin-bottom: 8px
}

.empty-desc {
    font-size: .9375rem;
    color: var(--text-secondary);
    max-width: 400px;
    margin-bottom: 32px
}

.suggestion-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
    max-width: 480px
}

.suggestion-card {
    padding: 14px 16px;
    border-radius: 12px;
    text-align: left;
    font-size: .8125rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all .2s ease;
    line-height: 1.45;
}

.suggestion-card:hover {
    border-color: var(--accent);
    color: var(--text-primary);
    box-shadow: var(--shadow-1);
    transform: translateY(-1px);
}

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

.suggestion-icon {
    margin-bottom: 6px;
    opacity: .5
}

/* Messages */
.message {
    display: flex;
    gap: 14px;
    margin-bottom: 24px;
    animation: msgIn .35s ease both
}

.message.user {
    justify-content: flex-end
}

.message.user .message-content {
    background: var(--user-msg-bg);
    border: 1px solid var(--user-msg-border);
    border-radius: 18px 18px 4px 18px;
    max-width: 72%;
    padding: 14px 18px;
}

.ai-avatar {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    flex-shrink: 0;
    margin-top: 2px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-avatar svg {
    width: 16px;
    height: 16px;
    color: #fff
}

.message.ai .message-content {
    flex: 1;
    max-width: calc(100% - 46px);
    padding: 2px 0;
}

.message-content p {
    margin-bottom: 12px
}

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

.message-content strong {
    font-weight: 600
}

.message-content code {
    font-family: 'JetBrains Mono', monospace;
    font-size: .85em;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--code-bg);
    color: var(--code-text);
}

.message-content pre {
    margin: 14px 0;
    padding: 16px;
    border-radius: 10px;
    background: var(--code-bg);
    overflow-x: auto;
    position: relative;
    border: 1px solid var(--border-subtle);
}

.message-content pre code {
    padding: 0;
    background: none;
    color: var(--text-primary);
    font-size: .8125rem;
    line-height: 1.6
}

.pre-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-subtle);
}

.pre-lang {
    font-size: .6875rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: .04em
}

.btn-copy {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: .6875rem;
    font-weight: 500;
    color: var(--text-tertiary);
    transition: color .2s ease;
}

.btn-copy:hover {
    color: var(--accent)
}

.btn-copy.copied {
    color: var(--success)
}

.message-content ul,
.message-content ol {
    margin: 10px 0;
    padding-left: 20px
}

.message-content li {
    margin-bottom: 6px
}

.message-content ol {
    list-style: decimal
}

.message-content ul {
    list-style: disc
}

/* Message actions */
.message-actions {
    display: flex;
    gap: 2px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity .2s ease;
}

.message:hover .message-actions {
    opacity: 1
}

.msg-action {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    color: var(--text-tertiary);
    transition: all .15s ease;
}

.msg-action:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary)
}

.msg-action:active {
    transform: scale(.9)
}

.msg-action svg {
    width: 14px;
    height: 14px
}

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

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

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

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

/* ═══════════ INPUT COMPOSER ═══════════ */
.composer-wrapper {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 5;
    padding: 0 24px 24px;
    background: linear-gradient(to top, var(--bg-primary) 60%, transparent);
}

.composer {
    max-width: 768px;
    margin: 0 auto;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-3);
    transition: border-color .2s ease, box-shadow .2s ease, background .4s ease;
}

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

.composer-input {
    display: flex;
    align-items: flex-end;
    padding: 0 16px;
    gap: 8px;
}

.composer-input textarea {
    flex: 1;
    resize: none;
    max-height: 160px;
    min-height: 24px;
    font-size: .9375rem;
    line-height: 1.5;
    color: var(--text-primary);
    background: transparent;
}

.composer-input textarea::placeholder {
    color: var(--text-tertiary)
}

.composer-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px 10px;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 2px
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 6px
}

.toolbar-hint {
    font-size: .6875rem;
    color: var(--text-tertiary)
}

.btn-send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
    transition: all .25s ease;
}

.btn-send.active {
    background: var(--accent);
    color: #fff;
    box-shadow: var(--shadow-1)
}

.btn-send.active:hover {
    background: var(--accent-hover);
    transform: scale(1.04)
}

.btn-send:active {
    transform: scale(.94) !important
}

/* ═══════════ BADGES & MISC ═══════════ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 9999px;
    font-size: .6875rem;
    font-weight: 500;
    background: var(--accent-subtle);
    color: var(--accent);
}

.tooltip {
    position: absolute;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: .6875rem;
    font-weight: 500;
    background: var(--bg-surface);
    color: var(--text-primary);
    box-shadow: var(--shadow-3);
    border: 1px solid var(--border);
    opacity: 0;
    pointer-events: none;
    transform: translateY(4px);
    transition: all .15s ease;
    white-space: nowrap;
    z-index: 50;
}

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

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

@keyframes typingBounce {

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

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

/* ═══════════ TRANSITIONS ═══════════ */
* {
    transition-property: color, background-color, border-color, box-shadow, opacity;
    transition-duration: 0s
}

.sidebar,
.top-bar,
.composer,
.message-content,
.nav-item,
.btn-new-chat,
.sidebar-search input,
.model-selector,
.suggestion-card,
.btn-icon,
.btn-send,
.user-avatar,
.ai-avatar,
.empty-logo {
    transition-duration: .4s;
    transition-timing-function: ease;
}

/* ═══════════ SELECTION ═══════════ */
::selection {
    background: var(--accent-subtle);
    color: var(--accent)
}

/* ═══════════ RESPONSIVE ═══════════ */
@media(max-width:768px) {
    .sidebar {
        position: fixed;
        z-index: 20;
        box-shadow: var(--shadow-5)
    }

    .chat-container {
        padding: 20px 16px 120px
    }

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

    .top-bar {
        padding: 12px 16px
    }

    .composer-wrapper {
        padding: 0 12px 12px
    }
}

/* ----------- PUBLIC APP EXTRAS ----------- */

/* Sidebar collapse via body class */
body.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
    min-width: 0;
    width: 0;
    opacity: 0;
    overflow: hidden
}

body.sidebar-open .sidebar {
    transform: translateX(0)
}

/* Sidebar toggle visibility */
.btn-sidebar-toggle {
    opacity: 1
}

/* Welcome screen - centered inside chat-scroll */
.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 48px 24px;
    text-align: center
}

.welcome.hide {
    display: none
}

/* Messages container */
.messages {
    display: flex;
    flex-direction: column;
    max-width: 768px;
    margin: 0 auto
}

/* History menu dot button */
.history-menu {
    opacity: 0;
    transition: opacity .15s ease;
    border-radius: 6px;
    padding: 4px;
    color: var(--text-tertiary)
}

.history-menu:hover {
    opacity: 1 !important;
    background: var(--bg-surface-hover);
    color: var(--text-primary)
}

.nav-item:hover .history-menu {
    opacity: 1
}

/* Mobile sidebar scrim */
.scrim {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9;
    background: rgba(0, 0, 0, .5)
}

@media(max-width:768px) {
    .sidebar {
        position: fixed;
        z-index: 20
    }

    body.sidebar-open .scrim {
        display: block
    }

    /* 모바일: 하단 컴포저 safe-area 대응 */
    .composer-wrapper {
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px))
    }
}

/* Reasoning popover positioning fix (inside top-bar) */
.top-bar-left {
    position: relative
}

.reasoning-popover {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 50;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-4);
    padding: 12px;
    width: min(320px, 90vw)
}

.reasoning-popover[hidden] {
    display: none
}

.reasoning-row {
    display: grid;
    gap: 8px
}

.reasoning-row>span {
    font-size: .6875rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-tertiary)
}

.segmented {
    position: relative;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    padding: 4px;
    border-radius: 9999px;
    background: var(--bg-secondary);
    overflow: hidden;
    --thumb-index: 1
}

.segmented-thumb {
    position: absolute;
    z-index: 0;
    top: 4px;
    left: 4px;
    width: calc((100% - 20px) / 4);
    height: calc(100% - 8px);
    border-radius: 9999px;
    background: var(--bg-surface);
    box-shadow: var(--shadow-1);
    transform: translateX(calc(var(--thumb-index) * (100% + 4px)));
    transition: transform 260ms ease
}

.segmented button {
    position: relative;
    z-index: 1;
    min-height: 32px;
    border-radius: 9999px;
    color: var(--text-secondary);
    font-size: .8125rem;
    font-weight: 500;
    transition: color .15s ease
}

.segmented button.active {
    color: var(--text-primary)
}

/* Thinking card */
.thinking-card {
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    background: var(--bg-secondary);
    padding: 10px 14px;
    margin-bottom: 12px;
    font-size: .8125rem;
    color: var(--text-secondary)
}

.thinking-card[hidden] {
    display: none
}

.thinking-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    color: var(--text-secondary)
}

.thinking-toggle strong {
    color: var(--text-primary);
    font-weight: 600
}

.thinking-detail {
    max-height: 0;
    overflow: hidden;
    white-space: pre-wrap;
    font-family: 'JetBrains Mono', monospace;
    font-size: .75rem;
    line-height: 1.5;
    transition: max-height .22s ease, opacity .18s ease;
    opacity: 0
}

.thinking-card.open .thinking-detail {
    max-height: 400px;
    overflow: auto;
    opacity: 1;
    margin-top: 8px
}

/* Attachment chips */
.attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 16px 0
}

.attachments[hidden] {
    display: none
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 220px;
    min-height: 30px;
    padding: 4px 10px;
    border-radius: 9999px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: .8125rem
}

.attachment-chip img {
    width: 18px;
    height: 18px;
    border-radius: 3px;
    object-fit: cover
}

/* Stop button */
.stop-button {
    background: var(--error) !important;
    color: #fff !important
}

.stop-button[hidden] {
    display: none !important
}

.stop-button:not([hidden])+.btn-send[type=submit] {
    display: none
}

/* Modal */
.modal-scrim {
    position: fixed;
    inset: 0;
    z-index: 90;
    background: rgba(0, 0, 0, .5);
    backdrop-filter: blur(4px)
}

.modal-scrim[hidden] {
    display: none
}

.chat-modal {
    position: fixed;
    z-index: 100;
    border-radius: 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-4);
    opacity: 0;
    transform: translateY(8px) scale(.98);
    pointer-events: none;
    transition: opacity .16s ease, transform .16s ease
}

.chat-modal[hidden] {
    display: none
}

.chat-modal.open {
    opacity: 1;
    transform: none;
    pointer-events: auto
}

.modal-card {
    display: grid;
    gap: 16px;
    padding: 20px
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between
}

.modal-head strong {
    font-weight: 600;
    font-size: 1rem
}

.rename-field {
    display: grid;
    gap: 8px
}

.rename-field span {
    font-size: .6875rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-tertiary)
}

.rename-field input {
    height: 40px;
    padding: 0 12px;
    border-radius: 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    transition: all .2s ease
}

.rename-field input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--border-focus)
}

.modal-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px
}

.btn-secondary {
    height: 38px;
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: .8125rem;
    font-weight: 500;
    transition: background .2s
}

.btn-secondary:hover {
    background: var(--bg-tertiary)
}

.btn-danger {
    height: 38px;
    border-radius: 8px;
    background: rgba(220, 38, 38, .1);
    color: var(--error);
    font-size: .8125rem;
    font-weight: 500
}

.btn-danger:hover {
    background: rgba(220, 38, 38, .18)
}

/* Auth gate */
.auth-gate {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 24px;
    background: var(--bg-primary)
}

.auth-gate[hidden] {
    display: none
}

.auth-card {
    display: grid;
    justify-items: center;
    text-align: center;
    max-width: 400px;
    gap: 0
}

.google-login {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: 9999px;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    font-size: .9375rem;
    transition: all .2s ease
}

.google-login:hover {
    background: var(--accent-hover);
    transform: translateY(-1px)
}

/* Theme toggle icon swap */
[data-theme="dark"] #theme-icon-moon {
    display: none
}

[data-theme="dark"] #theme-icon-sun {
    display: block !important
}

[data-theme="light"] #theme-icon-moon {
    display: block
}

[data-theme="light"] #theme-icon-sun {
    display: none
}

/* Model selector effort animation */
.model-selector.effort-changing {
    animation: pulse .24s ease both
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1)
    }

    50% {
        transform: scale(1.03)
    }
}

[data-effort-label].text-changing {
    animation: effortSwap .22s ease both
}

@keyframes effortSwap {
    0% {
        opacity: .3;
        transform: translateY(3px)
    }

    100% {
        opacity: 1;
        transform: none
    }
}

/* drag-over state */
.composer.drag-over {
    border-color: var(--accent);
    box-shadow: var(--shadow-3), 0 0 0 3px var(--border-focus)
}

/* Send button always active (form-based, always accent) */
.btn-send[type=submit] {
    background: var(--accent);
    color: #fff
}

.btn-send[type=submit]:hover {
    background: var(--accent-hover)
}