/* RLRL Chat - Styles */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    height: 100dvh;
    overflow: hidden;
}

/* Three-column layout */
.app-container {
    display: flex;
    height: 100dvh;
}

/* Sidebars */
.sidebar {
    background: #fff;
    border-right: 1px solid #e0e0e0;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.left-sidebar {
    width: 250px;
    min-width: 200px;
}

.right-sidebar {
    width: 200px;
    min-width: 150px;
    border-right: none;
    border-left: 1px solid #e0e0e0;
}

.sidebar h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: #666;
}

/* Session list */
.session-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.session-date {
    font-size: 0.75rem;
    color: #888;
    font-weight: 600;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}

.session-item {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    margin: 0.25rem 0;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.session-item:hover {
    background-color: #f0f0f0;
}

.session-item.active {
    background-color: #e3f2fd;
    border-left: 3px solid #1976d2;
}

.session-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.875rem;
}

.delete-btn {
    opacity: 0;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    font-size: 0.875rem;
    color: #999;
}

.session-item:hover .delete-btn {
    opacity: 1;
}

.delete-btn:hover {
    color: #e53935;
}

.no-sessions {
    color: #999;
    font-size: 0.875rem;
    text-align: center;
    padding: 1rem;
}

/* Main content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fafafa;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
}

.chat-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.model-badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    background: #e3f2fd;
    color: #1976d2;
    border-radius: 4px;
}

/* Health profile */
.health-profile-wrapper {
    margin: 1rem 1.5rem;
    padding: 1rem;
    background: #fff;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.health-profile-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.health-profile-label {
    font-weight: 600;
    color: #1976d2;
    flex: 1;
}

.health-profile-details {
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
}

.health-profile-details summary {
    cursor: pointer;
    font-size: 0.875rem;
    color: #666;
    padding: 0.25rem 0;
}

.health-profile-content {
    margin-top: 0.75rem;
    font-size: 0.875rem;
    max-height: 50vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-top: 0.5rem;
    border-top: 1px solid #e0e0e0;
}

.copy-btn {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

.copy-status {
    color: #4caf50;
    font-size: 0.875rem;
}

/* Messages container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 1rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 0;
}

/* Message bubbles */
.message {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    line-height: 1.5;
}

.user-message {
    align-self: flex-end;
    background: #1976d2;
    color: #fff;
}

.assistant-message {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #e0e0e0;
}

.message-content {
    word-wrap: break-word;
}

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

.message-content p:first-child {
    margin-top: 0;
}

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

.message-content code {
    background: rgba(0, 0, 0, 0.1);
    padding: 0.125rem 0.25rem;
    border-radius: 3px;
    font-size: 0.875em;
}

.message-content pre {
    background: #f5f5f5;
    padding: 0.75rem;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.5rem 0;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.user-message .message-content code {
    background: rgba(255, 255, 255, 0.2);
}

/* Tool details */
.tool-details {
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
}

.tool-details summary {
    cursor: pointer;
    color: #666;
    font-weight: 500;
}

.tool-args, .tool-result {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: #f5f5f5;
    border-radius: 4px;
    font-size: 0.75rem;
    max-height: 150px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

/* Typing indicator */
.typing-indicator {
    color: #999;
    font-style: italic;
}

.error {
    color: #e53935;
}

/* Input form */
.input-form {
    display: flex;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    background: #fff;
    border-top: 1px solid #e0e0e0;
}

.input-form textarea {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    resize: none;
    font-size: 1rem;
    font-family: inherit;
    line-height: 1.5;
    max-height: 150px;
}

.input-form textarea:focus {
    outline: none;
    border-color: #1976d2;
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: background-color 0.2s;
}

.btn-primary {
    background: #1976d2;
    color: #fff;
}

.btn-primary:hover {
    background: #1565c0;
}

.btn-send {
    background: #1976d2;
    color: #fff;
    padding: 0.75rem 1rem;
}

.btn-send:hover {
    background: #1565c0;
}

.btn-send:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.send-icon {
    font-size: 1.25rem;
}

.new-chat-btn {
    width: 100%;
    margin-bottom: 1rem;
}

/* Quick action buttons */
.btn-action {
    width: 100%;
    margin-bottom: 0.5rem;
    background: #f5f5f5;
    text-align: left;
}

.btn-action:hover {
    background: #e0e0e0;
}

.btn-action.active, .btn-health.active {
    background: #e3f2fd;
    color: #1976d2;
}

.btn-danger {
    background: #ffebee;
    color: #e53935;
    width: 100%;
}

.btn-danger:hover {
    background: #ffcdd2;
}

.version-info {
    font-size: 0.75rem;
    color: #999;
    margin-top: 1rem;
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e0e0e0;
    border-top-color: #1976d2;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Mobile header - hidden on desktop */
.mobile-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    padding-top: calc(0.75rem + env(safe-area-inset-top));
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    position: sticky;
    top: 0;
    z-index: 50;
}

.mobile-header h1 {
    font-size: 1.1rem;
    font-weight: 600;
}

.hamburger-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.hamburger-btn span {
    display: block;
    width: 22px;
    height: 2px;
    background: #333;
    border-radius: 1px;
}

.mobile-health-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    opacity: 0.6;
}

.mobile-health-btn.active {
    opacity: 1;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
}

.sidebar-overlay.visible {
    display: block;
}

.sidebar-header {
    display: none;
}

.close-sidebar-btn {
    display: none;
}

/* Mobile quick actions - hidden on desktop */
.mobile-quick-actions {
    display: none;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
    background: #fff;
    border-top: 1px solid #e0e0e0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.mobile-action-btn {
    flex-shrink: 0;
    padding: 0.5rem 1rem;
    background: #f5f5f5;
    border: none;
    border-radius: 20px;
    font-size: 0.875rem;
    cursor: pointer;
    white-space: nowrap;
}

.mobile-action-btn:active {
    background: #e0e0e0;
}

/* Responsive */
@media (max-width: 900px) {
    .right-sidebar {
        display: none;
    }
}

@media (max-width: 700px) {
    .app-container {
        flex-direction: column;
    }

    .mobile-header {
        display: flex;
    }

    .mobile-quick-actions {
        display: flex;
    }

    .chat-header {
        display: none;
    }

    .sidebar-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 1rem;
    }

    .sidebar-header h2 {
        margin-bottom: 0;
    }

    .close-sidebar-btn {
        display: block;
        background: none;
        border: none;
        font-size: 1.5rem;
        cursor: pointer;
        padding: 0.25rem 0.5rem;
        color: #666;
    }

    .left-sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        height: 100%;
        width: 280px;
        z-index: 100;
        transition: left 0.3s ease;
        box-shadow: none;
    }

    .left-sidebar.open {
        left: 0;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
    }

    .main-content {
        flex: 1;
        width: 100%;
        min-height: 0;
    }

    .messages-container {
        padding: 0.75rem;
    }

    .message {
        max-width: 90%;
        padding: 0.625rem 0.875rem;
    }

    .input-form {
        padding: 0.75rem;
        gap: 0.5rem;
    }

    .input-form textarea {
        padding: 0.625rem 0.875rem;
        font-size: 16px; /* Prevents iOS zoom */
    }

    .health-profile-wrapper {
        margin: 0.25rem 0.5rem;
        padding: 0.5rem;
    }

    .health-profile-content {
        max-height: 25vh;
    }

    .btn-send {
        padding: 0.625rem 0.875rem;
    }

    /* Larger touch targets */
    .session-item {
        padding: 0.75rem;
        min-height: 44px;
    }

    .delete-btn {
        opacity: 1;
        padding: 0.5rem;
        font-size: 1rem;
    }

    .btn {
        min-height: 44px;
    }

    .new-chat-btn {
        padding: 0.75rem 1rem;
    }
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #999;
}
