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

html,
body {
    height: 100%;
    font-family: Helvetica, Arial, sans-serif;
    font-size: 15px;
    background: #fff;
    color: #111;
}

#app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ── */
#sidebar {
    width: 33.333%;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #ddd;
    overflow: hidden;
}

#search-bar {
    padding: 10px;
    border-bottom: 1px solid #ddd;
    display: flex;
    align-items: center;
    gap: 8px;
}

#home-link {
    font-size: 17px;
    font-weight: bold;
    font-style: italic;
    color: #e00;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
    font-family: Helvetica, Arial, sans-serif;
}

#home-link:hover {
    text-decoration: none;
    color: #e00;
}

#search-input-wrap {
    position: relative;
    flex: 1;
}

#q {
    width: 100%;
    padding: 7px 30px 7px 9px;
    font-size: 15px;
    border: 1px solid #ccc;
    outline: none;
    background: #fff;
    border-radius: 3px;
}

#q:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

#clear-btn {
    display: none;
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    color: #aaa;
    padding: 2px 4px;
}

#clear-btn:hover {
    color: #555;
}

#bookmarks-bar {
    padding: 4px 10px;
    border-bottom: 1px solid #eee;
}

#bookmarks-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    color: #888;
    padding: 0;
}

#bookmarks-btn:hover {
    color: #2563eb;
}

#bookmarks-btn.active {
    color: #2563eb;
    font-weight: bold;
}

#status {
    font-size: 12px;
    color: #888;
    padding: 4px 10px;
    border-bottom: 1px solid #eee;
    min-height: 24px;
}

#results {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.result {
    padding: 9px 28px 9px 11px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    line-height: 1.45;
    position: relative;
}

.bookmark-btn {
    position: absolute;
    top: 7px;
    right: 7px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    padding: 2px;
    color: #ccc;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
}

.result:hover .bookmark-btn,
.bookmark-btn.bookmarked {
    opacity: 1;
}

.bookmark-btn.bookmarked {
    color: #2563eb;
}

.result:hover {
    background: #f0f6ff;
}
.result.active {
    background: #dbeafe;
}

.result-title {
    font-weight: bold;
    font-size: 14px;
    color: #1d4ed8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-meta {
    font-size: 12px;
    color: #888;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-snippet {
    font-size: 13px;
    color: #444;
    margin-top: 3px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.result-snippet mark {
    background: #fef08a;
    color: inherit;
    font-style: normal;
    padding: 0;
}

/* ── Date Histogram ── */
#date-hist {
    display: none;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}

#hist-header {
    padding: 5px 10px;
    font-size: 12px;
    color: #3b82f6;
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
}

#hist-header:hover {
    color: #1d4ed8;
}

#hist-body {
    display: none;
    padding: 4px 10px 6px;
    font-family: monospace;
    font-size: 12px;
    line-height: 1.6;
    max-height: 180px;
    overflow-y: auto;
}

.hist-year {
    color: #555;
    margin-top: 4px;
    cursor: pointer;
}

.hist-year:first-child {
    margin-top: 0;
}
.hist-year:hover {
    color: #1d4ed8;
}
.hist-year.hist-sel {
    color: #1d4ed8;
    font-weight: bold;
}

.hist-row {
    display: flex;
    align-items: center;
    padding: 2px 0 2px 12px;
    cursor: pointer;
    gap: 6px;
}

.hist-mn {
    min-width: 16px;
    font-size: 12px;
    color: #888;
    flex-shrink: 0;
}

.hist-bar-wrap {
    flex: 1;
    height: 14px;
}

.hist-bar-fill {
    height: 100%;
    background: #93c5fd;
    display: flex;
    align-items: center;
    padding: 0 5px;
    min-width: 28px;
}

.hist-count {
    color: #1e3a5f;
    font-size: 10px;
    white-space: nowrap;
    line-height: 1;
}

.hist-row:hover .hist-bar-fill {
    background: #60a5fa;
}
.hist-row.hist-sel .hist-bar-fill {
    background: #2563eb;
}
.hist-row.hist-sel .hist-count {
    color: #fff;
}

/* ── Pagination ── */
#pagination {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 7px 10px;
    border-top: 1px solid #eee;
    font-size: 12px;
    color: #888;
    flex-shrink: 0;
}

#pagination button {
    background: none;
    border: 1px solid #93c5fd;
    padding: 3px 10px;
    font-size: 13px;
    cursor: pointer;
    color: #2563eb;
    border-radius: 3px;
}

#pagination button:hover:not(:disabled) {
    background: #eff6ff;
    border-color: #2563eb;
}

#pagination button:disabled {
    opacity: 0.3;
    cursor: default;
}

/* ── Viewer ── */
#viewer {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

#viewer-header {
    display: none;
    align-items: center;
    gap: 16px;
    padding: 6px 14px;
    border-bottom: 1px solid #ddd;
    background: #fff;
    flex-shrink: 0;
    min-height: 42px;
}

#viewer-header h1 {
    font-weight: bold;
    font-style: italic;
    font-size: 22px;
    color: #111;
    white-space: nowrap;
    flex-shrink: 0;
}

#viewer-header-meta {
    font-size: 12px;
    color: #555;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

#viewer-header-url {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #1d4ed8;
}

#viewer-header-ts {
    color: #888;
    white-space: nowrap;
}

#intro {
    max-width: 900px;
    margin: 48px auto;
    padding: 0 48px;
    font-size: 17px;
    line-height: 1.75;
    color: #222;
}

#intro p {
    margin-bottom: 1.2em;
}

#intro a {
    color: #1d4ed8;
    text-decoration: none;
}

#intro a:hover {
    text-decoration: underline;
}

#frame {
    width: 100%;
    flex: 1;
    border: none;
    min-height: 0;
}

/* ── Back button (mobile only) ── */
#back-btn {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: #2563eb;
    padding: 0 4px;
    flex-shrink: 0;
}

/* ── Mobile layout ── */
@media (max-width: 768px) {
    #app {
        flex-direction: column;
    }

    /* Sidebar shrinks to its content; results list scrolls inside it */
    #sidebar {
        width: 100%;
        flex: 0 0 auto;
        border-right: none;
        border-bottom: 1px solid #ddd;
        max-height: 55vh;
    }

    /* Viewer fills the remaining height and shows the intro by default */
    #viewer {
        flex: 1;
        min-height: 0;
    }

    /* When an article is open, viewer covers the whole screen */
    #app.viewer-open #sidebar {
        display: none;
    }

    #app.viewer-open #viewer {
        position: fixed;
        inset: 0;
        z-index: 10;
        background: #fff;
        overflow-y: auto;
    }

    #back-btn {
        display: block;
    }

    #intro {
        padding: 0 20px;
        font-size: 15px;
        margin: 32px auto;
    }
}
