:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --text: #1a1d21;
    --text-muted: #6b7280;
    --border: #e3e6ea;
    --primary: #2f6fed;
    --primary-hover: #2159c9;
    --danger: #d64545;
    --success-bg: #e7f6ec;
    --success-text: #1a7a3e;
    --error-bg: #fdeaea;
    --error-text: #b42318;
    --info-bg: #eaf1fd;
    --info-text: #1a4fb0;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14171a;
        --surface: #1c2024;
        --surface-2: #23282d;
        --text: #e8eaed;
        --text-muted: #9aa2ab;
        --border: #2c3237;
        --primary: #4d86f7;
        --primary-hover: #6699ff;
        --danger: #e06666;
        --success-bg: #16301f;
        --success-text: #7ee0a0;
        --error-bg: #3a1d1c;
        --error-text: #f0a0a0;
        --info-bg: #17233b;
        --info-text: #9bc0ff;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

.wrap {
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
}
.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 650;
    font-size: 1.05rem;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
}
.brand-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #7aa5ff);
}
.site-nav {
    display: flex;
    align-items: center;
    gap: 18px;
}
.site-nav a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.95rem;
}
.site-nav a:hover { color: var(--text); }

/* Layout blocks */
main.wrap { padding-top: 28px; padding-bottom: 48px; }

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px 24px;
    margin-bottom: 22px;
}
.panel h1 { font-size: 1.3rem; margin: 0 0 6px; }
.panel h2 { font-size: 1.1rem; margin: 0; }
.panel-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}
.count {
    background: var(--surface-2);
    color: var(--text-muted);
    border-radius: 20px;
    padding: 1px 10px;
    font-size: 0.82rem;
    font-weight: 600;
}

.muted { color: var(--text-muted); }
.empty { color: var(--text-muted); padding: 12px 0; }

/* Forms */
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack label { display: flex; flex-direction: column; gap: 5px; font-size: 0.9rem; font-weight: 550; }

input[type="text"], input[type="password"], select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.98rem;
}
textarea { font-family: inherit; line-height: 1.5; resize: vertical; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.15);
}
.button-row { display: flex; gap: 10px; }
.term-cloud { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

.row-form { display: flex; gap: 10px; margin-top: 10px; }
.row-form input { flex: 1; }

.btn {
    display: inline-block;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 0.92rem;
    font-weight: 550;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.12s, border-color 0.12s;
}
.btn:hover { border-color: var(--text-muted); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-small { padding: 6px 11px; font-size: 0.85rem; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); background: var(--error-bg); }

.inline-form { display: inline; margin: 0; }
.link-button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.95rem;
    padding: 0;
    font-family: inherit;
}
.link-button:hover { color: var(--text); }

/* Alerts */
.alert {
    padding: 11px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.92rem;
}
.alert code { background: rgba(0,0,0,0.06); padding: 1px 5px; border-radius: 4px; }
.alert-success { background: var(--success-bg); color: var(--success-text); }
.alert-error { background: var(--error-bg); color: var(--error-text); }
.alert-info { background: var(--info-bg); color: var(--info-text); }

/* Source list */
.source-list, .feed-list { list-style: none; margin: 0; padding: 0; }
.source-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 0;
    border-top: 1px solid var(--border);
}
.source-item:first-child { border-top: none; }
.source-main { min-width: 0; }
.source-title {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-weight: 600;
}
.source-title a { color: var(--text); text-decoration: none; }
.source-title a:hover { color: var(--primary); }
.source-meta { font-size: 0.85rem; margin-top: 3px; word-break: break-word; }
.source-actions { display: flex; gap: 8px; flex-shrink: 0; }

.badge {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.badge-feed { background: var(--info-bg); color: var(--info-text); }
.badge-watch { background: var(--surface-2); color: var(--text-muted); }
.badge-error { background: var(--error-bg); color: var(--error-text); }

/* Feed selection */
.feed-item { padding: 4px 0; border-top: 1px solid var(--border); }
.feed-item:first-child { border-top: none; }
.feed-check {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    padding: 10px 0;
    cursor: pointer;
    font-weight: normal;
}
.feed-check input { margin-top: 4px; width: 17px; height: 17px; flex-shrink: 0; }
.feed-info { display: flex; flex-direction: column; min-width: 0; }
.feed-title { font-weight: 600; }
.feed-url { font-size: 0.82rem; word-break: break-all; }

.back-link { color: var(--text-muted); text-decoration: none; font-size: 0.9rem; }
.back-link:hover { color: var(--text); }

.panel-head.between { justify-content: space-between; align-items: flex-start; }
.run-info { font-size: 0.85rem; margin: 4px 0 0; }
.run-info a { color: var(--primary); text-decoration: none; }
.text-error { color: var(--error-text); }
.toolbar { display: flex; gap: 8px; flex-shrink: 0; }

/* Archive */
.archive-list { list-style: none; margin: 0; padding: 0; }
.archive-item {
    display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
    padding: 12px 0; border-top: 1px solid var(--border);
}
.archive-item:first-child { border-top: none; }
.archive-date { color: var(--text); font-weight: 600; text-decoration: none; }
.archive-date:hover { color: var(--primary); }
.archive-meta { font-size: 0.85rem; }

/* Status */
.status-grid { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 24px; }
.status-grid li { display: flex; flex-direction: column; gap: 6px; }
.status-label { font-size: 0.85rem; color: var(--text-muted); }
.code-block {
    background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
    padding: 12px 14px; font-size: 0.85rem; overflow-x: auto; margin: 6px 0 14px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.table-scroll { overflow-x: auto; }
.runs-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.runs-table th { text-align: left; color: var(--text-muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.runs-table td { padding: 8px; border-bottom: 1px solid var(--border); }
.runs-table tr:last-child td { border-bottom: none; }

/* Briefing */
.briefing { border-left: 3px solid var(--primary); }
.briefing-body h3 { font-size: 1.1rem; margin: 16px 0 6px; }
.briefing-body h4 { font-size: 0.98rem; margin: 14px 0 4px; }
.briefing-body p { margin: 0 0 10px; }
.briefing-body ul { margin: 8px 0 12px; padding-left: 20px; }
.briefing-body li { margin: 3px 0; }
.briefing-body > :first-child { margin-top: 0; }
.briefing-body > :last-child { margin-bottom: 0; }

/* Digest articles */
.article-list { list-style: none; margin: 0; padding: 0; }
.article {
    display: flex;
    gap: 16px;
    padding: 18px 0;
    border-top: 1px solid var(--border);
}
.article:first-child { border-top: none; }
.article-thumb {
    flex-shrink: 0;
    width: 120px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface-2);
}
.article-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.article.no-img .article-thumb { display: none; }
.article-body { min-width: 0; flex: 1; }
.article-source {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}
.article-title { font-size: 1.05rem; margin: 3px 0 6px; line-height: 1.35; }
.article-title a { color: var(--text); text-decoration: none; }
.article-title a:hover { color: var(--primary); }
.article-excerpt { margin: 0 0 6px; font-size: 0.92rem; color: var(--text); }
.article-meta { font-size: 0.8rem; }

/* Changed pages */
.change-list { list-style: none; margin: 0; padding: 0; }
.change-item { padding: 9px 0; border-top: 1px solid var(--border); }
.change-item:first-child { border-top: none; }
.change-item a { color: var(--text); font-weight: 600; text-decoration: none; }
.change-item a:hover { color: var(--primary); }

@media (max-width: 560px) {
    .article-thumb { width: 88px; height: 66px; }
}

/* Auth card */
.auth-card {
    max-width: 380px;
    margin: 40px auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 30px 28px;
}
.auth-card h1 { font-size: 1.35rem; margin: 0 0 18px; }

/* Footer */
.site-footer {
    border-top: 1px solid var(--border);
    padding: 20px 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

@media (max-width: 640px) {
    .header-inner { height: auto; flex-wrap: wrap; gap: 4px 14px; padding: 10px 0; }
    .site-nav { gap: 14px; flex-wrap: wrap; }
    .site-header { position: static; }
    .panel-head.between { flex-direction: column; gap: 12px; }
    .toolbar { width: 100%; }
    .toolbar .inline-form { flex: 1; }
    .toolbar .btn { width: 100%; }
}

@media (max-width: 560px) {
    .row-form { flex-direction: column; }
    .source-item { flex-direction: column; align-items: stretch; }
    .source-actions { justify-content: flex-end; }
}
