/* Disaster Clippy — Chat interface styles */

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


/* Connection status indicator */
.connection-status {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    padding: 0.25rem 0;
    margin-bottom: 0.5rem;
}

.connection-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.connection-dot.online { background: #45644d; }
.connection-dot.checking { background: #8a9c8e; animation: pulse 0.5s infinite; }
.connection-dot.unstable { background: #c8943a; }
.connection-dot.disconnected { background: #ad4f2d; }
.connection-dot.offline { background: #8a9c8e; animation: none; }
.connection-dot.recovering { background: #8a9c8e; animation: pulse 0.5s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.connection-label {
    color: #5f6b61;
}

.container {
    display: flex;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    height: calc(100vh - 140px);
    min-height: 400px;
}

/* Chat Panel */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    min-height: 0;
}

.message {
    margin-bottom: 1.25rem;
    padding: 0.85rem 1.1rem;
    border-radius: 8px;
}

.message.user {
    background: #ead9b8;
    border: 1px solid #d5c8a9;
    margin-left: auto;
    max-width: 75%;
}

.message.assistant {
    background: #fff9ee;
    border: 1px solid #d5c8a9;
    font-family: Georgia, 'Times New Roman', serif;
    line-height: 1.7;
    max-width: min(96%, 960px);
}

.message-content {
    white-space: pre-wrap;
    line-height: 1.6;
}

.message-content a {
    color: #6b2d16;
    text-decoration: underline;
    text-underline-offset: 0.15em;
}

.message-content a:hover {
    color: #ad4f2d;
}

.message-content .md-header {
    color: #1a2c24;
    margin: 0.75rem 0 0.5rem 0;
    font-size: 1rem;
    font-family: Georgia, 'Times New Roman', serif;
}

.message-content h2.md-header {
    font-size: 1.1rem;
}

.message-content strong {
    color: #1a2c24;
}

.chat-input {
    padding: 1rem;
    background: #fff9ee;
    border-top: 1px solid #d5c8a9;
}

.chat-input form {
    display: flex;
    gap: 0.5rem;
}

.chat-input textarea {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid #d5c8a9;
    border-radius: 8px;
    background: #f4efe2;
    color: #1a2c24;
    font-size: 1rem;
    resize: none;
    min-height: 50px;
    font-family: inherit;
}

.chat-input textarea:focus {
    outline: none;
    border-color: #ad4f2d;
}

.chat-input button {
    padding: 0.75rem 1.5rem;
    background: #ad4f2d;
    color: #fff9ee;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
}

.chat-input button:hover {
    background: #6b2d16;
}

.chat-input button:disabled {
    background: #8a9c8e;
    cursor: not-allowed;
}

/* Focus states for keyboard navigation */
.chat-input button:focus-visible,
.stats-bar button:focus-visible,
.sources-actions button:focus-visible {
    outline: 2px solid #ad4f2d;
    outline-offset: 2px;
}

/* Inline references — attached below each assistant message */
.message-references {
    margin-top: 1rem;
    padding-top: 0.85rem;
    border-top: 1px solid #d5c8a9;
}

.references-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #8a9c8e;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    margin-bottom: 0.6rem;
}

.reference-cards {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5rem;
}

.article-card {
    background: #f4efe2;
    border: 1px solid #d5c8a9;
    border-top: 2px solid #d5c8a9;
    border-radius: 4px;
    padding: 0.6rem 0.75rem;
    transition: border-top-color 0.15s;
    min-width: 0; /* prevent grid blowout */
}

.article-card:hover {
    border-top-color: #ad4f2d;
}

.article-card-header {
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
    margin-bottom: 0.25rem;
}

.cite-num {
    font-size: 0.65rem;
    color: #8a9c8e;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    flex-shrink: 0;
}

.article-card h3 {
    font-size: 0.8rem;
    font-family: Georgia, 'Times New Roman', serif;
    font-weight: normal;
    margin: 0;
    line-height: 1.35;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.article-card h3 a {
    color: #6b2d16;
    text-decoration: none;
}

.article-card h3 a:hover {
    text-decoration: underline;
}

.article-meta {
    font-size: 0.7rem;
    color: #8a9c8e;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    margin-bottom: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.article-snippet {
    font-size: 0.75rem;
    color: #5f6b61;
    line-height: 1.4;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

.zim-title {
    color: #ad4f2d;
}

.article-card h3 a.zim-link {
    color: #6b2d16;
    text-decoration: none;
}

.article-card h3 a.zim-link:hover {
    text-decoration: underline;
}

.message-content a.zim-link {
    color: #6b2d16;
}

.message-content a.zim-link:hover {
    color: #ad4f2d;
}

.zim-badge {
    display: inline-block;
    background: #d5e8d8;
    color: #45644d;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    font-size: 0.65rem;
    margin-left: 0.5rem;
    text-transform: uppercase;
}

.empty-state {
    text-align: center;
    color: #8a9c8e;
    padding: 2rem;
    font-style: italic;
}

.loading {
    display: none;
    text-align: center;
    padding: 1rem;
    color: #5f6b61;
}

.loading.active {
    display: block;
}

/* Stats bar */
.stats-bar {
    padding: 0.5rem 1rem;
    background: #ead9b8;
    border-bottom: 1px solid #d5c8a9;
    font-size: 0.8rem;
    color: #5f6b61;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stats-bar button {
    background: transparent;
    border: 1px solid #ad4f2d;
    color: #ad4f2d;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

.stats-bar button:hover {
    background: #ad4f2d;
    color: #fff9ee;
}

/* Collection Panel */
.sources-panel {
    background: #fff6e7;
    border-bottom: 1px solid #d5c8a9;
    padding: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
}

.sources-panel.open {
    max-height: 300px;
    padding: 1rem;
}

.sources-panel h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #5f6b61;
    margin-bottom: 0.75rem;
}

.sources-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
}

.source-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}

.source-item input[type="checkbox"] {
    accent-color: #ad4f2d;
    width: 16px;
    height: 16px;
}

.source-item label {
    cursor: pointer;
    color: #1a2c24;
}

.source-item label:hover {
    color: #ad4f2d;
}

.source-item .source-count {
    color: #8a9c8e;
    font-size: 0.75rem;
}

.source-item .source-badge {
    font-size: 0.65rem;
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    margin-left: 0.25rem;
    text-transform: uppercase;
    font-weight: 500;
}

.source-badge.offline {
    background: #d5e8d8;
    color: #45644d;
}

.source-badge.online {
    background: #ead9b8;
    color: #5f6b61;
    border: 1px solid #d5c8a9;
}

.source-badge.both {
    background: #d5e8d8;
    color: #45644d;
}

.sources-actions {
    margin-top: 0.75rem;
    display: flex;
    gap: 0.5rem;
}

.sources-actions button {
    background: transparent;
    border: 1px solid #d5c8a9;
    color: #5f6b61;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
}

.sources-actions button:hover {
    border-color: #ad4f2d;
    color: #ad4f2d;
}

/* Responsive */
@media (max-width: 900px) {
    .container {
        height: auto;
        min-height: calc(100vh - 140px);
    }
    .chat-panel {
        height: auto;
        min-height: 500px;
    }
    .chat-messages {
        max-height: 65vh;
    }
    .message.assistant {
        max-width: 98%;
    }
    .reference-cards {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 600px) {
    .reference-cards {
        grid-template-columns: repeat(2, 1fr);
    }
}
