/* ─── Brand tokens ─────────────────────────────────────────────────────────── */
:root {
    --deep:           #07101a;
    --surface:        #0c1824;
    --card:           #111f2e;
    --card-raised:    #162436;
    --bubble-ai:      #162030;
    --border:         rgba(255, 255, 255, 0.07);
    --border-mid:     rgba(255, 255, 255, 0.11);
    --text:           #dce8f5;
    --text-muted:     #5c7e98;
    --text-dim:       #344f66;
    --orange:         #e07840;
    --orange-light:   #f09464;
    --orange-glow:    rgba(224, 120, 64, 0.22);
    --teal:           #1b6878;
    --teal-light:     #2a8fa0;

    /* The signature gradient — used on header, user bubbles, accents */
    --brand-gradient: linear-gradient(135deg, #000000 0%, #091d2e 18%, #1a5270 42%, #c24830 72%, #e8753c 100%);

    --radius-lg:      18px;
    --radius-md:      12px;
    --radius-sm:      8px;
    --shadow-deep:    0 32px 80px rgba(0, 0, 0, 0.6);
    --shadow-card:    0 4px 20px rgba(0, 0, 0, 0.35);
    --transition:     0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* ─── Body ─────────────────────────────────────────────────────────────────── */
body {
    font-family: 'Plus Jakarta Sans', -apple-system, sans-serif;
    background: var(--deep);
    /* Subtle radial glows matching the brand palette */
    background-image:
        radial-gradient(ellipse 70% 55% at 15% 85%, rgba(224, 120, 64, 0.07) 0%, transparent 55%),
        radial-gradient(ellipse 55% 70% at 85% 15%, rgba(26, 104, 120, 0.09) 0%, transparent 55%);
    min-height: 100vh;
    min-height: calc(var(--vh, 1vh) * 100);
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    overflow: hidden;
    color: var(--text);
}

.container {
    width: 100%;
    max-width: 920px;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* ─── Chat container ───────────────────────────────────────────────────────── */
.chat-container {
    background: var(--surface);
    border: 1px solid var(--border-mid);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-deep);
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 820px;
    overflow: hidden;
    flex: 1;
}

/* ─── Header ───────────────────────────────────────────────────────────────── */
.chat-header {
    background: var(--brand-gradient);
    padding: 20px 28px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

/* Subtle noise-like grain overlay on the header */
.chat-header::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
    background-size: 200px 200px;
    pointer-events: none;
    opacity: 0.5;
}

.header-inner {
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
    z-index: 1;
}

.header-logo-wrap {
    background: #000;
    border-radius: 12px;
    padding: 5px;
    flex-shrink: 0;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}

.header-logo {
    height: 46px;
    width: auto;
    display: block;
    border-radius: 8px;
}

.header-text h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: #ffffff;
    line-height: 1.2;
}

.subtitle {
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.55);
    margin-top: 3px;
}

.start-over-btn {
    margin-left: auto;
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: rgba(255, 255, 255, 0.7);
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    flex-shrink: 0;
}

.start-over-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

/* ─── Messages area ────────────────────────────────────────────────────────── */
.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 28px 24px;
    background: var(--card);
    /* Subtle dot grid texture */
    background-image: radial-gradient(circle, rgba(255,255,255,0.035) 1px, transparent 1px);
    background-size: 28px 28px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}
.chat-messages::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.18); }

/* ─── Welcome message ──────────────────────────────────────────────────────── */
.welcome-message {
    text-align: center;
    padding: 52px 24px;
    animation: fadeUp 0.6s ease both;
}

.welcome-subtitle {
    font-family: 'Outfit', sans-serif;
    font-size: 22px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 14px;
}

.welcome-hint {
    font-size: 14px;
    color: var(--text-muted);
    max-width: 440px;
    margin: 0 auto;
    line-height: 1.7;
}

/* Decorative divider under welcome */
.welcome-message::after {
    content: '';
    display: block;
    width: 48px;
    height: 2px;
    background: var(--brand-gradient);
    border-radius: 2px;
    margin: 20px auto 0;
}

/* ─── Message bubbles ──────────────────────────────────────────────────────── */
.message {
    display: flex;
    animation: fadeUp 0.3s ease both;
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

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

.message-bubble {
    max-width: 72%;
    padding: 13px 18px;
    border-radius: var(--radius-lg);
    word-wrap: break-word;
    line-height: 1.6;
    font-size: 14.5px;
}

/* User bubble — brand gradient */
.message.user .message-bubble {
    background: var(--brand-gradient);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255,255,255,0.06);
}

/* Assistant bubble — dark glass card */
.message.assistant .message-bubble {
    max-width: 90%;
    background: var(--bubble-ai);
    color: var(--text);
    border: 1px solid var(--border-mid);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-card);
}

.message-content {
    /* pre-wrap only for user messages — assistant content is rendered HTML */
}

.message.user .message-content {
    white-space: pre-wrap;
}

/* ─── Markdown inside assistant bubbles ────────────────────────────────────── */
.message-content p {
    margin: 0 0 11px 0;
}
.message-content p:last-child { margin-bottom: 0; }

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    line-height: 1.3;
    margin: 16px 0 8px;
    color: #eaf2fa;
}
.message-content h1:first-child,
.message-content h2:first-child,
.message-content h3:first-child { margin-top: 0; }

.message-content h1 { font-size: 1.25em; }
.message-content h2 { font-size: 1.1em; }
.message-content h3 { font-size: 1em; color: var(--orange-light); }
.message-content h4 { font-size: 0.95em; }

.message-content ul,
.message-content ol {
    margin: 8px 0 12px 0;
    padding-left: 22px;
}
.message-content li { margin: 5px 0; }

.message-content strong { font-weight: 600; color: #eaf2fa; }
.message-content em { font-style: italic; opacity: 0.85; }

.message-content code {
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 2px 7px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.88em;
    color: var(--orange-light);
}

.message-content pre {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    overflow-x: auto;
    margin: 12px 0;
}
.message-content pre code {
    background: none;
    border: none;
    padding: 0;
    color: #c8daea;
}

.message-content blockquote {
    border-left: 3px solid var(--orange);
    margin: 12px 0;
    padding: 8px 14px;
    background: rgba(224, 120, 64, 0.07);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-style: italic;
    color: var(--text-muted);
}

.message-content a {
    color: var(--orange-light);
    text-decoration: none;
    border-bottom: 1px solid rgba(224, 120, 64, 0.3);
    transition: border-color var(--transition);
}
.message-content a:hover { border-color: var(--orange-light); }

.message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 14px 0;
    font-size: 13px;
}
.message-content th,
.message-content td {
    border: 1px solid var(--border-mid);
    padding: 8px 12px;
    text-align: left;
}
.message-content th {
    background: rgba(255, 255, 255, 0.05);
    font-weight: 600;
    color: #eaf2fa;
}
.message-content tr:nth-child(even) td {
    background: rgba(255, 255, 255, 0.02);
}

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

/* ─── Collapsible sections (details/summary) ───────────────────────────────── */
.message-content details {
    border: 1px solid var(--border-mid);
    border-radius: var(--radius-md);
    margin: 8px 0;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.15);
}
.message-content details + details { margin-top: 6px; }

.message-content summary {
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 0.95em;
    padding: 11px 14px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.04);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 9px;
    color: #d0e4f0;
    user-select: none;
    transition: background var(--transition);
}
.message-content summary::-webkit-details-marker { display: none; }
.message-content summary::before {
    content: '▶';
    font-size: 9px;
    color: var(--orange);
    transition: transform 0.2s ease;
    flex-shrink: 0;
}
.message-content details[open] > summary {
    background: rgba(224, 120, 64, 0.08);
    border-bottom: 1px solid var(--border);
    color: #eaf2fa;
}
.message-content details[open] > summary::before { transform: rotate(90deg); }
.message-content details > *:not(summary) {
    padding: 10px 14px 4px;
}

/* ─── Show-more clamp ──────────────────────────────────────────────────────── */
.message-clamp {
    position: relative;
    max-height: 400px;
    overflow: hidden;
}
.message-clamp::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 90px;
    background: linear-gradient(to bottom, transparent, var(--bubble-ai));
    pointer-events: none;
}
.message.assistant .message-bubble.expanded .message-clamp {
    max-height: none;
}
.message.assistant .message-bubble.expanded .message-clamp::after {
    display: none;
}

.show-more-btn {
    display: block;
    margin: 10px auto 2px;
    background: transparent;
    border: 1px solid rgba(224, 120, 64, 0.4);
    color: var(--orange-light);
    border-radius: 20px;
    padding: 5px 20px;
    font-size: 12.5px;
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
    letter-spacing: 0.03em;
}
.show-more-btn:hover {
    background: rgba(224, 120, 64, 0.12);
    border-color: var(--orange);
    color: var(--orange);
}

/* ─── Typing indicator ─────────────────────────────────────────────────────── */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 18px;
    background: var(--bubble-ai);
    border: 1px solid var(--border-mid);
    border-radius: var(--radius-lg);
    border-bottom-left-radius: 4px;
    width: fit-content;
    box-shadow: var(--shadow-card);
}
.typing-indicator span {
    height: 7px;
    width: 7px;
    background: var(--text-muted);
    border-radius: 50%;
    display: inline-block;
    animation: typing 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

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

/* ─── Input area ───────────────────────────────────────────────────────────── */
.chat-input-container {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 18px 24px 12px;
    flex-shrink: 0;
}

.data-notice {
    margin-top: 8px;
    text-align: center;
    font-size: 11px;
    color: var(--text-dim);
    letter-spacing: 0.02em;
}

.chat-form {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    background: var(--card-raised);
    border: 1px solid var(--border-mid);
    border-radius: var(--radius-lg);
    padding: 10px 10px 10px 18px;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.chat-form:focus-within {
    border-color: rgba(224, 120, 64, 0.4);
    box-shadow: 0 0 0 3px var(--orange-glow);
}

.message-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 14.5px;
    font-family: 'Plus Jakarta Sans', sans-serif;
    resize: none;
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.55;
    padding: 4px 0;
}
.message-input::placeholder { color: var(--text-dim); }

.message-input::-webkit-scrollbar { width: 4px; }
.message-input::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.send-button {
    background: #ffffff;
    color: #000000;
    border: none;
    border-radius: 12px;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--transition), transform var(--transition);
    flex-shrink: 0;
}
.send-button:hover:not(:disabled) {
    background: #e8e8e8;
    transform: scale(1.05);
}
.send-button:disabled { opacity: 0.3; cursor: not-allowed; }

.send-icon { font-size: 18px; line-height: 1; }

/* ─── Error message ────────────────────────────────────────────────────────── */
.error-message {
    background: rgba(196, 72, 48, 0.12);
    color: #f08070;
    padding: 11px 16px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(196, 72, 48, 0.25);
    text-align: center;
    font-size: 13.5px;
}

/* ─── Login page ───────────────────────────────────────────────────────────── */
.login-container {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border-mid);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-deep);
    width: 100%;
    max-width: 380px;
    overflow: hidden;
}

.login-header {
    background: var(--brand-gradient);
    color: white;
    padding: 32px 24px 28px;
    text-align: center;
    position: relative;
    overflow: hidden;
}
.login-header::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
    background-size: 200px 200px;
    pointer-events: none;
}

.login-header h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.3px;
    position: relative;
    z-index: 1;
}
.login-header .subtitle {
    position: relative;
    z-index: 1;
    margin-top: 4px;
}

.login-form {
    padding: 28px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--surface);
}

.login-field { display: flex; flex-direction: column; }

.login-input {
    background: var(--card-raised);
    border: 1px solid var(--border-mid);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    font-size: 14.5px;
    font-family: 'Plus Jakarta Sans', sans-serif;
    color: var(--text);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.login-input::placeholder { color: var(--text-dim); }
.login-input:focus {
    border-color: rgba(224, 120, 64, 0.45);
    box-shadow: 0 0 0 3px var(--orange-glow);
}
.login-input--error { border-color: rgba(196, 72, 48, 0.5); }

.login-error {
    color: #f08070;
    font-size: 13px;
    text-align: center;
    margin-top: -8px;
}

.login-button {
    background: var(--brand-gradient);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: 13px;
    font-size: 14.5px;
    font-weight: 600;
    font-family: 'Outfit', sans-serif;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: opacity var(--transition), transform var(--transition), box-shadow var(--transition);
    box-shadow: 0 2px 16px rgba(224, 120, 64, 0.2);
}
.login-button:hover {
    opacity: 0.92;
    transform: translateY(-1px);
    box-shadow: 0 6px 22px rgba(224, 120, 64, 0.3);
}
.login-button:active { transform: translateY(0); }

/* ─── Compatibility warning ────────────────────────────────────────────────── */
.compat-warning {
    background: var(--surface);
    border: 1px solid var(--border-mid);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-deep);
    width: 100%;
    max-width: 380px;
    overflow: hidden;
}

.compat-warning__header {
    background: var(--brand-gradient);
    color: white;
    padding: 32px 24px 28px;
    text-align: center;
    position: relative;
    overflow: hidden;
}
.compat-warning__header::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
    background-size: 200px 200px;
    pointer-events: none;
}
.compat-warning__header h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.3px;
    position: relative;
    z-index: 1;
}
.compat-warning__header .subtitle {
    position: relative;
    z-index: 1;
    margin-top: 4px;
    font-size: 14px;
    opacity: 0.85;
}

.compat-warning__body {
    padding: 28px 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.compat-warning__icon {
    font-size: 36px;
    text-align: center;
    line-height: 1;
}

.compat-warning__title {
    font-family: 'Outfit', sans-serif;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    text-align: center;
}

.compat-warning__msg {
    font-size: 13.5px;
    color: var(--text-muted);
    line-height: 1.6;
    text-align: center;
}

.compat-warning__items {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.compat-warning__items li {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 13.5px;
    color: var(--text-muted);
    line-height: 1.5;
}

.compat-warning__items li span:first-child {
    font-size: 15px;
    flex-shrink: 0;
    margin-top: 1px;
}

.compat-warning__items li.compat-fail {
    color: #f08070;
}

.compat-warning__items li.compat-ok {
    color: var(--teal-light);
}

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    body {
        padding: 0;
        overflow: hidden;
        position: relative;
        width: 100%;
    }

    body.keyboard-open {
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100);
    }

    .container {
        min-height: 100vh;
        min-height: calc(var(--vh, 1vh) * 100);
        max-width: 100%;
        display: flex;
        flex-direction: column;
    }

    .chat-container {
        flex: 1;
        display: flex;
        flex-direction: column;
        min-height: 0;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .chat-header {
        border-radius: 0;
        padding: 14px 18px;
        flex-shrink: 0;
    }

    .header-logo { height: 40px; }
    .header-text h1 { font-size: 18px; }

    .chat-messages {
        padding: 14px;
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    body.keyboard-open .chat-messages {
        flex: 1;
        overflow-y: auto;
    }

    .message-bubble {
        max-width: 88%;
        padding: 10px 14px;
        font-size: 14px;
    }

    .message.assistant .message-bubble { max-width: 95%; }

    .chat-input-container {
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        flex-shrink: 0;
        position: relative;
        z-index: 100;
    }

    body.keyboard-open .chat-input-container { position: relative; }

    .message-input {
        font-size: 16px; /* prevent iOS zoom */
        touch-action: manipulation;
    }

    .send-button { width: 40px; height: 40px; }
}

@media (max-width: 480px) {
    .chat-header { padding: 12px 14px; }
    .header-logo { height: 34px; }
    .header-text h1 { font-size: 16px; }
    .subtitle { font-size: 10px; }

    .chat-messages { padding: 10px; }

    .message-bubble {
        max-width: 92%;
        font-size: 13.5px;
        padding: 9px 12px;
    }

    .welcome-message { padding: 36px 14px; }
    .welcome-subtitle { font-size: 18px; }
    .welcome-hint { font-size: 13px; }

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

    .chat-form { gap: 8px; padding: 8px 8px 8px 14px; }
    .send-button { width: 38px; height: 38px; border-radius: 10px; }
    .send-icon { font-size: 16px; }
}
