/* ═══════════════════════════════════════════════════════════════
   DESIGN TOKENS
═══════════════════════════════════════════════════════════════ */
:root {
    --surface:                    #131313;
    --surface-container-lowest:   #0e0e0e;
    --surface-container-low:      #1c1b1b;
    --surface-container:          #20201f;
    --surface-container-high:     #2a2a2a;
    --surface-container-highest:  #353535;
    --on-surface:                 #e5e2e1;
    --on-surface-variant:         #d2c5ab;
    --primary:                    #ffcc00;
    --on-primary:                 #3d2f00;
    --on-primary-container:       #6f5700;
    --outline-variant:            rgba(78, 70, 50, 0.3);
    --outline:                    #9a9078;
    --error:                      #ffb4ab;
}

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

html {
    background: var(--surface);
    color: var(--on-surface);
}

body {
    font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--surface);
    color: var(--on-surface);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

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

a {
    color: var(--primary);
    text-decoration: none;
    transition: opacity 0.2s;
}

a:hover { opacity: 0.75; }

.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    user-select: none;
    vertical-align: middle;
}

/* ═══════════════════════════════════════════════════════════════
   HEADER
═══════════════════════════════════════════════════════════════ */
.app-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: linear-gradient(to bottom, #131313, #1a1a1a);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
    height: 4rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.brand-icon {
    color: var(--primary);
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

.brand-name {
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--primary);
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.nav-link {
    color: var(--on-surface-variant);
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    text-decoration: none;
    transition: color 0.2s;
    padding-bottom: 2px;
}

.nav-link:hover {
    color: var(--primary);
    opacity: 1;
}

.nav-link--active {
    color: var(--primary);
    border-bottom: 2px solid var(--primary);
}

.clear-btn {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    background: transparent;
    border: none;
    border-radius: 0.5rem;
    color: var(--on-surface-variant);
    font-size: 0.6875rem;
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    cursor: pointer;
    transition: color 0.2s, background 0.2s;
    font-family: inherit;
    flex-shrink: 0;
}

.clear-btn .material-symbols-outlined {
    font-size: 1rem;
}

.clear-btn:hover {
    color: var(--error);
    background: rgba(255, 180, 171, 0.08);
}

/* ═══════════════════════════════════════════════════════════════
   MAIN LAYOUT
═══════════════════════════════════════════════════════════════ */
.app-main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2.5rem 2rem 6rem;
}

/* ═══════════════════════════════════════════════════════════════
   WELCOME / HERO SECTION
═══════════════════════════════════════════════════════════════ */
.welcome-screen {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.welcome-heading {
    font-size: clamp(2rem, 4vw, 3.5rem);
    font-weight: 700;
    letter-spacing: -0.04em;
    line-height: 1.1;
    background: linear-gradient(135deg, var(--primary) 0%, var(--on-surface-variant) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    flex-shrink: 0;
    max-width: 18ch;
}

.welcome-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding-top: 0.5rem;
    max-width: 36rem;
}

.welcome-text {
    color: var(--on-surface-variant);
    font-size: 1rem;
    line-height: 1.65;
}

.welcome-attribution {
    color: var(--on-surface-variant);
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    opacity: 0.6;
    margin-top: 0.5rem;
}

.welcome-attribution a {
    color: inherit;
}

.welcome-attribution a:hover {
    color: var(--primary);
    opacity: 1;
}

/* ═══════════════════════════════════════════════════════════════
   TWO-COLUMN CONTENT GRID
═══════════════════════════════════════════════════════════════ */
.content-grid {
    display: grid;
    grid-template-columns: 5fr 7fr;
    gap: 2rem;
    align-items: start;
}

/* Collapse form column when script.js hides the build form */
.form-panel-wrapper:has(#buildForm[style*="display: none"]) {
    display: none;
}

.form-panel-wrapper:has(#buildForm[style*="display: none"]) ~ .chat-panel {
    grid-column: 1 / -1;
}

/* ═══════════════════════════════════════════════════════════════
   BUILD FORM PANEL
═══════════════════════════════════════════════════════════════ */
.build-form {
    background: var(--surface-container-low);
    border: 1px solid var(--outline-variant);
    border-radius: 0.75rem;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.panel-header-icon {
    color: var(--primary);
    font-size: 1.25rem;
}

.panel-header-label {
    font-size: 0.6875rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--primary);
}

.form-fields {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.field-row-two {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.field-label {
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--on-surface-variant);
}

.field-input,
.field-textarea {
    width: 100%;
    background: var(--surface-container-lowest);
    border: 1px solid var(--outline-variant);
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    color: var(--on-surface);
    font-size: 0.875rem;
    font-family: inherit;
    line-height: 1.5;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.field-input::placeholder,
.field-textarea::placeholder {
    color: var(--outline);
}

.field-input:focus,
.field-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(255, 204, 0, 0.15);
}

.field-textarea {
    resize: vertical;
}

/* Build Button */
.build-button {
    width: 100%;
    padding: 1rem 1.5rem;
    background: linear-gradient(135deg, var(--primary) 0%, #6f5700 100%);
    border: none;
    border-radius: 0.5rem;
    color: var(--on-primary);
    font-size: 0.9375rem;
    font-weight: 700;
    font-family: inherit;
    letter-spacing: -0.01em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    box-shadow: 0 0 20px rgba(255, 204, 0, 0.2);
    transition: box-shadow 0.2s, transform 0.15s;
    position: relative;
}

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

.build-button:hover:not(:disabled) {
    box-shadow: 0 0 32px rgba(255, 204, 0, 0.4);
    transform: scale(1.01);
}

.build-button:active:not(:disabled) {
    transform: scale(0.98);
}

.build-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ═══════════════════════════════════════════════════════════════
   CHAT PANEL
═══════════════════════════════════════════════════════════════ */
.chat-panel {
    background: var(--surface-container);
    border: 1px solid var(--outline-variant);
    border-radius: 0.75rem;
    display: flex;
    flex-direction: column;
    height: 870px;
    overflow: hidden;
    position: relative;
}

.chat-panel-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--outline-variant);
    background: rgba(42, 42, 42, 0.5);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.chat-avatar {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(255, 204, 0, 0.2);
}

.chat-avatar .material-symbols-outlined {
    color: var(--on-primary);
    font-size: 1.25rem;
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

.chat-identity {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.chat-name {
    font-size: 0.875rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--on-surface);
}

.chat-status {
    font-size: 0.625rem;
    font-weight: 500;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--primary);
    opacity: 0.8;
}

/* ═══════════════════════════════════════════════════════════════
   MESSAGES CONTAINER
═══════════════════════════════════════════════════════════════ */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    scrollbar-width: none;
}

.messages-container::-webkit-scrollbar {
    display: none;
}

/* ═══════════════════════════════════════════════════════════════
   MESSAGES (rendered by script.js)
═══════════════════════════════════════════════════════════════ */
.message {
    display: flex;
    width: 100%;
}

.message.ai  { justify-content: flex-start; }
.message.user { justify-content: flex-end; }

.message-wrapper {
    max-width: 85%;
    display: flex;
    flex-direction: column;
}

.message.ai .message-wrapper  { align-items: flex-start; }
.message.user .message-wrapper { align-items: flex-end; }

.message-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.375rem;
}

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

.message-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message.ai .message-avatar {
    background: var(--surface-container-highest);
    border: 1px solid rgba(255, 204, 0, 0.2);
}

.message.ai .message-avatar svg   { stroke: var(--primary); }

.message.user .message-avatar {
    background: var(--primary);
}

.message.user .message-avatar svg { stroke: var(--on-primary); }

.message-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

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

.message-sender {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--on-surface-variant);
}

/* Phase badge (Built / Edited) */
.message-model {
    font-size: 0.5625rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    background: var(--surface-container-highest);
    color: var(--on-surface-variant);
    border: 1px solid var(--outline-variant);
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
}

.message-bubble {
    word-wrap: break-word;
    max-width: 100%;
    padding: 0.75rem 1.125rem;
}

.message.ai .message-bubble {
    background: var(--surface-container-high);
    color: var(--on-surface);
    border-radius: 1rem 1rem 1rem 0.25rem;
}

.message.user .message-bubble {
    background: var(--primary);
    color: var(--on-primary);
    border-radius: 1rem 1rem 0.25rem 1rem;
}

.message-text {
    font-size: 0.875rem;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-words;
}

.message-footer {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
    font-size: 0.6875rem;
    color: var(--on-surface-variant);
    opacity: 0.55;
    letter-spacing: 0.06em;
}

.message.user .message-footer { justify-content: flex-end; }
.message.ai  .message-footer  { justify-content: flex-start; }

/* ═══════════════════════════════════════════════════════════════
   LOADING INDICATOR
═══════════════════════════════════════════════════════════════ */
.loading-indicator {
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: center;
    flex-shrink: 0;
}

.loading-pill {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(53, 53, 53, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 204, 0, 0.2);
    padding: 0.5rem 1.125rem;
    border-radius: 9999px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.loading-dots {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.dot {
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: 50%;
    animation: bounce 1.4s ease-in-out infinite;
}

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

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.65); opacity: 0.45; }
    40%            { transform: scale(1);    opacity: 1; }
}

.loading-text {
    font-size: 0.6875rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--primary);
}

/* ═══════════════════════════════════════════════════════════════
   CHAT INPUT AREA
═══════════════════════════════════════════════════════════════ */
.chat-input-area {
    padding: 1.125rem 1.5rem;
    border-top: 1px solid var(--outline-variant);
    background: var(--surface-container);
    flex-shrink: 0;
}

.chat-form {
    display: flex;
    align-items: flex-end;
    gap: 0.625rem;
}

.message-textarea {
    flex: 1;
    background: var(--surface-container-lowest);
    border: 1px solid var(--outline-variant);
    border-radius: 1rem;
    padding: 0.75rem 1.25rem;
    color: var(--on-surface);
    font-size: 0.875rem;
    font-family: inherit;
    line-height: 1.5;
    min-height: 3rem;
    max-height: 8rem;
    resize: none;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    scrollbar-width: none;
}

.message-textarea::-webkit-scrollbar { display: none; }

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

.message-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(255, 204, 0, 0.15);
}

.message-textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.send-button {
    width: 3rem;
    height: 3rem;
    background: var(--primary);
    border: none;
    border-radius: 0.625rem;
    color: var(--on-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(255, 204, 0, 0.25);
    transition: transform 0.15s, box-shadow 0.2s;
    position: relative;
}

.send-button:hover:not(:disabled) {
    transform: scale(1.06);
    box-shadow: 0 6px 18px rgba(255, 204, 0, 0.35);
}

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

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-footer-text {
    text-align: center;
    font-size: 0.5625rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--on-surface-variant);
    opacity: 0.35;
    margin-top: 0.625rem;
}

/* ═══════════════════════════════════════════════════════════════
   SPINNERS
═══════════════════════════════════════════════════════════════ */
.btn-spinner {
    width: 1.125rem;
    height: 1.125rem;
    border: 2px solid rgba(61, 47, 0, 0.35);
    border-top-color: var(--on-primary);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
    position: absolute;
}

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

/* ═══════════════════════════════════════════════════════════════
   MOBILE BOTTOM NAV
═══════════════════════════════════════════════════════════════ */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, #131313, #1a1a1a);
    border-top: 1px solid var(--outline-variant);
    padding: 0.625rem 1.5rem;
    justify-content: space-between;
    align-items: center;
    z-index: 50;
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--on-surface-variant);
    transition: color 0.2s;
    font-family: inherit;
    padding: 0.375rem;
}

.mobile-nav-item--active {
    color: var(--primary);
}

.mobile-nav-label {
    font-size: 0.5625rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════════════════════ */
@media (max-width: 1023px) {
    .header-nav {
        gap: 1.25rem;
    }
    .mobile-nav {
        display: none;
    }
    .header-content {
        height: auto;
        min-height: 4rem;
        padding: 0.625rem 2rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .content-grid {
        grid-template-columns: 1fr;
    }

    /* Reset full-width chat override (not needed in single-column) */
    .form-panel-wrapper:has(#buildForm[style*="display: none"]) ~ .chat-panel {
        grid-column: 1;
    }

    .chat-panel { height: 600px; }

    .welcome-screen {
        flex-direction: column;
        gap: 1rem;
    }

    .welcome-heading {
        max-width: none;
        font-size: 2rem;
    }
}

@media (max-width: 639px) {
    .app-main {
        padding: 1.5rem 1rem 2rem;
    }

    .header-content {
        padding: 0.625rem 1rem;
        gap: 0.375rem;
    }

    .header-nav {
        display: flex;
        width: 100%;
        gap: 0.875rem;
        overflow-x: auto;
        padding-bottom: 0.375rem;
        scrollbar-width: none;
    }

    .header-nav::-webkit-scrollbar {
        display: none;
    }

    .nav-link {
        font-size: 0.75rem;
        white-space: nowrap;
    }

    .build-form { padding: 1.25rem; }

    .field-row-two { grid-template-columns: 1fr; }

    .chat-panel { height: 500px; }

    .welcome-heading { font-size: 1.75rem; }
}
