:root {
  --bg: #f4f5f7; --card: #fff; --ink: #1a1d24; --muted: #6b7280; --line: #e5e7eb;
  --pos: #059669; --neg: #dc2626; --neu: #9ca3af;
  --risk-low: #059669; --risk-mid: #d97706; --risk-high: #dc2626;
  --accent: #1f2937;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  font-size: 15px; line-height: 1.5;
}
a { color: inherit; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, Menlo, monospace; }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }

/* top bar */
.topbar {
  background: var(--accent); color: #fff; padding: 12px 20px;
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
}
.brand { font-weight: 700; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs a {
  padding: 6px 14px; border-radius: 999px; text-decoration: none;
  color: #d1d5db; font-size: 14px;
}
.tabs a.on { background: #fff; color: var(--accent); font-weight: 600; }
.tabs a:hover { color: #fff; }

.container { max-width: 1080px; margin: 0 auto; padding: 24px 20px 60px; }
h1 { font-size: 22px; margin: 0 0 4px; }

/* filters */
.filters { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.filters label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); }
.filters select, .filters input, .filters button {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 14px;
}
.filters button { cursor: pointer; background: var(--accent); color: #fff; border-color: var(--accent); }

/* feed cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.card h2 { font-size: 17px; margin: 0 0 10px; }
.articles { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.article { border-left: 3px solid var(--neu); padding: 6px 0 6px 12px; }
.article.sent-pos { border-color: var(--pos); }
.article.sent-neg { border-color: var(--neg); }
.article.sent-neu { border-color: var(--neu); }
.article .title { font-weight: 600; text-decoration: none; display: inline-block; margin: 2px 0; }
.article .title:hover { text-decoration: underline; }
.summary { margin: 4px 0; font-size: 13.5px; color: #374151; }
.meta { font-size: 12px; }

/* badges */
.badges { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 6px; font-weight: 600; background: #eef1f5; color: #374151; }
.badge.imp-A { background: #fee2e2; color: #b91c1c; }
.badge.imp-B { background: #fef3c7; color: #b45309; }
.badge.imp-C { background: #e5e7eb; color: #6b7280; }
.badge.sent.pos { background: #dcfce7; color: #15803d; }
.badge.sent.neg { background: #fee2e2; color: #b91c1c; }
.badge.sent.neu { background: #e5e7eb; color: #6b7280; }
.badge.cat  { background: #ecfeff; color: #0e7490; }
.badge.rec  { background: #dcfce7; color: #166534; }
.badge.pw   { background: #f3f4f6; color: #9ca3af; }

/* sentiment text-color distinction (titles follow the article's sentiment) */
.sent-neg .title { color: #b91c1c; }
.sent-pos .title { color: #15803d; }
.sent-neu .title { color: var(--ink); }

/* matrix */
table.matrix { width: 100%; border-collapse: collapse; background: #fff; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
table.matrix th, table.matrix td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
table.matrix th { background: #f9fafb; font-size: 13px; color: var(--muted); }
.concerns { font-size: 13.5px; max-width: 520px; }
.score { display: inline-block; min-width: 34px; text-align: center; padding: 4px 8px; border-radius: 8px; font-weight: 700; color: #fff; }
.risk-low  { background: var(--risk-low); }
.risk-mid  { background: var(--risk-mid); }
.risk-high { background: var(--risk-high); }

/* highlights — toggles bar is sticky too (freeze-pane) */
.toggles {
  display: flex; gap: 8px; align-items: center; margin: 14px 0 18px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 60;
  background: var(--bg); padding: 10px 4px;
  box-shadow: 0 6px 8px -6px rgba(15, 23, 42, .18);
}
.pill { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: #fff; text-decoration: none; font-size: 14px; }
.pill.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.sep { width: 1px; height: 20px; background: var(--line); }
.highlights { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.hl {
  background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--neu);
  border-radius: 10px; padding: 0; display: flex; align-items: stretch; overflow: hidden;
}
.hl.sent-neg { border-left-color: var(--neg); }
.hl.sent-pos { border-left-color: var(--pos); }
.hl.starred { box-shadow: 0 0 0 2px #dcfce7 inset; }
.hl .title { font-weight: 600; text-decoration: none; display: inline-block; margin: 4px 0; }

/* company block on the left of each highlight card — click = filter to that company */
.hl-co {
  flex: 0 0 128px; display: flex; flex-direction: column; justify-content: center; gap: 2px;
  padding: 12px 12px; background: #f8fafc; border-right: 1px solid var(--line);
  text-decoration: none; text-align: center; transition: background .15s;
}
.hl-co:hover { background: #e0f2fe; }
.hl-co-name { font-weight: 700; font-size: 13.5px; line-height: 1.25; word-break: keep-all; }
.hl-co-tkr { font-size: 11px; color: var(--muted); }
.hl-main { flex: 1; padding: 12px 16px; min-width: 0; }
@media (max-width: 560px) {
  .hl { flex-direction: column; }
  .hl-co { flex-basis: auto; flex-direction: row; justify-content: flex-start; gap: 8px;
           border-right: none; border-bottom: 1px solid var(--line); }
}

/* active company-filter banner */
.co-active {
  display: flex; align-items: center; gap: 10px; margin: 0 0 14px;
  padding: 8px 14px; background: #e0f2fe; border: 1px solid #7dd3fc; border-radius: 10px;
  font-size: 14px;
}
.small-pill { padding: 3px 10px; font-size: 12.5px; }

/* language toggle */
.langtoggle { display: flex; gap: 4px; margin-left: auto; }
.langtoggle a { padding: 4px 11px; border-radius: 999px; color: #d1d5db; text-decoration: none; font-size: 13px; }
.langtoggle a.on { background: #fff; color: var(--accent); font-weight: 700; }
.langtoggle a:hover { color: #fff; }
.langtoggle a.on:hover { color: var(--accent); }

/* feed = checkerboard grid of company tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; align-items: start; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.tile[open] { grid-column: 1 / -1; }
.tile > summary { list-style: none; cursor: pointer; }
.tile > summary::-webkit-details-marker { display: none; }
.tile-face { padding: 14px; display: flex; flex-direction: column; gap: 10px; min-height: 108px; }
.tile[open] > summary { border-bottom: 1px solid var(--line); background: #fafbfc; border-radius: 12px 12px 0 0; }
.tile-name { font-weight: 700; font-size: 16px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.tile-tkr { font-size: 12px; font-weight: 400; }
.counts { display: flex; gap: 5px; }
.cnt { flex: 1; text-align: center; padding: 7px 0; border-radius: 8px; font-size: 14px; font-weight: 700; }
.cnt.neg { background: #fee2e2; color: #b91c1c; }
.cnt.neu { background: #eef1f5; color: #6b7280; }
.cnt.pos { background: #dcfce7; color: #166534; }
.tile-total { font-size: 12px; text-align: right; margin-top: auto; }
.tile-body { padding: 8px 16px 14px; }

/* sector sections */
.sector { margin-bottom: 26px; }
.sector-head {
  font-size: 15px; margin: 0 0 10px; padding: 6px 12px;
  background: var(--accent); color: #fff; border-radius: 8px; display: inline-block;
}
.sector-head .muted { color: #cbd5e1; font-size: 12.5px; }

/* importance groups inside an expanded tile */
.impgroup { margin-top: 12px; }
.imp-head { display: flex; align-items: center; gap: 8px; padding: 4px 0 6px; border-bottom: 1px dashed var(--line); margin-bottom: 6px; }

/* category filter — contained card, obvious selected/unselected states.
   position:sticky = excel freeze-pane: stays at the viewport top while the
   article list scrolls, so filters are always reachable. */
.catfilter {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 16px; margin: 0 0 20px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, .08);
  position: sticky; top: 0; z-index: 60;
}
.catfilter-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.flabel {
  font-size: 11.5px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; margin-right: 6px; white-space: nowrap;
}
.catbtns { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.catbtn {
  padding: 6px 13px; border: 1px solid #d1d5db; border-radius: 999px;
  background: #f9fafb; font-size: 13px; cursor: pointer; color: #4b5563;
  transition: background .15s, color .15s, border-color .15s, box-shadow .15s;
}
.catbtn:hover { border-color: #0e7490; color: #0e7490; background: #fff; }
.catbtn.on {
  background: #0e7490; border-color: #0e7490; color: #fff; font-weight: 700;
  box-shadow: 0 1px 5px rgba(14, 116, 144, .4);
}
.catbtn.on::before { content: "✓ "; }
.catbtn.clearbtn { border-style: dashed; color: var(--muted); background: #fff; }
.catbtn.clearbtn:hover { color: #b91c1c; border-color: #fca5a5; }
.filter-status {
  margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line);
  font-size: 12.5px; color: var(--muted);
}
.filter-status.active { color: #0e7490; font-weight: 700; }
.filter-status.active::before { content: "● "; }

/* matrix: sub-score columns (news raw / fundamentals baseline) */
td.subscore { text-align: center; color: #6b7280; font-weight: 600; }

/* event ledger */
.evt-count {
  display: inline-block; min-width: 24px; padding: 2px 8px; border-radius: 999px;
  background: #fef3c7; color: #b45309; font-weight: 700; text-decoration: none; font-size: 12.5px;
}
.evt-count:hover { background: #fde68a; }
.evt-card { margin-bottom: 14px; }
.evt-row { display: block !important; }
.evt-title { font-weight: 600; margin-top: 3px; }
.evt-row.resolved .evt-title { font-weight: 400; }

/* matrix: carried-forward (stale) eval dates */
td.stale { color: #9ca3af; }
td.stale::after { content: " ↩"; font-size: 11px; }
.stale-hint { color: #9ca3af; }

/* trends chips */
.chip-actions { display: flex; gap: 8px; align-items: center; margin: 12px 0 6px; flex-wrap: wrap; }
.chip-score {
  display: inline-block; min-width: 20px; text-align: center; padding: 0 5px;
  border-radius: 6px; font-size: 11px; font-weight: 700; color: #fff;
}

/* delta (day-over-day risk change) */
.delta { display: inline-block; min-width: 30px; text-align: center; padding: 3px 7px; border-radius: 7px; font-size: 12px; font-weight: 700; }
.delta.up   { background: #fee2e2; color: #b91c1c; }
.delta.down { background: #dcfce7; color: #15803d; }
.delta.flat { color: #9ca3af; }
.delta.new  { background: #e0e7ff; color: #3730a3; font-size: 10.5px; }

/* drill-down links (company -> its feed) */
a.drill { text-decoration: none; border-bottom: 1px dotted #9ca3af; }
a.drill:hover { color: #0e7490; border-bottom-color: #0e7490; }

/* dashboard */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 18px 0 22px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px; text-decoration: none; color: inherit; display: block;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04); transition: box-shadow .15s, border-color .15s;
}
a.stat:hover { border-color: #94a3b8; box-shadow: 0 3px 10px rgba(15, 23, 42, .08); }
.stat-num { font-size: 30px; font-weight: 800; line-height: 1.1; }
.stat-num.imp { color: #b45309; }
.stat-num.neg { color: #b91c1c; }
.stat-num.pos { color: #15803d; }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 4px; }
.dash-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.dash-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}
.dash-card h2 { font-size: 15px; margin: 0 0 12px; }
.mini-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.mini-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 4px; border-bottom: 1px solid #f1f5f9; font-size: 14px;
}
.mini-list li:last-child { border-bottom: none; }
.mini-right { display: inline-flex; gap: 6px; align-items: center; }
.mini-list .cnt { flex: none; min-width: 30px; padding: 3px 8px; }
.morelink { display: inline-block; margin-top: 10px; font-size: 13px; color: #0e7490; text-decoration: none; }
.morelink:hover { text-decoration: underline; }

/* global polish: interactive hover feedback */
.tile { transition: box-shadow .15s, border-color .15s; box-shadow: 0 1px 2px rgba(15, 23, 42, .04); }
.tile:hover { border-color: #94a3b8; box-shadow: 0 3px 10px rgba(15, 23, 42, .1); }
table.matrix tbody tr { transition: background .1s; }
table.matrix tbody tr:hover { background: #f8fafc; }
.pill { transition: background .15s, color .15s, border-color .15s; }
.pill:hover { border-color: #94a3b8; }
.hl { transition: box-shadow .15s; }
.hl:hover { box-shadow: 0 2px 8px rgba(15, 23, 42, .08); }
.topbar { box-shadow: 0 1px 4px rgba(0, 0, 0, .15); }

/* sentiment pills (highlights filters) */
.pill.sentpill.pos.on { background: #15803d; border-color: #15803d; }
.pill.sentpill.neg.on { background: #b91c1c; border-color: #b91c1c; }
.pill.sentpill.neu.on { background: #6b7280; border-color: #6b7280; }

/* matrix head + csv */
.matrix-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.csvbtn { padding: 8px 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff; text-decoration: none; font-size: 14px; white-space: nowrap; }
.csvbtn:hover { background: #f3f4f6; }
.table-scroll { overflow-x: auto; }

/* trends */
.chip-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0 18px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font-size: 14px; cursor: pointer; }
.chart-wrap { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 20px; }

/* peers & supply-chain tabs */
.rel-card { margin-bottom: 14px; }
.peer-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 6px 14px; }
.peer-item { display: flex; flex-direction: column; padding: 6px 8px; background: #f8fafc; border-radius: 6px; }
.peer-name { font-weight: 600; }
/* 3-column flow: upstream -> company -> downstream */
.chain { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: start; }
.chain-col { min-width: 0; }
.chain-head { font-weight: 700; font-size: .85rem; margin-bottom: 6px; padding: 4px 8px; border-radius: 6px; display: inline-block; }
.chain-head.up { background: #eff6ff; color: #1d4ed8; }
.chain-head.down { background: #f0fdf4; color: #15803d; }
.chain-mid { display: flex; align-items: center; gap: 8px; padding-top: 22px; }
.chain-center { text-align: center; padding: 10px 14px; border: 2px solid #cbd5e1; border-radius: 10px; background: #fff; white-space: nowrap; }
.chain-arrow { color: #94a3b8; font-size: 1.3rem; }
.edge-list { list-style: none; margin: 0; padding: 0; }
.edge-list li { padding: 5px 8px; border-bottom: 1px solid #f1f5f9; display: flex; flex-direction: column; }
.edge-name { font-weight: 600; }
.edge-item { color: #64748b; font-size: .82rem; }
@media (max-width: 760px) {
  .chain { grid-template-columns: 1fr; }
  .chain-mid { padding-top: 0; justify-content: center; }
}

/* keep the CSV button top-right even when the left column's text is long */
.matrix-head > div:first-child { flex: 1 1 0; min-width: 260px; }
/* abstract-group node marker in the supply-chain map */
.badge.grp { background: #f1f5f9; color: #475569; border: 1px dashed #94a3b8; }

/* events filter: severity list never grows (only 2 values), so the category
   group gets all remaining width and wraps in fewer rows */
.catbtns.sevgrp { flex: 0 0 auto; margin-right: 26px; }

/* dashboard cards: tighter rows so 7-entry lists stay compact */
.dash-card .mini-list { gap: 2px; }
.dash-card .mini-list li { padding: 4px 4px; font-size: 13.5px; }
.dash-card h2 { margin-bottom: 8px; }

/* trends: sector-grouped company chips (collapsed by default) */
.sector-group { background: #fff; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; }
.sector-group > summary { cursor: pointer; padding: 10px 14px; font-weight: 700; font-size: 14px; list-style: none; }
.sector-group > summary::-webkit-details-marker { display: none; }
.sector-group > summary::before { content: "▸ "; color: var(--muted); }
.sector-group[open] > summary::before { content: "▾ "; }
.sector-group.has-sel > summary { color: #1d4ed8; }
.sector-group .chip-row { padding: 0 12px 12px; }
.scorebtn { padding: 3px 6px; }
.newsonly { display: flex; align-items: center; gap: 6px; font-size: 13.5px; white-space: nowrap; }
.newsonly input { width: 15px; height: 15px; }

/* trends: stacked display-mode checkboxes + news-score chip styling */
.mode-stack { display: flex; flex-direction: column; gap: 4px; }
.chip-score.nscore { opacity: .65; margin-left: 2px; }

/* trends filter: [최종점수 5x2][뉴스점수 5x2][섹터(남는 폭 전부)][모드+초기화 세로 스택] */
.tr-filter { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.score-block, .sec-block { display: flex; flex-direction: column; gap: 5px; }
.score-grid { display: grid; grid-template-columns: repeat(5, auto); gap: 4px; }
.score-grid .catbtn { padding: 3px 6px; }   /* both rows identical size */
.sec-block { flex: 1 1 0; min-width: 260px; }
.mode-stack { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.mode-stack .clearbtn { margin-top: 2px; }

/* score groups stacked vertically in one narrow column -> sector gets the width */
.score-col { display: flex; flex-direction: column; gap: 10px; flex: 0 0 auto; }

/* pipeline-stale warning banner (home) */
.stale-banner {
  background: #fef2f2; border: 1px solid #fca5a5; border-left: 5px solid #dc2626;
  color: #7f1d1d; border-radius: 10px; padding: 12px 16px; margin-bottom: 16px; font-size: 14px;
}

/* login page */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 28px 30px;
  width: 340px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .08);
}
.login-brand { font-weight: 700; font-size: 17px; margin-bottom: 4px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.login-card input[type=text], .login-card input[type=password] {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font-size: 15px; color: var(--ink);
}
.login-card .login-remember { flex-direction: row; align-items: center; gap: 6px; }
.login-card button {
  padding: 10px; border: none; border-radius: 8px; background: var(--accent); color: #fff;
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.login-error { background: #fef2f2; border: 1px solid #fca5a5; color: #991b1b; border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.langtoggle a.logout { margin-left: 8px; border: 1px solid #4b5563; }
