/* Q2T Compass - Modern Dark Theme */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #f97316;
    --primary-hover: #fb923c;
    --primary-muted: rgba(249, 115, 22, 0.15);
    
    --bg-primary: #1e1e24;
    --bg-secondary: #282830;
    --bg-tertiary: #32323a;
    --bg-elevated: #3c3c45;
    --bg-input: #35353e;
    
    --text-primary: #f8f8fa;
    --text-secondary: #b4b4bc;
    --text-muted: #8e8e98;
    
    --border: #4a4a54;
    --border-subtle: #3a3a42;
    
    --success: #22c55e;
    --error: #ef4444;
    --warning: #f59e0b;
    
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    
    --transition: 150ms ease;
}

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* Screen Management */
.screen {
    display: none;
    min-height: 100vh;
}

.screen.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Login Screen */
.login-container {
    width: 100%;
    max-width: 380px;
    padding: 40px 32px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.login-header p {
    color: var(--text-muted);
    font-size: 14px;
}

.login-form {
    margin-bottom: 24px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.form-group input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 15px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-muted);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.login-btn {
    width: 100%;
    padding: 12px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), transform var(--transition);
}

.login-btn:hover {
    background: var(--primary-hover);
}

.login-btn:active {
    transform: scale(0.98);
}

.login-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.error-message {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, 0.2);
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    margin-top: 16px;
    font-size: 14px;
}

.login-footer {
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
}

.login-footer p {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.login-footer ul {
    list-style: none;
}

.login-footer li {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 4px 0;
}

.login-footer li::before {
    content: "→";
    color: var(--primary);
    margin-right: 8px;
}

/* Chat Screen */
#chatScreen.active {
    display: flex;
    align-items: stretch;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    max-width: 850px;
    margin: 0 auto;
}

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

.user-info h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.user-info p {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.chat-controls {
    display: flex;
    gap: 8px;
}

.control-btn {
    padding: 8px 14px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.control-btn:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--text-muted);
}

.logout-btn {
    color: var(--error);
    border-color: rgba(239, 68, 68, 0.3);
}

.logout-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--error);
    color: var(--error);
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    scroll-behavior: smooth;
}

.message {
    margin-bottom: 24px;
    animation: fadeIn 0.2s ease;
}

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

.message-content {
    max-width: 85%;
    padding: 16px 20px;
    border-radius: var(--radius-lg);
    line-height: 1.7;
}

/* User Message */
.user-message .message-content {
    background: var(--bg-elevated);
    color: var(--text-primary);
    margin-left: auto;
    border-bottom-right-radius: var(--radius-sm);
}

/* Assistant Message */
.assistant-message .message-content {
    background: transparent;
    padding: 0;
    max-width: 100%;
    color: var(--text-primary);
}

/* System Message */
.system-message {
    margin-bottom: 32px;
}

.system-message .message-content {
    max-width: 100%;
    padding: 20px 24px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    text-align: center;
}

.system-message strong {
    color: var(--text-primary);
}

.system-message p {
    color: var(--text-secondary);
    margin-bottom: 12px;
}

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

.system-message ul {
    display: inline-block;
    text-align: left;
    list-style: none;
    margin-top: 12px;
    padding: 0;
}

.system-message li {
    color: var(--text-muted);
    font-size: 14px;
    padding: 4px 0;
}

.system-message li::before {
    content: "•";
    color: var(--primary);
    margin-right: 10px;
}

/* Markdown Content Styling (Dark Mode) */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
    color: var(--text-primary);
    margin: 20px 0 12px 0;
    font-weight: 600;
}

.message-content h1:first-child,
.message-content h2:first-child,
.message-content h3:first-child {
    margin-top: 0;
}

.message-content h1 { font-size: 1.5rem; }
.message-content h2 { font-size: 1.25rem; }
.message-content h3 { font-size: 1.1rem; }
.message-content h4 { font-size: 1rem; }

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

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

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

.message-content li {
    margin: 6px 0;
    color: var(--text-primary);
}

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

.message-content em {
    font-style: italic;
}

/* Code Styling */
.message-content code {
    background: var(--bg-elevated);
    color: #e879f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 0.9em;
}

.message-content pre {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin: 16px 0;
    overflow-x: auto;
}

.message-content pre code {
    background: transparent;
    padding: 0;
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
}

/* Tables */
.message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 16px 0;
    font-size: 14px;
}

.message-content th,
.message-content td {
    padding: 10px 14px;
    text-align: left;
    border: 1px solid var(--border);
}

.message-content th {
    background: var(--bg-elevated);
    font-weight: 600;
    color: var(--text-primary);
}

.message-content td {
    color: var(--text-secondary);
}

.message-content tr:hover td {
    background: var(--bg-tertiary);
}

/* Blockquotes */
.message-content blockquote {
    border-left: 3px solid var(--primary);
    margin: 16px 0;
    padding: 12px 20px;
    background: var(--bg-tertiary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-secondary);
}

/* Currency and Percentages */
.message-content .currency {
    color: var(--success);
    font-weight: 600;
}

.message-content .percentage {
    color: #3b82f6;
    font-weight: 600;
}

/* Upcoming trips (get_user_bookings HTML cards) */
.message-content .trip-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin: 16px 0 20px;
    max-width: 560px;
}

.message-content .trip-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px 18px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.message-content .trip-card__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 10px;
    margin-bottom: 10px;
}

.message-content .trip-card__ordinal {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    min-width: 1.5em;
}

.message-content .trip-card__badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--primary);
    background: var(--primary-muted);
    padding: 4px 10px;
    border-radius: 999px;
}

.message-content .trip-card__status {
    font-size: 12px;
    font-weight: 600;
    color: var(--success);
    margin-left: auto;
}

.message-content .trip-card h4.trip-card__route {
    margin: 0 0 6px 0;
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.35;
    color: var(--text-primary);
}

.message-content .trip-card__req {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
}

.message-content .trip-card__req strong {
    color: var(--text-primary);
}

.message-content .trip-card__when {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0 0 6px 0;
}

.message-content .trip-card__traveller {
    font-size: 14px;
    color: var(--text-primary);
    margin: 0 0 6px 0;
}

.message-content .trip-card__summary {
    font-size: 13px;
    color: var(--text-muted);
    margin: 0 0 10px 0;
    line-height: 1.5;
}

.message-content .trip-card__meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
}

.message-content .trip-card ul.trip-segments {
    list-style: none;
    padding: 0;
    margin: 0 0 12px 0;
    border-top: 1px solid var(--border-subtle);
    padding-top: 10px;
}

.message-content .trip-card li.trip-segment {
    margin: 0 0 8px 0;
    padding-left: 14px;
    position: relative;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.45;
}

.message-content .trip-card li.trip-segment::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0.55em;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary);
    opacity: 0.85;
}

.message-content .trip-card__cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 4px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    color: var(--bg-primary);
    background: var(--primary);
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: background var(--transition), transform var(--transition);
}

.message-content .trip-card__cta:hover {
    background: var(--primary-hover);
    color: var(--bg-primary);
}

.message-content .trip-card__cta:active {
    transform: scale(0.98);
}

/* Message Metadata */
.message-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-subtle);
    font-size: 12px;
}

.tools-used {
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 4px 10px;
    border-radius: 12px;
}

.response-time {
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    max-width: fit-content;
}

.typing-stage {
    font-size: 14px;
    color: var(--text-secondary);
}

.typing-dots {
    display: flex;
    gap: 4px;
}

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

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

@keyframes pulse {
    0%, 60%, 100% { opacity: 0.3; transform: scale(1); }
    30% { opacity: 1; transform: scale(1.1); }
}

.typing-timer {
    font-size: 12px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* Chat Input Area */
.chat-input-container {
    padding: 16px 24px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg-primary);
}

.chat-input-wrapper {
    display: flex;
    gap: 12px;
    padding: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.chat-input-wrapper:focus-within {
    border-color: var(--text-muted);
}

#chatInput {
    flex: 1;
    padding: 10px 14px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 150px;
    line-height: 1.5;
}

#chatInput:focus {
    outline: none;
}

#chatInput::placeholder {
    color: var(--text-muted);
}

.send-btn {
    padding: 10px 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), opacity var(--transition);
    align-self: flex-end;
}

.send-btn:hover:not(:disabled) {
    background: var(--primary-hover);
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Input Hints */
.input-hints {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.hint-btn {
    padding: 6px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition);
}

.hint-btn:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--text-muted);
}

/* Quick Actions (CTA buttons in messages) */
.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-subtle);
}

.quick-action-btn {
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.quick-action-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.loading-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: 32px 40px;
    border-radius: var(--radius-lg);
    text-align: center;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

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

.loading-content p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Connection Notifications */
.connection-warning {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--warning);
    color: var(--bg-primary);
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 14px;
    z-index: 10000;
    animation: slideIn 0.3s ease;
}

.disconnection-notice {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 32px;
    border-radius: var(--radius-lg);
    text-align: center;
    max-width: 380px;
    z-index: 10001;
}

.disconnection-notice .notice-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.disconnection-notice h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--warning);
}

.disconnection-notice .notice-reason {
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.disconnection-notice .notice-action {
    color: var(--text-muted);
    font-size: 13px;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Responsive Design */
@media (max-width: 768px) {
    .login-container {
        margin: 16px;
        padding: 32px 24px;
    }
    
    .chat-header {
        padding: 12px 16px;
    }
    
    .chat-messages {
        padding: 16px;
    }
    
    .message-content {
        max-width: 95%;
    }
    
    .chat-input-container {
        padding: 12px 16px 20px;
    }
}

@media (max-width: 480px) {
    .chat-header {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }
    
    .chat-input-wrapper {
        flex-direction: column;
    }
    
    .send-btn {
        align-self: stretch;
    }
    
    .form-group input {
        font-size: 16px;
    }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-elevated);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
