:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --border: #e3e6eb;
    --text: #1a2230;
    --text-muted: #667085;
    --primary: #2563eb;
    --primary-ink: #ffffff;
    --accent: #0ea5e9;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
    --maxw: 1080px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f172a;
        --surface: #182234;
        --surface-2: #1f2b40;
        --border: #2a3852;
        --text: #e6ebf3;
        --text-muted: #94a3b8;
        --primary: #3b82f6;
        --shadow: 0 1px 3px rgba(0, 0, 0, .3);
    }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    font-size: 15px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }

/* ---------- Header ---------- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: color-mix(in srgb, var(--surface) 85%, transparent);
    backdrop-filter: saturate(180%) blur(10px);
    border-bottom: 1px solid var(--border);
}
.header-inner {
    display: flex;
    align-items: center;
    gap: 16px;
    height: 60px;
}
.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 800;
    font-size: 18px;
    color: var(--text);
    white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    font-size: 18px;
}
.search { flex: 1; max-width: 420px; margin-left: auto; }
.search input {
    width: 100%;
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 14px;
}
.search input:focus { outline: 2px solid var(--primary); outline-offset: 0; }
.site-nav { display: flex; align-items: center; gap: 16px; }
.site-nav a { color: var(--text-muted); font-weight: 600; font-size: 14px; }
.site-nav a:hover { color: var(--text); text-decoration: none; }
.site-nav .rss {
    padding: 4px 9px; border: 1px solid var(--border); border-radius: 6px;
    font-size: 12px; letter-spacing: .04em;
}
.lang-switch {
    display: inline-flex; align-items: center;
    border: 1px solid var(--border); border-radius: 6px; overflow: hidden;
}
.lang-switch a {
    padding: 4px 9px; font-size: 12px; font-weight: 700; color: var(--text-muted);
}
.lang-switch a:hover { background: var(--surface-2); text-decoration: none; }
.lang-switch a.active { background: var(--primary); color: var(--primary-ink); }

/* ---------- Hero ---------- */
.hero {
    padding: 40px 0 8px;
}
.hero h1 { font-size: clamp(26px, 4vw, 38px); line-height: 1.25; margin: 0 0 12px; letter-spacing: -.01em; }
.hero h1 strong { color: var(--primary); }
.hero p { color: var(--text-muted); max-width: 640px; margin: 0 0 18px; font-size: 16px; }
.hero-stats { display: flex; flex-wrap: wrap; gap: 20px; color: var(--text-muted); font-size: 14px; }
.hero-stats strong { color: var(--text); font-size: 17px; }

/* Daily-updates bar chart under the hero stats. */
.hero-chart { margin: 20px 0 0; width: 100%; }
.hero-chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.hero-chart-head .muted { font-weight: 400; font-size: 12px; color: var(--text-muted); }
.hero-chart-bars { display: flex; align-items: flex-end; gap: 2px; height: 64px; padding-bottom: 1px; border-bottom: 1px solid var(--border); }
.hero-chart-bar { flex: 1 1 0; min-width: 2px; height: var(--h); border-radius: 2px 2px 0 0;
    background: linear-gradient(180deg, var(--accent), var(--primary)); opacity: .8; transition: opacity .12s; }
.hero-chart-bar:hover { opacity: 1; }
.hero-chart-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); margin-top: 5px; }
.hero-chart-note { margin: 8px 0 0; font-size: 11px; color: var(--text-muted); line-height: 1.6; }

/* ---------- Layout ---------- */
.layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 28px;
    padding: 28px 0 60px;
    align-items: start;
}
.sidebar { }
.filter-block h3 {
    font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--text-muted); margin: 0 0 8px;
}
.filter-list { list-style: none; margin: 0 0 24px; padding: 0; }
.filter-list a {
    display: flex; justify-content: space-between; align-items: center;
    padding: 7px 10px; border-radius: 8px; color: var(--text); font-size: 14px; font-weight: 500;
}
.filter-list a:hover { background: var(--surface-2); text-decoration: none; }
.filter-list a.active { background: var(--primary); color: var(--primary-ink); }
.filter-list a.active .count { color: var(--primary-ink); }
.filter-list .count { color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.filter-source { display: flex; align-items: center; gap: 8px; min-width: 0; }
.filter-source .filter-dot {
    flex: none; width: 9px; height: 9px; border-radius: 3px;
    background: var(--chip, var(--primary));
}
.filter-list a.active .filter-dot { box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-ink) 60%, transparent); }

/* Collapsible source tree (category -> services) */
.source-tree { margin-bottom: 24px; }
.tree-cat { border-bottom: 1px solid var(--border); }
.tree-cat > summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    padding: 8px 10px 8px 26px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    user-select: none;
}
.tree-cat > summary::-webkit-details-marker { display: none; }
.tree-cat > summary::before {
    content: "";
    position: absolute;
    left: 10px;
    width: 0;
    height: 0;
    border-left: 5px solid var(--text-muted);
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    transition: transform .15s ease;
}
.tree-cat[open] > summary::before { transform: rotate(90deg); }
.tree-cat > summary:hover { background: var(--surface-2); }
.tree-cat-name { flex: 1; min-width: 0; }
.tree-cat > summary .count { color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.tree-sources { list-style: none; margin: 2px 0 8px; padding: 0 0 0 26px; }
.tree-sources a {
    display: flex;
    padding: 5px 10px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}
.tree-sources a:hover { background: var(--surface-2); text-decoration: none; }
.tree-sources a.active { background: var(--primary); color: var(--primary-ink); }

/* Multi-select sources */
.tree-src { display: flex; align-items: center; gap: 4px; }
.tree-src a { flex: 1 1 auto; min-width: 0; }
.src-check { flex: none; width: 15px; height: 15px; margin: 0 0 0 2px; accent-color: var(--primary); cursor: pointer; }
.src-apply { display: flex; align-items: center; gap: 10px; margin: 10px 2px 0; }
.src-apply-btn {
    flex: 1; padding: 8px 12px; border: 0; border-radius: 8px; cursor: pointer;
    background: var(--primary); color: var(--primary-ink); font-weight: 700; font-size: 13px;
}
.src-apply-btn:hover { filter: brightness(1.06); }
.src-clear-wrap { margin: 10px 2px 0; }
.src-clear { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.src-clear:hover { color: var(--primary); }
.tree-filter { width: 100%; box-sizing: border-box; padding: 6px 10px; margin: 0 0 8px;
    border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); font-size: 13px; }
.tree-filter:focus { outline: 2px solid var(--primary); outline-offset: 0; }
.tree-nomatch { font-size: 12px; color: var(--text-muted); padding: 4px 2px; margin: 4px 0 0; }

/* Selected-source chips above the timeline */
.selected-tags { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 14px; }
.selected-tags .tag {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 4px 4px 10px; border: 1px solid var(--border); border-radius: 999px;
    background: var(--surface-2); font-size: 13px; font-weight: 600; color: var(--text);
}
.selected-tags .tag-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--chip); flex: none; }
.tag-x {
    display: inline-flex; align-items: center; justify-content: center;
    width: 18px; height: 18px; border-radius: 50%; color: var(--text-muted);
    font-size: 15px; line-height: 1; text-decoration: none;
}
.tag-x:hover { background: var(--primary); color: var(--primary-ink); text-decoration: none; }
.tag-clear { font-size: 12px; color: var(--text-muted); margin-left: 2px; }
.tag-clear:hover { color: var(--primary); }

/* ---------- Feed ---------- */
.feed { min-width: 0; } /* let the grid 1fr track shrink so long summaries wrap instead of overflowing */
.feed-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 4px; }
.feed-head h2 { font-size: 20px; margin: 0; }
.feed-count { color: var(--text-muted); font-size: 13px; }
.feed-meta { display: inline-flex; align-items: center; gap: 10px; }
.feed-rss {
    padding: 2px 8px; border: 1px solid var(--border); border-radius: 6px;
    font-size: 11px; font-weight: 700; letter-spacing: .04em; color: var(--text-muted);
}
.feed-rss:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }

.item-list { display: flex; flex-direction: column; }
.item {
    display: flex;
    gap: 14px;
    padding: 18px 0;
    border-bottom: 1px solid var(--border);
}
.item-avatar {
    flex: none;
    width: 40px; height: 40px;
    border-radius: 10px;
    display: grid; place-items: center;
    background: var(--chip, var(--primary));
    color: #fff; font-weight: 700; font-size: 18px;
}
.item-avatar.large { width: 56px; height: 56px; font-size: 24px; border-radius: 14px; }
.item-body { min-width: 0; flex: 1; }
.item-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 3px; }
.item-source { font-weight: 700; color: var(--text); }
.item-cat {
    color: var(--text-muted); background: var(--surface-2);
    padding: 1px 8px; border-radius: 999px; font-size: 12px;
}
.item-version {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    background: color-mix(in srgb, var(--accent) 16%, transparent);
    color: var(--accent); padding: 1px 7px; border-radius: 6px; font-size: 12px; font-weight: 600;
}
.item-time { color: var(--text-muted); margin-left: auto; }
.item-title { font-size: 16px; line-height: 1.45; margin: 2px 0 4px; font-weight: 600; overflow-wrap: anywhere; }
.item-title a { color: var(--text); }
.item-title a:hover { color: var(--primary); }
.item-summary { color: var(--text-muted); margin: 0; font-size: 14px; overflow-wrap: anywhere; }

.empty { padding: 60px 20px; text-align: center; color: var(--text-muted); }

/* Operational state for a Status source with no current incidents. */
.status-operational {
    display: flex; align-items: center; gap: 12px;
    padding: 20px 22px; margin: 4px 0;
    background: rgba(34, 197, 94, 0.08);
    border: 1px solid rgba(34, 197, 94, 0.35);
    border-radius: 12px;
}
.status-operational-dot {
    flex: none; width: 12px; height: 12px; border-radius: 50%;
    background: #22c55e; box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.18);
}
.status-operational-body { display: flex; flex-direction: column; gap: 2px; }
.status-operational-body strong { color: #15803d; }

/* ---------- Pagination ---------- */
.pagination { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 28px; justify-content: center; }
.page-link {
    min-width: 38px; text-align: center;
    padding: 7px 12px; border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); font-size: 14px; background: var(--surface);
}
.page-link:hover { background: var(--surface-2); text-decoration: none; }
.page-link.current { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.page-gap { padding: 7px 4px; color: var(--text-muted); }

/* ---------- Source page ---------- */
.source-header { display: flex; gap: 18px; align-items: center; padding: 32px 0 20px; }
.breadcrumb { font-size: 13px; color: var(--text-muted); margin-bottom: 2px; }
.source-header h1 { margin: 0 0 6px; font-size: 26px; }
.source-links { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; font-size: 14px; }
.muted { color: var(--text-muted); }

/* ---------- Sources list ---------- */
.page-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; padding: 32px 0 8px; }
.page-head h1 { margin: 0; font-size: 26px; }
.source-group { padding: 16px 0; }
.source-group-title { font-size: 16px; color: var(--text-muted); margin: 0 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.source-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.source-card {
    display: flex; gap: 12px; align-items: center;
    padding: 14px; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); color: var(--text);
}
.source-card:hover { text-decoration: none; border-color: var(--primary); transform: translateY(-1px); transition: .15s; }
.source-card { position: relative; }

/* Feed health indicator */
.feed-health { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.feed-health--ok { background: #22c55e; }
.feed-health--error { background: #ef4444; }
.feed-health--unknown { background: var(--text-muted); opacity: .35; }
.source-card > .feed-health { position: absolute; top: 10px; right: 10px; }
.health-legend { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); }
.health-legend > span { display: inline-flex; align-items: center; gap: 5px; }

/* Fetch-error alert (top of sources page) */
.alert-errors {
    margin: 24px 0 4px;
    padding: 14px 16px;
    border: 1px solid #ef4444;
    background: color-mix(in srgb, #ef4444 10%, transparent);
    border-radius: var(--radius);
}
.alert-errors-head { display: flex; align-items: center; gap: 8px; font-weight: 700; color: #ef4444; }
.alert-errors-icon { font-size: 16px; }
.alert-errors-list { list-style: none; margin: 10px 0 0; padding: 0; font-size: 13px; }
.alert-errors-list li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; padding: 3px 0; }
.alert-errors-list a { font-weight: 600; }
.alert-errors-reason { color: var(--text-muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* Source name filter */
.source-filter-bar { margin: 8px 0 16px; }
.source-filter-bar input {
    width: 100%;
    max-width: 360px;
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 14px;
}
.source-filter-bar input:focus { outline: 2px solid var(--primary); outline-offset: 0; }
.source-card-body { display: flex; flex-direction: column; min-width: 0; }
.source-card-body strong { font-size: 15px; }

/* ---------- Prose / About ---------- */
.prose { max-width: 720px; padding: 32px 0 60px; }
.prose h1 { font-size: 28px; margin: 0 0 16px; }
.prose h2 { font-size: 19px; margin: 30px 0 8px; }
.prose p { color: var(--text); }
.stat-list { padding-left: 20px; color: var(--text-muted); }
.stat-list strong { color: var(--text); }

/* ---------- Error ---------- */
.error-page { text-align: center; padding: 80px 20px; }
.error-page h1 { font-size: 72px; margin: 0; color: var(--primary); }

/* ---------- Buttons / Admin ---------- */
.btn {
    display: inline-block; padding: 9px 16px; border-radius: 8px;
    background: var(--primary); color: #fff; border: none; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn:hover { text-decoration: none; opacity: .92; }
.btn-danger { background: none; border: 1px solid #ef4444; color: #ef4444; padding: 5px 10px; border-radius: 6px; font-size: 12px; cursor: pointer; }
.btn-danger:hover { background: #ef4444; color: #fff; }
.flash { background: color-mix(in srgb, var(--accent) 14%, transparent); border: 1px solid var(--accent); padding: 10px 14px; border-radius: 8px; margin-bottom: 20px; }
.admin { padding: 24px 0 60px; }
.admin h2 { font-size: 18px; margin: 28px 0 12px; }
.admin-form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.admin-form label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.admin-form input { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th, .admin-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
.admin-table th { font-size: 12px; color: var(--text-muted); text-transform: uppercase; }
.admin-table tr.inactive { opacity: .5; }
.admin-table .status { font-size: 12px; color: var(--text-muted); max-width: 240px; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); margin-top: 20px; padding: 28px 0; color: var(--text-muted); font-size: 13px; }
.footer-inner { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.footer-inner p { margin: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
    .layout { grid-template-columns: 1fr; gap: 0; }
    .sidebar { position: static; margin-bottom: 8px; }
    .filter-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
    .filter-list a { border: 1px solid var(--border); }
    .filter-block h3 { display: none; }
    .search { order: 3; max-width: none; flex-basis: 100%; }
    .header-inner { flex-wrap: wrap; height: auto; padding: 10px 0; gap: 10px; }
    .grid2 { grid-template-columns: 1fr; }
    .item-time { margin-left: 0; }
}
