/**
 * Planetary Dharma AI - Web Interface Styles
 *
 * Simple, clean, accessible design for chat interface.
 * Mobile-first responsive approach.
 */

/* CSS Reset and Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #4a90a4;
    --primary-dark: #6bb5cc;
    --secondary-color: #7ec8de;
    --background: #000000;
    --surface: #1a1a1a;
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --border: #333333;
    --error: #ff6b6b;
    --success: #51cf66;
    --shadow: rgba(255, 255, 255, 0.05);
    --shadow-strong: rgba(255, 255, 255, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
                 Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--background);
    min-height: 100vh;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Earth Horizon Background */
.earth-horizon {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40vh;
    background-image: url('/static/images/earth-horizon.png');
    background-size: cover;
    background-position: center bottom;
    background-repeat: no-repeat;
    z-index: 0;
    pointer-events: none;
}

/* Password Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background-color: var(--surface);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 20px var(--shadow-strong);
    border: 1px solid var(--border);
    max-width: 400px;
    width: 90%;
    text-align: center;
    position: relative;
    z-index: 1001;
}

.modal-content h2 {
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.modal-content p {
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
}

#password-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#password-input {
    padding: 0.75rem;
    border: 2px solid var(--border);
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

#password-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Chat Container */
#chat-container {
    max-width: 900px;
    margin: 0 auto;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: transparent;
    position: relative;
    z-index: 1;
}

/* Header */
header {
    padding: 1.5rem;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    color: white;
    text-align: center;
    box-shadow: 0 2px 4px var(--shadow);
    border-bottom: 1px solid var(--border);
}

header h1 {
    font-size: 1.75rem;
    margin-bottom: 0.25rem;
    color: var(--primary-color);
}

header .subtitle {
    font-size: 0.9rem;
    opacity: 0.8;
    color: var(--text-secondary);
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
}

.message {
    padding: 1rem;
    border-radius: 8px;
    max-width: 80%;
    animation: fadeIn 0.3s ease-in;
}

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

.user-message {
    align-self: flex-end;
    background-color: rgba(74, 144, 164, 0.3);
    border: 1px solid var(--primary-color);
    color: white;
    margin-left: auto;
}

.assistant-message {
    align-self: flex-start;
    background-color: rgba(26, 26, 26, 0.8);
    border-left: 4px solid var(--secondary-color);
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.system-message {
    align-self: center;
    background-color: rgba(26, 26, 26, 0.6);
    color: var(--text-secondary);
    font-style: italic;
    max-width: 90%;
    text-align: center;
    border: 1px solid var(--border);
}

.message p {
    margin: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Markdown Content Styling */
.assistant-message h1,
.assistant-message h2,
.assistant-message h3,
.assistant-message h4 {
    margin: 1rem 0 0.5rem 0;
    color: var(--primary-color);
}

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

.assistant-message p {
    margin: 0.5rem 0;
}

.assistant-message ul,
.assistant-message ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.assistant-message li {
    margin: 0.25rem 0;
}

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

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

.assistant-message code {
    background-color: rgba(0, 0, 0, 0.05);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.assistant-message pre {
    background-color: rgba(0, 0, 0, 0.05);
    padding: 0.75rem;
    border-radius: 4px;
    overflow-x: auto;
}

.assistant-message pre code {
    background-color: transparent;
    padding: 0;
}

.assistant-message blockquote {
    border-left: 3px solid var(--secondary-color);
    padding-left: 1rem;
    margin: 0.5rem 0;
    color: var(--text-secondary);
}

.assistant-message hr {
    border: none;
    border-top: 2px solid var(--border);
    margin: 1rem 0;
}

/* Loading Spinner */
.loading-spinner {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    color: var(--text-secondary);
    background-color: rgba(0, 0, 0, 0.8);
    border-radius: 8px;
    border: 1px solid var(--border);
    z-index: 10;
}

.spinner {
    border: 3px solid var(--border);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Input Container */
.input-container {
    padding: 1rem;
    border-top: 2px solid var(--border);
    background-color: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
}

#chat-form {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

#message-input {
    flex: 1;
    padding: 0.75rem;
    border: 2px solid var(--border);
    border-radius: 4px;
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
    min-height: 60px;
    max-height: 200px;
    transition: border-color 0.2s;
    background-color: var(--surface);
    color: var(--text-primary);
}

#message-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

#message-input::placeholder {
    color: var(--text-secondary);
}

/* Buttons */
button {
    padding: 0.75rem 1.5rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

button:hover {
    background-color: var(--primary-dark);
}

button:active {
    transform: scale(0.98);
}

button:disabled {
    background-color: var(--border);
    cursor: not-allowed;
}

#send-button {
    min-width: 80px;
}

/* Error Handling */
.error {
    color: var(--error);
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

.error-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background-color: var(--error);
    color: white;
    padding: 1rem;
    text-align: center;
    z-index: 999;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
    }
    to {
        transform: translateY(0);
    }
}

.error-banner button {
    margin-top: 0.5rem;
    background-color: white;
    color: var(--error);
}

/* Responsive Design */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.5rem;
    }

    .chat-messages {
        padding: 1rem;
    }

    .message {
        max-width: 90%;
    }

    #chat-form {
        flex-direction: column;
    }

    #send-button {
        width: 100%;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus Indicators */
*:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

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

.chat-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}
