* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #1a1a2e;
    --surface: #16213e;
    --surface-light: #1f2f50;
    --accent: #4A90D9;
    --accent-soft: #6BA3E0;
    --text: #eee;
    --text-dim: #8892b0;
    --bot-bg: #1f2f50;
    --user-bg: #4A90D9;
    --input-bg: #0f3460;
    --border: #2a3a5e;
    --success: #4ecdc4;
    --warning: #f39c12;
    --danger: #e74c3c;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    height: 100dvh;
    overflow: hidden;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 900px;
    margin: 0 auto;
}

/* Header */
.header {
    padding: 16px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-link {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: inherit;
}

.logo-icon {
    font-size: 36px;
}

.logo-text h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--accent-soft);
}

.subtitle {
    font-size: 13px;
    color: var(--text-dim);
}

.header-nav {
    display: flex;
    gap: 12px;
}

.nav-link {
    color: var(--text-dim);
    text-decoration: none;
    font-size: 13px;
    padding: 4px 10px;
    border-radius: 8px;
    transition: color 0.2s, background 0.2s;
}

.nav-link:hover {
    color: var(--text);
    background: var(--surface-light);
}

/* Disclaimer banner */
.disclaimer-banner {
    padding: 10px 20px;
    background: linear-gradient(135deg, #c0392b, #e74c3c);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.4;
}

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

.disclaimer-text {
    flex: 1;
}

/* History panel */
.history-panel {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    overflow: hidden;
}

.history-toggle {
    width: 100%;
    padding: 10px 20px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 13px;
    font-family: var(--font);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: color 0.2s;
}

.history-toggle:hover {
    color: var(--text);
}

.history-toggle-icon {
    font-size: 10px;
    transition: transform 0.2s;
    display: inline-block;
}

.history-toggle-icon.collapsed {
    transform: rotate(-90deg);
}

.history-count {
    background: var(--accent);
    color: white;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

.history-list {
    max-height: 260px;
    overflow-y: auto;
    padding: 0 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.history-list.collapsed {
    display: none;
}

.history-item {
    padding: 10px 14px;
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
}

.history-item:hover {
    border-color: var(--accent);
    background: rgba(74, 144, 217, 0.05);
}

.history-item-info {
    flex: 1;
    min-width: 0;
}

.history-item-query {
    font-size: 13px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.history-item-meta {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 3px;
}

.history-item-date {
    font-size: 11px;
    color: var(--text-dim);
}

.history-item-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 6px;
    background: rgba(78, 205, 196, 0.15);
    color: var(--success);
}

/* Chat */
.chat {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    gap: 10px;
    max-width: 90%;
    animation: fadeIn 0.3s ease;
}

.message.bot {
    align-self: flex-start;
}

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    background: var(--surface-light);
}

.message.user .message-avatar {
    background: var(--accent);
    font-size: 14px;
}

.message-content {
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.5;
    font-size: 14px;
}

.message.bot .message-content {
    background: var(--bot-bg);
    border-bottom-left-radius: 4px;
}

.message.user .message-content {
    background: var(--user-bg);
    border-bottom-right-radius: 4px;
}

.message-content p {
    margin-bottom: 8px;
}

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

.message-content ul, .message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.message-content li {
    margin-bottom: 4px;
    color: var(--text-dim);
}

.message-content .hint {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 8px;
}

.hint-link {
    color: var(--success);
    text-decoration: underline;
    text-decoration-color: rgba(78, 205, 196, 0.3);
}

.hint-link:hover {
    color: #fff;
}

/* Onboarding steps */
.onboarding-steps {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 10px 0;
}

.onboarding-step {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.step-num {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
}

.step-body {
    font-size: 13px;
    line-height: 1.4;
}

.step-body strong {
    color: var(--text);
}

.step-hint {
    display: block;
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 2px;
}

/* Example query buttons */
.example-queries {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 8px 0 4px;
}

.example-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 6px 14px;
    color: var(--success);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, transform 0.1s;
    font-family: inherit;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.example-btn:hover {
    background: rgba(78, 205, 196, 0.1);
    border-color: var(--success);
}

.example-btn:active {
    transform: scale(0.97);
}

/* Markdown in chat */
.message-content h2 {
    font-size: 16px;
    font-weight: 700;
    margin: 16px 0 8px 0;
    color: var(--accent-soft);
}

.message-content h3 {
    font-size: 14px;
    font-weight: 700;
    margin: 12px 0 6px 0;
    color: var(--text);
}

.message-content strong {
    color: var(--text);
    font-weight: 600;
}

.message-content a {
    color: var(--success);
    text-decoration: underline;
    text-decoration-color: rgba(78, 205, 196, 0.3);
}

.message-content a:hover {
    color: #fff;
}

.message-content code {
    background: var(--surface);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
}

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

.message-content blockquote {
    border-left: 3px solid var(--accent);
    margin: 8px 0;
    padding: 4px 12px;
    color: var(--text-dim);
    font-size: 13px;
}

/* Disclaimer in bot responses */
.response-disclaimer {
    margin-top: 12px;
    padding: 8px 12px;
    background: rgba(231, 76, 60, 0.1);
    border: 1px solid rgba(231, 76, 60, 0.3);
    border-radius: 8px;
    font-size: 12px;
    color: var(--danger);
    font-weight: 500;
    line-height: 1.4;
}

/* Loading */
.loading-text {
    font-weight: 600;
    color: var(--accent-soft);
}

.loading-text .dots::after {
    content: '';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}

.loading-bar {
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    margin: 8px 0;
    overflow: hidden;
}

.loading-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    animation: loadProgress 90s ease-out forwards;
}

@keyframes loadProgress {
    0% { width: 0%; }
    10% { width: 12%; }
    30% { width: 35%; }
    50% { width: 55%; }
    70% { width: 72%; }
    90% { width: 88%; }
    100% { width: 95%; }
}

.loading-status {
    font-size: 12px;
    color: var(--text-dim);
}

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

/* Limit banner */
.limit-banner {
    padding: 12px 20px;
    background: var(--warning);
    color: #1a1a2e;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.limit-timer {
    font-variant-numeric: tabular-nums;
}

/* Input area */
.input-area {
    padding: 12px 20px calc(16px + env(safe-area-inset-bottom, 0px));
    background: var(--surface);
    border-top: 1px solid var(--border);
    touch-action: manipulation;
}

.input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.upload-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--surface-light);
    border: 1px solid var(--border);
    color: var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.2s, border-color 0.2s;
}

.upload-btn:hover {
    color: var(--accent-soft);
    border-color: var(--accent);
}

.upload-btn.has-file {
    color: var(--success);
    border-color: var(--success);
}

#messageInput {
    flex: 1;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 12px 20px;
    color: var(--text);
    font-size: 15px;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.2s;
}

#messageInput:focus {
    border-color: var(--accent);
}

#messageInput::placeholder {
    color: var(--text-dim);
}

#sendBtn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, opacity 0.15s;
    flex-shrink: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
}

#sendBtn:hover {
    transform: scale(1.05);
}

#sendBtn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.send-icon {
    display: inline-block;
    transform: rotate(-30deg);
}

/* Photo/file preview */
.photo-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding: 6px 12px;
    background: var(--surface-light);
    border-radius: 8px;
    font-size: 13px;
}

.photo-file-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.photo-name {
    color: var(--text-dim);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.photo-remove {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.photo-remove:hover {
    color: var(--accent);
}

/* Mobile */
@media (max-width: 600px) {
    .message {
        max-width: 95%;
    }

    .header {
        padding: 12px 16px;
    }

    .chat {
        padding: 12px;
    }

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

    .disclaimer-banner {
        padding: 8px 12px;
        font-size: 12px;
    }

    .history-list {
        max-height: 200px;
        padding: 0 8px 8px;
    }

    .history-toggle {
        padding: 8px 16px;
    }

    .history-item {
        padding: 8px 10px;
    }
}
