:root {
  color-scheme: light;
  --ink: #122126;
  --muted: #63757c;
  --line: #d8e2e4;
  --paper: #f6f8f7;
  --card: #ffffff;
  --navy: #07171d;
  --mint: #04b985;
  --mint-soft: #dff7ef;
  --gold: #d9a441;
  --gold-soft: #fbf1d9;
  --blue: #5277d9;
  --cash: #c7d1d4;
  --danger: #c64a51;
  --shadow: 0 14px 40px rgba(15, 42, 48, .07);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }

[hidden] { display: none !important; }
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 20%, rgba(4,185,133,.18), transparent 27%),
    radial-gradient(circle at 84% 72%, rgba(82,119,217,.17), transparent 30%),
    var(--navy);
}
.login-card {
  width: min(440px, 100%);
  padding: 44px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 28px;
  background: rgba(255,255,255,.97);
  box-shadow: 0 32px 80px rgba(0,0,0,.3);
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: var(--mint);
  color: #06231c;
  font-weight: 900;
  letter-spacing: -.06em;
}
.brand-mark.small { width: 40px; height: 40px; border-radius: 13px; font-size: 13px; }
.login-card h1 { margin: 8px 0; font-size: 34px; letter-spacing: -.05em; }
.eyebrow { margin: 20px 0 3px; font-size: 12px; font-weight: 800; letter-spacing: .16em; color: #168064; }
.eyebrow.mint { color: #57dcb8; }
.muted { color: var(--muted); }
.stack-form { display: grid; gap: 16px; margin-top: 28px; }
label { display: grid; gap: 7px; color: #4f626a; font-size: 13px; font-weight: 700; }
input, select {
  width: 100%;
  min-height: 46px;
  padding: 10px 13px;
  border: 1px solid #cbd7da;
  border-radius: 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
}
input:focus, select:focus { border-color: var(--mint); box-shadow: 0 0 0 3px rgba(4,185,133,.12); }
.primary, .secondary, .danger, .ghost {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid transparent;
  padding: 0 17px;
  font-weight: 800;
}
.primary { background: var(--mint); color: #06231c; }
.secondary { border-color: #cbdadd; background: #f7faf9; color: var(--ink); }
.danger { background: #fff2f2; border-color: #f0c4c6; color: #a03239; }
.ghost { min-height: 36px; background: transparent; border-color: rgba(255,255,255,.14); color: #b9c7cc; }
.ghost-link { display: inline-flex; align-items: center; text-decoration: none; }
.full { width: 100%; margin-top: 18px; }
.security-note { margin: 24px 0 0; color: #7f8e93; font-size: 12px; text-align: center; }
.form-error, .form-message { min-height: 20px; margin: 0; color: var(--danger); font-size: 13px; }
.form-message.ok { color: #08765a; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 12px max(24px, calc((100vw - 1440px) / 2));
  background: rgba(7,23,29,.96);
  backdrop-filter: blur(16px);
  color: white;
}
.brand { display: flex; gap: 12px; align-items: center; color: white; text-decoration: none; }
.brand b, .brand small { display: block; }
.brand b { letter-spacing: .08em; }
.brand small { color: #88a0a8; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.chip, .tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 11px;
  background: var(--mint-soft);
  color: #08684f;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.chip.dark { background: rgba(255,255,255,.08); color: #bcd0d6; border: 1px solid rgba(255,255,255,.08); }
.tag.preview { background: #eef2f3; color: #64757b; }
.tag.manual { background: var(--gold-soft); color: #805915; }

.page { width: min(1440px, calc(100% - 48px)); margin: 0 auto; padding: 36px 0 80px; }
.panel { border: 1px solid var(--line); border-radius: 24px; background: var(--card); box-shadow: var(--shadow); padding: 28px; }
.dark-panel { background: var(--navy); border-color: #173038; color: white; }
.hero { display: grid; grid-template-columns: 1.5fr .8fr; gap: 48px; align-items: center; min-height: 260px; padding: 38px; overflow: hidden; position: relative; }
.hero::after { content: ""; position: absolute; width: 360px; height: 360px; border: 60px solid rgba(4,185,133,.045); border-radius: 50%; right: -170px; top: -210px; }
.hero h1 { max-width: 760px; margin: 6px 0 10px; font-size: clamp(30px, 4vw, 52px); line-height: 1.12; letter-spacing: -.055em; }
.hero-copy { color: #9fb1b7; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 24px; }
.hero-status { position: relative; z-index: 1; display: grid; grid-template-columns: 1fr 1fr; border: 1px solid #253b43; border-radius: 20px; background: rgba(255,255,255,.025); }
.hero-status div { padding: 18px; border-bottom: 1px solid #253b43; }
.hero-status div:nth-child(odd) { border-right: 1px solid #253b43; }
.hero-status div:nth-last-child(-n+2) { border-bottom: 0; }
.hero-status span, .hero-status strong { display: block; }
.hero-status span { color: #80959d; font-size: 12px; margin-bottom: 4px; }
.hero-status strong { font-size: 14px; }
.safe { color: #54d8b4; }

.data-gate-banner { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-top: 20px; padding: 18px 22px; border: 1px solid; border-radius: 18px; }
.data-gate-banner > div:first-child { min-width: 0; }
.data-gate-banner span { display: inline-block; margin-right: 9px; padding: 4px 8px; border-radius: 8px; font-size: 11px; font-weight: 900; letter-spacing: .08em; }
.data-gate-banner b { font-size: 15px; }
.data-gate-banner p { margin: 5px 0 0; font-size: 12px; }
.data-gate-banner.pass { border-color: #a9dacb; background: var(--mint-soft); color: #165d4c; }
.data-gate-banner.pass span { background: #08775a; color: white; }
.data-gate-banner.hold { border-color: #e6c9a0; background: var(--gold-soft); color: #75541d; }
.data-gate-banner.hold span { background: #9c6811; color: white; }
.provider-states { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.provider-states em { padding: 5px 9px; border-radius: 999px; background: rgba(255,255,255,.65); font-size: 11px; font-style: normal; font-weight: 800; white-space: nowrap; }

.backtest-panel { margin-top: 20px; scroll-margin-top: 92px; }
.backtest-layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(300px, .8fr); gap: 22px; align-items: start; margin-top: 22px; }
.backtest-form { padding: 20px; border: 1px solid var(--line); border-radius: 18px; background: #fbfcfc; }
.field-hint { margin: -3px 0 2px; color: #718188; font-size: 11px; line-height: 1.55; }
.field-hint.invalid { color: #b43838; font-weight: 800; }
.snapshot-card { padding: 22px; border-radius: 18px; background: var(--navy); color: white; }
.snapshot-topline { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.snapshot-topline span { padding: 4px 8px; border-radius: 999px; background: rgba(4,185,133,.16); color: #65dbba; font-size: 11px; font-weight: 800; }
.snapshot-card dl { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 18px 0; }
.snapshot-card dl div { padding: 12px; border: 1px solid #263c44; border-radius: 12px; }
.snapshot-card dt { color: #80959d; font-size: 10px; }.snapshot-card dd { margin: 3px 0 0; font-size: 13px; font-weight: 800; overflow-wrap: anywhere; }
.snapshot-card p { margin: 0; color: #97aab0; font-size: 12px; line-height: 1.7; }
.backtest-status { margin-top: 20px; padding: 18px; border: 1px solid #c9dfe0; border-radius: 16px; background: #f0f7f6; }
.backtest-status > div:first-child { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.backtest-status span { color: #61757c; font-size: 12px; }
.progress-track { height: 9px; margin-top: 13px; overflow: hidden; border-radius: 999px; background: #dce8e7; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--mint), #54d8b4); transition: width .35s ease; }
.backtest-result { margin-top: 22px; padding-top: 22px; border-top: 1px solid var(--line); }
.result-context { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; }
.result-context b { font-size: 21px; }.result-context span { color: #73858b; font-size: 12px; text-align: right; }
.backtest-metrics { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; margin: 18px 0; }
.backtest-metrics div { padding: 15px; border: 1px solid var(--line); border-radius: 14px; background: #fbfcfc; }
.backtest-metrics span, .backtest-metrics strong, .backtest-metrics small { display: block; }
.backtest-metrics span { color: #718188; font-size: 11px; }.backtest-metrics strong { margin: 4px 0 2px; font-size: 19px; }.backtest-metrics small { color: #8b989d; font-size: 10px; }
.chart-panel { padding: 18px; border: 1px solid var(--line); border-radius: 18px; background: #fbfcfc; overflow: hidden; }
.chart-panel h3, .backtest-detail-grid h3, .revision-history h3 { margin: 0 0 8px; font-size: 16px; }
.chart-panel .section-heading { margin-bottom: 4px; }.chart-panel .section-heading p { margin: 2px 0 0; font-size: 11px; }
.backtest-chart { width: 100%; min-height: 240px; overflow: visible; }
.backtest-detail-grid { margin-top: 18px; }.backtest-detail-grid > div { min-width: 0; padding: 17px; border: 1px solid var(--line); border-radius: 16px; }
.backtest-notes { margin-top: 16px; padding: 15px 17px; border-radius: 13px; background: #f2f6f5; color: #5c7077; font-size: 12px; }
.backtest-notes summary { cursor: pointer; color: #176f59; font-weight: 800; }.backtest-notes ul { margin-bottom: 0; padding-left: 20px; }
.backtest-history-tabs { align-items: center; justify-content: space-between; margin-top: 24px; padding-bottom: 10px; color: #54686f; font-size: 13px; }
#backtest-history button { min-height: 32px; padding: 4px 9px; border: 1px solid #c8d8da; border-radius: 8px; background: #f8fbfa; color: #176f59; font-weight: 800; }
.revision-history { margin-top: 20px; padding: 18px; border: 1px solid #e8c8ca; border-radius: 16px; background: #fff8f8; }

.workflow-strip { display: grid; grid-template-columns: repeat(6, 1fr); margin: 20px 0; border: 1px solid var(--line); border-radius: 18px; overflow: hidden; background: white; }
.workflow-strip div { position: relative; display: flex; gap: 9px; align-items: center; padding: 14px; font-size: 12px; color: #52666d; }
.workflow-strip div:not(:last-child) { border-right: 1px solid var(--line); }
.workflow-strip b { display: grid; place-items: center; min-width: 24px; height: 24px; border-radius: 8px; background: var(--mint-soft); color: #08775a; }

.grid { display: grid; gap: 20px; margin-top: 20px; }
.two-one { grid-template-columns: minmax(0, 2fr) minmax(330px, 1fr); }
.half { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.section-heading .eyebrow { margin-top: 0; }
.section-heading h2 { margin: 0; letter-spacing: -.04em; font-size: 24px; }
.inline-form { display: flex; gap: 12px; align-items: end; margin: 20px 0 14px; }
.inline-form label { flex: 1; }
.notice { padding: 13px 15px; border-radius: 12px; background: #eef5f4; color: #51676e; font-size: 13px; }
.notice.bad { background: #fff0f0; color: #9a343a; }
.notice.good { background: var(--mint-soft); color: #08684f; }

.allocation-layout { display: grid; grid-template-columns: 190px 1fr; gap: 24px; align-items: center; margin-top: 24px; }
.allocation-ring { display: grid; place-items: center; width: 176px; height: 176px; border-radius: 50%; background: conic-gradient(var(--cash) 0 100%); position: relative; }
.allocation-ring::after { content: ""; position: absolute; width: 112px; height: 112px; border-radius: 50%; background: white; }
.allocation-ring span { position: relative; z-index: 1; color: #6a7b81; text-align: center; font-size: 12px; }
.allocation-ring b { color: var(--ink); font-size: 20px; }
.allocation-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.allocation-cards > div { position: relative; padding: 16px; border: 1px solid var(--line); border-radius: 15px; background: #fbfcfc; }
.allocation-cards p { margin: 4px 0 0; font-size: 13px; color: #596c73; }
.allocation-cards strong { display: block; margin: 2px 0; font-size: 26px; }
.allocation-cards small { color: #829096; }
.dot { position: absolute; right: 13px; top: 13px; width: 8px; height: 8px; border-radius: 50%; }
.dot.qld { background: var(--mint); }.dot.gld { background: var(--gold); }.dot.cash { background: var(--cash); }
.action-row { display: flex; align-items: center; gap: 16px; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.action-row p { margin: 0; color: #89979b; font-size: 12px; }

.rule-list { display: grid; gap: 10px; }
.rule-row { display: grid; grid-template-columns: 38px 1fr auto; gap: 11px; align-items: center; padding: 14px 0; border-bottom: 1px solid #e6ecee; }
.rule-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 11px; background: #eef4f3; color: #0d8061; font-weight: 900; }
.rule-row b, .rule-row small { display: block; }.rule-row small { color: #829096; }
.rule-row strong { font-size: 13px; }
.state-on { color: var(--danger); }.state-off { color: #08775a; }
.data-contract { display: flex; gap: 11px; align-items: center; margin-bottom: 12px; padding: 13px 14px; border: 1px solid #d9e6e3; border-radius: 14px; background: #f3f8f7; }
.data-contract b, .data-contract small { display: block; }
.data-contract b { font-size: 13px; }.data-contract small { color: #71838a; margin-top: 2px; }
.live-dot { width: 10px; height: 10px; flex: 0 0 10px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 5px rgba(217,164,65,.16); }
.rule-help { margin: -10px 0 2px 49px; padding: 0 0 11px; border-bottom: 1px solid #e6ecee; color: #61737a; font-size: 12px; }
.rule-help summary { cursor: pointer; width: max-content; color: #188064; font-weight: 800; list-style-position: inside; }
.rule-help p { margin: 8px 0 0; padding: 11px 12px; border-radius: 10px; background: #f5f8f8; line-height: 1.65; }
.rule-result { margin-top: 18px; padding: 20px; border-radius: 16px; background: var(--navy); color: white; }
.rule-result span, .rule-result strong, .rule-result small { display: block; }
.rule-result span { color: #8ba0a7; font-size: 12px; }.rule-result strong { margin: 3px 0; font-size: 24px; }.rule-result small { color: #9dafb5; }
.signal-source-box { margin-top: 12px; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: #fbfcfc; }
.signal-source-box > b { font-size: 13px; }.signal-source-box > p { margin: 5px 0 13px; color: #718188; font-size: 12px; }
.signal-source-box dl { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; }
.signal-source-box dl div { padding: 9px 10px; border-radius: 9px; background: #eef4f3; }
.signal-source-box dt { color: #718188; font-size: 10px; }.signal-source-box dd { margin: 2px 0 0; font-size: 12px; font-weight: 800; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.form-grid .wide { grid-column: 1 / -1; }
.compact-panel { align-self: start; }
.metric-row { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 15px; overflow: hidden; }
.metric-row div { padding: 15px; }.metric-row div:not(:last-child) { border-right: 1px solid var(--line); }
.metric-row span, .metric-row strong { display: block; }.metric-row span { color: #718289; font-size: 12px; }.metric-row strong { margin-top: 3px; }
.empty-state { padding: 34px 20px; border: 1px dashed #c9d7da; border-radius: 16px; text-align: center; color: #77888e; }
.empty-state b { color: #4c6067; }.empty-state p { margin-bottom: 0; }
.order-list { display: grid; gap: 8px; margin-top: 14px; }
.order-item { display: grid; grid-template-columns: 70px 70px 1fr auto; gap: 10px; align-items: center; padding: 13px; border-radius: 12px; background: #f2f7f6; }
.order-item .buy { color: #0b8061; }.order-item .sell { color: var(--danger); }
.warning { padding: 12px; border-radius: 10px; background: var(--gold-soft); color: #7b5a21; font-size: 12px; }
.replay-actions { display: flex; gap: 9px; margin: 20px 0 12px; }.replay-actions button { flex: 1; }

.history-panel { margin-top: 20px; }
.history-tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); }
.tab { padding: 10px 14px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: #74858b; font-weight: 800; }
.tab.active { border-color: var(--mint); color: #08775a; }
.table-wrap { overflow-x: auto; min-height: 140px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 14px 12px; border-bottom: 1px solid #e4eaec; text-align: left; white-space: nowrap; }
th { color: #6f8086; font-size: 11px; letter-spacing: .04em; }
td strong { color: var(--ink); }.empty-cell { padding: 42px; text-align: center; color: #829096; }
.principle-banner { display: flex; gap: 22px; align-items: center; margin-top: 20px; padding: 20px 24px; border: 1px solid #bbdfd4; border-radius: 18px; background: var(--mint-soft); }
.principle-banner p { margin: 0; color: #37675a; }
.toast { position: fixed; z-index: 100; right: 24px; bottom: 24px; max-width: 380px; padding: 14px 18px; border-radius: 13px; background: var(--navy); color: white; box-shadow: 0 12px 40px rgba(0,0,0,.22); opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1000px) {
  .two-one, .half, .hero, .backtest-layout { grid-template-columns: 1fr; }
  .backtest-metrics { grid-template-columns: repeat(3, 1fr); }
  .workflow-strip { grid-template-columns: repeat(3, 1fr); }
  .workflow-strip div:nth-child(3) { border-right: 0; }
  .workflow-strip div:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
}
@media (max-width: 680px) {
  .page { width: min(100% - 24px, 1440px); padding-top: 14px; }
  .topbar { padding: 10px 12px; }.header-actions .chip { display: none; }
  .hero, .panel { padding: 20px; border-radius: 18px; }
  .hero-status, .form-grid, .allocation-cards { grid-template-columns: 1fr; }
  .hero-status div, .hero-status div:nth-child(odd) { border-right: 0; border-bottom: 1px solid #253b43; }
  .hero-status div:last-child { border-bottom: 0; }
  .workflow-strip { grid-template-columns: 1fr 1fr; }.workflow-strip div { border: 0 !important; border-bottom: 1px solid var(--line) !important; }
  .allocation-layout { grid-template-columns: 1fr; }.allocation-ring { margin: auto; }
  .inline-form, .action-row, .principle-banner, .data-gate-banner { align-items: stretch; flex-direction: column; }
  .provider-states { justify-content: flex-start; }
  .metric-row { grid-template-columns: 1fr; }.metric-row div:not(:last-child) { border-right: 0; border-bottom: 1px solid var(--line); }
  .signal-source-box dl { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .login-card { padding: 30px 24px; }
  .backtest-metrics, .snapshot-card dl { grid-template-columns: 1fr 1fr; }
  .result-context, .backtest-status > div:first-child { align-items: flex-start; flex-direction: column; }
}
