/* --- Apple-Style Premium Minimalism Theme --- */

:root {
    /* Color Palette */
    --color-bg: #f9f8f6; /* Warm off-white background */
    --color-panel-bg: #ffffff; /* Clean panel cards */
    --color-primary: #1d1d1f; /* Dark slate text */
    --color-secondary: #86868b; /* Cool grey text */
    --color-accent: #0071e3; /* Apple premium blue link/action */
    --color-accent-hover: #0077ed;
    --color-border: #e8e8ed; /* Hairline borders */
    
    /* Semantic Colors */
    --color-user-bubble: #f2f2f7; /* Very light grey */
    --color-ai-bubble: #ffffff;
    --color-warning-bg: #fffbe6; /* Pastel yellow-orange for exclusions */
    --color-warning-border: #ffe58f;
    --color-warning-text: #b7791f;
    --color-success-bg: #e6ffed; /* Light green for questions/positive details */
    --color-success-border: #b7eb8f;
    
    /* Layout & Shadows */
    --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --radius-lg: 20px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.04);
    --shadow-medium: 0 8px 30px rgba(0, 0, 0, 0.08);
    --transition-smooth: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

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

body {
    font-family: var(--font-family);
    background-color: var(--color-bg);
    color: var(--color-primary);
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.app-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: var(--color-bg);
}

/* Header styling */
.app-header {
    height: 64px;
    background-color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    z-index: 10;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 1.5px solid var(--color-border);
}

.logo-text h1 {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-primary);
}

.logo-text span {
    font-size: 11px;
    color: var(--color-secondary);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* Buttons */
.mobile-toggle {
    display: none;
}

.btn-secondary {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    background-color: #ffffff;
    color: var(--color-primary);
    font-family: var(--font-family);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.btn-secondary:hover {
    background-color: var(--color-bg);
    border-color: var(--color-secondary);
}

/* Body / Column grid layout */
.app-body {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr; /* Initial state: Chat takes full screen */
    gap: 0;
    overflow: hidden;
    padding: 0;
    transition: var(--transition-smooth);
}

/* When document is shown, make it 2 columns */
.app-body.split-view {
    grid-template-columns: 1fr 1fr;
    padding: 20px;
    gap: 20px;
}

/* Left Panel: Original Document Viewer */
.document-panel {
    background-color: var(--color-panel-bg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-soft);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
}

.document-panel.hidden {
    display: none !important;
}

.panel-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h2 {
    font-size: 15px;
    font-weight: 600;
}

.file-name {
    font-size: 13px;
    color: var(--color-secondary);
    background-color: var(--color-bg);
    padding: 4px 10px;
    border-radius: var(--radius-lg);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.panel-content {
    flex: 1;
    padding: 0;
    overflow: hidden;
    background-color: #fafbfc;
}

.document-view-box {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.pdf-canvas-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background-color: #8e8e93; /* Cool slate document-viewer background */
    overflow-y: auto;
    height: 100%;
    width: 100%;
    -webkit-overflow-scrolling: touch;
}

.pdf-page-canvas {
    max-width: 100%;
    height: auto !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    background-color: #ffffff;
    border-radius: 4px;
}

/* Right Panel: Chat Interface Container */
.chat-panel {
    background-color: var(--color-panel-bg);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    position: relative;
    transition: var(--transition-smooth);
}

/* Decorate chat panel with border and rounded corners ONLY in split view */
.app-body.split-view .chat-panel {
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-soft);
}

/* Welcome view */
.welcome-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 40px;
    max-width: 580px;
    margin: 0 auto;
}

.welcome-avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 24px;
    border: 3px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}

.welcome-container h2 {
    font-size: 26px;
    font-weight: 600;
    margin-bottom: 12px;
}

.welcome-container p {
    font-size: 15px;
    color: var(--color-secondary);
    line-height: 1.6;
}

.compare-selector-container {
    margin-top: 24px;
    background-color: var(--color-bg);
    border: 1px solid var(--color-border);
    padding: 12px 18px;
    border-radius: var(--radius-md);
    display: inline-flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow-sm);
}

.compare-selector-container label {
    font-size: 13.5px;
    font-weight: 500;
    color: var(--color-primary);
}

.compare-selector-container select {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background-color: var(--color-bg);
    font-family: inherit;
    font-size: 13.5px;
    color: var(--color-primary);
    cursor: pointer;
    outline: none;
    transition: border-color var(--transition-fast);
}

.compare-selector-container select:focus {
    border-color: var(--color-accent);
}

/* Chat History area */
.chat-history-container {
    flex: 1;
    padding: 30px 40px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Smooth layout adjustment when switching container widths */
.app-body.split-view .chat-history-container {
    padding: 24px;
}

/* Message Bubbles */
.message-row {
    display: flex;
    width: 100%;
    animation: fadeIn 0.4s ease-out;
}

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

.message-row.user-msg {
    justify-content: flex-end;
}

.message-row.ai-msg {
    justify-content: flex-start;
}

.chat-bubble {
    max-width: 85%;
    padding: 16px 20px;
    border-radius: var(--radius-lg);
    font-size: 15px;
    line-height: 1.6;
}

.user-msg .chat-bubble {
    background-color: var(--color-user-bubble);
    color: var(--color-primary);
    border-bottom-right-radius: 4px;
}

.ai-msg .chat-bubble {
    background-color: var(--color-ai-bubble);
    border: 1px solid var(--color-border);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
    border-bottom-left-radius: 4px;
    color: var(--color-primary);
}

/* Special markdown styling inside AI response */
.chat-bubble p {
    margin-bottom: 12px;
}

.chat-bubble p:last-child {
    margin-bottom: 0;
}

.chat-bubble ul, .chat-bubble ol {
    margin-left: 20px;
    margin-bottom: 12px;
}

.chat-bubble li {
    margin-bottom: 6px;
}

.chat-bubble em {
    color: var(--color-secondary);
    font-style: italic;
}

/* Tables inside chat bubbles */
.table-scroll-wrapper {
    width: 100%;
    overflow-x: auto;
    margin: 16px 0;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    -webkit-overflow-scrolling: touch; /* Smooth momentum scrolling on iOS */
}

.chat-bubble table {
    width: 100%;
    min-width: 550px; /* Prevent table text squishing on narrow mobile screens */
    border-collapse: collapse;
    margin: 0;
    font-size: 13.5px;
    border: none;
}

.chat-bubble th {
    background-color: var(--color-bg);
    color: var(--color-primary);
    font-weight: 600;
    text-align: left;
    padding: 10px 14px;
    border-bottom: 2px solid var(--color-border);
}

.chat-bubble td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-primary);
    line-height: 1.5;
}

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

.chat-bubble tr:nth-child(even) {
    background-color: rgba(0, 0, 0, 0.02);
}

/* Callout Box: Exclusions / Warnings */
.exclusion-box {
    background-color: var(--color-warning-bg);
    border: 1px solid var(--color-warning-border);
    color: var(--color-warning-text);
    padding: 14px 18px;
    border-radius: var(--radius-md);
    margin-top: 14px;
    margin-bottom: 14px;
}

.exclusion-box h4 {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Callout Box: Agent Questions Card */
.questions-card {
    background-color: var(--color-bg);
    border: 1px solid var(--color-border);
    padding: 16px 20px;
    border-radius: var(--radius-md);
    margin-top: 14px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.01);
}

.questions-card h4 {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 10px;
    color: var(--color-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.questions-list {
    list-style: none !important;
    margin-left: 0 !important;
}

.questions-list li {
    position: relative;
    padding-left: 24px;
    margin-bottom: 8px;
    font-size: 13.5px;
    color: #444;
}

.questions-list li::before {
    content: "❓";
    position: absolute;
    left: 0;
    top: 1px;
    font-size: 12px;
}

/* Footer / Input area styling */
.chat-footer {
    padding: 16px 40px 24px;
    background-color: var(--color-panel-bg);
    border-top: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.app-body.split-view .chat-footer {
    padding: 16px 20px 20px;
}

/* Quick Jargon Chips */
.quick-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-width: 768px;
    margin: 0 auto;
    width: 100%;
}

.chip-btn {
    border: 1px solid var(--color-border);
    background-color: #ffffff;
    padding: 6px 12px;
    border-radius: var(--radius-lg);
    font-family: var(--font-family);
    font-size: 12px;
    color: var(--color-secondary);
    cursor: pointer;
    transition: var(--transition-smooth);
}

.chip-btn:hover {
    background-color: var(--color-user-bubble);
    color: var(--color-primary);
    border-color: var(--color-secondary);
}

/* Input Bar Group */
.chat-input-bar {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    border: 1px solid var(--color-border);
    border-radius: 26px;
    padding: 8px 16px;
    background-color: #ffffff;
    max-width: 768px;
    margin: 0 auto;
    width: 100%;
    box-shadow: var(--shadow-soft);
    transition: var(--transition-smooth);
}

.chat-input-bar:focus-within {
    border-color: var(--color-secondary);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

/* Attachment paperclip button */
.attach-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: var(--color-secondary);
    cursor: pointer;
    transition: var(--transition-smooth);
}

.attach-btn:hover {
    background-color: var(--color-user-bubble);
    color: var(--color-primary);
}

/* Textarea input */
.chat-input-bar textarea {
    flex: 1;
    border: none;
    outline: none;
    font-family: var(--font-family);
    font-size: 14.5px;
    line-height: 1.5;
    padding: 8px 0;
    resize: none;
    max-height: 120px;
    color: var(--color-primary);
    background: transparent;
}

.chat-input-bar textarea::placeholder {
    color: var(--color-secondary);
}

/* Send button */
.send-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background-color: var(--color-primary);
    color: #ffffff;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.send-btn:hover {
    transform: scale(1.05);
    background-color: #000000;
}

.send-btn:disabled {
    background-color: var(--color-border);
    color: var(--color-secondary);
    cursor: not-allowed;
    transform: none;
}

/* Footer bottom note */
.footer-note {
    text-align: center;
    font-size: 11px;
    color: var(--color-secondary);
}

/* Loading animations */
.loading-bubble {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
}

.dot {
    width: 6px;
    height: 6px;
    background-color: var(--color-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

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

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

/* Responsive Rules */
@media (max-width: 768px) {
    body {
        height: 100dvh;
    }
    
    .app-container {
        height: 100dvh;
    }

    .app-header {
        padding: 0 16px;
    }
    
    .logo-text h1 {
        font-size: 14.5px;
    }
    
    .logo-text span {
        font-size: 9px;
    }

    .app-body.split-view {
        display: flex;
        flex-direction: column;
        height: calc(100dvh - 64px);
        overflow: hidden;
    }
    
    /* Initially hide document panel completely on mobile */
    .document-panel {
        display: none !important;
        border-radius: 0;
        border: none;
    }
    
    /* Show chat panel fully */
    .chat-panel {
        display: flex !important;
        flex: 1;
        height: 100% !important;
        border-radius: 0 !important;
        border: none !important;
    }
    
    /* When viewing document, show document panel at top half, and chat panel at bottom half */
    body.mobile-show-document .document-panel {
        display: flex !important;
        height: 40dvh !important;
        width: 100% !important;
        border-bottom: 2px solid var(--color-border);
    }
    
    body.mobile-show-document .chat-panel {
        display: flex !important;
        flex: 1;
        height: auto !important;
    }

    .welcome-container {
        padding: 24px 16px;
    }
    
    .welcome-avatar {
        width: 80px;
        height: 80px;
        margin-bottom: 16px;
    }
    
    .welcome-container h2 {
        font-size: 19px;
        line-height: 1.3;
    }
    
    .welcome-container p {
        font-size: 13px;
    }
    
    .compare-selector-container {
        width: 100%;
        padding: 10px 14px;
        font-size: 13px;
    }
    
    .chat-history-container {
        padding: 14px;
    }

    .chat-bubble {
        max-width: 90%;
        padding: 12px 14px;
        font-size: 14px;
    }
    
    .chat-footer {
        padding: 12px;
    }
    
    .quick-chips {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 8px;
        margin-bottom: 8px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    
    .quick-chips::-webkit-scrollbar {
        display: none;
    }
    
    .chip-btn {
        white-space: nowrap;
    }

    .mobile-toggle {
        display: flex !important;
        align-items: center;
        gap: 6px;
    }
    .mobile-toggle.hidden {
        display: none !important;
    }
}
