/* Chat Interface Components */

/* Chat Box - Takes remaining space in right column */
.chat-box {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        background-color: var(--bg-secondary);
        border-radius: 1.5rem;
        padding: 1rem;
        margin: 1rem 1rem 1rem 1rem; /* Add top margin since header is now above */
        border: none;
        box-shadow: none;
        transition: background-color 0.3s ease;
        -webkit-overflow-scrolling: touch;
        min-height: 0; /* Allow flex shrinking */
}

/* Chat Input - Fixed at bottom of right column */
.chat-input-container {
        background-color: var(--bg-primary);
        padding: 0.5rem 1rem;
        border-top: none;
        transition: background-color 0.3s ease;
}

.chat-input-bar {
        display: flex;
        align-items: center;
        border-radius: 1.5rem;
        background: var(--bg-secondary);
        max-width: 100%;
        overflow: hidden;
        transition: background-color 0.3s ease, box-shadow 0.3s ease;
        border: none;
        box-shadow: none;
}

.chat-input-bar textarea {
        flex: 1;
        padding: 1rem 1.5rem 1rem 1.5rem;
        border: none;
        background: var(--bg-secondary);
        color: var(--text-primary);
        font-size: 1rem;
        outline: none;
        min-height: 3rem;
        max-height: 8rem;
        resize: none;
        overflow-y: auto;
        font-family: inherit;
        transition: background-color 0.3s ease, color 0.3s ease;
}

.chat-input-bar:focus-within {
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2), 0 4px 8px rgba(0, 0, 0, 0.15);
        border-color: var(--accent-color);
}

.chat-input-bar button {
        background: none;
        border: none;
        color: var(--accent-color);
        font-size: 1.4rem;
        padding: 0 0.75rem;
        cursor: pointer;
        transition: color 0.3s ease;
}

input[type="file"] {
        display: none;
}

/* Chat Messages */
.message {
        margin-bottom: 1rem;
}

.message.user {
        text-align: right;
}

.message.user > span {
        display: inline-block;
        background-color: var(--user-bubble);
        color: var(--text-primary);
        padding: 0.75rem 1rem;
        border-radius: 1rem;
        max-width: 75%;
        word-wrap: break-word;
        transition: background-color 0.3s ease;
}

.message.assistant {
        text-align: left;
}

.message.assistant > span {
        display: block;
        background-color: transparent;
        color: var(--text-primary);
        padding: 0.75rem 1rem;
        border-radius: 1rem;
        width: 100%;
        word-wrap: break-word;
        line-height: 1.51em;
        transition: color 0.3s ease;
        box-sizing: border-box;
}

/* Links in assistant bubbles */
.message.assistant span a {
        color: var(--link-color);
        text-decoration: none;
}

.message.assistant span a:hover {
        color: var(--link-hover);
}

/* Source reference links - Semantic UI pointing label styling */
.message.assistant span a.source-reference {
        color: white !important;
        text-decoration: none !important;
        font-size: 0.85em !important;
        font-weight: 400 !important;
        opacity: 0.8 !important;
        transition: all 0.2s ease !important;
        margin: 0 2px !important;
}

/* Override Semantic UI label colors for dark theme */
.message.assistant span .ui.small.pointing.label {
        background-color: #e8e8e8 !important;
        border-color: #d4d4d5 !important;
        color: #767676 !important;
}

.message.assistant span .ui.small.pointing.label:hover {
        background-color: #cacbcd !important;
        color: #4c4c4c !important;
}

.message.assistant span a.source-reference:hover {
        color: var(--accent-color);
        opacity: 1;
}

/* Light theme uses standard Semantic UI colors */
[data-theme="light"] .message.assistant span .ui.small.pointing.label {
        background-color: #e8e8e8 !important;
        border-color: #d4d4d5 !important;
        color: #767676 !important;
}

[data-theme="light"] .message.assistant span .ui.small.pointing.label:hover {
        background-color: #cacbcd !important;
        color: #4c4c4c !important;
}

/* Suggestion Buttons */
.suggestion-container {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;   /* center the buttons */
        gap: 0.5rem;
        width: 100%;               /* take up the full bubble width */
        margin: 0.5rem auto;       /* vertical & auto-center horizontally if needed */
}

.suggestion-container .suggestion-button {
        background: var(--suggestion-bg);
        color: var(--text-secondary);
        border: 1px solid var(--suggestion-border);
        border-radius: 1rem;
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
        font-weight: 500;
        cursor: pointer;
        white-space: normal;
        text-align: center;
        transition: background 0.2s, border 0.2s, color 0.2s;
}

.suggestion-container .suggestion-button:hover {
        background: var(--suggestion-hover);
        border-color: var(--border-color);
        color: var(--text-primary);
}

.suggestion-button{
        font-family: inherit;
        width: 280px;
        min-height: 100px;  /* Baseline minimum height */
        height: auto;       /* Allow flexible height expansion */
        margin-bottom: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 0.85rem;
        line-height: 1.4;   /* Good line height for readability */
        overflow: visible;  /* CRITICAL: Allow content to be fully visible */
        word-wrap: break-word;
        hyphens: auto;
        padding: 12px;      /* Adequate padding for text spacing */
        box-sizing: border-box;
        text-align: center;
        white-space: normal; /* Allow text wrapping */
}

/* Loading Animation */
.notched.circle.loading.icon {
        animation-duration: 1s !important;
        color: var(--accent-color);
}

.fade-in {
        animation: fadeIn 0.4s ease-in;
}

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

/* Mobile chat adjustments */
@media (max-width: 768px) {
        .chat-box {
                margin: 0.5rem;
                margin-bottom: 0; /* Remove bottom margin to save space */
                flex: 1;
                min-height: 0;
        }

        .chat-input-container {
                padding: 0.5rem;
                background-color: var(--bg-primary);
                position: sticky;
                bottom: 0;
                z-index: 10;
        }

        /* Ensure right content takes full available space */
        .right-content {
                height: 100%;
                min-height: calc(100svh - 40px);
                display: flex;
                flex-direction: column;
        }
}

/* Light theme shadow adjustments */
[data-theme="light"] .chat-box {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .chat-input-bar {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .chat-input-bar:focus-within {
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12), 0 4px 8px rgba(0, 0, 0, 0.08);
}

/* Source Links */
.source-link {
    color: #2563eb;
    text-decoration: underline;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.2s ease;
}

.source-link:hover {
    color: #1d4ed8;
    text-decoration: none;
    background-color: rgba(37, 99, 235, 0.1);
    padding: 1px 3px;
    border-radius: 3px;
}

.source-link:visited {
    color: #7c3aed;
}

/* Ensure source links are properly formatted in chat messages */
.chat-message .source-link {
    display: inline-block;
    margin: 0 2px;
}

/* Source link styling */
.source-link {
  color: var(--primary-color) !important;
  text-decoration: none;
  font-weight: 500;
  border-bottom: 1px solid var(--primary-color);
  transition: all 0.2s ease;
}

.source-link:hover {
  background-color: var(--primary-color);
  color: white !important;
  padding: 2px 4px;
  border-radius: 3px;
}

/* Semantic UI pointing label styling for page references */
.ui.pointing.label {
  padding: 0.5em 0.8em !important;
  font-size: 0.85em !important;
  font-weight: 600 !important;
  display: inline-block;
  cursor: pointer;
  transition: all 0.2s ease;
  margin: 0 0.3em;
  text-decoration: none !important;
  position: relative;
}

/* Light theme - light background with black text */
[data-theme="light"] .ui.pointing.label {
  background: #e9ecef !important;
  color: #000000 !important;
  border: 1px solid #e9ecef !important;
}

[data-theme="light"] .ui.pointing.label:hover {
  background: var(--accent-color) !important;
  color: white !important;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Dark theme - dark background with black text */
[data-theme="dark"] .ui.pointing.label {
  background: #373a40 !important;
  color: #000000 !important;
  border: 1px solid #373a40 !important;
}

[data-theme="dark"] .ui.pointing.label:hover {
  background: var(--accent-color) !important;
  color: white !important;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Page reference links inherit pointing label styling and use theme-aware colors */
.source-link, .page-only-link, .page-range-start, .page-range-end {
    margin: 0 0.3em;
    font-size: 0.85em;
    text-decoration: none !important;
    transition: all 0.2s ease;
}

/* Light theme - light background with black text */
[data-theme="light"] .source-link,
[data-theme="light"] .page-only-link,
[data-theme="light"] .page-range-start,
[data-theme="light"] .page-range-end {
    background-color: #e9ecef !important;
    color: #000000 !important;
    border: 1px solid #e9ecef !important;
}

[data-theme="light"] .source-link:hover,
[data-theme="light"] .page-only-link:hover,
[data-theme="light"] .page-range-start:hover,
[data-theme="light"] .page-range-end:hover {
    background-color: var(--accent-color) !important;
    color: white !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Dark theme - dark background with black text */
[data-theme="dark"] .source-link,
[data-theme="dark"] .page-only-link,
[data-theme="dark"] .page-range-start,
[data-theme="dark"] .page-range-end {
    background-color: #373a40 !important;
    color: #000000 !important;
    border: 1px solid #373a40 !important;
}

[data-theme="dark"] .source-link:hover,
[data-theme="dark"] .page-only-link:hover,
[data-theme="dark"] .page-range-start:hover,
[data-theme="dark"] .page-range-end:hover {
    background-color: var(--accent-color) !important;
    color: white !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Add a subtle visual connection between range labels */
.page-range-start {
    margin-right: 0.2em;
}

.page-range-end {
    margin-left: 0.2em;
}


/* Embedded Images in Chat */
.embedded-image-container {
    margin: 15px 0;
    text-align: center;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 10px;
    background: #fafafa;
    max-width: 100%;
}

.embedded-image-container img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.embedded-image-container img:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.embedded-image-container .image-caption {
    margin-top: 8px;
    font-size: 0.9em;
    color: #666;
    font-style: italic;
}

/* Image zoom overlay */
.image-zoomed {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) scale(1.2) !important;
    z-index: 9999 !important;
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3) !important;
    max-width: 90vw;
    max-height: 90vh;
}

