/* ── Variables ────────────────────────────────────────────────────── */

:root {
    --bg: #fbf7f0;
    --bg-subtle: #f3ede4;
    --text: #1a1a1a;
    --text-secondary: #5c5c5c;
    --text-dim: #8a8a8a;
    --rule: #c8bfb0;
    --rule-light: #ddd5c8;
    --accent: #8b2500;
    --accent-hover: #a83000;
    --green: #2d6a30;
    --red: #9b2c2c;
    --serif: 'Libre Baskerville', 'Georgia', serif;
    --display: 'Playfair Display', 'Georgia', serif;
}

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

body {
    font-family: var(--serif);
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    padding: 0 2rem 3rem;
    max-width: 780px;
    margin: 0 auto;
    -webkit-font-smoothing: antialiased;
}

/* ── Masthead ────────────────────────────────────────────────────── */

.masthead {
    padding: 1.5rem 0 0;
}

.masthead-rule {
    height: 2px;
    background: var(--text);
}

/* ── Page layout ─────────────────────────────────────────────────── */

.page-layout {
    margin-top: 1.5rem;
}

.main-col {
    /* content column — sidebar is fixed outside */
}

/* ── Sidebar (scan panel) ────────────────────────────────────────── */

.sidebar {
    width: 220px;
    flex-shrink: 0;
    position: fixed;
    top: 2rem;
    right: 2rem;
}

.sidebar-section {
    border: 1px solid var(--rule);
    padding: 14px 16px;
    margin-bottom: 12px;
}

.sidebar-heading {
    font-family: var(--serif);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-secondary);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--rule-light);
}

.sidebar-subheading {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    margin-top: 0;
    margin-bottom: 6px;
}

.sidebar-info {
    font-size: 0.78rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.sidebar-info .info-label {
    color: var(--text-dim);
}

.sidebar-info .info-value {
    color: var(--text);
}

.sidebar-info .info-cost {
    color: var(--green);
    font-weight: 700;
}

.sidebar-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 12px;
}

.sidebar-btn {
    padding: 7px 12px;
    background: var(--bg);
    border: 1px solid var(--rule);
    font-family: var(--serif);
    font-size: 0.72rem;
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    text-align: center;
    letter-spacing: 0.02em;
}

.sidebar-btn:hover {
    background: var(--bg-subtle);
    border-color: var(--text-secondary);
}

.sidebar-btn:disabled {
    cursor: not-allowed;
    opacity: 0.4;
}

.sidebar-btn.scanning {
    border-color: var(--accent);
    color: var(--accent);
    font-style: italic;
}

.sidebar-btn--settings {
    border-style: dashed;
    color: var(--text-secondary);
    width: 100%;
}

.sidebar-btn--settings:hover {
    color: var(--text);
}

/* ── Welcome (no report) ─────────────────────────────────────────── */

.welcome {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.welcome-tagline {
    font-family: var(--serif);
    font-size: 2rem;
    font-weight: 400;
    color: var(--text);
    text-align: center;
    line-height: 1.5;
    margin-bottom: 3.5rem;
}

.welcome-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    min-height: 5.5rem;
}

.welcome-btn {
    font-family: var(--serif);
    font-size: 0.85rem;
    padding: 0.6rem 1.8rem;
    border: 1px solid var(--rule);
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    letter-spacing: 0.03em;
}

.welcome-btn:hover {
    background: var(--bg-subtle);
}

.welcome-btn--go {
    background: var(--text);
    color: var(--bg);
    border-color: var(--text);
}

.welcome-btn--go:hover {
    opacity: 0.85;
    background: var(--text);
}

/* ── Login screen ────────────────────────────────────────────────── */

.login-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    z-index: 200;
}

.login-brand {
    position: absolute;
    top: 1.5rem;
    left: 2rem;
    font-family: var(--display);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
}

.login-card {
    text-align: center;
    max-width: 600px;
    padding: 2rem;
}

.login-tagline {
    font-family: var(--display);
    font-size: 4.5rem;
    font-weight: 900;
    color: var(--text);
    line-height: 1.1;
    letter-spacing: -0.03em;
    margin-bottom: 3.5rem;
}

.login-btn {
    font-family: var(--serif);
    font-size: 0.88rem;
    padding: 0.7rem 2rem;
    background: var(--text);
    color: var(--bg);
    border: none;
    cursor: pointer;
    letter-spacing: 0.03em;
    transition: opacity 0.15s;
}

.login-btn:hover {
    opacity: 0.8;
}

/* ── Sidebar user / logout ───────────────────────────────────────── */

.sidebar-section--user {
    border: none;
    padding: 10px 16px;
}

.sidebar-user {
    font-size: 0.68rem;
    color: var(--text-dim);
    margin-bottom: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-btn--logout {
    border-style: dashed;
    color: var(--text-dim);
    width: 100%;
    font-size: 0.68rem;
}

.sidebar-btn--logout:hover {
    color: var(--red);
    border-color: var(--red);
}

/* ── Welcome logout (bottom-right) ───────────────────────────────── */

.welcome-logout {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 0.5rem;
    line-height: 1;
    transition: color 0.15s;
}

.welcome-logout svg {
    width: 28px;
    height: 28px;
}

.welcome-logout:hover {
    color: var(--red);
}

/* ── App brand (post-login) ───────────────────────────────────────── */

.app-brand {
    position: fixed;
    top: 1.5rem;
    left: 2rem;
    font-family: var(--display);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
    z-index: 50;
}

/* ── Loading ─────────────────────────────────────────────────────── */

.loading-msg {
    color: var(--text-dim);
    font-style: italic;
    font-size: 0.95rem;
    padding: 2rem 0;
}

/* ── Masthead dateline ────────────────────────────────────────────── */

.masthead-dateline {
    font-family: var(--serif);
    font-size: 0.7rem;
    letter-spacing: 0.03em;
    color: var(--text-dim);
    text-align: right;
    padding-bottom: 0.35rem;
}

/* ── Feed items ──────────────────────────────────────────────────── */

.feed-item {
    padding: 1rem 0;
    border-bottom: 1px solid var(--rule-light);
}

.feed-item:last-child {
    border-bottom: none;
}

.feed-item--digest {
    border-bottom: 2px solid var(--text);
    padding-bottom: 1.5rem;
    margin-bottom: 0.5rem;
    display: flex;
    flex-direction: column;
    max-height: none;
}

.feed-item-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.3rem;
    font-size: 0.75rem;
}

.feed-source {
    display: inline-block;
    font-family: var(--serif);
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 0.1rem 0;
    text-decoration: none;
    flex-shrink: 0;
}

.feed-source--digest   { color: var(--text); }
.feed-source--podcast  { color: var(--green); }
.feed-source--substack { color: #6b3fa0; }
.feed-source--hackernews { color: #c65d07; }
.feed-source--hf_paper { color: #e5a100; }
.feed-source--twitter  { color: #2a6496; }

a.feed-source:hover {
    text-decoration: underline;
}

.feed-source-name {
    color: var(--text-secondary);
    font-size: 0.78rem;
}

.feed-score {
    color: #c65d07;
    font-size: 0.72rem;
    font-weight: 700;
}

.feed-date {
    color: var(--text-dim);
    font-size: 0.72rem;
    margin-left: auto;
    flex-shrink: 0;
}

.feed-item-title {
    font-family: var(--display);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.3rem;
    line-height: 1.35;
}

.feed-item-title a {
    color: var(--accent);
    text-decoration: none;
}

.feed-item-title a:hover {
    text-decoration: underline;
}

/* ── Synthesis / body text ───────────────────────────────────────── */

.card-synthesis {
    font-size: 0.92rem;
    color: var(--text);
    line-height: 1.75;
}

.card-synthesis .citation-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.75em;
    font-weight: 700;
    vertical-align: super;
}

.card-synthesis .citation-link:hover {
    text-decoration: underline;
}

/* ── Digest HTML content ─────────────────────────────────────────── */

.feed-item--digest .card-synthesis h3 {
    font-family: var(--display);
    color: var(--text);
    font-size: 1.15rem;
    font-weight: 700;
    margin: 1.8rem 0 0.5rem 0;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--rule-light);
}

.feed-item--digest .card-synthesis h3:first-child {
    margin-top: 0.3rem;
}

.feed-item--digest .card-synthesis p {
    margin: 0.5rem 0;
    text-align: justify;
    hyphens: auto;
}

.feed-item--digest .card-synthesis ul,
.feed-item--digest .card-synthesis ol {
    margin: 0.5rem 0 0.5rem 1.6rem;
}

.feed-item--digest .card-synthesis li {
    margin-bottom: 0.35rem;
}

.feed-item--digest .card-synthesis a {
    color: var(--accent);
    text-decoration: none;
}

.feed-item--digest .card-synthesis a:hover {
    text-decoration: underline;
}

.card-error {
    color: var(--red);
    font-size: 0.85rem;
}

.empty {
    color: var(--text-dim);
    font-style: italic;
    padding: 0.5rem 0;
}

/* Twitter extras */
.tweet-quoted {
    border-left: 2px solid var(--rule);
    padding-left: 0.8rem;
    margin-top: 0.4rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-style: italic;
}

.tweet-stats {
    font-size: 0.72rem;
    color: var(--text-dim);
    margin-top: 0.3rem;
}

.tweet-stats span {
    margin-right: 1rem;
}

.cost-tag {
    color: var(--green);
}

/* ── Scan progress ───────────────────────────────────────────────── */

#scan-progress {
    margin-top: 0.5rem;
}

.scan-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--rule);
}

.scan-title {
    font-family: var(--display);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
}

.scan-cost {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.scan-cost .cost-amount {
    color: var(--green);
    font-weight: 700;
}

.scan-cost .cost-saved {
    color: var(--text-dim);
    margin-left: 0.4rem;
}

/* Phase cards */
.scan-phase {
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--rule-light);
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    transition: opacity 0.3s;
}

.scan-phase .phase-icon {
    margin-top: 0.15rem;
}

.scan-phase:last-child {
    border-bottom: none;
}

.scan-phase.active {
    /* no special bg needed */
}

.scan-phase.done .phase-icon {
    color: var(--green);
}

.phase-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    font-size: 0.85rem;
}

.phase-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--rule);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.phase-body {
    flex: 1;
    min-width: 0;
}

.phase-label {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
}

.phase-detail {
    font-size: 0.72rem;
    color: var(--text-dim);
    margin-top: 0.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.scan-phase.waiting .phase-label {
    color: var(--text-dim);
}

.scan-complete {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding: 0.5rem 0;
    font-size: 0.85rem;
    color: var(--green);
    border-top: 1px solid var(--rule);
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.scan-complete .complete-icon {
    font-size: 1rem;
}

.cache-saved-tag {
    color: var(--text-dim);
}

/* Streaming digest teletype — sits to the right of phase-body */
.digest-stream {
    flex: 1;
    min-width: 0;
    max-height: 4.5rem;
    overflow-y: auto;
    scrollbar-width: none;
    font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
    font-size: 0.6rem;
    line-height: 1.45;
    color: var(--text-dim);
    white-space: pre-wrap;
    word-break: break-word;
}

.digest-stream::-webkit-scrollbar {
    display: none;
}

/* When streaming, keep phase-body from growing */
.scan-phase:has(.digest-stream) .phase-body {
    flex: 0 0 auto;
}

@keyframes scan-spin {
    to { transform: rotate(360deg); }
}

/* ── Settings overlay & panel ─────────────────────────────────────── */

.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    z-index: 100;
    display: flex;
    justify-content: flex-end;
}

.settings-overlay.hidden {
    display: none;
}

.settings-panel {
    width: 420px;
    max-width: 90vw;
    height: 100%;
    background: var(--bg);
    border-left: 2px solid var(--text);
    display: flex;
    flex-direction: column;
    animation: slideIn 0.2s ease-out forwards;
}

@keyframes slideIn {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.settings-overlay.closing .settings-panel {
    animation: slideOut 0.2s ease-in forwards;
}

@keyframes slideOut {
    from { transform: translateX(0); }
    to { transform: translateX(100%); }
}

.settings-loading {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    font-style: italic;
    font-size: 0.9rem;
}

.settings-body {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
}

.settings-section {
    margin-bottom: 1.8rem;
}

.settings-section h3 {
    font-family: var(--display);
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 0.6rem;
    border-bottom: 1px solid var(--rule);
    padding-bottom: 0.3rem;
}

/* Prompt textarea */
.prompt-input {
    width: 100%;
    height: 10rem;
    background: #fff;
    border: 1px solid var(--rule);
    color: var(--text);
    padding: 0.5rem 0.6rem;
    font-family: var(--serif);
    font-size: 0.85rem;
    line-height: 1.6;
    resize: none;
    overflow-y: auto;
    outline: none;
}

.prompt-input:focus {
    border-color: var(--text-secondary);
}

.settings-search {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.settings-search input {
    flex: 1;
    background: #fff;
    border: 1px solid var(--rule);
    color: var(--text);
    padding: 0.4rem 0.6rem;
    font-family: var(--serif);
    font-size: 0.85rem;
    outline: none;
}

.settings-search input:focus {
    border-color: var(--text-secondary);
}

.settings-search button {
    background: var(--text);
    color: var(--bg);
    border: none;
    padding: 0.4rem 0.8rem;
    cursor: pointer;
    font-family: var(--serif);
    font-size: 0.8rem;
    letter-spacing: 0.03em;
}

.settings-search button:hover {
    background: var(--text-secondary);
}

.settings-search button:disabled {
    background: var(--rule);
    color: var(--text-dim);
    cursor: not-allowed;
}

/* Search results dropdown */
.search-results {
    background: #fff;
    border: 1px solid var(--rule);
    max-height: 200px;
    overflow-y: auto;
    display: none;
    margin-bottom: 0.5rem;
}

.search-results.active {
    display: block;
}

.search-result-item {
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--rule-light);
    color: var(--text);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: var(--bg-subtle);
}

.search-result-item small {
    color: var(--text-dim);
}

.search-result-item.no-results {
    color: var(--text-dim);
    cursor: default;
    font-style: italic;
}

.search-result-item--add {
    color: var(--text-secondary);
    font-style: italic;
}

/* Source list items */
.source-list {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.source-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
    border: 1px solid var(--rule-light);
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
    transition: background 0.3s;
}

.source-item.flash {
    background: var(--bg-subtle);
}

.source-item .item-info {
    flex: 1;
    min-width: 0;
}

.source-item .item-name {
    color: var(--text);
}

.source-item .item-slug {
    color: var(--text-dim);
    font-size: 0.75rem;
    margin-left: 0.3rem;
}

.yt-badge {
    color: #c00;
    font-weight: 600;
}

.source-item .remove-btn {
    background: none;
    border: none;
    color: var(--red);
    cursor: pointer;
    font-size: 1rem;
    padding: 0 0.3rem;
    flex-shrink: 0;
}

.source-item .remove-btn:hover {
    color: #c53030;
}

/* Toggle row */
.toggle-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text);
    cursor: pointer;
}

/* Twitter items */
.twitter-item-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
}

.twitter-item-row .item-handle {
    color: var(--accent);
    font-weight: 700;
    min-width: 0;
}

.twitter-item-row .following-toggle {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-left: auto;
    flex-shrink: 0;
}

.dupe-status {
    font-size: 0.8rem;
    color: var(--red);
    padding: 0.2rem 0;
}

/* Validation status */
.validation-status {
    font-size: 0.8rem;
    padding: 0.2rem 0;
    min-height: 1.2rem;
}

.validation-status.success {
    color: var(--green);
}

.validation-status.error {
    color: var(--red);
}

.validation-status.loading {
    color: var(--text-dim);
    font-style: italic;
}
