/* General Setup */

body {
    margin: 0;
    font-family: "Courier New", Courier, monospace; /* Basic mono font */
    background-color: #0a0a0a; /* Dark background */
    color: #ededed; /* Light text */
    background-image: url('background.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed; /* Fixed ensures it covers viewport */
    overflow: hidden; /* Prevent body scroll */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

a {
    color: #34d399; /* Green accent for links */
    text-decoration: none;
}

a:hover {
    color: #a7f3d0;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

/* View Handling */
.view {
    display: none; /* Hide views by default */
    flex-grow: 1;
    width: 100%;
    position: relative; /* Added for pseudo-element positioning */
}

.view::before {
    content: "";
    position: absolute;
    inset: 0; /* Cover the entire view */
    background-color: rgba(0, 0, 0, 0.3); /* <<< Adjusted opacity for BRIGHTER background */
    z-index: 1; /* Sit ON TOP of view background, behind specific content */
    -webkit-backface-visibility: hidden;
}

.active-view {
    display: flex; /* Show the active view */
    flex-direction: column;
}

/* Landing Page Styles */
#landing-view {
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px;
    box-sizing: border-box;
    position: relative; 
    z-index: 2; /* Sit above overlay */
}

.top-nav {
    position: absolute;
    top: 15px;
    left: 15px;
    right: 15px;
    display: flex;
    justify-content: space-between;
    font-size: 0.9em;
    color: #9ca3af;
    z-index: 3; /* <<< Ensure nav is above content/overlay */
}

.top-nav a {
    color: #9ca3af; /* <<< ENSURE default color is greyish */
}

.top-nav a:hover {
    color: #34d399; /* Green only on hover */
}

.landing-content {
    max-width: 600px;
    position: relative; 
    z-index: 2; /* Sit above overlay */
}

.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8em;
    color: #9ca3af;
    margin-bottom: 40px;
    letter-spacing: 1px;
    margin-top: 0; /* Reset for desktop */
}

.status-dot {
    width: 8px;
    height: 8px;
    background-color: #34d399;
    border-radius: 50%;
    opacity: 0.7;
    /* Apply the existing pulse animation */
    animation: pulse-anim 1.5s infinite ease-in-out;
}

#landing-view h1 {
    font-size: 2.5em;
    margin: 0 0 10px 0;
    font-weight: bold;
    color: #f3f4f6;
}

.subtitle {
    font-size: 1.1em;
    color: #9ca3af;
    margin-bottom: 30px;
}

.landing-logo {
    width: 64px;
    height: 64px;
    margin-bottom: 25px;
}

#begin-investigation-btn,
.support-link {
    display: block;
    width: 100%;
    max-width: 350px;
    margin: 15px auto;
    padding: 20px;
    font-size: 1em;
    font-weight: bold;
    text-align: center;
    border: 2px solid rgba(52, 211, 153, 0.3); /* Green border */
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#begin-investigation-btn {
    color: #34d399; /* Green text */
    background-color: rgba(16, 185, 129, 0.05);
}

#begin-investigation-btn:hover {
    border-color: rgba(52, 211, 153, 0.5);
    background-color: rgba(16, 185, 129, 0.1);
    color: #a7f3d0;
}

.support-link {
    color: #fbbf24; /* Amber text */
    border-color: rgba(251, 191, 36, 0.3); /* Amber border */
    background-color: rgba(251, 191, 36, 0.05);
}

.support-link:hover {
    border-color: rgba(251, 191, 36, 0.5);
    background-color: rgba(251, 191, 36, 0.1);
    color: #fde68a;
}

.date-boxes {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 40px;
    font-size: 0.8em;
}

.date-boxes > div {
    border: 1px solid rgba(107, 114, 128, 0.3);
    background-color: rgba(31, 41, 55, 0.2);
    padding: 15px;
    color: #9ca3af;
}

.date-boxes > div span {
    display: block;
    font-size: 0.9em;
    color: #6b7280;
    margin-top: 5px;
}

.disclaimer {
    margin-top: 30px;
    font-size: 0.7em;
    color: #ef4444; /* Red text */
    border: 1px solid rgba(239, 68, 68, 0.3);
    background-color: rgba(239, 68, 68, 0.05);
    padding: 10px 15px;
    display: inline-block;
}

.landing-footer {
    margin-top: 40px;
    font-size: 0.7em;
    color: #6b7280;
}

.landing-footer a {
    /* Keep default green or set specific */
    color: #34d399;
}
.landing-footer a:hover {
    color: #a7f3d0;
    text-decoration: underline;
}

/* Chat Interface Styles */
#chat-view {
    overflow: hidden; /* Prevent this view itself from scrolling */
    height: 100vh; 
    box-sizing: border-box;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid rgba(52, 211, 153, 0.2); 
    background-color: rgba(17, 24, 39, 0.8);
    flex-shrink: 0; 
    position: relative; 
    z-index: 2; /* Sit above overlay */
}

.chat-header button {
    color: #9ca3af;
    font-size: 1em;
    padding: 5px 10px;
}

.chat-header button:hover {
    color: #34d399;
}

.chat-header span {
    color: #a7f3d0;
    font-weight: bold;
}

.message-list {
    flex-grow: 1; 
    overflow-y: auto; 
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-height: 0; 
    position: relative;
    z-index: 2; /* Sit above overlay */
}

.message {
    padding: 10px 15px;
    border-radius: 8px;
    max-width: 80%;
    line-height: 1.5;
    word-wrap: break-word;
}

.message.user {
    background-color: rgba(55, 65, 81, 0.4); /* Gray user message */
    color: #d1d5db;
    align-self: flex-end; /* Position bubble on right side */
    text-align: left; /* Keep text left-aligned inside the bubble */
    white-space: pre-wrap; /* Ensure line breaks are preserved */
}

.message.bot {
    background-color: rgba(17, 24, 39, 0.5); /* Darker bot message */
    color: #e5e7eb;
    align-self: flex-start;
    border: 1px solid rgba(52, 211, 153, 0.1);
    /* Allow internal elements to control width */
    /* max-width: 80%; */ 
}

/* Styles for Thinking/Answer structure */
.thinking-details {
    margin-bottom: 0; /* Remove margin */
    padding-bottom: 0; 
}

.thinking-summary {
    cursor: pointer;
    color: #a7f3d0; /* Light green */
    font-style: italic;
    font-size: 0.9em;
    display: inline-block; /* Allows pulse to be beside text */
    list-style: none; /* Remove default marker */
    padding: 2px 5px;
    border-radius: 3px;
    background-color: rgba(52, 211, 153, 0.1);
}

.thinking-summary::marker, /* Firefox */
.thinking-summary::-webkit-details-marker /* Chrome/Safari */ {
    display: none;
}

.thinking-summary:hover {
   background-color: rgba(52, 211, 153, 0.2);
}

.thinking-content {
    padding: 8px 10px;
    margin-top: 5px;
    border-left: 2px solid rgba(52, 211, 153, 0.3);
    font-size: 0.85em;
    color: #9ca3af; /* Grayish for thinking */
    background-color: rgba(31, 41, 55, 0.15);
    border-radius: 0 4px 4px 0;
    white-space: pre-wrap; /* Preserve whitespace */
}

/* Hide details content when closed (default) */
.thinking-details:not([open]) .thinking-content {
    display: none;
}

/* Style the main answer content */
.answer-content {
   white-space: pre-wrap; 
   margin-top: 0px; 
   /* Keep padding for space after 'Show Thoughts' */
   padding-top: 1em; 
}

/* Reset vertical margins on all common block elements first */
.message.bot p,
.message.bot ul,
.message.bot ol,
.message.bot li,
.message.bot h1,
.message.bot h2,
.message.bot h3,
.message.bot h4,
.message.bot h5,
.message.bot h6,
.message.bot pre,
.message.bot blockquote,
.message.bot dl,
.message.bot dd,
.message.bot figure {
    margin-top: 0;
    margin-bottom: 0;
}

/* Ensure lists and list items have NO vertical margins or padding */
.answer-content ul,
.answer-content ol,
.answer-content li {
    margin-top: 0;
    margin-bottom: 0;
    padding-top: 0;
    padding-bottom: 0;
}

/* Add specific margins ONLY where needed within .answer-content */
.answer-content p {
    margin-top: 0; /* Keep top margin 0 */
    margin-bottom: 0.5em; /* Space AFTER paragraphs */
}

/* Override paragraph margin when inside a list item */
.answer-content li p {
    margin: 0 !important; /* Force zero margin */
    padding: 0 !important; /* Force zero padding */
    line-height: inherit !important; /* Inherit li's tighter line-height */
}

.answer-content h1,
.answer-content h2,
.answer-content h3,
.answer-content h4,
.answer-content h5,
.answer-content h6 {
    margin-top: 0.75em; /* Space BEFORE headings */
    margin-bottom: 0.1em; /* Reduce space AFTER headings */
}

/* Fix: Remove spacing between headings and lists */
.answer-content h1 + ul,
.answer-content h2 + ul,
.answer-content h3 + ul,
.answer-content h4 + ul,
.answer-content h5 + ul,
.answer-content h6 + ul,
.answer-content h1 + ol,
.answer-content h2 + ol,
.answer-content h3 + ol,
.answer-content h4 + ol,
.answer-content h5 + ol,
.answer-content h6 + ol {
    margin-top: 0 !important; /* Remove space after heading when followed by list */
}

/* Keep necessary padding/borders for lists, quotes, code blocks */
.message.bot ul, .message.bot ol {
    padding-left: 25px;
    margin-top: 0.2em; /* Reduce space before list */
    margin-bottom: 0.2em; /* Reduce space after list */
}
.message.bot blockquote {
    border-left: 3px solid #34d399;
    padding-left: 10px;
    color: #9ca3af;
    font-style: italic;
}
.message.bot pre {
    background-color: rgba(31, 41, 55, 0.3);
    padding: 10px;
    border-radius: 4px;
    overflow-x: auto;
}

/* Basic Markdown Element Styling within Messages */
.message.bot strong, .message.bot b {
    color: #a7f3d0; /* Lighter green for bold */
    font-weight: bold;
}

.message.bot em, .message.bot i {
    color: #fde68a; /* Lighter amber for emphasis */
    font-style: italic;
}

.message.bot code {
    background-color: rgba(107, 114, 128, 0.2); /* Faint grey background */
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.9em;
    color: #e5e7eb; /* Use default text color or slightly different */
}

.message.bot pre code {
    background-color: transparent; /* Reset background for code inside pre */
    padding: 0;
}

/* Pulsing indicator */
.pulse {
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-left: 6px;
    background-color: #34d399;
    border-radius: 50%;
    opacity: 0.7;
    animation: pulse-anim 1.5s infinite ease-in-out;
}

@keyframes pulse-anim {
    0%, 100% {
        transform: scale(1);
        opacity: 0.7;
    }
    50% {
        transform: scale(0.8);
        opacity: 0.4;
    }
}

/* Fix: Eliminate spacing between list items */
.answer-content li {
    margin: 0 !important; /* Force zero margin */
    padding: 0 !important; /* Force zero padding */
    line-height: 1.1 !important; /* Even tighter line height */
}

/* Fix: Add special case for lists that follow each other */
.answer-content ul + ul,
.answer-content ol + ol,
.answer-content ul + ol,
.answer-content ol + ul {
    margin-top: 0 !important;
}

/* Fix: Reduce spacing between paragraph and list */
.answer-content p + ul,
.answer-content p + ol {
    margin-top: 0.1em !important;
}

.chat-footer {
    padding: 15px 20px;
    border-top: 1px solid rgba(52, 211, 153, 0.2); 
    background-color: rgba(17, 24, 39, 0.8);
    flex-shrink: 0; 
    position: relative;
    z-index: 2; /* Sit above overlay */
}

#message-form {
    display: flex;
    gap: 10px;
}

#message-input {
    flex-grow: 1;
    padding: 10px 15px;
    border-radius: 5px;
    border: 1px solid rgba(107, 114, 128, 0.3);
    background-color: rgba(55, 65, 81, 0.3);
    color: #e5e7eb;
    font-family: inherit;
    font-size: 1em;
    line-height: 1.4;
    min-height: 40px; /* Base height */
    max-height: 120px; /* Limit max height */
    resize: none;
    overflow-y: hidden; /* Hide scrollbar, JS handles height */
    box-sizing: border-box;
}

#message-input:focus {
    outline: none;
    border-color: rgba(52, 211, 153, 0.5);
}

#message-form button {
    padding: 10px 20px;
    background-color: rgba(16, 185, 129, 0.7); /* Green button */
    color: #064e3b; /* Dark green text */
    border-radius: 5px;
    font-weight: bold;
    transition: background-color 0.2s ease;
}

#message-form button:hover {
    background-color: rgba(5, 150, 105, 0.8);
}

#message-form button:disabled {
    background-color: rgba(107, 114, 128, 0.4);
    cursor: not-allowed;
    color: #4b5563;
}

/* Add simple fade-in animation */
/*
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.view {
    animation: fadeIn 0.5s ease-out;
}
*/

.view {
    animation: fadeIn 0.5s ease-out;
}

.answer-content li {
    margin: 0 !important; /* Force zero margin */
    padding: 0 !important; /* Force zero padding */
    line-height: 1.2 !important; /* Force tighter line height */
}

/* Add responsive styles for mobile devices */
@media (max-width: 768px) {
    /* Safari iOS specific fixes */
    body {
        position: fixed;
        width: 100%;
        height: 100%;
        overflow: hidden;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Landing page adjustments */
    .top-nav {
        padding-top: max(10px, env(safe-area-inset-top, 10px));
        padding-left: 0;
        padding-right: 0;
        position: relative;
        z-index: 20;
        display: flex;
        justify-content: space-between;
        width: 100%;
        box-sizing: border-box;
    }
    
    .top-nav a {
        padding: 8px;
        font-size: 0.9em;
        white-space: nowrap;
    }
    
    .status-indicator {
        margin-top: 120px; /* Significantly increased to ensure visibility on iOS */
        width: 100%;
        text-align: center;
        display: flex;
        justify-content: center;
    }
    
    #landing-view {
        padding: 20px 15px; /* Reduce horizontal padding */
        padding-top: max(20px, env(safe-area-inset-top, 20px));
        padding-bottom: max(20px, env(safe-area-inset-bottom, 20px));
        height: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .landing-content {
        max-width: 100%; /* Allow content to use full width */
        padding-bottom: 50px; /* Add extra padding at bottom for iOS */
    }
    
    #begin-investigation-btn,
    .support-link {
        max-width: 90%; /* Keep buttons from overflowing */
        width: 90%;
        box-sizing: border-box;
    }
    
    /* Chat view fixes */
    #chat-view {
        position: fixed; /* Switch to fixed positioning for iOS */
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        height: 100%; /* Full height */
        width: 100%;  /* Full width */
        overflow: hidden;
    }
    
    .chat-header {
        position: sticky;
        top: 0;
        z-index: 50;
        padding-top: max(15px, env(safe-area-inset-top, 15px)); /* Account for notch */
        padding-left: env(safe-area-inset-left, 20px);
        padding-right: env(safe-area-inset-right, 20px);
    }
    
    .message-list {
        position: absolute;
        top: 60px; /* Account for header height */
        bottom: 70px; /* Account for footer height */
        left: 0;
        right: 0;
        padding: 8px; /* Match padding with input area */
        padding-bottom: calc(90px + env(safe-area-inset-bottom, 10px)); /* Increased padding to prevent overlap */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        height: auto; /* Let position determine height */
    }
    
    .chat-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 15px 8px; /* Reduced horizontal padding to match gap */
        padding-left: max(8px, env(safe-area-inset-left, 8px));
        padding-right: max(8px, env(safe-area-inset-right, 8px));
        padding-bottom: max(15px, env(safe-area-inset-bottom, 15px));
        z-index: 200;
        background-color: rgba(17, 24, 39, 0.95);
    }
    
    #message-form {
        gap: 8px; /* Keep this gap consistent */
        width: 100%;
        align-items: center; /* Ensure vertical alignment */
    }
    
    #message-input {
        height: 44px; /* Taller input for better touch targets */
        font-size: 16px; /* Prevent iOS zoom on focus */
        box-sizing: border-box !important; /* Force same box model */
        min-height: 44px; /* Force minimum height */
        max-height: 44px; /* Force maximum height */
        margin: 0; /* Reset margins */
        -webkit-appearance: none; /* Remove iOS styling */
    }
    
    #message-form button {
        min-width: 70px; /* Ensure button has enough width */
        height: 44px !important; /* Force exact height */
        padding: 0 20px; /* Horizontal padding only */
        margin: 0; /* Reset margins */
        line-height: 44px; /* Match height */
        box-sizing: border-box !important; /* Force same box model */
        display: flex;
        align-items: center;
        justify-content: center;
        -webkit-appearance: none; /* Remove iOS styling */
    }
    
    /* Match message bubble padding with input area */
    .message.user,
    .message.bot {
        max-width: calc(100% - 16px); /* Factor in the padding */
        margin-right: 0; /* Remove any auto margins */
        margin-left: 0; /* Remove any auto margins */
    }
    
    .message.user {
        align-self: flex-end; /* Position at right */
        margin-left: auto; /* Push to right edge */
    }
    
    .message.bot {
        align-self: flex-start; /* Position at left */
        margin-right: auto; /* Push to left edge */
    }
}

/* Add iPad-specific styles */
@media only screen and (min-width: 768px) and (max-width: 1024px) and (orientation: portrait),
       only screen and (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    /* Only apply these styles when chat view is active */
    #chat-view.active-view {
        position: relative;
        display: flex;
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
    }
    
    /* Fix header to stay visible on iPad */
    #chat-view.active-view .chat-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 150; /* Higher than footer */
        padding: 15px;
        background-color: rgba(17, 24, 39, 0.95); /* Same as footer for consistency */
    }
    
    /* Fix message list to not overflow - only when active */
    #chat-view.active-view .message-list {
        flex: 1;
        overflow-y: auto;
        padding-top: 60px; /* Space for fixed header */
        padding-bottom: 80px; /* Make room for input area */
    }
    
    /* Ensure chat footer stays at bottom - only when active */
    #chat-view.active-view .chat-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 15px;
        background-color: rgba(17, 24, 39, 0.95);
        z-index: 100;
    }
}

/* View Handling - Fix iPad issues */
.view {
    display: none; /* Hide views by default */
}

.active-view {
    display: flex; /* Show the active view */
    flex-direction: column;
    min-height: 100vh;
}

/* Make sure chat elements are hidden properly on iPad */
#chat-view:not(.active-view) .chat-footer,
#chat-view:not(.active-view) .message-list,
#chat-view:not(.active-view) .chat-header {
    display: none !important;
}

/* <<< ADDED: Styling for source citation list >>> */
.sources-list {
    margin-top: 12px; /* Space above the source list */
    padding-top: 8px;  /* Space between answer and sources heading */
    border-top: 1px solid rgba(107, 114, 128, 0.2); /* Faint separator line */
}

.sources-list h4 {
    font-size: 0.85em;
    color: #9ca3af; /* Slightly muted color */
    margin-bottom: 4px;
    font-weight: bold;
}

.sources-list ul {
    list-style: disc; /* Use standard bullet points */
    padding-left: 20px; /* Indent the list */
    margin: 0;
}

.sources-list li {
    font-size: 0.8em;
    color: #6b7280; /* Muted text color for sources */
    margin-bottom: 3px;
    line-height: 1.3;
    word-break: break-all; /* Allow long filenames to wrap */
}
/* <<< END ADDED >>> */

/* <<< ADDED: Styling for COLLAPSIBLE source list >>> */
.sources-details {
    /* Inherits margin/padding from .sources-list */
}

.sources-summary {
    cursor: pointer;
    color: #a7f3d0; /* Light green - same as thinking summary */
    font-style: italic;
    font-size: 0.9em;
    display: inline-block;
    list-style: none; /* Remove default marker */
    padding: 2px 5px;
    border-radius: 3px;
    background-color: rgba(52, 211, 153, 0.1);
    margin-bottom: 5px; /* Space below summary when closed */
}

.sources-summary::marker, /* Firefox */
.sources-summary::-webkit-details-marker /* Chrome/Safari */ {
    display: none;
}

.sources-summary:hover {
   background-color: rgba(52, 211, 153, 0.2);
}

.sources-content { /* Style the UL inside */
    list-style: disc;
    padding-left: 20px;
    margin: 0;
    border-left: 2px solid rgba(52, 211, 153, 0.3); /* Match thinking content border */
    padding-top: 5px; /* Add some space above list */
    padding-bottom: 5px; /* Add some space below list */
}

.sources-content li {
    font-size: 0.8em;
    color: #9ca3af; 
    margin-bottom: 3px;
    line-height: 1.3;
    word-break: break-all;
}

/* Hide the UL when details is not open */
.sources-details:not([open]) .sources-content {
    display: none;
}

/* Remove bottom margin from summary when details is open */
.sources-details[open] .sources-summary {
    margin-bottom: 5px; 
}

/* <<< END ADDED >>> */

.message.user {
    background-color: rgba(55, 65, 81, 0.4); /* Gray user message */
    color: #d1d5db;
    align-self: flex-end; /* Position bubble on right side */
    text-align: left; /* Keep text left-aligned inside the bubble */
    white-space: pre-wrap; /* Ensure line breaks are preserved */
}

/* Add responsive styles for mobile devices */
@media (max-width: 768px) {
    /* Safari iOS specific fixes */
    body {
        position: fixed;
        width: 100%;
        height: 100%;
        overflow: hidden;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Landing page adjustments */
    .top-nav {
        padding-top: max(10px, env(safe-area-inset-top, 10px));
        padding-left: 0;
        padding-right: 0;
        position: relative;
        z-index: 20;
        display: flex;
        justify-content: space-between;
        width: 100%;
        box-sizing: border-box;
    }
    
    .top-nav a {
        padding: 8px;
        font-size: 0.9em;
        white-space: nowrap;
    }
    
    .status-indicator {
        margin-top: 120px; /* Significantly increased to ensure visibility on iOS */
        width: 100%;
        text-align: center;
        display: flex;
        justify-content: center;
    }
    
    #landing-view {
        padding: 20px 15px; /* Reduce horizontal padding */
        padding-top: max(20px, env(safe-area-inset-top, 20px));
        padding-bottom: max(20px, env(safe-area-inset-bottom, 20px));
        height: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .landing-content {
        max-width: 100%; /* Allow content to use full width */
        padding-bottom: 50px; /* Add extra padding at bottom for iOS */
    }
    
    #begin-investigation-btn,
    .support-link {
        max-width: 90%; /* Keep buttons from overflowing */
        width: 90%;
        box-sizing: border-box;
    }
    
    /* Chat view fixes */
    #chat-view {
        position: fixed; /* Switch to fixed positioning for iOS */
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        height: 100%; /* Full height */
        width: 100%;  /* Full width */
        overflow: hidden;
    }
    
    .chat-header {
        position: sticky;
        top: 0;
        z-index: 50;
        padding-top: max(15px, env(safe-area-inset-top, 15px)); /* Account for notch */
        padding-left: env(safe-area-inset-left, 20px);
        padding-right: env(safe-area-inset-right, 20px);
    }
    
    .message-list {
        position: absolute;
        top: 60px; /* Account for header height */
        bottom: 70px; /* Account for footer height */
        left: 0;
        right: 0;
        padding: 8px; /* Match padding with input area */
        padding-bottom: calc(90px + env(safe-area-inset-bottom, 10px)); /* Increased padding to prevent overlap */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        height: auto; /* Let position determine height */
    }
    
    .chat-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 15px 8px; /* Reduced horizontal padding to match gap */
        padding-left: max(8px, env(safe-area-inset-left, 8px));
        padding-right: max(8px, env(safe-area-inset-right, 8px));
        padding-bottom: max(15px, env(safe-area-inset-bottom, 15px));
        z-index: 200;
        background-color: rgba(17, 24, 39, 0.95);
    }
    
    #message-form {
        gap: 8px; /* Keep this gap consistent */
        width: 100%;
        align-items: center; /* Ensure vertical alignment */
    }
    
    #message-input {
        height: 44px; /* Taller input for better touch targets */
        font-size: 16px; /* Prevent iOS zoom on focus */
        box-sizing: border-box !important; /* Force same box model */
        min-height: 44px; /* Force minimum height */
        max-height: 44px; /* Force maximum height */
        margin: 0; /* Reset margins */
        -webkit-appearance: none; /* Remove iOS styling */
    }
    
    #message-form button {
        min-width: 70px; /* Ensure button has enough width */
        height: 44px !important; /* Force exact height */
        padding: 0 20px; /* Horizontal padding only */
        margin: 0; /* Reset margins */
        line-height: 44px; /* Match height */
        box-sizing: border-box !important; /* Force same box model */
        display: flex;
        align-items: center;
        justify-content: center;
        -webkit-appearance: none; /* Remove iOS styling */
    }
    
    /* Match message bubble padding with input area */
    .message.user,
    .message.bot {
        max-width: calc(100% - 16px); /* Factor in the padding */
        margin-right: 0; /* Remove any auto margins */
        margin-left: 0; /* Remove any auto margins */
    }
    
    .message.user {
        align-self: flex-end; /* Position at right */
        margin-left: auto; /* Push to right edge */
    }
    
    .message.bot {
        align-self: flex-start; /* Position at left */
        margin-right: auto; /* Push to left edge */
    }
}

/* Add iPad-specific styles */
@media only screen and (min-width: 768px) and (max-width: 1024px) and (orientation: portrait),
       only screen and (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    /* Only apply these styles when chat view is active */
    #chat-view.active-view {
        position: relative;
        display: flex;
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
    }
    
    /* Fix header to stay visible on iPad */
    #chat-view.active-view .chat-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 150; /* Higher than footer */
        padding: 15px;
        background-color: rgba(17, 24, 39, 0.95); /* Same as footer for consistency */
    }
    
    /* Fix message list to not overflow - only when active */
    #chat-view.active-view .message-list {
        flex: 1;
        overflow-y: auto;
        padding-top: 60px; /* Space for fixed header */
        padding-bottom: 80px; /* Make room for input area */
    }
    
    /* Ensure chat footer stays at bottom - only when active */
    #chat-view.active-view .chat-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 15px;
        background-color: rgba(17, 24, 39, 0.95);
        z-index: 100;
    }
}

/* View Handling - Fix iPad issues */
.view {
    display: none; /* Hide views by default */
}

.active-view {
    display: flex; /* Show the active view */
    flex-direction: column;
    min-height: 100vh;
}

/* Make sure chat elements are hidden properly on iPad */
#chat-view:not(.active-view) .chat-footer,
#chat-view:not(.active-view) .message-list,
#chat-view:not(.active-view) .chat-header {
    display: none !important;
}

/* <<< ADDED: Styling for source citation list >>> */
.sources-list {
    margin-top: 12px; /* Space above the source list */
    padding-top: 8px;  /* Space between answer and sources heading */
    border-top: 1px solid rgba(107, 114, 128, 0.2); /* Faint separator line */
}

.sources-list h4 {
    font-size: 0.85em;
    color: #9ca3af; /* Slightly muted color */
    margin-bottom: 4px;
    font-weight: bold;
}

.sources-list ul {
    list-style: disc; /* Use standard bullet points */
    padding-left: 20px; /* Indent the list */
    margin: 0;
}

.sources-list li {
    font-size: 0.8em;
    color: #6b7280; /* Muted text color for sources */
    margin-bottom: 3px;
    line-height: 1.3;
    word-break: break-all; /* Allow long filenames to wrap */
}
/* <<< END ADDED >>> */

/* List styling inside the sources box */
.sources-box ul {
    list-style: none; /* <<< ADDED: Remove default bullets */
    padding-left: 0;
    margin: 0 auto; 
    text-align: left; 
    max-width: fit-content;
}

.sources-box li {
    font-size: 1em; /* INCREASED to 1em */
    color: #d1d5db; 
    padding: 2px 0; /* REDUCED padding */
    border-bottom: 1px solid rgba(107, 114, 128, 0.1); 
}

.sources-box li a {
    color: #ededed; /* <<< ADDED: Set default link color to white/light */
    text-decoration: none; /* Ensure no default underline */
}

.sources-box li a:hover {
    color: #a7f3d0; /* <<< ADDED: Set hover color to light green */
    text-decoration: underline; /* Optional: Add underline on hover */
}

/* --- END SOURCES BOX STYLES --- */

/* --- Update Footer Links Style --- */
.footer-links-container {
    margin-top: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
}
.footer-links-container a {
    color: #9ca3af; /* Set base color to grey */
    text-decoration: none;
    font-size: 1.1em; /* Adjusted size slightly */
    transition: color 0.2s ease;
}
.footer-links-container a:hover {
    color: #a7f3d0; /* Set hover to light green */
    text-decoration: none; /* No underline for icons/text */
}
/* --- End Footer Links Style --- */

.nara-link-paragraph {
    margin-top: 1.5rem; 
    font-size: 0.9em !important; /* INCREASED size and added !important */
    color: #6b7280; 
} 