:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1c2230;
  --muted: #6b7385;
  --line: #e3e6ec;
  --primary: #2f5bea;
  --primary-weak: #e8eeff;
  --up: #d63b3b;      /* 상승(한국식) */
  --down: #2f64d6;    /* 하락 */
  --good: #13866f;
  --good-weak: #e2f5ef;
  --warn: #b7791f;
  --warn-weak: #fdf3e1;
  --bad: #c0392b;
  --bad-weak: #fdeaea;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  font-size: 14px; line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 54px;
  background: #151b2c; color: #fff; position: sticky; top: 0; z-index: 20;
}
.topbar .brand { color: #fff; font-weight: 800; font-size: 16px; white-space: nowrap; }
.topbar nav { display: flex; gap: 4px; overflow-x: auto; }
.topbar nav a { color: #c5cbe0; padding: 6px 12px; border-radius: 6px; white-space: nowrap; }
.topbar nav a:hover { background: #242c44; text-decoration: none; }
.topbar nav a.active { background: #2f5bea; color: #fff; }
.topbar .logout { margin-left: auto; }
.topbar .logout button { background: transparent; color: #c5cbe0; border-color: #39425e; }

.login-box { max-width: 360px; padding-top: 80px; }
.login-box label { display: block; margin: 8px 0 12px; }
.login-box input { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; font: inherit; border: 1px solid var(--line); border-radius: 7px; }
.login-box button { width: 100%; padding: 9px; }
.login-error { color: var(--bad); margin: 0 0 12px; }

.container { max-width: 1920px; margin: 0 auto; padding: 20px 20px 60px; }
h1 { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 16px 0 8px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: Consolas, "D2Coding", monospace; }
.hidden { display: none !important; }

button, .btn {
  font: inherit; border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 6px 12px; border-radius: 7px; cursor: pointer; white-space: nowrap;
}
button:hover { border-color: #b9c1d3; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { background: #2448c4; }
button.danger { color: var(--bad); }
button.ghost { border-color: transparent; background: transparent; padding: 4px 6px; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea {
  font: inherit; border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px; background: #fff; color: var(--text);
}
textarea { width: 100%; min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-weak); border-color: var(--primary); }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.field > input, label.field > select { color: var(--text); font-size: 14px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; position: sticky; top: 0; white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:hover td { background: #fafbff; }
.sticky-head { max-height: 70vh; overflow: auto; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: #eef0f4; color: #454d60; white-space: nowrap; margin: 1px 2px 1px 0; }
.badge.src-minority { background: #fde8f3; color: #a32a6f; }
.badge.src-market_view { background: #efe7fd; color: #6334b8; }
.badge.src-index { background: #e6f0ff; color: #2352b3; }
.badge.src-sector_etf { background: #e3f6f5; color: #11746c; }
.badge.src-sp500_fav { background: #fff4d6; color: #8a6300; }
.badge.src-holding { background: #fdeaea; color: #b03030; }
.badge.good { background: var(--good-weak); color: var(--good); }
.badge.warn { background: var(--warn-weak); color: var(--warn); }
.badge.bad { background: var(--bad-weak); color: var(--bad); }
.badge.stage-watch { background: #eef0f4; }
.badge.stage-analysis { background: #e6f0ff; color: #2352b3; }
.badge.stage-deep { background: #efe7fd; color: #6334b8; }
.badge.stage-candidate { background: var(--good-weak); color: var(--good); }
.badge .x { cursor: pointer; margin-left: 4px; opacity: .6; }
.badge .x:hover { opacity: 1; }

.score { display: inline-block; min-width: 44px; text-align: center; padding: 2px 6px; border-radius: 6px; font-weight: 700; font-variant-numeric: tabular-nums; }
.score.s-hi { background: var(--good-weak); color: var(--good); }
.score.s-mid { background: #eef0f4; color: #3c4456; }
.score.s-lo { background: var(--warn-weak); color: var(--warn); }
.score.s-na { color: #aab0bd; font-weight: 400; }
.up { color: var(--up); }
.down { color: var(--down); }

.big-score { font-size: 40px; font-weight: 900; line-height: 1.1; }
.kpi { display: flex; flex-direction: column; gap: 2px; }
.kpi .label { font-size: 12px; color: var(--muted); }
.kpi .value { font-size: 20px; font-weight: 800; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }
.alert.warn { background: var(--warn-weak); color: #7a4f0f; }
.alert.info { background: var(--primary-weak); color: #1f3c9c; }
.alert.bad { background: var(--bad-weak); color: #8e241a; }

.progress { height: 6px; background: #e8ebf1; border-radius: 99px; overflow: hidden; min-width: 160px; }
.progress > div { height: 100%; background: var(--primary); width: 0; transition: width .3s; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 3px 11px; cursor: pointer; background: #fff; font-size: 13px; user-select: none; }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }

.stepper { display: flex; gap: 0; }
.stepper button { border-radius: 0; margin-left: -1px; }
.stepper button:first-child { border-radius: 7px 0 0 7px; }
.stepper button:last-child { border-radius: 0 7px 7px 0; }
.stepper button.on { background: var(--primary); color: #fff; border-color: var(--primary); position: relative; }

.modal-bg { position: fixed; inset: 0; background: rgba(15, 20, 35, .45); display: flex; align-items: flex-start; justify-content: center; padding-top: 8vh; z-index: 50; }
.modal { background: #fff; border-radius: 12px; padding: 20px 22px; width: min(560px, 94vw); max-height: 84vh; overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal h2 { margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.form-grid .full { grid-column: 1 / -1; }

#toast-box { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1c2230; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 18px rgba(0,0,0,.2); max-width: 420px; animation: fadein .2s; }
.toast.error { background: #a4282b; }
.toast.success { background: #13866f; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.comment { border-bottom: 1px solid var(--line); padding: 10px 0; }
.comment .meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.comment .body { white-space: pre-wrap; margin-top: 4px; }
.reason { white-space: pre-wrap; font-size: 13px; color: #3c4456; }
.dropzone { border: 2px dashed #c6ccd9; border-radius: 10px; padding: 18px; text-align: center; color: var(--muted); cursor: pointer; }
.dropzone.drag { border-color: var(--primary); background: var(--primary-weak); }
.status-new td:first-child { box-shadow: inset 3px 0 0 var(--up); }
.status-removed td:first-child { box-shadow: inset 3px 0 0 var(--down); }
.status-removed td { color: var(--muted); }

tr.group-start td { border-top: 2px solid #c9cfdb; }

/* 주가 차트 */
.chart-box { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.chart-head { display: flex; gap: 8px; align-items: baseline; margin-bottom: 4px; }
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; }
.chart-tip { position: absolute; pointer-events: none; background: #1c2230; color: #fff; font-size: 12px; padding: 5px 8px;
  border-radius: 6px; white-space: nowrap; transform: translate(-50%, -110%); top: 0; display: none; z-index: 5; }
.chart-legend { display: flex; gap: 10px; font-size: 11px; color: var(--muted); margin-top: 2px; }
.chart-legend i { display: inline-block; width: 14px; height: 0; border-top: 2px dashed; vertical-align: middle; margin-right: 3px; }
