* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Roboto', Arial, sans-serif;
    max-width: 1024px;
    width: 100%;
    margin: 0 auto;
    padding: 0;
    background-color: #1a1a1a;
    color: #e0e0e0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    /* Safe area support for devices with notches */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

#header {
    background-color: #1a1a1a;
    border-bottom: 1px solid #333;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    position: sticky;
    top: 0;
    z-index: 100;
    flex-shrink: 0;
}

#header-left {
    width: 40px;
}

#header-center {
    flex: 1;
    display: flex;
    justify-content: center;
    min-width: 0; /* Allow flex child to shrink */
}

#header-right {
    width: 40px;
    display: flex;
    justify-content: flex-end;
}

#logo {
    height: 32px;
    max-width: 160px;
    min-width: 32px;
    background-image: url('logo.svg');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    border-radius: 4px;
    /* Try to expand to fit content, but respect max-width */
    width: 160px;
    flex-shrink: 1;
}

#settings-button {
    width: 36px;
    height: 36px;
    background-color: transparent;
    border: none;
    border-radius: 50%;
    color: #e0e0e0;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    padding: 0;
}

#settings-button:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

#settings-button:active {
    background-color: rgba(255, 255, 255, 0.2);
}

/* Hamburger menu icon */
.hamburger-icon {
    width: 18px;
    height: 14px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.hamburger-icon span {
    width: 100%;
    height: 2px;
    background-color: #e0e0e0;
    border-radius: 1px;
    transition: background-color 0.2s;
}

#settings-button:hover .hamburger-icon span {
    background-color: #ffffff;
}

/* Welcome Screen Styles */
#welcome-screen {
    display: none;
    height: 100vh;
    background-color: #1a1a1a;
    color: #e0e0e0;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 20px;
}

#welcome-screen.show {
    display: flex;
}

#welcome-logo {
    width: 120px;
    height: 120px;
    background-image: url('logo.svg');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    border-radius: 12px;
    margin-bottom: 40px;
}

#welcome-text {
    max-width: 400px;
    margin-bottom: 50px;
}

#welcome-title {
    font-size: 2rem;
    font-weight: 500;
    margin-bottom: 15px;
    color: #ffffff;
}

#welcome-subtitle {
    font-size: 1.1rem;
    color: #b0b0b0;
    line-height: 1.5;
}

#welcome-auth-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 250px;
}

.welcome-auth-button {
    padding: 15px 25px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    transition: background-color 0.2s;
    font-weight: 500;
}

.welcome-google-btn {
    background-color: #ffffff;
    color: #1f1f1f;
    border: 1px solid #dadce0;
}

.welcome-google-btn:hover {
    background-color: #f8f9fa;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.welcome-apple-btn {
    background-color: #666;
    color: #aaa;
    border: 1px solid #555;
    cursor: not-allowed;
    opacity: 0.6;
}

.welcome-apple-btn:hover {
    background-color: #666;
    cursor: not-allowed;
}

/* Main App Container */
#main-app {
    display: none;
    height: 100vh;
    flex-direction: column;
}

#main-app.show {
    display: flex;
}

/* Settings Menu */
#settings-menu {
    position: absolute;
    top: 50px;
    right: 15px;
    background-color: #2a2a2a;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 10px;
    min-width: 200px;
    display: none;
    z-index: 200;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

#settings-menu.show {
    display: block;
}

.menu-section {
    margin-bottom: 15px;
}

.menu-section:last-child {
    margin-bottom: 0;
}

.menu-title {
    font-size: 0.85rem;
    color: #888;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.user-info {
    padding: 10px;
    background-color: #333;
    border-radius: 6px;
    font-size: 0.9rem;
}

.user-name {
    font-weight: 500;
    margin-bottom: 4px;
}

.user-email {
    color: #aaa;
    font-size: 0.8rem;
}

.logout-btn {
    background-color: #ff4757;
    color: white;
    padding: 8px 15px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    width: 100%;
    margin-top: 8px;
}

.logout-btn:hover {
    background-color: #ff3742;
}

#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 10px;
    min-height: 0;
}

#chat-container {
    flex: 1;
    border: 1px solid #333;
    overflow-y: auto;
    padding: 10px;
    margin-bottom: 15px;
    background-color: #1a1a1a;
    min-height: 0;
    /* Thin scrollbar styling */
    scrollbar-width: thin;
    scrollbar-color: #666 #2a2a2a;
}

/* Webkit browsers (Chrome, Safari, Edge) */
#chat-container::-webkit-scrollbar {
    width: 6px;
}

#chat-container::-webkit-scrollbar-track {
    background: #2a2a2a;
    border-radius: 3px;
}

#chat-container::-webkit-scrollbar-thumb {
    background: #666;
    border-radius: 3px;
}

#chat-container::-webkit-scrollbar-thumb:hover {
    background: #888;
}

.message {
    margin-bottom: 15px;
    padding: 12px;
    border-radius: 8px;
    max-width: 85%;
    word-wrap: break-word;
}

.user-message {
    background-color: rgba(255, 255, 255, 0.08);
    margin-left: auto;
    margin-right: 0;
}

.assistant-message {
    background-color: transparent;
    margin-left: 0;
    margin-right: auto;
}

.message-role {
    font-weight: bold;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.message-content {
    white-space: pre-wrap;
    line-height: 1.5;
    font-size: 0.95rem;
}

.message-time {
    font-size: 0.75rem;
    color: #888;
    margin-top: 8px;
}

#input-container {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

#controls-container {
    display: flex;
    gap: 10px;
    justify-content: space-between;
    align-items: center;
}

#delete-button {
    padding: 8px 16px;
    background-color: #ff4757;
    color: #ffffff;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9em;
}

#delete-button:hover {
    background-color: #ff3742;
}

#delete-button:disabled {
    background-color: #666;
    cursor: not-allowed;
}

#message-input {
    flex: 1;
    padding: 10px;
    border: 1px solid #333;
    border-radius: 5px;
    background-color: #2a2a2a;
    color: #e0e0e0;
}

#message-input::placeholder {
    color: #888;
}

#send-button {
    padding: 10px 20px;
    background-color: #4a4a4a;
    color: #e0e0e0;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

#send-button:hover {
    background-color: #5a5a5a;
}

#send-button:disabled {
    background-color: #333;
    cursor: not-allowed;
}

#status {
    margin-top: 10px;
    padding: 5px;
    font-size: 0.9em;
    color: #888;
    /* Extra padding for devices with rounded corners */
    padding-bottom: max(5px, env(safe-area-inset-bottom, 0px));
}

.loading {
    color: #66b3ff;
}

.error {
    color: #ff6b6b;
}

.success {
    color: #51cf66;
}

/* Markdown formatting styles */
.message-content strong {
    font-weight: bold;
    color: #ffffff;
}

.message-content em {
    font-style: italic;
    color: #b8b8b8;
}

.message-content code {
    background-color: #2d2d2d;
    color: #ff6b6b;
    padding: 3px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
}

.message-content del {
    text-decoration: line-through;
    color: #666;
}

.message-content a {
    color: #66b3ff;
    text-decoration: none;
}

/* YouTube embed styles */
.youtube-embed-container {
    margin: 10px 0;
    background-color: #2a2a2a;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #444;
    max-width: 500px;
    width: 100%;
}

.youtube-embed-wrapper {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
}

.youtube-embed-wrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

/* Mobile responsiveness for YouTube embeds */
@media (max-width: 768px) {
    .youtube-embed-container {
        margin: 8px 0;
        max-width: 100%; /* Allow full width on mobile */
    }
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    #main-content {
        padding: 5px;
    }
    
    #header {
        padding: 0 10px;
    }
    
    .message {
        max-width: 90%;
        padding: 10px;
    }
    
    .message-content {
        font-size: 0.9rem;
    }
    
    #message-input {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    #controls-container {
        gap: 8px;
        align-items: stretch;
    }
    
    #status {
        text-align: center;
    }
}

@media (max-width: 480px) {
    #input-container {
        gap: 8px;
    }
    
    #send-button {
        padding: 12px 16px;
    }
    
    .message {
        max-width: 95%;
    }
}