:root {
    color-scheme: light;
    --bg: #f0f4fa;
    --panel: #ffffff;
    --panel-soft: #f7faff;
    --border: #cfd9e8;
    --text: #0c1f33;
    --muted: #4f6a8a;
    --accent: #1e6fff;
    --accent-soft: rgba(30, 111, 255, 0.12);
    --header-bg: #0a1d3a;
    --header-text: #ffffff;
    --score-high-bg: #ecfdf3;
    --score-high-border: #b7ebc6;
    --score-med-bg: #fff7e6;
    --score-med-border: #f7d9a8;
    --signal-pill-bg: #f3f6fb;
    --signal-pill-text: #486581;
}

* {
    box-sizing: border-box;
}

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

/* ── Header ─────────────────────────────────────────────── */

.app-header {
    background: var(--header-bg);
    color: var(--header-text);
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.app-header-inner {
    max-width: 1120px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-logo {
    display: block;
    height: 60px;
    width: auto;
    color: var(--header-text);
}

/* ── Sticky context bar ─────────────────────────────────── */

.sticky-context-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    display: none;
}

.sticky-context-bar.visible {
    display: block;
}

.sticky-context-inner {
    max-width: 1120px;
    margin: 0 auto;
    padding: 8px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.sticky-context-view {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.sticky-context-count {
    font-size: 12px;
    color: var(--muted);
}

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

.page {
    max-width: 1120px;
    margin: 0 auto;
    padding: 24px;
}

.layout {
    display: grid;
    gap: 20px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px;
}

.panel-header-simple {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.filters-panel:not(.expanded) .panel-header-simple {
    margin-bottom: 0;
}

.panel-header-simple h2 {
    margin: 0;
    font-size: 18px;
}

.panel-subtitle {
    font-size: 13px;
    color: var(--muted);
}

/* ── Filter panel ────────────────────────────────────────── */

.filter-context-label {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.3;
}


.filter-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.filters-panel {
    padding: 18px 20px;
}

.filter-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.filter-item label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--muted);
}

.filter-select {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    font-size: 14px;
}

.filter-reset-button {
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    border-radius: 10px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    transition: border-color 120ms ease, color 120ms ease;
}

.filter-reset-button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

#filters-content {
    display: none;
}

.filters-panel.expanded #filters-content {
    display: grid;
}

.filter-chips {
    display: none;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 0;
}

.filter-chips.has-chips {
    display: flex;
    margin-bottom: 14px;
}

.filters-panel.expanded .filter-chips.has-chips {
    margin-bottom: 14px;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px 4px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--panel-soft);
    color: var(--text);
    font-size: 12px;
    line-height: 1.3;
    cursor: pointer;
    font-family: inherit;
}

.filter-chip:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.filter-chip-label {
    font-weight: 500;
}

.filter-chip-x {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 999px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
}

.filter-chip:hover {
    border-color: var(--accent);
}

.filter-chip:hover .filter-chip-x {
    background: var(--accent-soft);
    color: var(--accent);
}

select option:disabled {
    color: #b0b9c4;
}

/* ── Summary strip ───────────────────────────────────────── */

.summary-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.summary-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 16px;
    min-height: 88px;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    color: inherit;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

.summary-card:hover {
    border-color: var(--accent);
}

.summary-card:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.summary-card.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.summary-card .label {
    display: block;
    margin-bottom: 8px;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.3;
}

.summary-card .value {
    font-size: 26px;
    font-weight: bold;
    line-height: 1.1;
}

.summary-card .value-text {
    font-size: 20px;
}

/* ── Feed panel ──────────────────────────────────────────── */

.feed-panel,
.trends-panel {
    background: var(--panel);
}

.feed-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.feed-header h2 {
    margin: 0;
    font-size: 20px;
}

.feed-count {
    font-size: 13px;
    color: var(--muted);
}

.feed-list {
    display: grid;
    gap: 14px;
}

.load-more-container {
    display: flex;
    justify-content: center;
    padding: 20px 0 8px;
}

.load-more-btn {
    padding: 10px 28px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-soft);
    color: var(--muted);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.load-more-btn:hover {
    background: var(--border);
    color: var(--text);
}

.load-more-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Event cards ─────────────────────────────────────────── */

.event-card {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 16px;
    background: var(--panel-soft);
    cursor: pointer;
    transition: border-color 120ms ease;
    position: relative;
}

.event-card:hover {
    border-color: var(--accent);
}

.event-card.score-high {
    background: var(--score-high-bg);
    border-color: var(--score-high-border);
    box-shadow: inset 3px 0 0 #16a34a;
}

.event-card.score-med {
    background: var(--score-med-bg);
    border-color: var(--score-med-border);
}

.event-card.score-low {
    background: var(--panel-soft);
    border-color: var(--border);
}

.event-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 8px;
}

.signal-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 9px;
    border-radius: 999px;
    background: var(--signal-pill-bg);
    border: 1px solid var(--border);
    color: var(--signal-pill-text);
    font-size: 11px;
    line-height: 1.2;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    flex-shrink: 0;
}

.signal-pill.signal-incident {
    background: var(--signal-pill-bg);
    color: var(--signal-pill-text);
}

.signal-pill.signal-activity {
    background: #f8fafc;
    color: #52606d;
}

.signal-pill.signal-intelligence {
    background: #f5f0ff;
    color: #6b46c1;
}

.event-card h3 {
    margin: 0;
    font-size: 18px;
    line-height: 1.35;
}

.event-summary-preview {
    margin: 4px 0 10px 0;
    color: var(--muted);
    line-height: 1.45;
    font-size: 14px;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.event-summary-preview:empty {
    display: none;
    margin: 0;
}

.event-card.expanded .event-summary-preview {
    display: none;
}

.event-summary-full {
    margin: 0 0 14px 0;
    color: var(--text);
    line-height: 1.5;
    font-size: 14px;
}

.event-time-inline {
    display: inline-block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--muted);
}

.event-card.expanded .event-time-inline {
    display: none;
}

.event-detail {
    display: none;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

.event-card.expanded .event-detail {
    display: block;
}

.event-detail-section {
    margin-bottom: 14px;
}

.event-detail-section:last-child {
    margin-bottom: 0;
}

.event-detail-section h4 {
    margin: 0 0 6px 0;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.factor-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.factor-chip {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 12px;
    font-weight: 600;
}

.source-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 8px;
}

.source-row {
    display: grid;
    grid-template-columns: minmax(0, auto) minmax(0, 1fr) auto;
    gap: 8px;
    align-items: baseline;
    padding: 8px 10px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.4;
}

.source-publisher {
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
}

.source-badge {
    display: inline-block;
    margin-left: 4px;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    vertical-align: middle;
}

.source-title a {
    color: var(--text);
    text-decoration: none;
    border-bottom: 1px solid transparent;
}

.source-title a:hover {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.source-date {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.cve-link {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    background: var(--accent-soft);
    color: var(--accent);
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
}

.cve-link:hover {
    background: var(--accent);
    color: var(--header-text);
}

.event-detail-meta {
    font-size: 12px;
    color: var(--muted);
}

/* ── Event meta pills ────────────────────────────────────── */

.event-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.event-meta:empty {
    display: none;
    margin-bottom: 0;
}

.meta-pill {
    display: inline-flex;
    align-items: center;
    padding: 5px 10px;
    border-radius: 999px;
    background: #edf2f7;
    border: 1px solid var(--border);
    font-size: 12px;
    color: var(--text);
    line-height: 1.2;
    font-weight: 500;
}

.meta-pill-victim {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #bfdbfe;
    font-weight: 600;
}

.meta-pill-attack {
    background: #fff1f2;
    color: #be123c;
    border-color: #fecdd3;
}

.meta-pill-actor {
    background: #f0fdfa;
    color: #0f766e;
    border-color: #99f6e4;
}

/* ── Card header pills ───────────────────────────────────── */

.event-card-header-pills {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.score-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 26px;
    padding: 0 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border: 1px solid transparent;
    white-space: nowrap;
}

.score-pill .score-icon {
    width: 11px;
    height: 11px;
    flex-shrink: 0;
}

.score-pill.score-high {
    background: #d1fadf;
    color: #054f31;
    border-color: #6ce9a6;
}

.score-pill.score-med {
    background: #fef0c7;
    color: #93370d;
    border-color: #fec84b;
}

.score-pill.score-low {
    background: #fee4e2;
    color: #912018;
    border-color: #fda29b;
}

.high-impact-badge {
    display: inline-flex;
    align-items: center;
    height: 26px;
    padding: 0 9px;
    border-radius: 999px;
    background: #fff7ed;
    border: 1px solid #fdba74;
    color: #c2410c;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Skeleton loading ────────────────────────────────────── */

@keyframes shimmer {
    0%   { background-position: -600px 0; }
    100% { background-position: 600px 0; }
}

.skeleton-card {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
    background: var(--panel-soft);
    overflow: hidden;
}

.skeleton-line {
    border-radius: 6px;
    background: linear-gradient(
        90deg,
        #e2e8f0 0%,
        #f1f5f9 50%,
        #e2e8f0 100%
    );
    background-size: 600px 100%;
    animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton-title {
    height: 20px;
    width: 62%;
    margin-bottom: 12px;
}

.skeleton-body {
    height: 14px;
    width: 100%;
    margin-bottom: 8px;
}

.skeleton-body-short {
    height: 14px;
    width: 42%;
    margin-bottom: 12px;
}

.skeleton-pills {
    display: flex;
    gap: 8px;
}

.skeleton-pill {
    height: 26px;
    border-radius: 999px;
}

/* ── Trends panel ────────────────────────────────────────── */

.trends-header {
    cursor: default;
    user-select: none;
}

.trends-header-text {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
}

.trends-header-text h2 {
    margin: 0;
    font-size: 18px;
}

.trends-toggle-icon {
    display: none;
    font-size: 16px;
    color: var(--muted);
    line-height: 1;
    flex-shrink: 0;
}

.trends-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.trend-block h3 {
    margin: 0 0 12px 0;
    font-size: 15px;
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.trend-window {
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
}

.trend-list {
    display: grid;
    gap: 8px;
}

.trend-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel-soft);
}

.trend-label {
    font-size: 14px;
    font-weight: 600;
    min-width: 0;
    line-height: 1.35;
}

.trend-count {
    font-size: 12px;
    color: var(--muted);
    font-weight: 500;
    flex-shrink: 0;
}

.trend-delta {
    font-size: 13px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    padding: 2px 8px;
    border-radius: 999px;
    line-height: 1.4;
}

.trend-delta-up {
    background: #d1fadf;
    color: #054f31;
}

.trend-delta-new {
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 11px;
    letter-spacing: 0.05em;
}

.trend-delta-down {
    background: #fee4e2;
    color: #912018;
}

.trend-delta-flat {
    background: #edf2f7;
    color: var(--muted);
}

.trend-filter-note {
    margin: -4px 0 10px;
    font-size: 11px;
    color: var(--muted);
    font-style: italic;
    line-height: 1.4;
}

/* ── Misc ────────────────────────────────────────────────── */

.placeholder-text {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

.loading {
    opacity: 0.5;
    pointer-events: none;
}

.page-footer {
    margin-top: 20px;
    padding: 4px 2px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.4;
}

.footer-left,
.footer-right {
    display: block;
}

/* ── Responsive: tablet ──────────────────────────────────── */

@media (max-width: 980px) {
    .filter-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .summary-strip {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .trends-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }
}

/* ── Responsive: mobile ──────────────────────────────────── */

@media (max-width: 640px) {
    .page {
        padding: 16px;
    }

    .app-header {
        padding: 10px 0;
    }

    .app-header-inner {
        padding: 0 16px;
    }

    .app-logo {
        height: 52px;
    }

    .sticky-context-inner {
        padding: 8px 16px;
    }

    .filter-row {
        grid-template-columns: 1fr;
    }

    .summary-strip {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: space-around;
        align-items: stretch;
        gap: 0;
        padding: 10px 8px;
        background: var(--panel);
        border: 1px solid var(--border);
        border-radius: 14px;
    }

    .summary-card {
        flex: 1 1 0;
        min-width: 0;
        background: transparent;
        border: none;
        border-right: 1px solid var(--border);
        border-radius: 0;
        padding: 4px 6px;
        min-height: 0;
        text-align: center;
    }

    .summary-card:last-child {
        border-right: none;
    }

    .summary-card .label {
        margin-bottom: 2px;
        font-size: 10px;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .summary-card .value {
        font-size: 18px;
    }

    .summary-card.active {
        background: var(--accent-soft);
        box-shadow: none;
        border-color: transparent;
    }

    .summary-card.active .label,
    .summary-card.active .value {
        color: var(--accent);
    }

    .panel-header-simple,
    .feed-header {
        flex-direction: row;
        align-items: center;
    }

    .event-card {
        padding: 12px 14px;
    }

    .event-card h3 {
        font-size: 16px;
    }

    .source-row {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .source-publisher,
    .source-date {
        white-space: normal;
    }

    .event-card-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .page-footer {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 2px;
    }

    /* Reorder layout: filters → summary → trends (collapsed) → feed */
    .filters-panel  { order: 1; }
    .summary-strip  { order: 2; }
    .trends-panel   { order: 3; }
    .feed-panel     { order: 4; }

    /* Trends panel: collapsible on mobile */
    .trends-header {
        cursor: pointer;
        margin-bottom: 0;
    }

    .trends-toggle-icon {
        display: block;
    }

    .trends-toggle-icon::before {
        content: "▾";
    }

    .trends-panel.expanded .trends-toggle-icon::before {
        content: "▴";
    }

    .trends-grid {
        display: none;
        margin-top: 16px;
    }

    .trends-panel.expanded .trends-grid {
        display: grid;
    }
}
