@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,300;0,400;1,300&family=Epilogue:wght@200;300;400;500&family=JetBrains+Mono:wght@400;500&display=swap');

/* ═══ LIGHT THEME ═══ */
[data-theme="light"] {
    --bg-primary: #f5f5f7;
    --bg-secondary: #ffffff;
    --bg-tertiary: #ebebed;
    --bg-elevated: #e2e2e6;
    --bg-hover: #e5e5ea;
    --bg-input: #ffffff;
    --text-primary: #1d1d1f;
    --text-secondary: #424245;
    --text-muted: #86868b;
    --text-dim: #c7c7cc;
    --border: rgba(0, 0, 0, 0.07);
    --border-light: rgba(0, 0, 0, 0.10);
    --border-medium: rgba(0, 0, 0, 0.14);
    --accent-dim: rgba(20, 104, 240, 0.07);
    --accent-border: rgba(20, 104, 240, 0.22);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 20px rgba(20, 104, 240, 0.12);
    --code-bg: #f0f0f5;
    --gradient-subtle: linear-gradient(135deg, rgba(20, 104, 240, 0.04), rgba(61, 139, 255, 0.02));
}

[data-theme="light"] .top-bar {
    background: rgba(245, 245, 247, 0.85)
}

[data-theme="light"] .app-container::before {
    background: radial-gradient(circle, rgba(20, 104, 240, 0.03), transparent 70%)
}

[data-theme="light"] .sidebar::after {
    opacity: 0.08
}

[data-theme="light"] pre {
    background: #f0f0f5 !important
}

[data-theme="light"] .browser-mockup-inner {
    background: #f5f5f7
}

/* ═══ ROOT / DARK THEME ═══ */
: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;
    --blue-glow: rgba(20, 104, 240, 0.18);

    --accent-dim: rgba(20, 104, 240, 0.1);
    --accent-border: rgba(20, 104, 240, 0.28);
    --accent-glow: rgba(20, 104, 240, 0.18);

    --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;
    --gradient-subtle: linear-gradient(135deg, rgba(20, 104, 240, 0.06), rgba(61, 139, 255, 0.03));

    --sidebar-width: 268px;
    --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);
    --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --r-xs: 6px;
    --r-sm: 10px;
    --r-md: 14px;
    --r-lg: 18px;
    --r-xl: 24px;
    --r-full: 9999px;
}

*,
*::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;
    text-rendering: optimizeLegibility;
}

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

.app-container::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;
    transition: transform .3s var(--ease);
    z-index: 100;
    position: relative;
    flex-shrink: 0;
}

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

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

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

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

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

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

.new-chat-btn {
    width: 36px;
    height: 36px;
    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;
    transition: all .2s var(--ease);
    flex-shrink: 0;
}

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

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

.sidebar-chats {
    flex: 1;
    overflow-y: auto;
    padding: 14px 10px;
    -webkit-overflow-scrolling: touch
}

.chat-section-label {
    padding: 8px 12px 6px;
    font-size: 10px;
    font-weight: 400;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 2px
}

.chat-history-item {
    padding: 11px 14px;
    border-radius: var(--r-sm);
    cursor: pointer;
    font-size: 12.5px;
    font-weight: 300;
    color: var(--text-secondary);
    transition: all .15s var(--ease);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
    min-height: 40px;
    display: flex;
    align-items: center;
}

.chat-history-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    padding-left: 18px
}

.chat-history-item.active {
    background: var(--accent-dim);
    color: var(--text-primary);
    border-left: 2px solid var(--blue);
    padding-left: 16px
}

.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--border)
}

.model-badge {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 11px;
    font-weight: 300;
    color: var(--text-muted);
    padding: 10px 14px;
    background: var(--gradient-subtle);
    border-radius: var(--r-sm);
    border: 1px solid var(--border-light);
    letter-spacing: .5px;
}

.pulse-dot {
    width: 7px;
    height: 7px;
    background: #22c55e;
    border-radius: 50%;
    position: relative;
    flex-shrink: 0
}

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

@keyframes pulseRing {

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

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

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

/* ═══ TOP BAR ═══ */
.top-bar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 13px 24px;
    border-bottom: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(20px) saturate(1.5);
    -webkit-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: 6px;
    border-radius: var(--r-xs);
    transition: all .15s var(--ease);
}

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

.top-bar-title {
    font-family: var(--font-b);
    font-size: 14px;
    font-weight: 300;
    letter-spacing: 3px;
    color: var(--text-primary)
}

.top-bar-actions {
    margin-left: auto;
    display: flex;
    gap: 8px
}

.icon-btn {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid var(--border-light);
    border-radius: var(--r-sm);
    color: var(--text-muted);
    cursor: pointer;
    text-decoration: none;
    transition: all .15s var(--ease);
}

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

/* ═══ CHAT AREA ═══ */
.chat-area {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    position: relative
}

/* ═══ WELCOME ═══ */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 60px 24px;
    text-align: center;
}

.welcome-screen.hidden {
    display: none
}

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

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

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

.welcome-subtitle {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 300;
    margin-bottom: 40px;
    line-height: 1.6;
    max-width: 380px
}

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

.suggestion-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    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);
}

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

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

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

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

/* ═══ MESSAGES ═══ */
.messages-container {
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
    padding: 24px 0 32px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.message {
    padding: 4px 16px;
    animation: msgIn .35s var(--ease) forwards
}

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

    to {
        opacity: 1;
        transform: none
    }
}

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

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

.message.assistant .message-inner {
    background: transparent
}

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

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

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 13px;
    font-weight: 400;
}

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

.message.assistant .message-avatar {
    background: var(--blue);
    box-shadow: 0 2px 8px rgba(20, 104, 240, 0.3)
}

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

.message-role {
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 8px
}

.message.assistant .message-role {
    color: var(--blue-b);
    opacity: .7
}

/* ═══ MESSAGE TEXT ═══ */
.message-text {
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.78;
    font-weight: 300
}

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

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

.message-text ul,
.message-text ol {
    padding-left: 20px;
    margin-bottom: 12px
}

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

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

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

.message-text a {
    color: var(--blue-b);
    text-decoration: none;
    border-bottom: 1px solid rgba(61, 139, 255, 0.3);
    transition: border-color .2s
}

.message-text a:hover {
    border-bottom-color: var(--blue-b)
}

.message-text h1,
.message-text h2,
.message-text h3 {
    font-family: var(--font-d);
    font-weight: 300;
    margin: 20px 0 10px;
    line-height: 1.2
}

.message-text h1 {
    font-size: 22px
}

.message-text h2 {
    font-size: 19px
}

.message-text h3 {
    font-size: 16px
}

.message-text blockquote {
    border-left: 2px solid var(--blue);
    margin: 12px 0;
    padding: 10px 16px;
    color: var(--text-secondary);
    font-style: italic;
}

.message-text pre {
    background: var(--code-bg);
    border: 1px solid var(--border-light);
    border-radius: var(--r-md);
    padding: 18px 20px;
    overflow-x: auto;
    margin: 14px 0;
    position: relative;
}

.message-text code {
    font-family: var(--font-m);
    font-size: 13px;
    line-height: 1.6;
    color: var(--blue-s);
    background: transparent;
}

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

.message-text table {
    border-collapse: collapse;
    width: 100%;
    margin: 14px 0;
    font-size: 13px
}

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

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

.message-text tr:nth-child(even) td {
    background: var(--bg-secondary)
}

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

/* ═══ TYPING ═══ */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 4px 0
}

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

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

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

@keyframes typingDot {

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

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

/* ═══ SEARCH BADGE ═══ */
.searching-indicator {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 12px;
    background: var(--accent-dim);
    border: 1px solid var(--accent-border);
    border-radius: var(--r-full);
    font-size: 11px;
    font-weight: 300;
    color: var(--blue-b);
    letter-spacing: .5px;
    margin-left: 46px;
    margin-bottom: 6px;
}

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

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

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

.input-wrapper textarea {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    resize: none;
    font-family: var(--font-b);
    font-size: 14px;
    font-weight: 300;
    line-height: 1.6;
    color: var(--text-primary);
    max-height: 200px;
    padding: 0;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.input-wrapper textarea::-webkit-scrollbar {
    display: none
}

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

.send-btn {
    width: 38px;
    height: 38px;
    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
}

.input-area>.input-wrapper {
    max-width: 760px
}

.input-disclaimer {
    text-align: center;
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 10px;
    font-weight: 300;
    letter-spacing: .2px
}

/* ═══ SCROLLBAR ═══ */
::-webkit-scrollbar {
    width: 4px
}

::-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.14)
}

/* ═══ RESPONSIVE ═══ */
@media(min-width:1200px) {

    .messages-container,
    .input-area .input-wrapper {
        max-width: 860px
    }
}

@media(max-width:1024px) {
    :root {
        --sidebar-width: 240px
    }

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

    .messages-container {
        max-width: 660px
    }
}

@media(max-width:768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        height: 100%;
        transform: translateX(-100%);
        width: 280px
    }

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

    .menu-toggle {
        display: flex
    }

    .messages-container {
        max-width: 100%;
        padding: 16px 0 24px
    }

    .message {
        padding: 3px 10px
    }

    .message-inner {
        padding: 10px 12px;
        gap: 10px
    }

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

    .message-text {
        font-size: 13.5px
    }

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

    .input-area {
        padding: 0 12px 16px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px))
    }

    .input-wrapper {
        padding: 9px 10px 9px 16px
    }

    .input-wrapper textarea {
        font-size: 16px;
        min-height: 24px;
    }

    .suggestion-grid {
        grid-template-columns: 1fr;
        max-width: 100%
    }

    .top-bar {
        padding: 10px 14px
    }

    .top-bar-title {
        font-size: 12px;
        letter-spacing: 2.5px
    }

    .welcome-screen {
        padding: 32px 16px
    }

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

    .welcome-logo {
        width: 56px;
        height: 56px;
        border-radius: 14px;
        margin-bottom: 20px;
    }

    .sidebar-footer {
        display: none
    }
}

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

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

    .suggestion-card {
        padding: 12px 14px;
        gap: 10px;
    }
    
    .suggestion-text {
        font-size: 12px;
    }

    .input-area {
        padding: 0 8px 8px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px))
    }

    .input-disclaimer {
        margin-top: 6px;
        font-size: 10px;
    }
}

/* ═══ BACKDROP ═══ */
.sidebar-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
}

.sidebar-backdrop.visible {
    display: block
}

@keyframes fadeIn {
    from {
        opacity: 0
    }

    to {
        opacity: 1
    }
}

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