/* ============================================================
   Claude AI — Telegram Mini App
   Complete Stylesheet — Editorial Minimal Aesthetic
   Follows DESIGN.md specification v1.1
   Screen-based navigation (no sidebar)
   ============================================================ */

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

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    scroll-behavior: smooth;
}

body {
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
    -webkit-appearance: none;
    appearance: none;
}

textarea {
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
}

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

ul, ol {
    list-style: none;
}

img {
    max-width: 100%;
    display: block;
}


/* === CSS VARIABLES — Section 9 === */

:root {
    /* === TYPOGRAPHY === */
    --font-serif: 'Crimson Pro', Georgia, 'Times New Roman', serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;

    --fs-xs: 10px;
    --fs-sm: 11px;
    --fs-code: 13px;
    --fs-input: 15px;
    --fs-body: 16px;
    --fs-body-lg: 17px;
    --fs-user: 14px;
    --fs-h3: 15px;
    --fs-h2: 20px;
    --fs-h1: 24px;
    --fs-empty: 28px;
    --fs-empty-lg: 36px;
    --fs-btn: 12px;

    --lh-tight: 1.2;
    --lh-code: 1.5;
    --lh-user: 1.55;
    --lh-body: 1.65;

    --fw-light: 300;
    --fw-regular: 400;
    --fw-medium: 500;
    --fw-semibold: 600;
    --fw-bold: 700;

    /* === SPACING === */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;

    /* === LAYOUT === */
    --header-height: 48px;
    --input-min-height: 44px;
    --input-max-height: 160px;
    --content-max-width: 720px;
    --send-btn-size: 40px;
    --touch-target-min: 44px;
    --code-header-height: 32px;

    /* === BORDERS === */
    --radius-sm: 3px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-xl: 12px;
    --radius-pill: 16px;
    --border-width: 1px;
    --border-accent-width: 2px;
    --border-quote-width: 3px;

    /* === TRANSITIONS === */
    --t-fast: 100ms;
    --t-normal: 150ms;
    --t-medium: 200ms;
    --t-slow: 250ms;
    --t-cursor: 800ms;
    --t-copied: 2000ms;
    --ease-out: cubic-bezier(0.0, 0.0, 0.2, 1);
    --ease-in: cubic-bezier(0.4, 0.0, 1, 1);
    --ease-in-out: cubic-bezier(0.4, 0.0, 0.2, 1);

    /* === Z-INDEX === */
    --z-content: 1;
    --z-header: 100;
    --z-scrim: 999;
    --z-sidebar: 1000;
    --z-modal-overlay: 1100;
    --z-modal: 1101;
    --z-dropdown: 1200;
}


/* === LIGHT THEME (default fallbacks) === */

:root {
    --color-bg: var(--tg-theme-bg-color, #f8f8f6);
    --color-text: var(--tg-theme-text-color, #1a1a18);
    --color-hint: var(--tg-theme-hint-color, #8a8a82);
    --color-link: var(--tg-theme-link-color, #b44a2d);
    --color-accent: var(--tg-theme-button-color, #b44a2d);
    --color-accent-text: var(--tg-theme-button-text-color, #ffffff);
    --color-secondary-bg: var(--tg-theme-secondary-bg-color, #efeeea);

    /* Derived colors */
    --color-border: #d8d5cc;
    --color-hover-bg: rgba(26, 26, 24, 0.04);
    --color-active-bg: rgba(26, 26, 24, 0.06);
    --color-user-border: var(--color-accent);
    --color-ai-border: #c4c0b8;
    --color-code-bg: #f0efe9;
    --color-code-border: #d8d5cc;
    --color-code-header-bg: #e8e7e1;
    --color-success: #5a8a42;
    --color-error: #c43b2d;
    --color-scrim: rgba(26, 26, 24, 0.4);
    --color-shadow: rgba(0, 0, 0, 0.12);

    /* Syntax highlighting */
    --hl-keyword: #8b5c3a;
    --hl-string: #5a7a42;
    --hl-number: #9a6030;
    --hl-comment: var(--color-hint);
    --hl-function: #6a5a8a;
    --hl-type: #5a7a8a;
    --hl-property: #7a6a5a;
}


/* === DARK THEME === */

.theme-dark {
    --color-bg: var(--tg-theme-bg-color, #0f0f0e);
    --color-text: var(--tg-theme-text-color, #e8e6e0);
    --color-hint: var(--tg-theme-hint-color, #6b6b63);
    --color-link: var(--tg-theme-link-color, #d4826a);
    --color-accent: var(--tg-theme-button-color, #d4826a);
    --color-accent-text: var(--tg-theme-button-text-color, #0f0f0e);
    --color-secondary-bg: var(--tg-theme-secondary-bg-color, #1a1a18);

    /* Derived colors */
    --color-border: #2a2a26;
    --color-hover-bg: rgba(232, 230, 224, 0.04);
    --color-active-bg: rgba(232, 230, 224, 0.06);
    --color-user-border: var(--color-accent);
    --color-ai-border: #3a3a35;
    --color-code-bg: #161614;
    --color-code-border: #2a2a26;
    --color-code-header-bg: #1e1e1c;
    --color-success: #7aaa62;
    --color-error: #e05545;
    --color-scrim: rgba(0, 0, 0, 0.5);
    --color-shadow: rgba(0, 0, 0, 0.4);

    /* Syntax highlighting */
    --hl-keyword: #d4826a;
    --hl-string: #8aaa6a;
    --hl-number: #d4a26a;
    --hl-comment: var(--color-hint);
    --hl-function: #a89ac4;
    --hl-type: #8ab4c4;
    --hl-property: #b4a494;
}


/* === BASE STYLES === */

body {
    font-family: var(--font-mono);
    font-size: var(--fs-body);
    line-height: var(--lh-body);
    color: var(--color-text);
    background-color: var(--color-bg);
}

#app {
    position: relative;
    height: 100dvh;
    width: 100%;
    overflow: hidden;
}


/* ============================================================
   SCREEN SYSTEM — Section 10
   ============================================================ */

.screen {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-bg);
    overflow: hidden;
    z-index: var(--z-content);
}

.screen.active {
    display: flex;
}

.screen-scroll {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Screen Transitions */
@keyframes slideInRight {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

@keyframes slideOutLeft {
    from { transform: translateX(0); }
    to { transform: translateX(-30%); opacity: 0.5; }
}

@keyframes slideInLeft {
    from { transform: translateX(-30%); opacity: 0.5; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOutRight {
    from { transform: translateX(0); }
    to { transform: translateX(100%); }
}

.slide-in-right {
    animation: slideInRight 250ms ease-out forwards;
    z-index: 2;
}

.slide-out-left {
    animation: slideOutLeft 250ms ease-out forwards;
    z-index: 1;
}

.slide-in-left {
    animation: slideInLeft 250ms ease-out forwards;
    z-index: 1;
}

.slide-out-right {
    animation: slideOutRight 250ms ease-out forwards;
    z-index: 2;
}

@media (prefers-reduced-motion: reduce) {
    .slide-in-right,
    .slide-out-left,
    .slide-in-left,
    .slide-out-right {
        animation: none;
    }
}

/* Screen header */
.screen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border);
    min-height: var(--header-height);
    font-family: var(--font-mono);
    flex-shrink: 0;
    background: var(--color-bg);
}

.screen-header h2 {
    font-family: var(--font-mono);
    font-size: var(--fs-code);
    font-weight: var(--fw-bold);
    color: var(--color-text);
    margin: 0;
}

.btn-header-action {
    font-family: var(--font-mono);
    font-size: 20px;
    color: var(--color-accent);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
}


/* ============================================================
   HOME SCREEN
   ============================================================ */

.home-header {
    padding: var(--space-8) var(--space-5) var(--space-4);
}

.home-title {
    font-family: var(--font-serif);
    font-size: var(--fs-h1);
    font-weight: var(--fw-semibold);
    color: var(--color-accent);
    margin: 0;
}

.btn-accent-full {
    display: block;
    width: calc(100% - var(--space-5) * 2);
    margin: var(--space-3) var(--space-5);
    padding: var(--space-3) var(--space-4);
    background: var(--color-accent);
    color: var(--color-accent-text);
    border: none;
    border-radius: var(--radius-lg);
    font-family: var(--font-mono);
    font-size: var(--fs-btn);
    font-weight: var(--fw-medium);
    text-align: center;
    cursor: pointer;
}

.home-nav {
    padding: var(--space-2) 0;
}

.nav-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: var(--space-4) var(--space-5);
    gap: var(--space-3);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text);
}

.nav-icon {
    font-size: 20px;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
}

.nav-text {
    flex: 1;
    text-align: left;
    font-family: var(--font-mono);
    font-size: var(--fs-body);
    font-weight: var(--fw-medium);
}

.nav-arrow {
    color: var(--color-hint);
    font-size: 18px;
}

.home-divider {
    height: 1px;
    background: var(--color-border);
    margin: var(--space-2) var(--space-5);
}

.home-recent {
    padding: var(--space-3) 0;
}

.home-section-title {
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    font-weight: var(--fw-bold);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--color-hint);
    padding: var(--space-2) var(--space-5);
    margin: 0;
}

.home-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--color-border);
    margin-top: auto;
}

.home-user {
    font-family: var(--font-mono);
    font-size: var(--fs-code);
    color: var(--color-hint);
}

.btn-icon-settings {
    font-size: 20px;
    color: var(--color-hint);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: none;
    border: none;
    border-radius: var(--radius-md);
}


/* ============================================================
   SEARCH BAR
   ============================================================ */

.search-bar {
    padding: var(--space-3) var(--space-4);
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--color-bg);
}

.search-bar input {
    width: 100%;
    padding: var(--space-3);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    background: var(--color-secondary-bg);
    font-family: var(--font-mono);
    font-size: var(--fs-code);
    color: var(--color-text);
    outline: none;
}

.search-bar input::placeholder {
    color: var(--color-hint);
}

.search-bar input:focus {
    border-color: var(--color-accent);
}


/* ============================================================
   LIST ITEMS
   ============================================================ */

.list-item {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
    transition: background var(--t-normal) ease;
}

.list-item-title {
    font-family: var(--font-mono);
    font-size: var(--fs-code);
    font-weight: var(--fw-medium);
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-item-meta {
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    color: var(--color-hint);
    margin-top: 2px;
}

.list-item-actions {
    display: flex;
    align-items: center;
}

.list-empty {
    padding: var(--space-6) var(--space-4);
    text-align: center;
    font-family: var(--font-mono);
    font-size: var(--fs-code);
    color: var(--color-hint);
}

.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.btn-delete-file {
    color: var(--color-error);
    font-size: 16px;
    background: none;
    border: none;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}


/* ============================================================
   PROJECT DETAIL
   ============================================================ */

.project-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
}

.project-card {
    background: var(--color-secondary-bg);
    border-radius: var(--radius-xl);
    padding: var(--space-4);
    cursor: pointer;
    text-align: center;
}

.project-card-icon {
    font-size: 28px;
    margin-bottom: var(--space-2);
}

.project-card-title {
    font-family: var(--font-mono);
    font-size: var(--fs-code);
    font-weight: var(--fw-medium);
    color: var(--color-text);
}

.project-card-meta {
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    color: var(--color-hint);
    margin-top: var(--space-1);
}

.project-detail-section {
    padding: var(--space-3) 0;
}

.section-title {
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    font-weight: var(--fw-bold);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--color-hint);
    padding: var(--space-2) var(--space-5);
    margin: 0;
}

.project-detail-bottom {
    padding: var(--space-4) var(--space-5);
    position: sticky;
    bottom: 0;
    background: var(--color-bg);
}

/* Project badge in chat */
.project-badge {
    padding: var(--space-2) var(--space-5);
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    color: var(--color-hint);
    background: var(--color-secondary-bg);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

/* Knowledge count */
.knowledge-count {
    font-family: var(--font-mono);
    font-size: var(--fs-code);
    color: var(--color-hint);
    padding: var(--space-3) var(--space-5);
}


/* ============================================================
   SETTINGS
   ============================================================ */

.settings-section {
    padding: var(--space-5);
}

.settings-label {
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    color: var(--color-hint);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--space-3);
    margin-top: 0;
}

.settings-select {
    width: 100%;
    padding: var(--space-3);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    background: var(--color-secondary-bg);
    font-family: var(--font-mono);
    font-size: var(--fs-code);
    color: var(--color-text);
    outline: none;
}

.settings-select:focus {
    border-color: var(--color-accent);
}

.settings-about {
    text-align: center;
    color: var(--color-hint);
    font-family: var(--font-mono);
    font-size: var(--fs-code);
}

.settings-hint {
    font-size: var(--fs-sm);
    margin-top: var(--space-1);
}

/* Theme switcher */
.theme-switcher {
    display: flex;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--color-border);
}

.theme-btn {
    flex: 1;
    padding: var(--space-3) var(--space-2);
    border: none;
    background: var(--color-secondary-bg);
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    color: var(--color-text);
    transition: background var(--t-normal) ease, color var(--t-normal) ease;
}

.theme-btn.active {
    background: var(--color-accent);
    color: var(--color-accent-text);
}


/* ============================================================
   CHAT HEADER — Section 5.2
   ============================================================ */

.chat-header {
    display: flex;
    align-items: center;
    height: var(--header-height);
    min-height: var(--header-height);
    padding: 0 var(--space-4);
    background: var(--color-bg);
    border-bottom: var(--border-width) solid var(--color-border);
    z-index: var(--z-header);
    flex-shrink: 0;
}

/* Breadcrumb title */
.chat-title {
    flex: 1;
    overflow: hidden;
    display: flex;
    align-items: center;
    min-width: 0;
}

#chat-name {
    font-family: var(--font-mono);
    font-size: var(--fs-code);
    font-weight: var(--fw-medium);
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-model {
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    color: var(--color-hint);
    margin-left: var(--space-2);
    flex-shrink: 0;
}

/* Header action buttons */
.chat-actions {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    flex-shrink: 0;
    margin-left: var(--space-2);
}

.btn-new-chat,
.btn-chat-settings {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    font-size: 18px;
    transition: background var(--t-normal) ease;
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
}

.btn-new-chat {
    color: var(--color-accent);
    font-weight: var(--fw-medium);
}

.btn-chat-settings {
    color: var(--color-hint);
    font-size: 20px;
    letter-spacing: -1px;
}


/* ============================================================
   MESSAGES AREA — Section 5.3 / 5.4
   ============================================================ */

.messages-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: var(--space-6) var(--space-4);
    scroll-behavior: smooth;
}

/* Message bubble — shared base (NOT bubbles — full-width text blocks) */
.message-bubble {
    max-width: var(--content-max-width);
    margin: 0 auto var(--space-6);
    padding: var(--space-3) 0 var(--space-3) var(--space-4);
    border-left: var(--border-accent-width) solid transparent;
    animation: message-fade-in var(--t-medium) ease;
}

/* Role label — shared */
.message-role {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.message-role-name {
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.message-timestamp {
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    font-weight: var(--fw-regular);
    color: var(--color-hint);
}


/* === USER MESSAGE — Section 5.3 === */

.message-bubble.user {
    border-left-color: var(--color-user-border);
}

.message-bubble.user .message-role-name {
    color: var(--color-accent);
}

.message-bubble.user .message-body {
    font-family: var(--font-mono);
    font-size: var(--fs-user);
    font-weight: var(--fw-regular);
    line-height: var(--lh-user);
    color: var(--color-text);
    white-space: pre-wrap;
    word-break: break-word;
}


/* === ASSISTANT MESSAGE — Section 5.4 === */

.message-bubble.assistant {
    border-left-color: var(--color-ai-border);
}

.message-bubble.assistant .message-role-name {
    color: var(--color-text);
    opacity: 0.7;
}

.message-model-badge {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: var(--fw-regular);
    color: var(--color-hint);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 1px 5px;
    margin-left: var(--space-2);
    vertical-align: middle;
}

/* Markdown rendered content inside assistant messages */
.message-bubble.assistant .message-body {
    font-family: var(--font-serif);
    font-size: var(--fs-body);
    font-weight: var(--fw-regular);
    line-height: var(--lh-body);
    color: var(--color-text);
    word-break: break-word;
}

/* Paragraphs */
.message-bubble.assistant .message-body p {
    margin-bottom: var(--space-4);
}

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

/* Headings in AI response */
.message-bubble.assistant .message-body h1 {
    font-family: var(--font-serif);
    font-size: var(--fs-h1);
    font-weight: var(--fw-semibold);
    margin-top: 28px;
    margin-bottom: var(--space-3);
    color: var(--color-text);
    line-height: var(--lh-tight);
}

.message-bubble.assistant .message-body h2 {
    font-family: var(--font-serif);
    font-size: var(--fs-h2);
    font-weight: var(--fw-semibold);
    margin-top: var(--space-6);
    margin-bottom: 10px;
    color: var(--color-text);
    line-height: var(--lh-tight);
}

.message-bubble.assistant .message-body h3 {
    font-family: var(--font-mono);
    font-size: var(--fs-h3);
    font-weight: var(--fw-bold);
    margin-top: var(--space-5);
    margin-bottom: var(--space-2);
    color: var(--color-text);
    line-height: var(--lh-tight);
}

/* Bold & italic */
.message-bubble.assistant .message-body strong {
    font-weight: var(--fw-semibold);
}

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

/* Inline code */
.message-bubble.assistant .message-body code:not([class*="language-"]) {
    font-family: var(--font-mono);
    font-size: var(--fs-code);
    background: var(--color-code-bg);
    padding: 2px 5px;
    border-radius: var(--radius-sm);
    line-height: inherit;
}

/* Links */
.message-bubble.assistant .message-body a {
    color: var(--color-link);
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color var(--t-normal) ease;
}

/* Unordered lists */
.message-bubble.assistant .message-body ul {
    padding-left: var(--space-5);
    margin-bottom: var(--space-4);
}

.message-bubble.assistant .message-body ul li {
    position: relative;
    padding-left: 0;
    margin-bottom: 6px;
    list-style: disc;
    font-family: var(--font-serif);
    font-size: inherit;
    line-height: inherit;
}

.message-bubble.assistant .message-body ul li::marker {
    color: var(--color-accent);
    font-size: 6px;
}

/* Nested list spacing */
.message-bubble.assistant .message-body ul ul,
.message-bubble.assistant .message-body ol ol,
.message-bubble.assistant .message-body ul ol,
.message-bubble.assistant .message-body ol ul {
    margin-top: var(--space-1);
    margin-bottom: var(--space-1);
}

.message-bubble.assistant .message-body ul ul li,
.message-bubble.assistant .message-body ol ol li {
    margin-bottom: var(--space-1);
}

/* Ordered lists */
.message-bubble.assistant .message-body ol {
    padding-left: var(--space-5);
    margin-bottom: var(--space-4);
    counter-reset: item;
    list-style: none;
}

.message-bubble.assistant .message-body ol li {
    counter-increment: item;
    margin-bottom: 6px;
    font-family: var(--font-serif);
}

.message-bubble.assistant .message-body ol li::before {
    content: counter(item) ".";
    font-family: var(--font-serif);
    font-weight: var(--fw-semibold);
    color: var(--color-accent);
    margin-right: var(--space-2);
}

/* Blockquotes */
.message-bubble.assistant .message-body blockquote {
    border-left: var(--border-quote-width) solid var(--color-accent);
    border-left-color: rgba(180, 74, 45, 0.4);
    padding-left: var(--space-4);
    margin: var(--space-4) 0;
    font-family: var(--font-serif);
    font-style: italic;
    font-size: var(--fs-body);
    color: var(--color-text);
    opacity: 0.85;
}

.theme-dark .message-bubble.assistant .message-body blockquote {
    border-left-color: rgba(212, 130, 106, 0.4);
}

/* Tables */
.message-bubble.assistant .message-body .table-wrapper {
    overflow-x: auto;
    margin: var(--space-4) 0;
    border-radius: var(--radius-sm);
    -webkit-overflow-scrolling: touch;
}

.message-bubble.assistant .message-body table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: var(--fs-btn);
    font-weight: var(--fw-regular);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-sm);
}

.message-bubble.assistant .message-body th {
    font-weight: var(--fw-medium);
    background: var(--color-code-bg);
    padding: var(--space-2) var(--space-3);
    text-align: left;
    border: var(--border-width) solid var(--color-border);
}

.message-bubble.assistant .message-body td {
    padding: var(--space-2) var(--space-3);
    border: var(--border-width) solid var(--color-border);
}

/* Horizontal rule */
.message-bubble.assistant .message-body hr {
    border: none;
    border-top: var(--border-width) solid var(--color-border);
    margin: var(--space-6) 0;
}


/* ============================================================
   CODE BLOCKS — Section 5.5
   ============================================================ */

.code-block {
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--color-code-bg);
    border: var(--border-width) solid var(--color-code-border);
    margin: var(--space-4) 0;
    max-width: 100%;
}

/* Override any default pre styles */
pre.code-block {
    padding: 0;
    white-space: pre;
}

/* Code header bar */
.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--code-header-height);
    padding: 0 var(--space-3);
    background: var(--color-code-header-bg);
    border-bottom: var(--border-width) solid var(--color-code-border);
}

.code-lang {
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-hint);
}

/* Copy button */
.copy-btn {
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    color: var(--color-hint);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    min-width: 32px;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--t-normal) ease;
}

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

/* Code content */
.code-block code {
    display: block;
    font-family: var(--font-mono);
    font-size: var(--fs-code);
    font-weight: var(--fw-regular);
    line-height: var(--lh-code);
    padding: 14px var(--space-4);
    color: var(--color-text);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    tab-size: 4;
    -moz-tab-size: 4;
    white-space: pre;
    word-wrap: normal;
}

/* Code selection */
.code-block code::selection,
.code-block code *::selection {
    background: rgba(180, 74, 45, 0.2);
}

.theme-dark .code-block code::selection,
.theme-dark .code-block code *::selection {
    background: rgba(212, 130, 106, 0.2);
}


/* ============================================================
   CUSTOM SYNTAX HIGHLIGHTING — Section 5.5 token colors
   Override highlight.js default theme
   ============================================================ */

/* Keywords: if, for, while, return, class, def, etc. */
.hljs-keyword,
.hljs-selector-tag,
.hljs-built_in,
.hljs-literal {
    color: var(--hl-keyword);
}

/* Strings */
.hljs-string,
.hljs-doctag,
.hljs-template-variable,
.hljs-template-tag {
    color: var(--hl-string);
}

/* Numbers */
.hljs-number {
    color: var(--hl-number);
}

/* Comments */
.hljs-comment,
.hljs-quote {
    color: var(--hl-comment);
    font-style: italic;
}

/* Functions */
.hljs-title.function_,
.hljs-title.class_.inherited__,
.hljs-section {
    color: var(--hl-function);
}

/* Types / Classes */
.hljs-title,
.hljs-type,
.hljs-title.class_ {
    color: var(--hl-type);
}

/* Operators & Variables — use text color */
.hljs-variable,
.hljs-selector-id,
.hljs-selector-class {
    color: var(--color-text);
}

/* Properties / Attributes */
.hljs-attr,
.hljs-attribute,
.hljs-name,
.hljs-params {
    color: var(--hl-property);
}

/* Meta / Preprocessor */
.hljs-meta,
.hljs-meta .hljs-keyword {
    color: var(--color-hint);
}

/* Deletion / Addition (diffs) */
.hljs-deletion {
    color: var(--color-error);
}

.hljs-addition {
    color: var(--color-success);
}

/* Emphasis */
.hljs-emphasis {
    font-style: italic;
}

.hljs-strong {
    font-weight: var(--fw-bold);
}

/* Reset any background from imported hljs themes */
.hljs {
    background: transparent !important;
    padding: 0 !important;
    color: var(--color-text);
}


/* ============================================================
   INPUT AREA — Section 5.6
   ============================================================ */

.input-area {
    flex-shrink: 0;
    padding: var(--space-3) var(--space-4);
    padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
    background: var(--color-bg);
    border-top: var(--border-width) solid var(--color-border);
    z-index: var(--z-content);
}

.input-wrapper {
    width: 100%;
}

.message-input {
    display: block;
    width: 100%;
    font-family: var(--font-mono);
    font-size: var(--fs-input);
    font-weight: var(--fw-regular);
    line-height: var(--lh-code);
    color: var(--color-text);
    background: var(--color-secondary-bg);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-3) 14px;
    min-height: var(--input-min-height);
    max-height: var(--input-max-height);
    resize: none;
    outline: none;
    overflow-y: auto;
    transition: border-color var(--t-normal) ease;
}

.message-input::placeholder {
    color: var(--color-hint);
}

.message-input:focus {
    border-color: var(--color-accent);
}

.input-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: var(--space-2);
}

.btn-send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--send-btn-size);
    height: var(--send-btn-size);
    border-radius: 50%;
    background: var(--color-accent);
    color: var(--color-accent-text);
    transition: transform var(--t-normal) ease, opacity var(--t-normal) ease;
    flex-shrink: 0;
}

.btn-send:disabled {
    opacity: 0.35;
    pointer-events: none;
}

.btn-send svg {
    width: 18px;
    height: 18px;
}


/* ============================================================
   STREAMING CURSOR — Section 5.7
   ============================================================ */

@keyframes cursor-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.streaming-cursor {
    display: inline-block;
    width: 8px;
    height: 1.1em;
    background: var(--color-accent);
    vertical-align: text-bottom;
    animation: cursor-pulse var(--t-cursor) ease-in-out infinite;
    margin-left: 2px;
}

.streaming-cursor.fade-out {
    animation: none;
    opacity: 0;
    transition: opacity 300ms ease;
}


/* ============================================================
   EMPTY STATE — Section 5.8
   ============================================================ */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    height: 100%;
    padding: var(--space-4);
    /* Offset slightly above true center */
    padding-bottom: 20%;
}

.empty-state-heading {
    font-family: var(--font-serif);
    font-size: var(--fs-empty);
    font-weight: var(--fw-light);
    color: var(--color-text);
    line-height: var(--lh-tight);
    margin-bottom: var(--space-4);
}

.empty-state-text {
    font-family: var(--font-serif);
    font-size: var(--fs-body);
    font-weight: var(--fw-light);
    color: var(--color-hint);
    line-height: 1.5;
    max-width: 280px;
    margin-bottom: var(--space-6);
}

/* Suggestion chips */
.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-1);
    max-width: 320px;
}

.chip {
    font-family: var(--font-mono);
    font-size: var(--fs-btn);
    font-weight: var(--fw-regular);
    color: var(--color-text);
    opacity: 0.8;
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-pill);
    padding: 6px 14px;
    background: transparent;
    cursor: pointer;
    transition: border-color var(--t-normal) ease, color var(--t-normal) ease;
    white-space: nowrap;
}


/* ============================================================
   MODAL / DIALOG — Section 5.9
   ============================================================ */

.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-scrim);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: var(--z-modal-overlay);
    opacity: 0;
    transition: opacity var(--t-medium) ease;
}

.modal-overlay.visible {
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
}

.modal {
    background: var(--color-bg);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-xl);
    box-shadow: 0 8px 32px var(--color-shadow);
    width: calc(100% - 48px);
    max-width: 400px;
    padding: var(--space-6);
    z-index: var(--z-modal);
    transform: translateY(8px);
    opacity: 0;
    transition: transform var(--t-medium) var(--ease-out),
                opacity var(--t-medium) var(--ease-out);
}

.modal-overlay.visible .modal {
    transform: translateY(0);
    opacity: 1;
}

.modal-title {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: var(--fw-bold);
    color: var(--color-text);
    margin-bottom: var(--space-3);
}

.modal-body {
    font-family: var(--font-serif);
    font-size: 15px;
    font-weight: var(--fw-regular);
    color: var(--color-text);
    margin-bottom: var(--space-5);
    line-height: var(--lh-body);
}

.modal-body .text-error {
    color: var(--color-error);
}

/* Modal input field */
.modal-body input[type="text"],
.modal-body .modal-input {
    display: block;
    width: 100%;
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: var(--fw-regular);
    color: var(--color-text);
    background: var(--color-secondary-bg);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-2) var(--space-3);
    height: 40px;
    outline: none;
    transition: border-color var(--t-normal) ease;
}

.modal-body input[type="text"]:focus,
.modal-body .modal-input:focus {
    border-color: var(--color-accent);
}

/* Modal buttons */
.modal-actions {
    display: flex;
    gap: var(--space-2);
    justify-content: flex-end;
}

.btn-modal-cancel {
    font-family: var(--font-mono);
    font-size: var(--fs-btn);
    font-weight: var(--fw-medium);
    color: var(--color-hint);
    background: transparent;
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-4);
    cursor: pointer;
    transition: background var(--t-normal) ease;
}

.btn-modal-confirm {
    font-family: var(--font-mono);
    font-size: var(--fs-btn);
    font-weight: var(--fw-medium);
    color: var(--color-accent-text);
    background: var(--color-accent);
    border: none;
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-4);
    cursor: pointer;
    transition: filter var(--t-normal) ease;
}

.btn-modal-delete {
    font-family: var(--font-mono);
    font-size: var(--fs-btn);
    font-weight: var(--fw-medium);
    color: #ffffff;
    background: var(--color-error);
    border: none;
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-4);
    cursor: pointer;
    transition: filter var(--t-normal) ease;
}


/* ============================================================
   OPTIONS DROPDOWN
   ============================================================ */

.options-dropdown {
    display: none;
    position: fixed;
    background: var(--color-bg);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 16px var(--color-shadow);
    z-index: var(--z-dropdown);
    min-width: 180px;
    padding: var(--space-1) 0;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity var(--t-normal) var(--ease-out),
                transform var(--t-normal) var(--ease-out);
}

.options-dropdown.visible {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.dropdown-item {
    display: block;
    width: 100%;
    text-align: left;
    font-family: var(--font-mono);
    font-size: var(--fs-code);
    font-weight: var(--fw-regular);
    color: var(--color-text);
    padding: var(--space-2) var(--space-4);
    cursor: pointer;
    transition: background var(--t-normal) ease;
}

.dropdown-item[data-action="delete-chat"] {
    color: var(--color-error);
}


/* ============================================================
   MESSAGE FADE-IN ANIMATION — Section 7
   ============================================================ */

@keyframes message-fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}


/* ============================================================
   HOVER STATES — Desktop only
   ============================================================ */

@media (hover: hover) {
    .nav-item:hover {
        background: var(--color-hover-bg);
    }

    .list-item:hover {
        background: var(--color-hover-bg);
    }

    .btn-accent-full:hover {
        filter: brightness(1.1);
    }

    .btn-icon-settings:hover {
        background: var(--color-hover-bg);
    }

    .btn-header-action:hover {
        background: var(--color-hover-bg);
    }

    .project-card:hover {
        filter: brightness(0.97);
    }

    .theme-btn:hover:not(.active) {
        background: var(--color-hover-bg);
    }

    .btn-new-chat:hover,
    .btn-chat-settings:hover {
        background: var(--color-hover-bg);
    }

    .chip:hover {
        border-color: var(--color-accent);
        color: var(--color-accent);
        opacity: 1;
    }

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

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

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

    .btn-modal-cancel:hover {
        background: var(--color-hover-bg);
    }

    .btn-modal-confirm:hover {
        filter: brightness(1.1);
    }

    .btn-modal-delete:hover {
        filter: brightness(1.1);
    }

    .dropdown-item:hover {
        background: var(--color-hover-bg);
    }

    .message-bubble.assistant .message-body a:hover {
        color: var(--color-accent);
    }
}


/* ============================================================
   FOCUS STATES — Accessibility
   ============================================================ */

button:focus-visible,
a:focus-visible,
textarea:focus-visible,
input:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* Remove default outline for mouse users */
button:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
    outline: none;
}


/* ============================================================
   RESPONSIVE — Section 8
   ============================================================ */

/* ----- Tablet: 769px+ ----- */

@media (min-width: 769px) {
    /* Chat padding adjustments */
    .messages-area {
        padding: var(--space-6) var(--space-5);
    }

    /* Font size adjustments */
    .message-bubble.assistant .message-body {
        font-size: var(--fs-body);
    }

    .code-block code {
        font-size: var(--fs-code);
    }

    .empty-state-heading {
        font-size: 32px;
    }

    .empty-state-text {
        font-size: 18px;
    }

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


/* ----- Desktop: 1025px+ ----- */

@media (min-width: 1025px) {
    /* Chat area padding */
    .messages-area {
        padding: var(--space-6);
    }

    /* Center messages with max-width */
    .message-bubble {
        max-width: var(--content-max-width);
        margin-left: auto;
        margin-right: auto;
    }

    /* Desktop font sizes */
    .message-bubble.assistant .message-body {
        font-size: var(--fs-body-lg);
    }

    .code-block code {
        font-size: 13.5px;
    }

    /* Empty state desktop size */
    .empty-state-heading {
        font-size: var(--fs-empty-lg);
    }

    .empty-state-text {
        font-size: 18px;
    }

    /* Input area */
    .input-area {
        padding: var(--space-3) var(--space-6);
        padding-bottom: var(--space-3);
    }

    /* Input and send centered */
    .input-wrapper {
        max-width: var(--content-max-width);
        margin: 0 auto;
    }

    .input-actions {
        max-width: var(--content-max-width);
        margin-left: auto;
        margin-right: auto;
    }

    /* Header padding */
    .chat-header {
        padding: 0 var(--space-6);
    }
}


/* ============================================================
   REDUCED MOTION — Section 7
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .streaming-cursor {
        animation: none;
        opacity: 1;
    }
}


/* ============================================================
   UTILITY CLASSES
   ============================================================ */

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.text-error {
    color: var(--color-error);
}

.text-success {
    color: var(--color-success);
}

.text-hint {
    color: var(--color-hint);
}


/* ============================================================
   SCROLLBAR STYLING
   ============================================================ */

.messages-area::-webkit-scrollbar,
.screen-scroll::-webkit-scrollbar,
.code-block code::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

.messages-area::-webkit-scrollbar-track,
.screen-scroll::-webkit-scrollbar-track,
.code-block code::-webkit-scrollbar-track {
    background: transparent;
}

.messages-area::-webkit-scrollbar-thumb,
.screen-scroll::-webkit-scrollbar-thumb,
.code-block code::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 2px;
}

.messages-area::-webkit-scrollbar-thumb:hover,
.screen-scroll::-webkit-scrollbar-thumb:hover {
    background: var(--color-hint);
}

/* Firefox scrollbar */
.messages-area,
.screen-scroll,
.code-block code {
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
}


/* ============================================================
   LOADING STATE — typing indicator
   ============================================================ */

.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: var(--space-2) 0;
}

.typing-indicator .dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--color-hint);
    animation: typing-bounce 1.4s ease-in-out infinite;
}

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

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

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}


/* ============================================================
   MESSAGE DIVIDER (between messages, date separator)
   ============================================================ */

.message-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: var(--space-6) auto;
    max-width: var(--content-max-width);
}

.message-divider span {
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    font-weight: var(--fw-regular);
    color: var(--color-hint);
    padding: 0 var(--space-3);
    background: var(--color-bg);
    position: relative;
    z-index: 1;
}

.message-divider::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: var(--border-width);
    background: var(--color-border);
}


/* ============================================================
   ERROR TOAST / NOTIFICATION BAR
   ============================================================ */

.toast {
    position: fixed;
    bottom: calc(var(--space-12) + var(--space-10) + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    font-family: var(--font-mono);
    font-size: var(--fs-code);
    font-weight: var(--fw-medium);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-lg);
    z-index: var(--z-modal);
    opacity: 0;
    transition: transform var(--t-medium) var(--ease-out),
                opacity var(--t-medium) var(--ease-out);
    white-space: nowrap;
}

.toast.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.error {
    background: var(--color-error);
    color: #ffffff;
}

.toast.success {
    background: var(--color-success);
    color: #ffffff;
}
