:root {
  --bg: #f7f7f5; --panel: #fff; --text: #1d1d1f; --muted: #8a8a8e; --line: #e6e6e3;
  --accent: #3182f6; --up: #e5383b; --down: #2f6fe4; --tag: #eef3fe; --tag-text: #2a5bd7;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #131416; --panel: #1c1d20; --text: #ececee; --muted: #8d8f96; --line: #2c2e33;
    --accent: #4b93ff; --up: #ff5a5f; --down: #5b9bff; --tag: #22304a; --tag-text: #9fc0ff; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.55 -apple-system, "Apple SD Gothic Neo", "Pretendard", sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-size: 12px; background: var(--tag); color: var(--tag-text); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); font-weight: normal; }
.small { font-size: 12px; }

.top { display: flex; align-items: center; gap: 24px; padding: 12px 24px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 16px; color: var(--text); }
.top nav { display: flex; gap: 4px; }
.top nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); }
.top nav a.on, .top nav a:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.status { margin-left: auto; font-size: 12px; max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.dot.done { background: #2bb673; } .dot.run, .dot.running { background: #f5a623; } .dot.error { background: var(--up); } .dot.holiday { background: var(--muted); }

main { padding: 24px; max-width: 1400px; margin: 0 auto; }
.layout { display: grid; grid-template-columns: 200px 1fr; gap: 24px; }
.dates { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 72px; align-self: start; max-height: calc(100vh - 96px); overflow: auto; }
.dates h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.dates a { padding: 6px 10px; border-radius: 8px; color: var(--text); display: flex; justify-content: space-between; }
select.month { font: inherit; font-size: 13px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); margin-bottom: 6px; width: 100%; }
.date-list { display: flex; flex-direction: column; gap: 2px; }
.dates a.on { background: var(--panel); box-shadow: 0 0 0 1px var(--line); font-weight: 600; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
h1 { font-size: 20px; margin: 0 0 8px; } h2 { font-size: 16px; margin: 28px 0 10px; }
.actions { display: flex; gap: 8px; align-items: center; }
.actions form { margin: 0; }
.btn { background: var(--accent); color: #fff; border: 0; padding: 7px 14px; border-radius: 8px; font: inherit; cursor: pointer; display: inline-block; }
.btn.ghost { background: var(--panel); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:hover { text-decoration: none; filter: brightness(1.05); }
.note { color: var(--muted); font-size: 12px; margin: 0 0 12px; }
.flash { background: var(--tag); color: var(--tag-text); padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 500; }
tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
td.reason { white-space: normal; font-size: 12px; color: var(--muted); min-width: 200px; }
.code { font-size: 11px; }
.up { color: var(--up); } .down { color: var(--down); }
.tag { display: inline-block; background: var(--tag); color: var(--tag-text); font-size: 11px; padding: 1px 7px; border-radius: 10px; margin-left: 4px; }
.links a { margin-right: 8px; font-size: 12px; }

.empty { background: var(--panel); border: 1px dashed var(--line); border-radius: 12px; padding: 24px; }
.empty p { color: var(--muted); margin: 6px 0 0; }

.upload { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.upload input { font-size: 12px; max-width: 100%; }
.drop { display: flex; flex-direction: column; gap: 2px; align-items: center; text-align: center; padding: 14px 10px; border: 1.5px dashed var(--accent); border-radius: 10px; background: var(--panel); cursor: pointer; }
.drop.over { background: var(--tag); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop b { color: var(--accent); }
.indices span { margin-right: 18px; }
.group { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; }
.group .stocks { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; margin-bottom: 8px; }
.group .stocks .tag { margin-left: 0; }
.stock { font-weight: 600; }
.news { padding: 8px 0 0; border-top: 1px dashed var(--line); margin-top: 8px; }
.news p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-top: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.card h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.card p { margin: 0; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
pre { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-size: 12px; overflow: auto; }


/* 검색 */
.search input { font: inherit; font-size: 13px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); width: 150px; }
.stock-link { font-weight: 600; color: var(--text); }
.show-m { display: none; }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; font-size: 12px; }
.link-btn:hover { color: var(--up); }
.card form { margin: 8px 0 6px; }

/* 종목 페이지 */
.stock-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.stock-head h1 { margin: 0; }
.price { margin: 4px 0; font-size: 15px; } .price b { font-size: 22px; margin-right: 6px; }
.kw { display: flex; flex-wrap: wrap; gap: 4px; } .kw .tag { margin-left: 0; }
.tag.pick { background: #fff1d6; color: #a86500; }
@media (prefers-color-scheme: dark) { .tag.pick { background: #3a2c10; color: #f5c063; } }
.tag.gray { background: var(--bg); color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
.tag small { opacity: .7; }
.stock-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.main-col, .side-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.panel h2 { margin: 0 0 10px; font-size: 15px; }
.panel .table-wrap { border: 0; border-radius: 0; margin: 0 -16px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; }
.chart { height: 420px; }
table.dense th, table.dense td { padding: 6px 10px; font-size: 13px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 12px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.seg { display: inline-flex; background: var(--bg); border-radius: 8px; padding: 2px; margin-bottom: 8px; }
.seg button { border: 0; background: none; color: var(--muted); font: inherit; font-size: 12px; padding: 4px 12px; border-radius: 6px; cursor: pointer; }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
.fin-chart { height: 200px; position: relative; } .fin-chart.small-chart { height: 150px; margin-top: 8px; }
.biz { margin: 0 0 6px; font-size: 13px; }
.holder { position: relative; display: flex; justify-content: space-between; gap: 8px; font-size: 13px; padding: 5px 8px; margin-bottom: 4px; border-radius: 6px; overflow: hidden; }
.holder i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--tag); z-index: 0; }
.holder span, .holder b { position: relative; z-index: 1; }
.peer { display: flex; gap: 8px; align-items: baseline; font-size: 13px; padding: 3px 0; } .peer a { flex: 1; }
.mini-news { font-size: 13px; padding: 5px 0; border-bottom: 1px dashed var(--line); } .mini-news:last-child { border: 0; }
.mini-news span { display: block; }
.reason-day { padding: 12px 0; border-top: 1px solid var(--line); } .reason-day:first-of-type { border-top: 0; padding-top: 0; }
.reason-head { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; } .reason-head .tag { margin-left: 0; }
.reason-day > p.small { margin: 6px 0 0; }

@media (max-width: 1000px) { .stock-grid { grid-template-columns: 1fr; } .chart { height: 320px; } }

/* 키워드 */
.kw-panel { margin: 8px 0 12px; }
.kw-row { display: flex; gap: 10px; align-items: baseline; padding: 4px 0; }
.kw-src { flex: 0 0 92px; font-size: 12px; color: var(--muted); }
.kw { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.small-gap { margin: 6px 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 14px; font-size: 12.5px; background: var(--bg); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); white-space: nowrap; }
.chip:hover { text-decoration: none; box-shadow: inset 0 0 0 1px var(--accent); }
.chip small { color: var(--muted); font-size: 11px; }
.chip.pdf { background: var(--tag); color: var(--tag-text); box-shadow: none; }
.chip.news { background: #e9f7ef; color: #17804a; box-shadow: none; font-weight: 600; }
.chip.news small { color: #4c9c70; font-weight: 400; }
@media (prefers-color-scheme: dark) { .chip.news { background: #163525; color: #7fd9a6; } .chip.news small { color: #5fae84; } }
.kw-more summary, .kw-broad summary { cursor: pointer; font-size: 12px; color: var(--muted); padding: 4px 0; }
.kw-broad { margin-top: 6px; border-top: 1px dashed var(--line); padding-top: 4px; }
.kw-add.inline { margin: 0; } .kw-add.inline input { padding: 3px 8px; font-size: 12px; max-width: 140px; } .kw-add.inline .btn { padding: 3px 10px; font-size: 12px; }
.reason-head .chip { font-size: 12px; padding: 2px 8px; }
/* 스크롤 시 종목명 고정 바 */
.stock-sticky { position: fixed; left: 0; right: 0; z-index: 1; display: flex; align-items: center; gap: 10px; padding: 8px 24px; background: var(--panel); border-bottom: 1px solid var(--line); box-shadow: 0 2px 8px rgba(0,0,0,.06); transform: translateY(-120%); opacity: 0; transition: transform .18s, opacity .18s; pointer-events: none; }
.stock-sticky.show { transform: none; opacity: 1; pointer-events: auto; }
.stock-sticky b { font-size: 15px; }
.sticky-price { font-variant-numeric: tabular-nums; }
.sticky-links { margin-left: auto; display: flex; gap: 12px; font-size: 12px; }
#keywords, #chartPanel, #reasons { scroll-margin-top: 120px; }
.chip.user { background: #fff1d6; color: #a86500; box-shadow: none; }
.chip.user a { color: inherit; }
.chip.user form { display: inline; margin: 0; }
.chip.user button { border: 0; background: none; color: inherit; cursor: pointer; padding: 0 0 0 2px; font-size: 13px; opacity: .6; }
.chip.user button:hover { opacity: 1; }
@media (prefers-color-scheme: dark) { .chip.user { background: #3a2c10; color: #f5c063; } }
.kw-add { display: flex; gap: 6px; margin-top: 8px; }
.kw-add input { font: inherit; font-size: 13px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); min-width: 0; flex: 1; max-width: 280px; }
.kw-desc { color: var(--muted); font-size: 13px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 4px 0 10px; }
.kw-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 12px; }

/* 로그인 */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-card img { margin: 0 auto; border-radius: 14px; }
.login-card h1 { margin: 0; }
.login-card p { margin: 0; font-size: 13px; }
.login-card input { font: inherit; font-size: 16px; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.login-card .btn { padding: 11px; font-size: 15px; }
.flash.err { background: #fde8e8; color: var(--up); }

@media (max-width: 760px) {
  main { padding: 16px; }
  .layout, .cols { grid-template-columns: 1fr; }
  .dates { position: static; flex-direction: row; overflow-x: auto; max-height: none; }
  .dates a { white-space: nowrap; }
  .dates:has(.date-list) { flex-direction: column; overflow: visible; }
  .date-list { flex-direction: row; overflow-x: auto; }
  .layout > * { min-width: 0; }
  .dates p, .dates code { white-space: normal; word-break: break-all; }
  .status { margin-left: 0; width: 100%; }
  .top { gap: 8px 12px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); }
  .top nav { order: 3; width: 100%; overflow-x: auto; margin: 0 -4px; }
  .top nav a { white-space: nowrap; padding: 6px 10px; }
  .search { flex: 1; } .search input { width: 100%; font-size: 16px; }
  .status { order: 4; font-size: 11px; }
  .head h1 { font-size: 18px; }
  .hide-m { display: none; }
  .kw-row { flex-direction: column; gap: 4px; }
  .stock-sticky { padding: 8px 16px; gap: 8px; }
  .sticky-links { display: none; }
  .kw-src { flex: none; }
  .kw-grid { grid-template-columns: 1fr; }
  .kw-add input { font-size: 16px; max-width: none; }
  .show-m { display: block; }
  .reason-m { font-size: 11px; color: var(--muted); white-space: normal; margin-top: 2px; }
  td, th { padding: 8px 10px; }
  .tag { margin: 2px 4px 0 0; }
  .actions { flex-wrap: wrap; }
}
