:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #15221d;
  --muted: #6c7772;
  --line: #e5e9e7;
  --green: #0d8a61;
  --green-dark: #086b4b;
  --green-soft: #e6f5ef;
  --mint: #b9f4d4;
  --orange: #e27b24;
  --orange-soft: #fff2e7;
  --red: #d94a48;
  --red-soft: #fff0ef;
  --navy: #172923;
  --shadow: 0 8px 30px rgba(20, 42, 34, .055);
  font-family: Inter, Pretendard, "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); min-width: 320px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.logout-form { margin: 0; }

.login-page { min-height: 100vh; background: linear-gradient(145deg, #10251e 0%, #1b3c31 48%, #eff6f2 48%); }
.login-shell { min-height: 100vh; min-width: 0; padding: 24px; display: grid; place-items: center; }
.login-card { width: min(420px, 100%); padding: 34px; border: 1px solid rgba(255,255,255,.5); border-radius: 20px; background: rgba(255,255,255,.98); box-shadow: 0 24px 70px rgba(4,20,14,.24); }
.login-brand { margin-bottom: 24px; }
.login-brand span { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 15px; color: var(--navy); background: var(--mint); font-size: 22px; font-weight: 900; transform: rotate(-4deg); }
.login-card h1 { margin-bottom: 10px; font-size: 27px; }
.login-help { margin-bottom: 22px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.login-error { margin-bottom: 18px; padding: 11px 13px; border-radius: 9px; color: #a53b39; background: var(--red-soft); font-size: 12px; font-weight: 700; }
.login-form { display: grid; gap: 9px; }
.login-form label { margin-top: 6px; color: #405048; font-size: 12px; font-weight: 800; }
.login-form input:not([type="hidden"]) { width: 100%; min-height: 48px; padding: 11px 13px; border: 1px solid #d7dfdb; border-radius: 10px; color: var(--ink); background: #fff; font-size: 16px; outline: none; }
.login-form input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(13,138,97,.12); }
.login-button { min-height: 48px; margin-top: 14px; font-size: 14px; }
.login-note { margin: 18px 0 0; color: #85918c; font-size: 10px; line-height: 1.6; text-align: center; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 26px 18px 20px; background: var(--navy); color: #fff; display: flex; flex-direction: column; z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 10px 30px; }
.brand-mark { width: 38px; height: 38px; border-radius: 12px; background: var(--mint); color: var(--navy); display: grid; place-items: center; font-weight: 900; font-size: 19px; transform: rotate(-4deg); }
.brand strong { display: block; font-size: 15px; letter-spacing: -.2px; }
.brand span { display: block; margin-top: 4px; color: #93a69f; font-size: 11px; }
nav { display: grid; gap: 6px; }
.nav-item { width: 100%; padding: 12px 13px; border: 0; border-radius: 10px; background: transparent; color: #9bada6; text-align: left; font-weight: 700; transition: .18s ease; }
.nav-item span { display: inline-grid; width: 26px; font-size: 17px; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-item.active { color: var(--mint); background: rgba(185,244,212,.1); }
.sidebar-bottom { margin-top: auto; padding: 16px 10px 4px; border-top: 1px solid rgba(255,255,255,.1); }
.system-dot-line { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #d1ddd8; }
.system-dot-line i { width: 8px; height: 8px; border-radius: 50%; background: #667670; }
.system-dot-line i.live { background: #45d498; box-shadow: 0 0 0 4px rgba(69,212,152,.13); }
.mini-info { margin: 11px 0 13px; color: #788b84; font-size: 10px; display: flex; justify-content: space-between; gap: 8px; }
.mini-info b { color: #a9b9b3; white-space: nowrap; }

main { min-width: 0; padding: 26px 34px 56px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; min-height: 70px; margin-bottom: 20px; }
.eyebrow { margin: 0 0 5px; color: var(--green); font-size: 10px; font-weight: 900; letter-spacing: 1.4px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 28px; letter-spacing: -1px; }
h2 { margin-bottom: 0; font-size: 18px; letter-spacing: -.45px; }
h3 { margin-bottom: 6px; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.badge, .status-pill { display: inline-flex; align-items: center; justify-content: center; border-radius: 999px; padding: 7px 10px; font-size: 10px; font-weight: 900; letter-spacing: .4px; background: #eef1ef; color: #53615c; white-space: nowrap; }
.badge.paper { color: #23648b; background: #e8f3fa; }
.badge.live { color: #a53b39; background: var(--red-soft); }
.badge.mock { color: #a85f20; background: var(--orange-soft); }
.badge.toss { color: var(--green-dark); background: var(--green-soft); }
.status-pill.safe { color: var(--green-dark); background: var(--green-soft); }
.status-pill.danger { color: var(--red); background: var(--red-soft); }

.button { border: 0; border-radius: 9px; padding: 10px 14px; font-weight: 800; font-size: 12px; transition: .15s ease; }
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.button.primary { background: var(--green); color: #fff; }
.button.secondary { color: var(--green-dark); background: var(--green-soft); }
.button.danger { color: #fff; background: var(--red); }
.button.danger.active { color: var(--red); background: var(--red-soft); box-shadow: inset 0 0 0 1px #f1bcba; }
.button.ghost { background: rgba(255,255,255,.06); color: #bdcac5; box-shadow: inset 0 0 0 1px rgba(255,255,255,.1); }
.panel .button.ghost { background: #f4f6f5; color: #4f5f59; box-shadow: inset 0 0 0 1px var(--line); }
.button.full { width: 100%; }
.text-button { border: 0; padding: 6px; color: var(--green); background: transparent; font-size: 11px; font-weight: 800; }

.notice { display: flex; gap: 12px; align-items: center; margin: 0 0 18px; padding: 12px 15px; border: 1px solid #f2d7bb; border-radius: 10px; color: #9b5a21; background: var(--orange-soft); font-size: 12px; }
.notice span { color: #8c6b50; }
.hidden { display: none !important; }
.page { display: none; }
.page.active { display: block; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; margin-bottom: 14px; }
.metric-card { min-height: 126px; padding: 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); }
.metric-card.accent { background: var(--navy); color: #fff; border-color: var(--navy); }
.metric-card > span { display: block; color: var(--muted); font-size: 11px; font-weight: 700; }
.metric-card.accent > span { color: #a4b3ad; }
.metric-card strong { display: block; margin: 13px 0 8px; font-size: 27px; letter-spacing: -1px; }
.metric-card strong.positive { color: var(--green); }
.metric-card strong.negative { color: var(--red); }
.metric-card strong em { margin-left: 3px; font-size: 12px; font-style: normal; color: var(--muted); }
.metric-card small { color: #8a9692; font-size: 10px; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(280px, .75fr); gap: 14px; margin-bottom: 14px; }
.panel { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { min-height: 76px; padding: 18px 20px 14px; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.panel-head.wrap { flex-wrap: wrap; align-items: flex-end; }
.subtext { margin: 7px 0 0; color: var(--muted); font-size: 11px; }
.hero-panel { min-height: 306px; }
.hero-content { padding: 0 20px 22px; display: grid; grid-template-columns: 155px 1fr; gap: 22px; }
.score-ring { --score: 0; width: 142px; height: 142px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--green) calc(var(--score) * 1%), #e9eeeb 0); position: relative; }
.score-ring::after { content: ""; position: absolute; inset: 12px; border-radius: 50%; background: #fff; }
.score-ring div { position: relative; z-index: 1; text-align: center; }
.score-ring strong { display: block; font-size: 39px; line-height: 1; }
.score-ring span { color: var(--muted); font-size: 10px; font-weight: 800; }
.top-stock-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 15px; }
.top-stock-head h3 { font-size: 21px; margin-bottom: 4px; }
.stock-code { color: var(--muted); font-size: 11px; }
.price-block { text-align: right; }
.price-block strong { display: block; }
.price-block .quote-time { display: block; margin-top: 3px; color: #8d9994; font-size: 8px; font-weight: 600; }
.detail-score .price-block .quote-time { color: #9fb0a9; }
.positive { color: var(--green) !important; }
.negative { color: var(--red) !important; }
.reason-chips { display: flex; flex-wrap: wrap; gap: 7px; margin: 12px 0 18px; }
.reason-chip { padding: 6px 8px; border-radius: 7px; color: #486058; background: #f0f5f2; font-size: 10px; font-weight: 700; }
.trade-plan { display: grid; grid-template-columns: repeat(4,1fr); gap: 8px; }
.trade-plan div { padding: 10px; border-radius: 8px; background: #f7f9f8; }
.trade-plan span { display: block; color: var(--muted); font-size: 9px; }
.trade-plan b { display: block; margin-top: 5px; font-size: 12px; }
.guard-panel { padding-bottom: 20px; }
.guard-list { padding: 0 20px 15px; display: grid; gap: 0; }
.guard-list div { display: flex; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 11px; }
.guard-list span { color: var(--muted); }
.guard-panel > .button, .guard-panel > .fine-print { width: calc(100% - 40px); margin-left: 20px; }
.auto-decision { width: calc(100% - 40px); margin: 12px 0 0 20px; padding: 11px 12px; border-radius: 9px; border: 1px solid var(--line); background: #f7f9f8; }
.auto-decision b, .auto-decision span, .auto-decision small { display: block; }
.auto-decision b { margin-bottom: 5px; color: #52615b; font-size: 9px; }
.auto-decision span { color: #71807a; font-size: 10px; line-height: 1.45; }
.auto-decision small { margin-top: 5px; color: #9aa39f; font-size: 8px; }
.auto-decision.bought { border-color: #bce5d3; background: var(--green-soft); }
.auto-decision.bought span { color: var(--green-dark); }
.auto-decision.skipped { border-color: #f1d4b7; background: var(--orange-soft); }
.auto-decision.skipped span { color: #8f612f; }
.fine-print { margin-top: 10px; margin-bottom: 0; color: #8a9591; font-size: 9px; line-height: 1.5; }
.empty-state { padding: 60px 20px; text-align: center; color: #9ba5a1; font-size: 12px; }

.table-panel { margin-top: 0; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th { padding: 11px 15px; color: #8a9591; background: #f8faf9; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: left; font-size: 9px; letter-spacing: .3px; }
td { padding: 14px 15px; border-bottom: 1px solid #edf0ee; font-size: 11px; }
tbody tr { transition: .12s ease; }
tbody tr.clickable:hover { background: #f5faf7; cursor: pointer; }
tbody tr:last-child td { border-bottom: 0; }
.stock-cell strong { display: block; font-size: 12px; }
.stock-cell span { display: block; margin-top: 3px; color: #919b97; font-size: 9px; }
.score-cell { min-width: 100px; }
.score-number { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 25px; border-radius: 7px; font-weight: 900; }
.score-number.strong { color: var(--green-dark); background: var(--green-soft); }
.score-number.watch { color: #a25e1e; background: var(--orange-soft); }
.score-number.low { color: #747f7b; background: #eef1ef; }
.signal { display: inline-flex; padding: 5px 8px; border-radius: 6px; font-size: 9px; font-weight: 900; }
.signal.strong { color: var(--green-dark); background: var(--green-soft); }
.signal.watch { color: #a25e1e; background: var(--orange-soft); }
.signal.low { color: #68746f; background: #eef1ef; }
.legend { color: #85908c; font-size: 9px; }
.dot { display: inline-block; width: 7px; height: 7px; margin: 0 4px 0 10px; border-radius: 50%; }
.dot.strong { background: var(--green); }
.dot.watch { background: var(--orange); }

.filters { display: flex; gap: 8px; }
.universe-filters { flex-wrap: wrap; justify-content: flex-end; }
.universe-summary { display: flex; flex-wrap: wrap; gap: 10px 22px; padding: 0 20px 14px; color: var(--muted); font-size: 10px; }
.universe-summary b { color: var(--ink); }
.universe-notice { margin: 0 20px 14px; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 16px 20px 20px; color: var(--muted); font-size: 10px; }
input, select { min-height: 38px; padding: 8px 10px; color: var(--ink); border: 1px solid #dce2df; border-radius: 8px; background: #fff; outline: none; font-size: 11px; }
input:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(13,138,97,.09); }
.filters input { min-width: 190px; }
.two-col, .settings-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 14px; }
.backtest-toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin: 4px 0 18px; }
.backtest-metrics { margin-top: 0; }
.backtest-warning { margin-top: 14px; margin-bottom: 0; }
.event-list { padding: 0 20px 20px; }
.event-item { display: grid; grid-template-columns: 72px 105px 1fr 150px; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); font-size: 11px; }
.event-item:last-child { border-bottom: 0; }
.event-level { font-size: 9px; font-weight: 900; }
.event-level.SUCCESS { color: var(--green); }
.event-level.WARN, .event-level.ERROR { color: var(--red); }
.event-category { color: var(--muted); font-size: 9px; }
.event-time { color: #9aa39f; text-align: right; font-size: 9px; }

.form-grid { padding: 0 20px 22px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid label { display: grid; gap: 6px; color: #5d6a65; font-size: 10px; font-weight: 800; }
.form-grid .check-label { display: flex; align-items: center; gap: 8px; }
.check-label input { min-height: auto; width: 16px; height: 16px; accent-color: var(--green); }
.form-grid button { align-self: end; min-height: 38px; }
.setup-panel { padding-bottom: 20px; }
.setup-steps { margin: 0 20px 20px; padding: 0; list-style: none; counter-reset: steps; display: grid; gap: 12px; }
.setup-steps li { counter-increment: steps; position: relative; padding-left: 34px; color: #5e6b66; font-size: 11px; line-height: 1.55; }
.setup-steps li::before { content: counter(steps); position: absolute; left: 0; top: -2px; width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; color: var(--green-dark); background: var(--green-soft); font-size: 10px; font-weight: 900; }
code { padding: 2px 5px; border-radius: 4px; color: #2c5547; background: #edf3f0; font-size: 10px; }
.security-box { margin: 0 20px 16px; padding: 13px; border-radius: 10px; background: #f4f7f5; }
.security-box strong, .security-box span { display: block; }
.security-box strong { margin-bottom: 6px; font-size: 11px; }
.security-box span { color: #71807a; font-size: 10px; line-height: 1.55; }
.setup-panel > .button { width: calc(100% - 40px); margin-left: 20px; }

.drawer { position: fixed; inset: 0; z-index: 100; pointer-events: none; visibility: hidden; }
.drawer.open { pointer-events: auto; visibility: visible; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(8,21,16,.45); opacity: 0; transition: opacity .22s ease; }
.drawer.open .drawer-backdrop { opacity: 1; }
.drawer-panel { position: absolute; top: 0; right: 0; width: min(600px, 92vw); height: 100%; padding: 28px; overflow-y: auto; background: #fff; transform: translateX(100%); transition: transform .25s ease; box-shadow: -15px 0 50px rgba(0,0,0,.12); }
.drawer.open .drawer-panel { transform: translateX(0); }
.drawer-close { position: absolute; right: 20px; top: 18px; border: 0; background: transparent; color: #71807a; font-size: 28px; }
.detail-header { padding-right: 40px; }
.detail-header h2 { font-size: 25px; margin: 7px 0 5px; }
.detail-score { display: flex; align-items: center; gap: 14px; margin: 22px 0; padding: 17px; border-radius: 12px; background: var(--navy); color: #fff; }
.detail-score strong { font-size: 34px; }
.detail-score span { color: #a9b9b3; font-size: 10px; }
.chart-wrap { margin: 20px 0; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
.chart-wrap svg { display: block; width: 100%; height: 180px; }
.factor-list { display: grid; gap: 12px; margin: 18px 0; }
.factor-row { display: grid; grid-template-columns: 88px 1fr 42px; align-items: center; gap: 10px; font-size: 10px; }
.factor-bar { height: 7px; border-radius: 10px; background: #e9eeeb; overflow: hidden; }
.factor-bar i { display: block; height: 100%; border-radius: inherit; background: var(--green); }
.factor-note { color: #89948f; font-size: 9px; }
.detail-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; }
.warning-box { padding: 10px 12px; border-radius: 8px; color: var(--red); background: var(--red-soft); font-size: 10px; }
.disclaimer { margin-top: 18px; color: #8b9691; font-size: 9px; line-height: 1.6; }

.toast { position: fixed; left: 50%; bottom: 26px; z-index: 200; transform: translate(-50%, 20px); padding: 11px 16px; border-radius: 9px; color: #fff; background: var(--navy); font-size: 11px; font-weight: 800; opacity: 0; pointer-events: none; transition: .2s ease; box-shadow: 0 8px 30px rgba(0,0,0,.18); }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.error { background: var(--red); }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid, .two-col, .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .login-shell { padding: 18px; }
  .login-card { padding: 27px 22px; border-radius: 16px; }
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 14px; }
  .brand { padding-bottom: 14px; }
  nav { display: flex; overflow-x: auto; }
  .nav-item { width: auto; min-width: max-content; }
  .sidebar-bottom { display: none; }
  main { padding: 18px 14px 40px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .backtest-toolbar { align-items: flex-start; flex-direction: column; }
  .top-actions { justify-content: flex-start; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric-card { min-height: 110px; padding: 16px; }
  .hero-content { grid-template-columns: 1fr; }
  .score-ring { margin: auto; }
  .trade-plan { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .event-item { grid-template-columns: 60px 85px 1fr; }
  .event-time { display: none; }
}
@media (max-width: 460px) {
  .metric-grid { grid-template-columns: 1fr; }
  .filters { width: 100%; flex-direction: column; }
  .filters input { min-width: 0; width: 100%; }
}
