/* REKOR x NOWHERE · 뉴스 대시보드 */

:root {
    color-scheme: light;
    --font: "Pretendard Variable", Pretendard, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
    --font-title: var(--font);

    --bg: #f3f4f6;
    --surface: #fff;
    --surface-2: #f7f8fa;
    --text: #16181d;
    --text-2: #4b5160;
    --text-3: #868c99;
    --line: #e6e8ec;
    --accent: #2f5bd3;
    --accent-text: #fff;
    --danger: #c62828;
    --danger-bg: #fdf1f1;
    --ok: #1f9d55;
    --warn: #d98a00;

    --radius: 12px;
    --gap: 20px;
    --max: 1240px;
    --row-pad: 10px;

    /* 분야 색 (config의 categories 순서) */
    --c0: #2f5bd3;
    --c1: #0f7c8c;
    --c2: #6b4fd8;
    --c3: #4d7c0f;
    --c4: #b7472a;
    --c5: #6b7280;
}

* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.55 var(--font);
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

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

[data-ci="0"] { --cc: var(--c0); }
[data-ci="1"] { --cc: var(--c1); }
[data-ci="2"] { --cc: var(--c2); }
[data-ci="3"] { --cc: var(--c3); }
[data-ci="4"] { --cc: var(--c4); }
[data-ci="5"] { --cc: var(--c5); }

/* ───────── 뼈대 ───────── */

.app {
    max-width: var(--max);
    margin: 0 auto;
    padding: 0 24px 40px;
}

.skip {
    position: absolute;
    left: -9999px;
}

.skip:focus {
    left: 16px;
    top: 12px;
    z-index: 30;
    padding: 10px 14px;
    background: var(--surface);
    color: var(--accent);
}

.topbar {
    display: flex;
    align-items: center;
    gap: 16px 24px;
    flex-wrap: wrap;
    padding: 22px 0 18px;
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-right: auto;
}

.brand h1 {
    margin: 0;
    font: 800 24px/1.1 var(--font-title);
    letter-spacing: -0.02em;
}

.brand-x {
    color: var(--text-3);
    font-weight: 500;
}

.tagline {
    margin: 0;
    color: var(--text-3);
    font-size: 13px;
}

.live {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-2);
    white-space: nowrap;
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-3);
}

.live[data-state="ok"] .live-dot { background: var(--ok); }
.live[data-state="warn"] .live-dot { background: var(--warn); }
.live[data-state="error"] .live-dot,
.live[data-state="offline"] .live-dot { background: var(--danger); }

.tools {
    display: flex;
    gap: 8px;
}

.tools input {
    width: 220px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
}

.tools input::placeholder {
    color: var(--text-3);
}

.refresh {
    min-width: 92px;
    padding: 9px 14px;
    border: 0;
    border-radius: 10px;
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
    white-space: nowrap;
}

.refresh:disabled {
    opacity: 0.6;
    cursor: progress;
}

/* ───────── 필터 ───────── */

.filterbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 10px 24px;
    padding: 12px 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    margin-bottom: var(--gap);
}

.chips {
    display: flex;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
}

.chips::-webkit-scrollbar {
    display: none;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-2);
    font-size: 14px;
    white-space: nowrap;
}

.chip-count {
    color: var(--text-3);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.chip.active {
    border-color: var(--text);
    background: var(--text);
    color: var(--surface);
}

.chip.active .chip-count {
    color: inherit;
    opacity: 0.7;
}

/* ───────── 본문 2단 ───────── */

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: var(--gap);
    align-items: start;
}

.side {
    position: sticky;
    top: 16px;
    display: grid;
    gap: 14px;
}

.list-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin: 0 0 10px;
}

.list-heading h2 {
    margin: 0;
    font: 700 18px/1.3 var(--font-title);
}

#count {
    color: var(--text-3);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

/* ───────── 기사 한 줄 ───────── */

.items {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}

.item {
    display: grid;
    grid-template-columns: 48px 64px minmax(0, 1fr) auto;
    align-items: baseline;
    gap: 12px;
    padding: var(--row-pad) 16px;
    border-top: 1px solid var(--line);
}

.item:first-child {
    border-top: 0;
}

.item:hover {
    background: var(--surface-2);
}

.item-time {
    color: var(--text-3);
    font: 500 13px/1.4 var(--font);
    font-variant-numeric: tabular-nums;
}

.cat {
    display: inline-block;
    justify-self: start;
    padding: 2px 8px;
    border-radius: 6px;
    background: color-mix(in srgb, var(--cc, var(--c5)) 12%, transparent);
    color: var(--cc, var(--c5));
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.item-title {
    font-size: 15.5px;
    font-weight: 600;
    line-height: 1.5;
    word-break: keep-all;
    overflow-wrap: anywhere;
}

.item-title:hover {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.item-meta {
    display: flex;
    gap: 8px;
    color: var(--text-3);
    font-size: 12.5px;
    white-space: nowrap;
}

.item-ago::before {
    content: "·";
    margin-right: 8px;
}

.item-ago:empty {
    display: none;
}

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

.empty h3 {
    margin: 0 0 8px;
    font-size: 17px;
    color: var(--text);
}

.empty p {
    margin: 0;
}

/* ───────── 오른쪽 패널 ───────── */

.panel {
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.panel h2 {
    margin: 0 0 12px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-2);
}

.source {
    display: grid;
    grid-template-columns: 8px minmax(0, 1fr) auto;
    align-items: center;
    gap: 4px 10px;
    padding: 6px 0;
    font-size: 13.5px;
}

.source-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
}

.source[data-ok="true"] .source-dot {
    background: var(--ok);
}

.source-count {
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}

.source-status {
    display: none;
    grid-column: 2 / 4;
    color: var(--danger);
    font-size: 12px;
}

.source[data-ok="false"] .source-status {
    display: block;
}

.note {
    margin: 10px 0 0;
    color: var(--text-3);
    font-size: 12.5px;
}

.note.notice {
    color: var(--danger);
}

.stat {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr) 28px;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 5px 0;
    border: 0;
    background: none;
    font-size: 13px;
    text-align: left;
}

.stat-bar {
    height: 8px;
    border-radius: 4px;
    background: var(--surface-2);
    overflow: hidden;
    position: relative;
}

.stat-bar::after {
    content: "";
    position: absolute;
    inset: 0;
    width: calc(var(--ratio, 0) * 100%);
    background: var(--cc, var(--c5));
    border-radius: inherit;
}

.stat-count {
    text-align: right;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
}

.stat.active .stat-name {
    font-weight: 700;
}

.links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
}

.links h2 {
    width: 100%;
    margin-bottom: 2px;
}

.links a {
    color: var(--accent);
    font-size: 13.5px;
}

.share button {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--accent);
    font-size: 13.5px;
    font-weight: 600;
}

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

/* ───────── 속보 ───────── */

.breaking:empty {
    display: none;
}

.breaking {
    display: grid;
    gap: 8px;
    margin-bottom: var(--gap);
}

.breaking-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
    border-left: 4px solid var(--danger);
    border-radius: 10px;
    background: var(--danger-bg);
}

.breaking-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 10px;
}

.breaking-label {
    color: var(--danger);
    font-size: 13px;
}

.breaking-title {
    font-weight: 700;
    overflow-wrap: anywhere;
}

.breaking-source {
    color: var(--text-3);
    font-size: 12.5px;
}

.breaking-close {
    padding: 5px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    font-size: 13px;
}

/* ───────── 하단 ───────── */

.footer {
    margin-top: 32px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    color: var(--text-3);
    font-size: 12px;
}

.footer p {
    margin: 4px 0;
}

/* ───────── 반응형 ───────── */

@media (max-width: 1000px) {
    .layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .side {
        position: static;
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    }
}

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

    .topbar {
        padding: 16px 0 12px;
    }

    .tagline {
        display: none;
    }

    .tools {
        width: 100%;
    }

    .tools input {
        flex: 1;
        width: auto;
        min-width: 0;
    }

    .filterbar {
        flex-direction: column;
        margin-left: -16px;
        margin-right: -16px;
        padding-left: 16px;
        padding-right: 16px;
    }

    .items {
        margin-left: -16px;
        margin-right: -16px;
        border-radius: 0;
        border-left: 0;
        border-right: 0;
    }

    .item {
        grid-template-columns: auto auto minmax(0, 1fr);
        grid-template-areas:
            "cat time meta"
            "title title title";
        gap: 4px 8px;
        padding: 12px 16px;
    }

    .item-time { grid-area: time; }
    .cat { grid-area: cat; }
    .item-title { grid-area: title; }
    .item-meta { grid-area: meta; justify-content: flex-end; }
}

/* ───────── 대시보드 테마 ───────── */

.topbar {
    position: relative;
}

.brand h1 {
    font-size: 22px;
}

.brand-main {
    color: var(--accent);
}

.live {
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
}

.filterbar {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 10px 12px;
}

.chip {
    border-color: transparent;
    background: var(--surface-2);
}

.chip[data-ci]:not(.active) .chip-label::before {
    content: "";
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 6px;
    border-radius: 50%;
    background: var(--cc);
    vertical-align: 1px;
}

.chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

@media (max-width: 640px) {
    .filterbar {
        border-radius: 0;
        border-left: 0;
        border-right: 0;
    }
}

/* ───────── 다크 모드 ─────────
   data-theme 없음: OS 설정을 따름 / "light"·"dark": 사용자가 고른 테마 (rekor.js가 저장) */

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #121212;
        --surface: #1b1b1b;
        --surface-2: #242424;
        --text: #ececec;
        --text-2: #b5b5b5;
        --text-3: #858585;
        --line: #2e2e2e;
        --accent: #e6e6e6;
        --accent-text: #121212;
        --danger: #ff6b6b;
        --danger-bg: #2b1618;
        --ok: #3ecf7a;
        --warn: #f2b33d;

        --c0: #8fa6d9;
        --c1: #5fb8b0;
        --c2: #a894d6;
        --c3: #a3be6a;
        --c4: #e0876a;
        --c5: #9a9a9a;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #121212;
    --surface: #1b1b1b;
    --surface-2: #242424;
    --text: #ececec;
    --text-2: #b5b5b5;
    --text-3: #858585;
    --line: #2e2e2e;
    --accent: #e6e6e6;
    --accent-text: #121212;
    --danger: #ff6b6b;
    --danger-bg: #2b1618;
    --ok: #3ecf7a;
    --warn: #f2b33d;

    --c0: #8fa6d9;
    --c1: #5fb8b0;
    --c2: #a894d6;
    --c3: #a3be6a;
    --c4: #e0876a;
    --c5: #9a9a9a;
}

.theme-toggle {
    display: grid;
    place-items: center;
    padding: 0 11px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text-2);
}

.theme-toggle svg {
    display: none;
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

:root:not([data-theme]) .theme-toggle .icon-auto,
:root[data-theme="light"] .theme-toggle .icon-light,
:root[data-theme="dark"] .theme-toggle .icon-dark {
    display: block;
}

.theme-toggle:hover {
    color: var(--text);
}
