/* ============================================
   FRACTAL_EDIT — "Fractal Monolith" Design System
   Mathematical Brutalism + Electric Accent
   ============================================ */

/* --- Design Tokens --- */
:root {
    /* Surface Hierarchy */
    --surface: #f9f9f9;
    --surface-dim: #dadada;
    --surface-bright: #f9f9f9;
    --surface-container-lowest: #ffffff;
    --surface-container-low: #f3f3f3;
    --surface-container: #eeeeee;
    --surface-container-high: #e8e8e8;
    --surface-container-highest: #e2e2e2;
    --surface-variant: #e2e2e2;

    /* Primary: Absolute Black */
    --primary: #000000;
    --primary-container: #3b3b3b;
    --on-primary: #ffffff;
    --on-primary-container: #ffffff;

    /* Accent: Electric Blue — the ONLY color */
    --accent: #0055FF;
    --accent-dim: #003FCC;
    --accent-light: #e8efff;
    --on-accent: #ffffff;

    /* Success */
    --success: #00CC66;
    --success-light: #e6fff0;

    /* Neutral Content */
    --on-surface: #1b1b1b;
    --on-surface-variant: #474747;
    --on-background: #1b1b1b;
    --outline: #777777;
    --outline-variant: #c6c6c6;
    --background: #f9f9f9;

    /* Error */
    --error: #ba1a1a;
    --on-error: #ffffff;

    /* Font Families */
    --font-headline: 'Space Grotesk', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-label: 'Inter', sans-serif;

    /* 0px corners */
    --radius: 0px;

    /* Transitions */
    --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

    /* Layout */
    --sidebar-width: 256px;
    --topbar-height: 64px;
    --preview-width: 450px;
}

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

html, body {
    height: 100%;
    overflow: hidden;
    background-color: var(--background);
    color: var(--on-surface);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

::selection {
    background: var(--accent);
    color: var(--on-accent);
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--outline-variant); }
::-webkit-scrollbar-thumb:hover { background: var(--outline); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

/* Fractal textures */
.fractal-bg {
    background-image: radial-gradient(circle at 2px 2px, var(--surface-container-highest) 1px, transparent 0);
    background-size: 24px 24px;
}

.fractal-noise {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.03;
}

/* ============================================
   MODAL — API Key
   ============================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s var(--ease-out);
}

.modal-card {
    background: var(--surface-container-lowest);
    border: 2px solid var(--primary);
    padding: 3rem;
    max-width: 420px;
    width: 90%;
    text-align: center;
    animation: scaleIn 0.4s var(--spring);
    box-shadow: 12px 12px 0px 0px rgba(0,0,0,1);
}

.modal-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 1.5rem;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-icon .material-symbols-outlined { color: var(--on-accent) !important; }

.modal-title {
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: 1.5rem;
    letter-spacing: -0.02em;
    text-transform: uppercase;
    margin-bottom: 0.75rem;
}

.modal-desc {
    font-size: 0.875rem;
    color: var(--on-surface-variant);
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

.modal-field-label {
    display: block;
    text-align: left;
    font-family: var(--font-headline);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    font-weight: 700;
    color: var(--on-surface-variant);
    margin-bottom: 0.4rem;
}

.modal-field-label + .modal-input { margin-bottom: 1.25rem; }

.modal-input {
    width: 100%;
    padding: 0.875rem 1rem;
    background: var(--surface);
    border: none;
    border-bottom: 2px solid var(--outline);
    color: var(--on-surface);
    font-family: var(--font-headline);
    font-size: 0.875rem;
    outline: none;
    transition: all 0.2s ease;
    margin-bottom: 1rem;
}

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

.modal-btn {
    width: 100%;
    padding: 0.875rem;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.modal-hint {
    margin-top: 1rem;
    font-size: 0.75rem;
    color: var(--on-surface-variant);
    font-family: var(--font-label);
}

.modal-hint a { color: var(--accent); }

/* ============================================
   TOP APP BAR
   ============================================ */
#top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

#top-bar::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--surface-container-highest);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 2.5rem;
}

.brand-logo {
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary);
    letter-spacing: -0.04em;
    text-transform: uppercase;
}

.topbar-nav { display: flex; gap: 2rem; }

.nav-link {
    font-family: var(--font-headline);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--outline);
    text-decoration: none;
    text-transform: uppercase;
    padding-bottom: 2px;
    transition: color 0.1s ease;
}

.nav-link:hover { color: var(--on-surface); text-decoration: none; }
.nav-link.active { color: var(--accent); border-bottom: 2px solid var(--accent); }

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* --- Buttons --- */
.btn-primary {
    background: var(--primary);
    color: var(--on-primary);
    border: 1px solid var(--primary);
    padding: 0.6rem 1.5rem;
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.btn-primary:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
}

.btn-primary:active { transform: scale(0.97); }
.btn-sm { padding: 0.5rem 1rem; font-size: 0.65rem; }

.btn-accent {
    background: var(--accent);
    color: var(--on-accent);
    border: 1px solid var(--accent);
    padding: 0.6rem 1.5rem;
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.btn-accent:hover { background: var(--accent-dim); }

.icon-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--on-surface);
    cursor: pointer;
    transition: all 0.1s ease;
}

.icon-btn:hover { background: var(--surface-container-highest); }

/* ============================================
   SIDEBAR
   ============================================ */
#sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--surface-container-lowest);
    display: flex;
    flex-direction: column;
    z-index: 50;
}

.sidebar-top { padding: 1.5rem 1rem 0; }

.sidebar-section-title {
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: 1rem;
    color: var(--primary);
    letter-spacing: -0.02em;
    margin-bottom: 0.25rem;
}

.sidebar-section-subtitle {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: var(--outline);
    font-weight: 500;
    margin-bottom: 1.25rem;
}

.new-doc-btn {
    width: 100%;
    padding: 0.75rem;
    background: var(--accent);
    border: none;
    color: var(--on-accent);
    font-family: var(--font-headline);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.15s ease;
}

.new-doc-btn:hover { background: var(--accent-dim); }
.new-doc-btn:active { transform: scale(0.97); }

.sidebar-nav { padding: 1.5rem 0.5rem 0.5rem; }

.nav-section-label {
    padding: 0.5rem 0.75rem;
    font-family: var(--font-headline);
    font-size: 0.55rem;
    text-transform: uppercase;
    letter-spacing: 0.25em;
    color: var(--outline);
    font-weight: 700;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0.75rem;
    font-family: var(--font-headline);
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--outline);
    text-decoration: none;
    transition: all 0.1s ease;
}

.sidebar-link:hover {
    color: var(--on-surface);
    background: var(--surface-container-high);
    text-decoration: none;
}

.sidebar-link.active {
    background: var(--accent-light);
    color: var(--accent);
}

.sidebar-link .material-symbols-outlined { font-size: 18px; }

/* Chat History */
.chat-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.chat-history-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.75rem;
    font-size: 0.75rem;
    font-family: var(--font-headline);
    font-weight: 500;
    color: var(--on-surface-variant);
    cursor: pointer;
    transition: all 0.1s ease;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    position: relative;
}

.chat-history-item:hover {
    background: var(--surface-container-high);
    color: var(--on-surface);
}

.chat-history-item.active {
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 700;
}

.chat-history-item .material-symbols-outlined { font-size: 14px; flex-shrink: 0; }

/* Chat item actions (star, delete) */
.chat-item-actions {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    display: none;
    gap: 2px;
}

.chat-history-item:hover .chat-item-actions { display: flex; }

.chat-item-action {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: var(--surface-container-lowest);
    color: var(--outline);
    cursor: pointer;
    transition: all 0.1s ease;
}

.chat-item-action:hover { color: var(--accent); }
.chat-item-action.starred { color: var(--accent); }
.chat-item-action.delete-action:hover { color: var(--error); }

/* Sidebar Bottom */
.sidebar-bottom {
    padding: 1rem;
    background: var(--surface-container-low);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    margin-bottom: 0.75rem;
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--on-accent);
    font-weight: 700;
    font-size: 0.75rem;
    font-family: var(--font-headline);
    flex-shrink: 0;
}

.user-info { overflow: hidden; }
.user-name {
    font-size: 0.75rem;
    font-weight: 700;
    font-family: var(--font-headline);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-plan {
    font-size: 0.55rem;
    color: var(--accent);
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

.sidebar-utils { display: flex; flex-direction: column; gap: 0.25rem; }

.sidebar-util-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.5rem;
    font-family: var(--font-headline);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--outline);
    text-decoration: none;
    transition: color 0.1s ease;
}

.sidebar-util-link:hover { color: var(--on-surface); text-decoration: none; }

/* Empty state for sidebar */
.sidebar-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--outline);
}

.sidebar-empty .material-symbols-outlined {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    opacity: 0.3;
}

.sidebar-empty p {
    font-family: var(--font-headline);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    font-weight: 700;
}

/* ============================================
   MAIN CONTENT AREA
   ============================================ */
#app-layout {
    display: flex;
    padding-top: var(--topbar-height);
    height: 100vh;
}

#main-content {
    display: flex;
    flex: 1;
    margin-left: var(--sidebar-width);
    overflow: hidden;
}

/* ============================================
   CHAT COLUMN
   ============================================ */
#chat-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
    background: var(--surface);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 3rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    scroll-behavior: smooth;
}

/* Message Rows */
.message-row {
    display: flex;
    gap: 1rem;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    animation: fadeScaleIn 0.3s var(--ease-out);
}

.message-row.user-message { flex-direction: row-reverse; }

.msg-avatar {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-avatar {
    background: var(--accent);
    color: var(--on-accent);
}

.ai-avatar .material-symbols-outlined { color: var(--on-accent); font-size: 18px; }

.user-avatar-msg {
    background: var(--surface-container-highest);
    border: 2px solid var(--primary);
}

.user-avatar-msg .material-symbols-outlined { color: var(--primary); font-size: 18px; }

.msg-content { max-width: 85%; }

.msg-bubble {
    padding: 1.25rem 1.5rem;
    line-height: 1.7;
    font-size: 0.95rem;
}

.user-message .msg-bubble {
    background: var(--surface-container-lowest);
    border: 2px solid var(--primary);
    box-shadow: 4px 4px 0px 0px rgba(0,0,0,1);
}

.ai-message .msg-bubble {
    background: var(--surface-container-low);
    border-left: 4px solid var(--accent);
}

.welcome-heading {
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: 2rem;
    letter-spacing: -0.03em;
    line-height: 1.15;
    margin-bottom: 0.75rem;
    text-transform: uppercase;
}

.welcome-sub {
    font-size: 0.95rem;
    color: var(--on-surface-variant);
    line-height: 1.65;
    margin-bottom: 1.5rem;
}

/* ============================================
   TEMPLATE CARDS — Visual Starting Points
   ============================================ */
.template-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    max-width: 600px;
}

.template-card {
    padding: 1rem 1.25rem;
    background: var(--surface-container-lowest);
    border: 2px solid var(--surface-container-highest);
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
    overflow: hidden;
}

.template-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent);
    opacity: 0;
    transition: opacity 0.15s ease;
}

.template-card:hover {
    border-color: var(--accent);
    box-shadow: 4px 4px 0px 0px rgba(0,85,255,0.2);
    transform: translate(-1px, -1px);
}

.template-card:hover::before { opacity: 1; }

.template-card-icon {
    font-size: 20px;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

.template-card-title {
    font-family: var(--font-headline);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    margin-bottom: 0.25rem;
}

.template-card-desc {
    font-size: 0.7rem;
    color: var(--outline);
    line-height: 1.4;
}

/* ============================================
   QUICK ACTION CHIPS — Below AI Responses
   ============================================ */
.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.75rem;
}

.quick-chip {
    padding: 0.35rem 0.75rem;
    background: var(--surface-container-lowest);
    border: 1px solid var(--surface-container-highest);
    font-family: var(--font-headline);
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--on-surface-variant);
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.quick-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 2px 2px 0px 0px rgba(0,85,255,0.15);
}

.quick-chip .material-symbols-outlined { font-size: 12px; }

/* Message status badge */
.msg-status {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-family: var(--font-headline);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    font-weight: 700;
    color: var(--accent);
    margin-top: 0.75rem;
    background: var(--accent-light);
    padding: 0.3rem 0.6rem;
}

.msg-status .material-symbols-outlined { font-size: 14px; }

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 0.4rem;
    padding: 1rem 1.25rem;
    align-items: center;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--accent);
    animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

/* ============================================
   SLASH COMMAND PALETTE
   ============================================ */
.slash-palette {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    max-width: 800px;
    margin: 0 auto 0.5rem;
    background: var(--surface-container-lowest);
    border: 2px solid var(--primary);
    box-shadow: 6px 6px 0px 0px rgba(0,0,0,1);
    z-index: 30;
    display: none;
    max-height: 280px;
    overflow-y: auto;
}

.slash-palette.active { display: block; animation: scaleIn 0.2s var(--ease-out); }

.slash-palette-header {
    padding: 0.5rem 1rem;
    font-family: var(--font-headline);
    font-size: 0.55rem;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: var(--outline);
    font-weight: 700;
    background: var(--surface-container-low);
}

.slash-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1rem;
    cursor: pointer;
    transition: all 0.1s ease;
}

.slash-item:hover, .slash-item.selected {
    background: var(--accent-light);
    color: var(--accent);
}

.slash-item-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-container-highest);
    flex-shrink: 0;
}

.slash-item-icon .material-symbols-outlined { font-size: 16px; }

.slash-item:hover .slash-item-icon,
.slash-item.selected .slash-item-icon {
    background: var(--accent);
    color: var(--on-accent);
}

.slash-item-text {
    display: flex;
    flex-direction: column;
}

.slash-item-name {
    font-family: var(--font-headline);
    font-size: 0.75rem;
    font-weight: 700;
}

.slash-item-desc {
    font-size: 0.65rem;
    color: var(--outline);
}

/* ============================================
   DRAG & DROP OVERLAY
   ============================================ */
.drop-overlay {
    position: absolute;
    inset: 0;
    z-index: 20;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    display: none;
    align-items: center;
    justify-content: center;
    border: 3px dashed var(--accent);
    margin: 1rem;
    transition: all 0.3s var(--spring);
}

.drop-overlay.active {
    display: flex;
    animation: scaleIn 0.3s var(--spring);
    transform: scale(1.02);
}

.drop-overlay-content { text-align: center; }

.drop-icon {
    font-size: 3rem;
    color: var(--accent);
    margin-bottom: 1rem;
    animation: float 2s ease-in-out infinite;
}

.drop-text {
    font-family: var(--font-headline);
    font-size: 1.25rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: -0.02em;
    margin-bottom: 0.25rem;
}

.drop-sub {
    font-size: 0.7rem;
    color: var(--outline);
    font-family: var(--font-headline);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

/* ============================================
   CHAT INPUT AREA
   ============================================ */
.chat-input-area {
    padding: 1rem 2rem 1.5rem;
    background: linear-gradient(to top, var(--surface) 60%, transparent);
    position: relative;
}

.drop-hint {
    text-align: center;
    margin-bottom: 0.5rem;
}

.drop-hint span {
    font-family: var(--font-headline);
    font-size: 0.55rem;
    text-transform: uppercase;
    letter-spacing: 0.3em;
    color: var(--outline-variant);
    font-weight: 700;
}

.input-capsule {
    max-width: 800px;
    margin: 0 auto;
    background: var(--surface-container-lowest);
    border: 2px solid var(--primary);
    overflow: hidden;
    transition: box-shadow 0.2s ease;
}

.input-capsule:focus-within {
    border-color: var(--accent);
    box-shadow: 6px 6px 0px 0px rgba(0,85,255,0.25);
}

.attached-files {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0;
    max-height: 0;
    overflow: hidden;
    transition: all 0.3s ease;
}

.attached-files.has-files { padding: 0.75rem 1rem 0; max-height: 200px; }

.attached-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--accent-light);
    padding: 0.35rem 0.75rem;
    font-family: var(--font-headline);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--accent);
    animation: scaleIn 0.3s var(--spring);
}

.attached-file-chip .remove-file {
    cursor: pointer;
    opacity: 0.5;
    font-size: 14px;
    transition: opacity 0.2s ease;
}
.attached-file-chip .remove-file:hover { opacity: 1; }

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
}

.attach-btn { flex-shrink: 0; width: 36px; height: 36px; }

.chat-textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--on-surface);
    font-family: var(--font-body);
    font-size: 0.9rem;
    padding: 0.5rem 0;
    resize: none;
    outline: none;
    max-height: 150px;
    overflow-y: auto;
    line-height: 1.5;
}

.chat-textarea::placeholder { color: var(--outline-variant); }

.send-btn {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border: none;
    background: var(--accent);
    color: var(--on-accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.send-btn:hover:not(:disabled) { background: var(--accent-dim); }
.send-btn:active:not(:disabled) { transform: scale(0.95); }
.send-btn:disabled { opacity: 0.3; cursor: default; }
.send-btn .material-symbols-outlined { font-size: 20px; }

/* ============================================
   MARKDOWN PREVIEW COLUMN
   ============================================ */
#preview-column {
    width: var(--preview-width);
    background: var(--surface-container-lowest);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

/* Resizer Handle */
.layout-resizer {
    width: 6px;
    background: var(--surface-container-highest);
    cursor: col-resize;
    position: relative;
    z-index: 10;
    transition: background 0.2s ease;
    border-left: 1px solid var(--primary);
}

.layout-resizer:hover, .layout-resizer.is-resizing {
    background: var(--accent);
}

.preview-header {
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background: var(--surface-container-low);
    flex-shrink: 0;
}

.preview-header-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.preview-status-dot {
    width: 8px;
    height: 8px;
    background: var(--success);
    animation: pulse 2s ease-in-out infinite;
}

.preview-status-dot.generating {
    background: var(--accent);
    animation: pulse 0.5s ease-in-out infinite;
}

.preview-status-dot.idle {
    background: var(--outline-variant);
    animation: none;
}

.preview-filename {
    font-family: var(--font-headline);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    font-weight: 700;
    color: var(--on-surface);
}

.preview-header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.preview-action {
    background: none;
    border: none;
    color: var(--on-surface-variant);
    cursor: pointer;
    font-family: var(--font-headline);
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.5rem;
    transition: all 0.1s ease;
}

.preview-action:hover { color: var(--accent); background: var(--surface-container-highest); }
.preview-action.active { color: var(--on-accent); background: var(--accent); }

.status-dot-wrap { display: flex; align-items: center; }

/* Preview Body — Rendered Markdown with Color */
.preview-body {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    font-size: 0.9rem;
    color: var(--on-surface);
}

/* Markdown Preview Styles — Monochrome + Accent Color */
.markdown-preview h1 {
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: 1.75rem;
    margin-bottom: 1rem;
    color: var(--accent);
    letter-spacing: -0.03em;
    text-transform: uppercase;
    border-left: 4px solid var(--accent);
    padding-left: 0.75rem;
}

.markdown-preview h2 {
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: 1.1rem;
    margin-top: 2rem;
    margin-bottom: 1rem;
    color: var(--on-surface);
    text-transform: uppercase;
    letter-spacing: -0.01em;
    padding-bottom: 0.4rem;
    border-bottom: 2px solid var(--surface-container-highest);
}

.markdown-preview h3 {
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: 0.95rem;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: var(--accent-dim);
    text-transform: uppercase;
}

.markdown-preview p { margin-bottom: 0.875rem; line-height: 1.7; }
.markdown-preview strong { color: var(--primary); font-weight: 700; }
.markdown-preview em { color: var(--on-surface-variant); }

.markdown-preview code {
    font-family: 'Space Grotesk', monospace;
    background: var(--accent-light);
    padding: 2px 6px;
    font-size: 0.85em;
    color: var(--accent-dim);
}

.markdown-preview pre {
    background: var(--primary);
    color: var(--on-primary);
    padding: 1.25rem;
    margin: 1rem 0;
    overflow-x: auto;
    position: relative;
}

.markdown-preview pre::before {
    content: 'CODE';
    position: absolute;
    top: 0;
    right: 0;
    padding: 0.2rem 0.5rem;
    font-family: var(--font-headline);
    font-size: 0.5rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--outline);
    background: var(--primary-container);
}

.markdown-preview pre code {
    background: none;
    padding: 0;
    font-size: 0.8rem;
    color: var(--on-primary);
}

.markdown-preview ul, .markdown-preview ol {
    padding-left: 1.5rem;
    margin-bottom: 1rem;
}

.markdown-preview li { margin-bottom: 0.5rem; }
.markdown-preview li::marker { color: var(--accent); font-weight: 700; }

.markdown-preview blockquote {
    border-left: 4px solid var(--accent);
    padding: 1rem 1rem 1rem 1.25rem;
    margin: 1rem 0;
    color: var(--on-surface-variant);
    background: var(--accent-light);
    font-style: italic;
}

.markdown-preview hr {
    border: none;
    height: 2px;
    background: linear-gradient(to right, var(--accent), transparent);
    margin: 2rem 0;
}

.markdown-preview a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
    font-weight: 600;
}

.markdown-preview table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    font-size: 0.85rem;
}

.markdown-preview th, .markdown-preview td {
    padding: 0.6rem 0.75rem;
    text-align: left;
}

.markdown-preview th {
    background: var(--accent);
    color: var(--on-accent);
    font-weight: 700;
    font-family: var(--font-headline);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.markdown-preview td { border-bottom: 1px solid var(--surface-container-highest); }
.markdown-preview img { max-width: 100%; margin: 1rem 0; }

/* Placeholder state */
.preview-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--outline);
    opacity: 0.5;
}

.preview-placeholder .material-symbols-outlined {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: var(--accent);
    opacity: 0.3;
}

.preview-placeholder p {
    font-family: var(--font-headline);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    font-weight: 700;
}

/* Preview Editor */
.preview-editor {
    flex: 1;
    background: var(--surface-container-lowest);
    color: var(--on-surface);
    font-family: 'Space Grotesk', monospace;
    font-size: 0.85rem;
    line-height: 1.7;
    border: none;
    padding: 2rem;
    resize: none;
    outline: none;
    overflow-y: auto;
}

/* Preview Footer */
.preview-footer {
    padding: 1rem 1.5rem;
    background: var(--surface-container-highest);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    flex-shrink: 0;
}

.filename-input {
    background: var(--surface-container-lowest);
    border: none;
    border-bottom: 2px solid var(--outline);
    color: var(--on-surface);
    font-family: var(--font-headline);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.5rem 0.75rem;
    outline: none;
    transition: all 0.2s ease;
}

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

.export-btn {
    width: 100%;
    padding: 0.75rem;
    background: var(--accent);
    border: none;
    color: var(--on-accent);
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.15s ease;
}

.export-btn:hover { background: var(--accent-dim); }
.export-btn:active { transform: scale(0.98); }
.export-btn .material-symbols-outlined { font-size: 18px; }

/* ============================================
   SETTINGS PANEL
   ============================================ */
.settings-panel { position: fixed; inset: 0; z-index: 200; }

.settings-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(6px);
}

.settings-drawer {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 380px;
    background: var(--surface-container-lowest);
    border-left: 2px solid var(--primary);
    box-shadow: -12px 0 0px 0px rgba(0,0,0,0.05);
    animation: slideInRight 0.3s var(--ease-out);
    display: flex;
    flex-direction: column;
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    background: var(--surface-container-low);
}

.settings-header h2 {
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: 1.1rem;
    text-transform: uppercase;
    letter-spacing: -0.02em;
}

.settings-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.setting-group { display: flex; flex-direction: column; gap: 0.5rem; }

.setting-label {
    font-family: var(--font-headline);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--on-surface-variant);
    font-weight: 700;
}

.setting-row { display: flex; gap: 0.5rem; }

.setting-input {
    flex: 1;
    padding: 0.65rem 0.75rem;
    background: var(--surface);
    border: none;
    border-bottom: 2px solid var(--outline);
    color: var(--on-surface);
    font-family: var(--font-headline);
    font-size: 0.8rem;
    outline: none;
    transition: all 0.2s ease;
}

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

select.setting-input {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23474747' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

.setting-textarea {
    width: 100%;
    padding: 0.65rem 0.75rem;
    background: var(--surface);
    border: none;
    border-bottom: 2px solid var(--outline);
    color: var(--on-surface);
    font-family: var(--font-body);
    font-size: 0.8rem;
    outline: none;
    resize: vertical;
    min-height: 80px;
    transition: all 0.2s ease;
}

.setting-textarea:focus { border-bottom-color: var(--accent); }

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */
.toast-container {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    background: var(--primary);
    color: var(--on-primary);
    padding: 0.75rem 1.25rem;
    font-family: var(--font-headline);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 6px 6px 0px 0px rgba(0,0,0,0.2);
    animation: toastIn 0.4s var(--spring), toastOut 0.3s ease 2.7s forwards;
    pointer-events: auto;
}

.toast .material-symbols-outlined { color: var(--on-primary); }
.toast.success { background: var(--accent); }
.toast.error { background: var(--error); }

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: scale(1); } }
@keyframes fadeScaleIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideInRight { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes typingBounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-4px); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-10px); } }
@keyframes confettiFall {
    0% { transform: translateY(-10px) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}
@keyframes badgePop { 0% { transform: scale(0); } 50% { transform: scale(1.3); } 100% { transform: scale(1); } }

/* ============================================
   PROJECT CARD DASHBOARD
   ============================================ */
#dashboard-view {
    display: none;
    position: fixed;
    top: var(--topbar-height);
    left: var(--sidebar-width);
    right: 0;
    bottom: 0;
    padding: 2rem 2.5rem;
    overflow-y: auto;
    background: var(--background);
    z-index: 40;
    animation: fadeIn 0.3s var(--ease-out);
}

#dashboard-view.active { display: block; }
#main-content.hidden { display: none !important; }

.dashboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
    gap: 1rem;
}

.dashboard-title {
    font-family: var(--font-headline);
    font-size: 1.5rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: -0.03em;
}

.dashboard-title span {
    color: var(--outline);
    font-weight: 400;
    font-size: 0.875rem;
    margin-left: 0.5rem;
}

.dashboard-search {
    flex: 1;
    max-width: 400px;
    position: relative;
}

.dashboard-search-input {
    width: 100%;
    padding: 0.65rem 1rem 0.65rem 2.5rem;
    background: var(--surface-container-lowest);
    border: 2px solid var(--surface-container-highest);
    color: var(--on-surface);
    font-family: var(--font-body);
    font-size: 0.85rem;
    outline: none;
    transition: all 0.2s ease;
}

.dashboard-search-input:focus {
    border-color: var(--accent);
    box-shadow: 4px 4px 0px 0px rgba(0,85,255,0.15);
}

.dashboard-search-input::placeholder { color: var(--outline-variant); }

.dashboard-search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--outline);
    font-size: 18px;
    pointer-events: none;
}

.dashboard-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.dashboard-sort {
    padding: 0.5rem 0.75rem;
    background: var(--surface-container-lowest);
    border: 2px solid var(--surface-container-highest);
    font-family: var(--font-headline);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--on-surface);
    cursor: pointer;
    appearance: none;
    outline: none;
    padding-right: 2rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23474747' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
}

/* Project Card Grid */
.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.project-card {
    background: var(--surface-container-lowest);
    border: 2px solid var(--surface-container-highest);
    padding: 1.25rem 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 160px;
}

.project-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0px;
    background: var(--accent);
    transition: width 0.15s ease;
}

.project-card:hover {
    border-color: var(--accent);
    box-shadow: 6px 6px 0px 0px rgba(0,85,255,0.15);
    transform: translate(-2px, -2px);
}

.project-card:hover::before { width: 4px; }

.project-card.starred::before {
    width: 4px;
    background: var(--accent);
}

.project-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.project-card-title {
    font-family: var(--font-headline);
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1.3;
    flex: 1;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

.project-card-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s ease;
    margin-left: 0.5rem;
    flex-shrink: 0;
}

.project-card:hover .project-card-actions { opacity: 1; }

.project-card-action {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--outline);
    cursor: pointer;
    transition: all 0.1s ease;
}

.project-card-action:hover { color: var(--accent); background: var(--accent-light); }
.project-card-action.starred { color: var(--accent); }
.project-card-action.delete-action:hover { color: var(--error); background: rgba(186,26,26,0.08); }

.project-card-preview {
    flex: 1;
    font-size: 0.75rem;
    color: var(--outline);
    line-height: 1.5;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    margin-bottom: 0.75rem;
}

.project-card-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-family: var(--font-headline);
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--outline);
    font-weight: 500;
    margin-top: auto;
}

.project-card-meta span {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.project-card-meta .material-symbols-outlined { font-size: 12px; }

/* Word count badge */
.word-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.15rem 0.4rem;
    font-family: var(--font-headline);
    font-size: 0.55rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.word-badge.milestone {
    background: var(--accent);
    color: var(--on-accent);
    animation: badgePop 0.4s var(--spring);
}

.word-badge.draft {
    background: var(--surface-container-highest);
    color: var(--outline);
}

/* New project card (+ button) */
.project-card-new {
    background: var(--surface);
    border: 2px dashed var(--surface-container-highest);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    min-height: 160px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.project-card-new:hover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.project-card-new .material-symbols-outlined {
    font-size: 2rem;
    color: var(--outline);
    transition: color 0.15s ease;
}

.project-card-new:hover .material-symbols-outlined { color: var(--accent); }

.project-card-new span:last-child {
    font-family: var(--font-headline);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--outline);
}

/* Empty dashboard state */
.dashboard-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4rem 2rem;
    color: var(--outline);
}

.dashboard-empty .material-symbols-outlined { font-size: 3rem; opacity: 0.2; margin-bottom: 1rem; }
.dashboard-empty h3 {
    font-family: var(--font-headline);
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}
.dashboard-empty p { font-size: 0.8rem; margin-bottom: 1.5rem; }

/* ============================================
   CONFETTI CANVAS
   ============================================ */
#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 9999;
}

/* ============================================
   AUTO TABLE OF CONTENTS
   ============================================ */
.toc-panel {
    background: var(--surface-container-low);
    border-bottom: 1px solid var(--surface-container-highest);
    padding: 0.75rem 1.5rem;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
}

.toc-panel.active {
    max-height: 300px;
    padding: 0.75rem 1.5rem;
    overflow-y: auto;
}

.toc-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    background: none;
    border: none;
    font-family: var(--font-headline);
    font-size: 0.55rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--outline);
    font-weight: 700;
    padding: 0;
    transition: color 0.1s ease;
    width: 100%;
}

.toc-toggle:hover { color: var(--accent); }
.toc-toggle .material-symbols-outlined { font-size: 14px; transition: transform 0.2s ease; }
.toc-panel.active .toc-toggle .material-symbols-outlined { transform: rotate(90deg); }

.toc-list {
    list-style: none;
    padding: 0.5rem 0 0;
    margin: 0;
}

.toc-item {
    padding: 0.3rem 0;
    font-family: var(--font-headline);
    font-size: 0.7rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--on-surface-variant);
    transition: color 0.1s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toc-item:hover { color: var(--accent); }
.toc-item.h2 { padding-left: 0; font-weight: 700; }
.toc-item.h3 { padding-left: 1rem; }
.toc-item.h4 { padding-left: 2rem; font-size: 0.65rem; }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
    #sidebar { display: none; }
    #main-content { margin-left: 0; }
    #dashboard-view { left: 0; }
    :root { --preview-width: 340px; }
}

@media (max-width: 768px) {
    #preview-column { display: none; }
    .topbar-nav { display: none; }
    .template-grid { grid-template-columns: 1fr; }
    .project-grid { grid-template-columns: 1fr; }
}
