/* Dashboard base */
body {
    background-color: #f5f6fa;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Stat cards */
.stat-card {
    border: none;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    transition: transform 0.15s;
}
.stat-card:hover {
    transform: translateY(-2px);
}
.stat-clickable {
    cursor: pointer;
}
.stat-clickable:hover {
    box-shadow: 0 3px 8px rgba(0,0,0,0.15);
}
.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: #2c3e50;
}
.stat-label {
    font-size: 0.85rem;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Relevance badges */
.badge-rel {
    display: inline-block;
    width: 28px;
    height: 28px;
    line-height: 28px;
    border-radius: 50%;
    text-align: center;
    font-weight: 700;
    font-size: 0.8rem;
    color: #fff;
}
.badge-rel-5 { background-color: #e74c3c; }
.badge-rel-4 { background-color: #e67e22; }
.badge-rel-3 { background-color: #f1c40f; color: #333; }
.badge-rel-2 { background-color: #3498db; }
.badge-rel-1 { background-color: #95a5a6; }
.badge-rel-0 { background-color: #ddd; color: #999; }
.badge-rel-empty {
    background-color: transparent;
    border: 2px dashed #ccc;
    color: #aaa;
    cursor: pointer;
    font-size: 1rem;
    line-height: 24px;
}
.badge-rel-empty:hover {
    border-color: #888;
    color: #666;
}
.badge-user {
    cursor: pointer;
}
.badge-user:not(.badge-rel-empty):hover {
    box-shadow: 0 0 0 3px rgba(52,152,219,0.3);
}
.badge-other-user {
    opacity: 0.7;
    cursor: default;
    border: 2px solid rgba(255,255,255,0.5);
    width: 24px;
    height: 24px;
    line-height: 20px;
    font-size: 0.7rem;
}

/* Status badges in table */
.badge-status {
    font-size: 0.68rem;
    font-weight: 500;
}

/* User notes in expanded detail */
.user-notes {
    background: #fffbeb;
    border-left: 3px solid #f59e0b;
    padding: 0.5rem 0.75rem;
    border-radius: 0 4px 4px 0;
}

/* Attributed notes (multi-user view) */
.attributed-note {
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
    border-radius: 0 4px 4px 0;
}
.attributed-note .note-author {
    font-weight: 600;
    font-size: 0.85rem;
}
.attributed-note .note-text {
    font-size: 0.9rem;
}
.user-notes-mine {
    background: #fffbeb;
    border-left: 3px solid #f59e0b;
}
.user-notes-other {
    background: #f0f9ff;
    border-left: 3px solid #3b82f6;
}

/* Relevance bar chart */
.rel-bar-row {
    display: flex;
    align-items: center;
    margin-bottom: 0.4rem;
}
.rel-bar-label {
    width: 90px;
    font-size: 0.85rem;
    font-weight: 500;
    text-align: right;
    padding-right: 0.75rem;
}
.rel-bar-track {
    flex: 1;
    background: #ecf0f1;
    border-radius: 4px;
    height: 22px;
    overflow: hidden;
}
.rel-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.6s ease;
    display: flex;
    align-items: center;
    padding-left: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #fff;
    min-width: 0;
}
.rel-bar-fill-5 { background-color: #e74c3c; }
.rel-bar-fill-4 { background-color: #e67e22; }
.rel-bar-fill-3 { background-color: #f1c40f; color: #333; }
.rel-bar-fill-2 { background-color: #3498db; }
.rel-bar-fill-1 { background-color: #95a5a6; }

/* Topics list */
.topic-badge {
    display: inline-block;
    padding: 0.3rem 0.65rem;
    margin: 0.2rem;
    background-color: #eef2ff;
    color: #4338ca;
    border-radius: 1rem;
    font-size: 0.8rem;
    font-weight: 500;
}
.topic-count {
    font-weight: 700;
    margin-left: 0.25rem;
    color: #6366f1;
}

/* Filter row */
.filter-row .form-select {
    min-width: 140px;
}

/* Articles table tweaks */
#articles-table {
    font-size: 0.88rem;
    table-layout: auto;
    width: 100% !important;
}
#articles-table th {
    white-space: nowrap;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #6c757d;
}
#articles-table td {
    vertical-align: middle;
}
/* Allow title column to shrink and wrap */
#articles-table td:nth-child(6) {
    word-break: break-word;
    min-width: 150px;
}
/* Allow journal to truncate */
#articles-table td:nth-child(7) {
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}
/* Allow pill columns to wrap compactly */
#articles-table td:nth-child(10),
#articles-table td:nth-child(11) {
    max-width: 120px;
}
td.dt-control {
    cursor: pointer;
    text-align: center;
}
td.dt-control::before {
    content: '\25B6';
    color: #6c757d;
    font-size: 0.7rem;
    transition: transform 0.2s;
    display: inline-block;
}
tr.shown td.dt-control::before {
    transform: rotate(90deg);
}

/* Expanded row detail */
.article-detail {
    padding: 1rem 1.5rem;
    background: #fafbfc;
    border-left: 4px solid #3498db;
}
.article-detail h6 {
    color: #2c3e50;
    font-weight: 600;
    margin-top: 0.75rem;
    margin-bottom: 0.35rem;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.article-detail h6:first-child {
    margin-top: 0;
}
.article-detail p,
.article-detail ul {
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 0.5rem;
    max-width: 80ch;
}
.article-detail ul {
    padding-left: 1.2rem;
}
.article-detail .reasoning {
    font-style: italic;
    color: #555;
}

/* Gap cards */
.gap-card {
    border: none;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border-left: 4px solid #95a5a6;
}
.gap-card.priority-5 { border-left-color: #e74c3c; }
.gap-card.priority-4 { border-left-color: #e67e22; }
.gap-card.priority-3 { border-left-color: #f1c40f; }
.gap-card.priority-2 { border-left-color: #3498db; }
.gap-card.priority-1 { border-left-color: #95a5a6; }

.gap-type-badge {
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    border-radius: 0.5rem;
    text-transform: uppercase;
    font-weight: 600;
}
.gap-type-methodological { background: #fde8e8; color: #c0392b; }
.gap-type-population { background: #e8f4fd; color: #2980b9; }
.gap-type-outcome { background: #fef9e7; color: #d4ac0d; }
.gap-type-data { background: #eafaf1; color: #27ae60; }

/* Search history */
#searches-table {
    font-size: 0.85rem;
}

/* Card headers */
.card-header {
    font-weight: 600;
    font-size: 0.9rem;
    background-color: #fff;
    border-bottom: 2px solid #f0f0f0;
}

/* Tabs */
.nav-tabs .nav-link {
    font-weight: 500;
}

/* PROM / method pills in table */
.pill-sm {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    margin: 0.1rem;
    border-radius: 0.75rem;
    font-size: 0.73rem;
    font-weight: 500;
    background: #e8f4fd;
    color: #2980b9;
    white-space: nowrap;
}
.pill-method {
    background: #eafaf1;
    color: #27ae60;
}

/* Tag badges - custom implementation (not using Bootstrap .badge) */
.tag-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3em 0.6em;
    margin: 2px;
    font-size: 0.8rem;
    font-weight: 500;
    line-height: 1.2;
    background-color: #f3e8ff;
    color: #7c3aed;
    border-radius: 0.375rem;
    white-space: nowrap;
    vertical-align: middle;
}
.tag-badge .btn-close {
    width: 0.65em;
    height: 0.65em;
    padding: 0;
    background: transparent url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%237c3aed'%3e%3cpath d='M.293.293a1 1 0 0 1 1.414 0L8 6.586 14.293.293a1 1 0 1 1 1.414 1.414L9.414 8l6.293 6.293a1 1 0 0 1-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L6.586 8 .293 1.707a1 1 0 0 1 0-1.414z'/%3e%3c/svg%3e") center/0.65em auto no-repeat;
    border: 0;
    opacity: 0.6;
    cursor: pointer;
}
.tag-badge .btn-close:hover {
    opacity: 1;
}
.tag-badge-clickable {
    cursor: pointer;
    transition: background-color 0.15s, transform 0.1s;
}
.tag-badge-clickable:hover {
    background-color: #e9d5ff;
    transform: scale(1.05);
}

/* Tag picker in rating picker */
.picker-tags-display {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    min-height: 28px;
    align-items: center;
}
.picker-tags-title {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.picker-existing-tags {
    max-height: 80px;
    overflow-y: auto;
}
#picker-tag-input {
    font-size: 0.85rem;
}

/* Tags in article detail */
.detail-tags-section {
    margin-top: 0.5rem;
}
.detail-tags-inline {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    margin-top: 0.25rem;
}

/* Rating picker popover */
.rating-picker {
    position: absolute;
    z-index: 1050;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    padding: 0.75rem;
    width: 240px;
}
.rating-picker-title {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.rating-picker-options {
    display: flex;
    gap: 6px;
    align-items: center;
}
.rating-option {
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.15s, transform 0.15s;
}
.rating-option:hover {
    opacity: 0.8;
    transform: scale(1.15);
}
.rating-option.selected {
    opacity: 1;
    transform: scale(1.2);
    box-shadow: 0 0 0 3px rgba(52,152,219,0.4);
}
.rating-clear {
    display: inline-block;
    width: 28px;
    height: 28px;
    line-height: 28px;
    border-radius: 50%;
    text-align: center;
    font-size: 0.8rem;
    background: #f0f0f0;
    color: #999;
}

/* ── Chat ─────────────────────────────────────────────────────────────── */

/* Status dot in tab */
.chat-status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #95a5a6;
    margin-left: 4px;
    vertical-align: middle;
}
.chat-status-dot.online { background: #27ae60; }
.chat-status-dot.offline { background: #e74c3c; }

.chat-status-dot-lg {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #95a5a6;
    margin-right: 6px;
}
.chat-status-dot-lg.online { background: #27ae60; }
.chat-status-dot-lg.offline { background: #e74c3c; }

/* Close button - hidden on desktop */
.btn-close-chat {
    display: none;
}

/* Chat container */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 320px);
    min-height: 400px;
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    background: #fff;
    overflow: hidden;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #eee;
    background: #fafbfc;
    flex-shrink: 0;
}

.chat-status-indicator {
    display: flex;
    align-items: center;
    font-size: 0.85rem;
    color: #555;
}

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.chat-welcome {
    text-align: center;
    padding: 2rem 1rem;
}

/* Message bubbles */
.chat-msg {
    max-width: 85%;
    padding: 0.6rem 0.85rem;
    border-radius: 0.75rem;
    font-size: 0.9rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-msg-user {
    align-self: flex-end;
    background: #2c3e50;
    color: #fff;
    border-bottom-right-radius: 0.2rem;
}

.chat-msg-assistant {
    align-self: flex-start;
    background: #f0f2f5;
    color: #1a1a1a;
    border-bottom-left-radius: 0.2rem;
}

/* Markdown inside assistant messages */
.chat-msg-assistant p { margin-bottom: 0.4rem; }
.chat-msg-assistant p:last-child { margin-bottom: 0; }
.chat-msg-assistant ul,
.chat-msg-assistant ol { margin-bottom: 0.4rem; padding-left: 1.2rem; }
.chat-msg-assistant code {
    background: #e2e6ea;
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-size: 0.82rem;
}
.chat-msg-assistant pre {
    background: #2c3e50;
    color: #ecf0f1;
    padding: 0.6rem 0.75rem;
    border-radius: 0.4rem;
    overflow-x: auto;
    font-size: 0.8rem;
    margin: 0.4rem 0;
}
.chat-msg-assistant pre code {
    background: none;
    padding: 0;
    color: inherit;
}
.chat-msg-assistant h1,
.chat-msg-assistant h2,
.chat-msg-assistant h3,
.chat-msg-assistant h4 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0.5rem 0 0.25rem;
}
.chat-msg-assistant table {
    font-size: 0.82rem;
    border-collapse: collapse;
    margin: 0.4rem 0;
    width: 100%;
}
.chat-msg-assistant th,
.chat-msg-assistant td {
    border: 1px solid #ccc;
    padding: 0.25rem 0.5rem;
}
.chat-msg-assistant a {
    color: #2980b9;
}

/* Tool activity indicator */
.chat-tool-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    color: #6c757d;
    border-top: 1px solid #eee;
    background: #fafbfc;
}

.chat-tool-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    background: #eafaf1;
    color: #27ae60;
    margin: 0.2rem 0;
}

/* Input area */
.chat-input-area {
    flex-shrink: 0;
    border-top: 1px solid #dee2e6;
    background: #fafbfc;
}

.chat-input-row {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    align-items: flex-end;
}

.chat-input-row textarea {
    resize: none;
    min-height: 38px;
    max-height: 120px;
    font-size: 0.9rem;
}

.chat-input-row .btn {
    flex-shrink: 0;
    height: 38px;
}

.chat-model-badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: 0.5rem;
    font-size: 0.65rem;
    font-weight: 500;
    background: #f0f0f5;
    color: #888;
    margin-top: 0.25rem;
}

#chat-model-select {
    height: 38px;
    font-size: 0.8rem;
    flex-shrink: 0;
}

/* Sync progress */
.chat-sync-progress {
    font-size: 0.8rem;
    color: #6c757d;
    padding: 0.25rem 0.75rem;
}

/* Papers / PDF buttons */
.btn-upload-pdf { font-size: 0.8rem; cursor: pointer; }
#btn-papers-unlock { font-size: 0.85rem; }
.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 9999; }
.toast-container .toast-msg {
    padding: 0.6rem 1rem;
    border-radius: 0.4rem;
    color: #fff;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    animation: toastFadeIn 0.3s ease;
}
.toast-msg.toast-success { background: #27ae60; }
.toast-msg.toast-danger { background: #e74c3c; }
.toast-msg.toast-info { background: #2980b9; }
@keyframes toastFadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* Synthesis buttons */
.synthesis-buttons {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    margin-top: 1rem;
}
.synthesis-buttons .btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    padding: 0.4rem 1rem;
    border-radius: 1.5rem;
    transition: all 0.2s ease;
}
.synthesis-buttons .btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.synthesis-buttons .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.synth-icon {
    font-size: 1rem;
}
.chat-download-btn {
    margin-top: 0.75rem;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.8rem;
    border-radius: 1rem;
}

/* Responsive */
@media (max-width: 768px) {
    /* Full-screen chat experience on mobile */
    body.chat-active {
        overflow: hidden;
    }

    .chat-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile browsers */
        border: none;
        border-radius: 0;
        z-index: 1050;
        min-height: unset;
    }

    .chat-header {
        padding: 0.75rem 1rem;
        padding-top: max(0.75rem, env(safe-area-inset-top));
        background: #2c3e50;
        color: #fff;
        border-bottom: none;
    }

    .chat-header .chat-status-indicator {
        color: #fff;
    }

    .chat-header .chat-status-dot-lg.online {
        background: #2ecc71;
    }

    .chat-header .btn-close-chat {
        display: block;
        background: none;
        border: none;
        color: #fff;
        font-size: 1.5rem;
        padding: 0.25rem 0.5rem;
        cursor: pointer;
    }

    .chat-header .btn {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
        border-color: rgba(255,255,255,0.5);
        color: #fff;
    }

    .chat-header .btn:hover {
        background: rgba(255,255,255,0.1);
    }

    .chat-messages {
        padding: 0.75rem;
        gap: 0.5rem;
        background: #f7f7f8;
    }

    .chat-msg {
        max-width: 88%;
        padding: 0.7rem 0.9rem;
        font-size: 0.95rem;
        line-height: 1.55;
        border-radius: 1.1rem;
    }

    .chat-msg-user {
        background: #2c3e50;
        border-bottom-right-radius: 0.3rem;
    }

    .chat-msg-assistant {
        background: #fff;
        border: 1px solid #e5e5e5;
        border-bottom-left-radius: 0.3rem;
    }

    .chat-input-area {
        padding-bottom: env(safe-area-inset-bottom);
        background: #fff;
        border-top: 1px solid #e5e5e5;
    }

    .chat-input-row {
        padding: 0.6rem 0.75rem;
    }

    .chat-input-row textarea {
        font-size: 1rem;
        min-height: 44px;
        border-radius: 1.25rem;
        padding: 0.6rem 1rem;
    }

    .chat-input-row .btn {
        height: 44px;
        width: 44px;
        border-radius: 50%;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    #chat-model-select {
        display: none; /* Hide model selector on mobile */
    }

    .chat-tool-status {
        font-size: 0.75rem;
        padding: 0.25rem 0.75rem;
    }

    .chat-welcome {
        padding: 3rem 1.5rem;
    }

    .chat-welcome h5 {
        font-size: 1.2rem;
    }

    /* Hide tabs when chat is active on mobile */
    body.chat-active .nav-tabs,
    body.chat-active .tab-content > :not(.chat-container),
    body.chat-active header,
    body.chat-active footer {
        display: none !important;
    }
}
