:root {
    --primary-color: #007bff;
    --bg-color: #f4f4f9;
    --chat-bg: #ffffff;
    --bot-msg-bg: #e9ecef;
    --user-msg-bg: #007bff;
    --user-msg-text: #ffffff;
    --border-color: #ddd;
}

body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
    height: 100dvh; /* Mobile viewport fix */
    width: 100vw;
    position: relative; /* Needed for absolute positioning on mobile */
}

/* Left Panel - Chat */
.left-panel {
    width: 50%;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    background-color: var(--bg-color);
}

.chat-container {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
    font-size: 15px;
    position: relative;
    word-wrap: break-word;
}

.bot-message {
    background-color: var(--bot-msg-bg);
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.user-message {
    background-color: var(--user-msg-bg);
    color: var(--user-msg-text);
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

/* Loading Bubble */
.loading-message {
    background-color: var(--bot-msg-bg);
    color: #666;
    font-style: italic;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-radius: 12px;
    border-bottom-left-radius: 2px;
    align-self: flex-start;
    max-width: 80%;
    font-size: 14px;
}

.loading-dots span {
    display: inline-block;
    width: 6px;
    height: 6px;
    background-color: #999;
    border-radius: 50%;
    animation: pulse 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes pulse {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

.input-area {
    padding: 20px;
    background-color: var(--chat-bg);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
}

#user-input {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    outline: none;
    font-size: 15px;
}

#send-btn {
    padding: 10px 20px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
}

#send-btn:hover {
    background-color: #0056b3;
}

/* Right Panel - PDF */
.right-panel {
    width: 50%;
    background-color: #525659;
    /* Standard PDF viewer bg color */
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

#pdf-controls {
    background-color: #333;
    color: white;
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    z-index: 10;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

#pdf-controls button {
    background: #555;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
}

#pdf-controls button:hover {
    background: #777;
}

#page-input {
    width: 50px;
    padding: 3px;
    border-radius: 4px;
    border: 1px solid #777;
    background: #444;
    color: white;
    text-align: center;
    -moz-appearance: textfield;
    /* Firefox */
}

/* Hide arrows/spinners for Chrome, Safari, Edge, Opera */
#page-input::-webkit-outer-spin-button,
#page-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

#search-input {
    width: 100px;
    padding: 3px;
    border-radius: 4px;
    border: 1px solid #777;
    background: #444;
    color: white;
    margin-left: 10px;
}

#pdf-viewer-container {
    flex: 1;
    overflow: auto;
    position: relative;
    display: flex;
    /* justify-content: center; Removed to fix left panning issue */
    cursor: grab;
}

#pdf-viewer-container:active {
    cursor: grabbing;
}

#pdf-viewer {
    /* This will contain the canvases */
    transition: transform 0.1s ease-out;
    transform-origin: top center;
    padding: 20px;
    margin: 0 auto;
    /* Center content horizontally */
}

.pdf-page {
    margin-bottom: 20px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    background-color: white;
}

#pdf-footer {
    background-color: #333;
    color: #ccc;
    padding: 8px;
    text-align: center;
    font-size: 12px;
    border-top: 1px solid #444;
}

#pdf-footer a {
    color: #4da3ff;
    text-decoration: none;
}

#pdf-footer a:hover {
    text-decoration: underline;
}

/* Formatting Styles */
strong {
    font-weight: 700;
    color: #2c3e50;
}

.citation {
    color: var(--primary-color);
    cursor: pointer;
    font-weight: bold;
    text-decoration: underline;
}

.citation:hover {
    color: #0056b3;
}

/* Table Styles */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
    font-size: 14px;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

th,
td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: #333;
}

tr:last-child td {
    border-bottom: none;
}

/* List Styles */
ol,
ul {
    margin: 10px 0;
    padding-left: 25px;
}

li {
    margin-bottom: 5px;
}

/* --- Mobile Phone Compliance --- */

/* Default (Desktop): Hide mobile tabs */
.mobile-tabs {
    display: none;
}

/* Mobile Styles */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
    }

    .mobile-tabs {
        display: flex;
        position: absolute;
        top: 0; /* Changed from bottom: 0 */
        left: 0;
        width: 100%;
        height: 50px;
        background: #fff;
        border-bottom: 1px solid #ccc; /* Changed from border-top */
        z-index: 1000;
    }

    .mobile-tabs button {
        flex: 1;
        border: none;
        background: #f8f9fa;
        font-size: 16px;
        font-weight: bold;
        color: #666;
        cursor: pointer;
        transition: background 0.2s;
    }

    .mobile-tabs button.active {
        background: var(--primary-color);
        color: white;
    }

    /* Panels on mobile take full width/height minus tab bar */
    .left-panel, .right-panel {
        position: absolute;
        top: 50px; /* Shifted down to accommodate top tabs */
        left: 0;
        width: 100%;
        bottom: 0; /* Anchor to bottom */
        height: auto; /* Let top/bottom define height */
        border-right: none;
        z-index: 1;
    }
    
    .input-area {
        padding-bottom: 30px; /* Increased padding for iPhone safari bar */
    }

    /* Visibility Toggling Classes */
    .panel-hidden {
        display: none !important; /* Force hide */
    }

    .panel-visible {
        display: flex !important; /* Force show as flex */
        z-index: 10; /* Ensure visible one is on top */
    }
}