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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.6;
    color: #111827;
    background: #f8f9fa;
}

nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    position: sticky;
    top: 0;
    z-index: 10;
}

.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: #111827;
    text-decoration: none;
}

.nav-links { display: flex; gap: 1rem; }
.nav-links a { color: #6b7280; text-decoration: none; }
.nav-links a:hover { color: #4f46e5; }

.nav-refresh { margin-left: auto; position: relative; }
.refresh-spinner { display: none; }
.nav-refresh.htmx-request .refresh-label { display: none; }
.nav-refresh.htmx-request .refresh-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #e5e7eb;
    border-top-color: #4f46e5;
    border-radius: 50%;
    animation: insights-spin 0.6s linear infinite;
    vertical-align: middle;
}
.nav-refresh[disabled] { opacity: 0.5; cursor: not-allowed; }

.refresh-result {
    font-size: 0.8rem;
    color: #16a34a;
    animation: refresh-fade 0.5s 3s forwards;
}
@keyframes refresh-fade { to { opacity: 0; } }

.nav-search { }
.nav-search input {
    padding: 0.4rem 0.75rem;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    font-size: 0.9rem;
    width: 200px;
}

main {
    max-width: 1200px;
    margin: 1.5rem auto;
    padding: 0 1rem;
}

/* Item cards */
.item-list { display: flex; flex-direction: column; gap: 0.75rem; }

.item-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    transition: opacity 0.2s, box-shadow 0.2s;
}

.item-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.item-card.read { opacity: 0.6; }
.item-card.starred { border-left: 3px solid #f59e0b; }
.item-card.focused { outline: 2px solid #4f46e5; outline-offset: -2px; }

.item-thumb {
    width: 160px;
    min-height: 100px;
    position: relative;
    flex-shrink: 0;
    background: #e5e7eb;
}

.item-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.15s;
}
.item-thumb img.loaded { opacity: 1; }

.badge-video {
    position: absolute;
    bottom: 4px;
    left: 4px;
    background: rgba(0,0,0,0.7);
    color: #fff;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 3px;
}

.item-body { padding: 0.75rem 1rem; flex: 1; min-width: 0; }

.item-meta {
    display: flex;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: #6b7280;
    margin-bottom: 0.25rem;
}

.item-source {
    background: #eef2ff;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 600;
}
.item-source.source-reddit { background: #ff44001a; color: #ff4500; }
.item-source.source-youtube { background: #ff00001a; color: #ff0000; }
.item-source.source-arxiv { background: #b31b1b1a; color: #b31b1b; }

a.item-source {
    text-decoration: none;
    cursor: pointer;
    transition: filter 0.15s;
}
a.item-source:hover {
    filter: brightness(0.85);
    text-decoration: underline;
}

.badge-paper {
    position: absolute;
    bottom: 4px;
    left: 4px;
    background: rgba(179,27,27,0.8);
    color: #fff;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 3px;
}

.item-badge-only {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    flex-shrink: 0;
}
.item-badge-only .badge-video,
.item-badge-only .badge-paper {
    position: static;
}

.item-meta time { margin-left: auto; }

.item-body h3 { font-size: 1.05rem; font-weight: 600; margin-bottom: 0.25rem; }
.item-card.read .item-body h3 { font-weight: 600; }
.item-body h3 a { color: #111827; text-decoration: none; }
.item-body h3 a:hover { color: #4f46e5; text-decoration: underline; }

.item-excerpt {
    font-size: 0.85rem;
    color: #6b7280;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.item-actions { margin-top: 0.5rem; display: flex; align-items: center; gap: 0.5rem; }

.item-reading-time {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-right: auto;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: #4f46e5;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: none;
}
.btn:hover { background: #4338ca; }

.btn-sm {
    padding: 0.25rem 0.6rem;
    font-size: 0.8rem;
    background: #f8f9fa;
    color: #6b7280;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    cursor: pointer;
}
.btn-sm:hover { background: #e5e7eb; }
.btn-sm.active { background: #fef3c7; border-color: #f59e0b; color: #92400e; }

/* Sources */
.add-source-form { margin-bottom: 1.5rem; }

.form-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.form-row input, .form-row select {
    padding: 0.5rem;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    font-size: 0.9rem;
}

.form-row input[name="name"] { flex: 1; min-width: 120px; }
.form-row input[name="url"] { flex: 2; min-width: 200px; }
.form-row input[name="interval"] { width: 100px; }

.source-list { display: flex; flex-direction: column; gap: 0.5rem; }

.source-card {
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 0.75rem 1rem;
}

.source-card-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.source-desc {
    font-size: 0.8rem;
    color: #9ca3af;
    margin-top: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.source-card.disabled { opacity: 0.5; }
.source-card.htmx-swapping { opacity: 0; transition: opacity 200ms; }

.source-info { display: flex; align-items: center; gap: 0.5rem; flex: 1; min-width: 0; }

.source-type {
    background: #eef2ff;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.source-interval { font-size: 0.8rem; color: #6b7280; }

.source-actions { display: flex; gap: 0.5rem; margin-left: 0.5rem; flex-shrink: 0; }

.btn-danger { color: #dc2626; border-color: #fca5a5; }
.btn-danger:hover { background: #fef2f2; }
.source-status .error { color: #dc2626; font-size: 0.85rem; }
.source-status .success { color: #16a34a; font-size: 0.85rem; }
.source-status .pending { color: #6b7280; font-size: 0.85rem; }

/* Empty state */
/* Source filter header */
.source-filter-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.source-filter-header a {
    color: #6b7280;
    text-decoration: none;
    font-size: 0.9rem;
}
.source-filter-header a:hover { color: #4f46e5; }
.source-filter-header h2 { font-size: 1.2rem; }
.source-filter-desc { font-size: 0.85rem; color: #9ca3af; margin-bottom: 0.75rem; }

.import-btn {
    cursor: pointer;
    display: inline-block;
}
.source-filter-header .btn-sm {
    font-size: 0.8rem;
    padding: 0.25rem 0.6rem;
    text-decoration: none;
}
.import-result {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

/* Source name link on sources page */
.source-name-link {
    color: inherit;
    text-decoration: none;
}
.source-name-link:hover {
    color: #4f46e5;
    text-decoration: underline;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #6b7280;
}

.pagination { text-align: center; margin-top: 1.5rem; }

/* Insights layout */
.inbox-layout {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
}

.inbox-layout .inbox { flex: 1; min-width: 0; max-width: 800px; }

.insights-panel {
    width: 380px;
    flex-shrink: 0;
    position: sticky;
    top: 4rem;
    max-height: calc(100vh - 5rem);
    overflow-y: auto;
}

.insights-panel:empty { display: none; }

.insights-content {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 1rem;
}

.insights-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.insights-header h3 { font-size: 1rem; font-weight: 600; }

.insights-section { margin-bottom: 0.75rem; }
.insights-section h4 { font-size: 0.85rem; font-weight: 600; color: #6b7280; margin-bottom: 0.25rem; }
.insights-section p { font-size: 0.9rem; line-height: 1.5; color: #111827; }
.insights-section ul { padding-left: 1.25rem; font-size: 0.9rem; line-height: 1.5; color: #111827; }
.insights-section li { margin-bottom: 0.25rem; }

.insights-footer {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid #e5e7eb;
}

.insights-error p { color: #dc2626; font-size: 0.9rem; }

.model-badge { font-size: 0.75rem; color: #6b7280; font-weight: 500; }

.btn-insights {
    background: #eef2ff;
    color: #4f46e5;
    border-color: #c7d2fe;
}
.btn-insights:hover { background: #e0e7ff; }

/* Source suggestions */
.suggestions-content {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 1rem;
}

.suggestion-card {
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}

.suggestion-card.added {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f0fdf4;
    border-color: #bbf7d0;
    animation: refresh-fade 0.5s 3s forwards;
}

.suggestion-card.duplicate {
    opacity: 0.6;
}

.suggestion-duplicate-badge {
    font-size: 0.7rem;
    color: #6b7280;
    background: #f3f4f6;
    padding: 1px 6px;
    border-radius: 3px;
    margin-left: auto;
}

.suggestion-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.suggestion-desc {
    font-size: 0.85rem;
    color: #6b7280;
    line-height: 1.4;
    margin-bottom: 0.25rem;
}

.suggestion-url {
    font-size: 0.75rem;
    color: #9ca3af;
    word-break: break-all;
    margin-bottom: 0.5rem;
}

.suggestion-card form { display: inline; }

.suggestion-added-badge {
    font-size: 0.8rem;
    color: #16a34a;
    font-weight: 600;
}

.suggestions-error { color: #dc2626; font-size: 0.9rem; }

/* Refine suggestions */
.refine-form {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid #e5e7eb;
}
.refine-form input[type="text"] {
    flex: 1;
    padding: 0.35rem 0.6rem;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    font-size: 0.85rem;
    min-width: 0;
}
.refine-form input[type="text"]:focus { outline: 2px solid #4f46e5; outline-offset: -1px; }
.refine-form button[disabled] { opacity: 0.5; cursor: not-allowed; }
.refine-context {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: #eef2ff;
    border-radius: 6px;
    padding: 0.3rem 0.6rem;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    color: #4f46e5;
}
.refine-context span { flex: 1; }
.refine-context .btn-sm { padding: 0 0.4rem; font-size: 0.75rem; border: none; background: transparent; color: #6b7280; }

/* Suggestion probe error state */
.suggestion-probe-error {
    border-color: #fca5a5;
    background: #fef2f2;
}

.probe-url-row {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.probe-url-input {
    flex: 1;
    padding: 0.35rem 0.6rem;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    font-size: 0.8rem;
    min-width: 0;
}

.probe-url-input:focus {
    outline: 2px solid #4f46e5;
    outline-offset: -1px;
}

/* Suggestion homepage link */
.suggestion-homepage {
    display: block;
    font-size: 0.75rem;
    color: #6b7280;
    text-decoration: none;
    margin-bottom: 0.25rem;
    word-break: break-all;
}

.suggestion-homepage:hover {
    color: #4f46e5;
    text-decoration: underline;
}

/* Suggestion low confidence indicator */
.suggestion-low-confidence {
    font-size: 0.7rem;
    color: #d97706;
    background: #fef3c7;
    padding: 1px 6px;
    border-radius: 3px;
    margin-left: auto;
}

/* Follow-up conversation */
.followup-thread { margin-top: 0.75rem; }
.followup-entry { margin-bottom: 0.75rem; }
.followup-question {
    font-size: 0.85rem;
    font-weight: 600;
    color: #4f46e5;
    margin-bottom: 0.25rem;
    padding: 0.4rem 0.6rem;
    background: #eef2ff;
    border-radius: 6px;
}
.followup-answer {
    font-size: 0.9rem;
    line-height: 1.5;
    color: #111827;
    padding: 0.4rem 0.6rem;
}
.followup-error {
    font-size: 0.85rem;
    color: #dc2626;
    padding: 0.4rem 0.6rem;
}
.followup-form {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid #e5e7eb;
}
.followup-form input {
    flex: 1;
    padding: 0.35rem 0.6rem;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    font-size: 0.85rem;
    min-width: 0;
}
.followup-form input:focus { outline: 2px solid #4f46e5; outline-offset: -1px; }
.followup-form button[disabled] { opacity: 0.5; cursor: not-allowed; }
.followup-form.htmx-request button::after {
    content: "";
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-left: 4px;
    border: 2px solid #c7d2fe;
    border-top-color: #4f46e5;
    border-radius: 50%;
    animation: insights-spin 0.6s linear infinite;
    vertical-align: middle;
}

/* Insights loading spinner */
.insights-panel.htmx-request { display: block !important; }
.insights-panel.htmx-request::after {
    content: "";
    display: block;
    width: 28px;
    height: 28px;
    margin: 2rem auto;
    border: 3px solid #e5e7eb;
    border-top-color: #4f46e5;
    border-radius: 50%;
    animation: insights-spin 0.6s linear infinite;
}
@keyframes insights-spin { to { transform: rotate(360deg); } }

/* Comparison container */
.insights-comparison {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.insights-comparison > .insights-header {
    flex-basis: 100%;
}
.insights-sub-panel { flex: 1; min-width: 0; }

/* Provider border colors */
.insights-sub-panel.provider-0 .insights-content { border-left: 3px solid #4f46e5; }
.insights-sub-panel.provider-1 .insights-content { border-left: 3px solid #059669; }

/* Wider panel for comparison */
.insights-panel.comparison-active { width: 700px; }

/* Sub-panel loading spinner */
.insights-sub-panel.htmx-request::after {
    content: "";
    display: block;
    width: 24px; height: 24px;
    margin: 2rem auto;
    border: 3px solid #e5e7eb;
    border-top-color: #4f46e5;
    border-radius: 50%;
    animation: insights-spin 0.6s linear infinite;
}

/* Responsive */
@media (max-width: 900px) {
    .insights-panel { width: 300px; }
    .insights-panel.comparison-active { width: 300px; }
    .insights-comparison { flex-direction: column; }
}

@media (max-width: 600px) {
    .inbox-layout { flex-direction: column; }
    .insights-panel { width: 100%; position: static; max-height: none; }
    .insights-panel.comparison-active { width: 100%; }
}

/* Login page */
.login-container {
    max-width: 360px;
    margin: 4rem auto;
    padding: 2rem;
    background: #fff;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    text-align: center;
}

.login-container h1 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    color: #111827;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.login-form input {
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95rem;
}

.login-error {
    background: #fef2f2;
    color: #991b1b;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.875rem;
    border: 1px solid #fecaca;
}

/* Nav user section */
.nav-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

.nav-username {
    font-size: 0.875rem;
    color: #6b7280;
}

/* Admin page */
.btn-danger {
    color: #dc2626;
    border-color: #fecaca;
}

.btn-danger:hover {
    background: #fef2f2;
}

.source-card.disabled {
    opacity: 0.6;
}

@media (max-width: 600px) {
    .item-card { flex-direction: column; }
    .item-thumb { width: 100%; height: 180px; }
    .form-row { flex-direction: column; }
    .form-row input, .form-row select { width: 100%; }
    .nav-user { margin-left: 0; }

    /* Nav bar — wrap onto multiple rows */
    nav { flex-wrap: wrap; padding: 0.5rem 0.75rem; gap: 0.5rem; }
    .nav-brand { font-size: 1rem; }
    .nav-links { gap: 0.5rem; font-size: 0.85rem; }
    .nav-search { order: 10; width: 100%; }
    .nav-search input { width: 100%; }

    /* Item card action buttons — wrap */
    .item-actions { flex-wrap: wrap; }

    /* Source card — stack vertically */
    .source-card-main { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
    .source-actions { margin-left: 0; }

    /* Source filter header — wrap */
    .source-filter-header { flex-wrap: wrap; }

    /* Form row min-widths — clear them */
    .form-row input[name="name"] { min-width: 0; }
    .form-row input[name="url"] { min-width: 0; }
    .form-row input[name="interval"] { width: 100%; }

    /* Login page — reduce top margin */
    .login-container { margin: 2rem auto; }

    /* Main content — tighter padding */
    main { margin: 1rem auto; padding: 0 0.5rem; }
}
