:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f0f2f5; --border: #e3e6eb;
  --text: #1b1f24; --muted: #667085; --accent: #1f5fd6; --accent-weak: #e8effc;
  --pos: #1a8a4a; --neu: #8a94a6; --neg: #d63b3b; --warn: #c77700;
  --pos-weak: #e5f5ec; --neg-weak: #fdeaea; --warn-weak: #fff4e0;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.05);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 "Noto Sans KR", "Malgun Gothic", sans-serif; }
h1 { font-size: 22px; margin: 0; } h2 { font-size: 18px; margin: 0; } h3 { font-size: 15px; margin: 0 0 12px; }
.muted { color: var(--muted); margin: 2px 0 0; } small { color: var(--muted); font-weight: 400; }
.hidden { display: none !important; }
.center { text-align: center; margin: 16px 0; }
a.link { color: var(--accent); text-decoration: none; font-size: 13px; }

/* 상단바 */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px; padding: 0 24px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border); }
.userbox { display: flex; align-items: center; gap: 8px; white-space: nowrap; font-size: 13px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; white-space: nowrap; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-weak); }
#tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
#tabs button { border: 0; background: none; padding: 17px 12px; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
#tabs button.active { color: var(--text); font-weight: 700; border-bottom-color: var(--accent); }
.collect { display: flex; align-items: center; gap: 10px; white-space: nowrap; }

button { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 14px; border-radius: 8px; cursor: pointer; }
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--neg); }
button.sm { padding: 4px 10px; font-size: 13px; }
button:disabled { opacity: .55; cursor: default; }

main { max-width: 1320px; margin: 0 auto; padding: 24px; }
.tab { display: none; } .tab.active { display: block; }
.section-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.section-head.sub { margin-top: 28px; }
.period { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.period button { border: 0; padding: 5px 12px; border-radius: 6px; }
.period button.active { background: var(--accent-weak); color: var(--accent); font-weight: 700; }
.row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-head h3 { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .card { margin-top: 16px; }
.dash-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; }
.dash-grid > .card { margin: 0; }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-6 { grid-column: span 6; } .span-4 { grid-column: span 4; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; grid-column: span 12; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi.pos .value { color: var(--pos); } .kpi.neg .value { color: var(--neg); } .kpi.warn .value { color: var(--warn); }
.meter { height: 6px; background: var(--surface-2); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.meter > div { height: 100%; background: var(--accent); border-radius: 3px; }

.alerts { grid-column: span 12; display: flex; flex-direction: column; gap: 6px; }
.alert { background: var(--neg-weak); color: #8f1f1f; border: 1px solid #f5c2c2; padding: 10px 14px; border-radius: 8px; font-weight: 500; }
.chart-box { position: relative; height: 240px; }
.chart-box.sm { height: 200px; }

/* 키워드 */
.cloud { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: baseline; line-height: 1.3; min-height: 120px; }
.cloud span { cursor: pointer; font-weight: 600; }
.cloud span:hover { text-decoration: underline; }
.legend-inline { display: flex; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend-inline i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.bars .bar-row { display: grid; grid-template-columns: 110px 1fr 36px; gap: 8px; align-items: center; margin: 6px 0; font-size: 13px; }
.bars .track { background: var(--surface-2); border-radius: 4px; height: 8px; overflow: hidden; }
.bars .fill { height: 100%; background: var(--accent); border-radius: 4px; }
.bars .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

/* 기사 */
.article-list { display: flex; flex-direction: column; gap: 8px; }
.article { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.card .article { border: 0; border-bottom: 1px solid var(--border); border-radius: 0; padding: 10px 0; }
.card .article:last-child { border-bottom: 0; }
.article .meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.article a.title { display: block; color: var(--text); font-weight: 600; text-decoration: none; margin: 3px 0; }
.article a.title:hover { color: var(--accent); }
.article .summary { font-size: 13px; color: #3a4250; }
.article .kw { font-size: 12px; color: var(--accent); margin-top: 3px; }
.badge { display: inline-block; padding: 0 8px; border-radius: 10px; font-size: 11px; font-weight: 700; line-height: 18px; }
.badge.positive { background: var(--pos-weak); color: var(--pos); }
.badge.neutral { background: var(--surface-2); color: var(--muted); }
.badge.negative { background: var(--neg-weak); color: var(--neg); }
.badge.high { background: var(--neg); color: #fff; } .badge.medium { background: var(--warn-weak); color: var(--warn); }
.badge.ch { background: var(--accent-weak); color: var(--accent); }
.badge.ok { background: var(--pos-weak); color: var(--pos); } .badge.fail { background: var(--neg-weak); color: var(--neg); }

.briefing { white-space: pre-wrap; background: var(--surface-2); border-radius: 8px; padding: 14px; font-size: 13.5px; }

/* 테이블 */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; color: var(--muted); font-weight: 500; padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr.clickable { cursor: pointer; } .table tr.clickable:hover td { background: var(--surface-2); }
.table tr.selected td { background: var(--accent-weak); }
.table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.mini-bar { display: flex; height: 8px; width: 120px; border-radius: 4px; overflow: hidden; background: var(--surface-2); }
.mini-bar .p { background: var(--pos); } .mini-bar .n { background: var(--neu); } .mini-bar .g { background: var(--neg); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { background: var(--surface-2); padding: 1px 8px; border-radius: 10px; font-size: 12px; }

/* 폼 */
.filters { display: flex; flex-wrap: wrap; gap: 8px; }
input, select, textarea { font: inherit; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-weak); border-color: var(--accent); }
.form label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-weight: 500; font-size: 13px; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.form .inline { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.history { max-height: 360px; overflow: auto; font-size: 12px; }
.history .h { border-bottom: 1px solid var(--border); padding: 8px 0; }
.history pre { white-space: pre-wrap; margin: 4px 0 0; color: var(--muted); font: inherit; }
.checklist { max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.checklist label { flex-direction: row !important; align-items: center; gap: 6px; font-weight: 400 !important; margin: 0 !important; }

.modal { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-box { background: var(--surface); border-radius: 12px; padding: 22px; width: 520px; max-width: 100%; max-height: 90vh; overflow: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1b1f24; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 60; max-width: 90vw; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

@media (max-width: 1000px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .span-8, .span-6, .span-4 { grid-column: span 12; }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 16px; gap: 6px; }
  #tabs { order: 3; width: 100%; } #tabs button { padding: 10px 8px; }
  main { padding: 16px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}

/* 비슷한 기사 묶음 */
.rel-toggle { margin-top: 6px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 12px; padding: 2px 10px; font: inherit; font-size: 12px; cursor: pointer; }
.rel-toggle::before { content: "▸ "; color: var(--muted); }
.rel-toggle.open::before { content: "▾ "; }
.rel-toggle:hover { border-color: var(--accent); color: var(--accent); }
.related { list-style: none; margin: 6px 0 0; padding: 6px 0 0 12px; border-left: 2px solid var(--border); display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.related a { color: var(--text); text-decoration: none; }
.related a:hover { color: var(--accent); text-decoration: underline; }
.related .badge { margin-right: 4px; }
.story { display: flex; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.story:last-child { border-bottom: 0; }
.story-size { flex: 0 0 52px; text-align: center; background: var(--accent-weak); color: var(--accent); border-radius: 8px; padding: 6px 0; align-self: flex-start; }
.story-size b { display: block; font-size: 20px; line-height: 1.1; }
.story-size small { color: var(--accent); }
.story-body { flex: 1; min-width: 0; }
.story-body .meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.story-body a.title { display: block; color: var(--text); font-weight: 600; text-decoration: none; margin: 3px 0 5px; }
.story-body a.title:hover { color: var(--accent); }
.filters label.check.inline { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
