/* Research-reader UI on top of Bootstrap 5 */

:root {
    --bg: #f3f4f1;
    --surface: #ffffff;
    --surface-muted: #f8f8f5;
    --border: #d9ddd3;
    --border-light: #eceee8;
    --border-strong: #b8c0b0;
    --text: #242923;
    --muted: #556054;
    --quiet: #5a6356;
    --accent: #236c63;
    --accent-soft: #e4efec;
    --mark: #fff2a8;
    --pdf-bg: #202422;
    --pdf-surface: #2b312e;
    --pdf-text: #edf1eb;
    --pdf-muted: #c0c8bd;
    --pdf-placeholder: #eef3ed;
    --reading-text: #3d443b;
}

html,
body {
    height: 100%;
    overflow: hidden;
    font-family: "Noto Sans SC", "Source Han Sans SC", -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--text);
    background: var(--bg);
}

.app-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.app-header {
    flex-shrink: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1.25rem;
    height: 54px;
    display: flex;
    align-items: center;
}

.app-header .logo {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    font-size: 1.02rem;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    margin-right: 2rem;
    white-space: nowrap;
}

.app-header .nav {
    gap: 0.25rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
}

.app-header .nav::-webkit-scrollbar {
    display: none;
}

.app-header .nav-link {
    color: var(--muted);
    font-size: 0.9rem;
    padding: 0.42rem 0.7rem;
    border-radius: 5px;
}

.app-header .nav-link:hover {
    color: var(--text);
    background: var(--surface-muted);
}

.app-header .nav-link.active {
    color: var(--accent);
    background: var(--accent-soft);
    font-weight: 600;
}

.app-main {
    flex: 1;
    overflow: hidden;
    display: flex;
    min-height: 0;
}

.breadcrumbs {
    flex-shrink: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.breadcrumbs a:hover { color: var(--accent) !important; }

.sidebar-left {
    width: 272px;
    min-width: 180px;
    max-width: 420px;
    flex: 0 0 272px;
    background: var(--surface);
    overflow-y: auto;
    padding: 1rem;
    border-right: 1px solid var(--border);
}

.sidebar-right {
    width: 600px;
    min-width: 280px;
    max-width: 900px;
    flex: 0 0 600px;
    background: var(--pdf-bg);
    display: flex;
    flex-direction: column;
}

.content-center {
    flex: 1 1 0%;
    min-width: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.1rem 1.35rem;
    background: var(--bg);
}

.resize-handle {
    width: 4px;
    cursor: col-resize;
    background: var(--border);
    flex-shrink: 0;
    transition: background 0.15s;
    position: relative;
}

.resize-handle:hover,
.resize-handle.dragging {
    background: var(--accent);
}

.resize-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 28px;
    border-radius: 2px;
    background: var(--border-strong);
}

.filter-group {
    margin-bottom: 1rem;
}

.filter-group label,
.section-kicker,
.section-header {
    display: block;
    font-size: 0.72rem;
    color: var(--muted);
    margin-bottom: 0.35rem;
    font-weight: 700;
    letter-spacing: 0.03em;
}

.same-day-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--muted);
    margin-bottom: 0.5rem;
}

.filter-group .form-control,
.filter-group .form-select {
    font-size: 0.86rem;
    padding: 0.42rem 0.55rem;
    border-color: var(--border);
    border-radius: 5px;
}

.search-input {
    font-size: 0.94rem !important;
}

.choice-list,
.source-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.source-list {
    max-height: 240px;
    overflow-y: auto;
    padding-right: 0.15rem;
}

.choice-row {
    display: grid !important;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.45rem;
    margin: 0 !important;
    padding: 0.42rem 0.45rem;
    border: 1px solid transparent;
    border-radius: 5px;
    color: var(--text) !important;
    font-size: 0.84rem !important;
    font-weight: 500 !important;
    letter-spacing: 0 !important;
    cursor: pointer;
}

.choice-row:hover {
    background: var(--surface-muted);
    border-color: var(--border);
}

.choice-row input {
    margin: 0;
    accent-color: var(--accent);
}

.choice-row small {
    color: var(--quiet);
    font-size: 0.72rem;
}

.filter-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 1rem;
}

.filter-actions .btn-primary {
    flex: 1;
    background: var(--accent);
    border-color: var(--accent);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.btn-primary:hover,
.btn-primary:focus {
    background: #1c5951;
    border-color: #1c5951;
    color: #fff;
}

/* Global focus-visible for keyboard users */
*:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* HTMX loading indicator */
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    opacity: 1;
}
.htmx-indicator {
    opacity: 0;
    transition: opacity 200ms ease-in;
}
#search-results.htmx-request {
    opacity: 0.5;
    pointer-events: none;
}

#search-suggestions {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    z-index: 50;
    max-height: 220px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 5px;
    box-shadow: 0 8px 18px rgba(24, 30, 24, 0.14);
    margin-top: 3px;
}

.result-count {
    color: var(--muted);
    font-size: 0.9rem;
}

.result-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
    font-size: 0.86rem;
}

.result-nav a {
    color: var(--accent);
    text-decoration: none;
}

.result-nav a:hover {
    text-decoration: underline;
}

.result-nav-page {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.entry-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 0.85rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.entry-card:hover {
    border-color: var(--border-strong);
    box-shadow: 0 3px 10px rgba(30, 36, 29, 0.08);
}

.entry-card.is-selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.entry-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    padding: 0.8rem 0.95rem 0.6rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border-light);
}

.entry-date {
    font-weight: 700;
    color: var(--accent);
    font-size: 0.98rem;
}

.entry-source {
    font-size: 0.78rem;
    color: var(--quiet);
    margin-top: 0.12rem;
}

.entry-actions {
    flex-shrink: 0;
}

.entry-actions .btn,
.entry-footer .btn,
.detail-link {
    font-size: 0.78rem;
}

.entry-content {
    padding: 0.75rem 0.95rem 0.85rem;
    color: var(--reading-text);
    line-height: 1.85;
    font-family: "Noto Serif SC", "Source Han Serif SC", "Songti SC", Georgia, serif;
    font-size: 0.92rem;
}

.entry-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.55rem 0.95rem;
    border-top: 1px solid var(--border-light);
    font-size: 0.78rem;
    color: var(--quiet);
}

.detail-link {
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
}

.detail-link:hover {
    text-decoration: underline;
}

mark.highlight {
    background: var(--mark);
    padding: 0 2px;
    border-radius: 2px;
}

.empty-title,
.placeholder-title {
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.35rem;
}

.pdf-toolbar {
    flex-shrink: 0;
    background: var(--pdf-surface);
    padding: 0.55rem 0.7rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.pdf-toolbar-title {
    color: var(--pdf-text);
    font-size: 0.82rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pdf-toolbar-controls {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}

.pdf-toolbar .form-control {
    background: var(--surface-muted);
    border-color: transparent;
    text-align: center;
    padding-left: 0.25rem;
    padding-right: 0.25rem;
}

.pdf-viewer {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 1rem;
}

.pdf-viewer img {
    max-width: 100%;
    background: white;
    box-shadow: 0 10px 24px rgba(0,0,0,0.35);
}

.pdf-placeholder,
.pdf-loading {
    color: var(--pdf-muted);
    text-align: center;
    padding: 3rem 1.5rem;
    max-width: 280px;
    line-height: 1.6;
}

.pdf-placeholder .placeholder-title {
    color: var(--pdf-placeholder);
}

.entry-full-header {
    padding: 1.25rem 1.5rem;
    background: var(--surface-muted);
    border-bottom: 1px solid var(--border);
}

.entry-full-date {
    font-size: 1.28rem;
    font-weight: 700;
    color: var(--accent);
}

.entry-full-source {
    font-size: 0.9rem;
    color: var(--muted);
    margin-top: 0.2rem;
}

.entry-full-content {
    padding: 1.5rem;
    max-width: 880px;
    font-size: 1.02rem;
    line-height: 2.05;
    font-family: "Noto Serif SC", "Source Han Serif SC", "Songti SC", Georgia, serif;
}

.entry-full-content p {
    margin: 0 0 1em 0;
    text-indent: 2em;
}

.entry-full-content p:first-child {
    text-indent: 0;
}

.citation-box {
    background: var(--surface-muted);
    border-top: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
}

.citation-label {
    font-size: 0.7rem;
    color: var(--quiet);
    font-weight: 700;
    letter-spacing: 0.04em;
    margin-bottom: 2px;
}

.citation-text {
    font-size: 0.9rem;
    color: var(--muted);
}

.nav-card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.75rem 0.85rem;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s, background 0.15s;
}

.nav-card:hover {
    border-color: var(--accent);
    background: var(--surface-muted);
    color: inherit;
}

.nav-label {
    font-size: 0.68rem;
    color: var(--quiet);
    font-weight: 700;
    letter-spacing: 0.03em;
}

.nav-date {
    font-weight: 700;
    color: var(--accent);
    font-size: 0.9rem;
}

.nav-preview {
    font-size: 0.8rem;
    color: var(--quiet);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.same-day-section {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-light);
}

.source-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 0.65rem;
}

.source-card,
.year-grid a {
    display: flex;
    flex-direction: column;
    padding: 0.8rem 0.85rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s, background 0.15s;
}

.source-card:hover,
.year-grid a:hover {
    border-color: var(--accent);
    background: var(--surface-muted);
    color: inherit;
}

.source-card-title {
    font-weight: 700;
    color: var(--text);
    font-size: 0.96rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

.source-card-meta,
.year-count {
    color: var(--quiet);
    font-size: 0.75rem;
    margin-top: 0.2rem;
}

.year-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: 0.45rem;
}

.year-grid a {
    align-items: center;
    padding: 0.65rem 0.5rem;
}

.year-num {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}

@media (max-width: 1100px) {
    html,
    body {
        overflow: auto;
        height: auto;
    }

    .app-wrapper {
        min-height: 100vh;
        height: auto;
    }

    .app-main {
        display: grid;
        grid-template-columns: 280px minmax(0, 1fr);
        overflow: visible;
    }

    .sidebar-left,
    .content-center,
    .sidebar-right {
        max-width: none;
    }

    .sidebar-right {
        grid-column: 1 / -1;
        width: auto;
        min-height: 420px;
    }

    .resize-handle {
        display: none;
    }
}

@media (max-width: 760px) {
    .app-header {
        padding: 0 0.8rem;
        overflow: hidden;
    }

    .app-header .logo {
        margin-right: 1rem;
    }

    .app-header .nav-link {
        white-space: nowrap;
        padding-left: 0.55rem;
        padding-right: 0.55rem;
    }

    .app-main {
        display: block;
    }

    .sidebar-left,
    .content-center,
    .sidebar-right {
        width: auto;
        min-width: 0;
    }

    .sidebar-left {
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .content-center {
        padding: 0.9rem;
    }

    .entry-header,
    .entry-footer {
        align-items: flex-start;
        flex-direction: column;
    }

    .entry-actions {
        width: 100%;
    }
}

.entry-full-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.45;
}

.wenji-meta {
    font-size: 0.82rem;
    color: var(--muted);
    margin-top: 0.2rem;
    line-height: 1.5;
}

.footnotes-section {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    background: var(--surface-muted);
}

.footnotes-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--muted);
    letter-spacing: 0.04em;
    margin-bottom: 0.4rem;
}

.footnotes-content {
    font-size: 0.85rem;
    color: var(--quiet);
    line-height: 1.7;
    white-space: pre-wrap;
}

.content-type-badge {
    display: inline;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    vertical-align: baseline;
}

.content-type-badge.wenji {
    color: #6b4c1e;
}

.content-type-badge.shuxin {
    color: #1a524a;
}

.content-type-badge.nianpu {
    color: #2d4a28;
}

.entity-type-badge {
    display: inline;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    vertical-align: baseline;
}

/* Entity badges use a distinct hue (indigo) from content-type badges (green/brown) */
.entity-type-badge.person {
    color: #3b3f8f;
}

.entity-type-badge.organization {
    color: #6d2e6d;
}

@media print {
    .app-header,
    .sidebar-left,
    .sidebar-right,
    .entry-actions,
    .pagination {
        display: none !important;
    }

    html,
    body,
    .app-wrapper,
    .app-main,
    .content-center {
        height: auto;
        overflow: visible;
        display: block;
        background: #fff;
    }
}

/* Calendar heatmap (/date/ index) */
.year-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
    max-height: 70vh;
    overflow-y: auto;
}
.year-link {
    display: flex;
    justify-content: space-between;
    padding: 0.2rem 0.45rem;
    border-radius: 4px;
    text-decoration: none;
    color: var(--text);
    font-size: 0.85rem;
}
.year-link:hover { background: var(--accent-soft); }
.year-link.active { background: var(--accent); color: #fff; }
.year-link.active .text-muted { color: rgba(255,255,255,0.75); }

.heatmap-wrap { padding: 1rem 0.95rem; }
.heatmap-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 3px;
}
.heatmap-month {
    width: 2.6rem;
    flex-shrink: 0;
    font-size: 0.78rem;
    color: var(--muted);
    text-decoration: none;
}
.heatmap-month:hover { color: var(--accent); text-decoration: underline; }
.heatmap-days { display: flex; gap: 2px; }
.hm-cell {
    width: 16px;
    height: 16px;
    border-radius: 2px;
    display: inline-block;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
}
.hm-invalid { visibility: hidden; }
.hm-0 { background: #e0e3dc; }
a.hm-cell:hover { outline: 1px solid var(--accent); }
.hm-1 { background: #b8d6cf; }
.hm-2 { background: #7eb3a6; }
.hm-3 { background: #4a8e7e; }
.hm-4 { background: #2d6b5e; }
.heatmap-legend {
    display: flex;
    align-items: center;
    gap: 3px;
    margin-top: 0.7rem;
    padding-left: 3.1rem;
}

/* Year overview cells */
.year-cells { gap: 4px; }
.year-cell {
    width: 52px;
    height: 30px;
    border-radius: 3px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    text-decoration: none;
    color: var(--muted);
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
}
a.year-cell:hover { outline: 1px solid var(--accent); }
.year-cell.hm-0 { color: var(--quiet); background: #e0e3dc; }
.year-cell.hm-1 { color: var(--text); }
.year-cell.hm-2, .year-cell.hm-3 { color: #fff; }
.year-cell.hm-4 { color: #fff; }

/* Filter chips */
.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: 12px;
    padding: 0.15rem 0.6rem;
    font-size: 0.78rem;
    font-weight: 500;
}
.chip-remove {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.9rem;
    line-height: 1;
    opacity: 0.6;
}
.chip-remove:hover {
    opacity: 1;
    text-decoration: none;
}

/* On this day (homepage) */
.on-this-day {
    padding: 0.75rem 0.95rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-muted);
}
.otd-row {
    display: flex;
    flex-wrap: nowrap;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.15rem 0;
    font-size: 0.88rem;
}
.otd-row .content-type-badge { flex-shrink: 0; }
.otd-year {
    font-weight: 600;
    color: var(--accent);
    text-decoration: none;
    flex-shrink: 0;
}
.otd-year:hover { text-decoration: underline; }
.otd-preview {
    flex: 1 1 auto;
    min-width: 0;
    color: var(--text);
    text-decoration: none;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    line-height: 1.6;
}
.otd-preview:hover { color: var(--accent); }
/* Beta login */
.beta-badge {
    padding: 0.2rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--muted);
    background: var(--surface-muted);
    font-size: 0.72rem;
    font-weight: 700;
}

.login-view {
    flex: 1;
    overflow-y: auto;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background: var(--bg);
}

.login-panel {
    width: min(100%, 25rem);
    padding: 2rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    box-shadow: 0 0.5rem 1.5rem rgba(36, 41, 35, 0.06);
}

.login-panel h1 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
}

.login-description {
    margin: 0.75rem 0 1.5rem;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.6;
}

.login-error {
    margin-bottom: 1rem;
    padding: 0.65rem 0.75rem;
    border-left: 3px solid #a13f35;
    background: #f8ece9;
    color: #7f3028;
    font-size: 0.86rem;
}

.login-form .btn {
    width: 100%;
}

.logout-form {
    display: contents;
}

.logout-button {
    border: 0;
    background: transparent;
    font: inherit;
}
