:root {
  color-scheme: dark;
  font-size: 17px;
  --bg: #050b13;
  --panel: #0a1421;
  --panel-2: #0d1a29;
  --line: #1c2d40;
  --text: #e7eef8;
  --muted: #8192a6;
  --cyan: #42e8d8;
  --green: #25dc87;
  --red: #ff5f74;
  --amber: #ffc857;
  --blue: #4a9eff;
  --radius: 14px;
  font-family: Inter, Pretendard, "Noto Sans KR", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 70% -20%, rgba(26, 81, 112, .28), transparent 40%),
    linear-gradient(160deg, #06101b, var(--bg) 45%);
}
button, input, select { font: inherit; }
button { cursor: pointer; }
.mono { font-family: "JetBrains Mono", Consolas, monospace; }
.muted { color: var(--muted); font-size: .74rem; }

.topbar {
  min-height: 76px;
  padding: 15px clamp(16px, 2.5vw, 34px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(4, 11, 19, .8);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 { margin: 1px 0 0; font-size: 1.45rem; letter-spacing: .16em; }
.brand-area { display: flex; align-items: center; gap: 13px; }
.menu-button {
  width: 42px; height: 42px; flex: 0 0 42px; display: grid; place-content: center; gap: 5px;
  border: 1px solid var(--line); border-radius: 9px; background: #091522; color: var(--text);
}
.menu-button:hover, .menu-button[aria-expanded="true"] { border-color: rgba(66, 232, 216, .5); background: rgba(66, 232, 216, .08); }
.menu-button span { display: block; width: 18px; height: 2px; border-radius: 2px; background: currentColor; }
.eyebrow { margin: 0; color: var(--cyan); font-size: .58rem; letter-spacing: .22em; }
.system-status { display: flex; align-items: center; gap: 18px; font-size: .68rem; color: var(--muted); letter-spacing: .08em; }
.system-status span { white-space: nowrap; }
.system-status strong { color: var(--text); margin-left: 4px; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; background: var(--amber); box-shadow: 0 0 10px currentColor; }
.dot.online { background: var(--green); }
.dot.offline { background: var(--red); }
.dot.mock { background: var(--blue); }
.chart-stream-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); font-size: .7rem; }
.chart-stream-toolbar strong { color: var(--cyan); }
.chart-stream-toolbar > span { color: var(--muted); flex: 1 1 220px; }
.chart-live-note { margin: 0; padding: 6px 14px 12px; color: var(--muted); font-size: .68rem; line-height: 1.6; }

.nav-backdrop { position: fixed; inset: 0; z-index: 69; background: rgba(0, 5, 11, .7); backdrop-filter: blur(3px); }
.nav-drawer {
  position: fixed; inset: 0 auto 0 0; z-index: 70; width: min(330px, 88vw); padding: 20px;
  display: flex; flex-direction: column; border-right: 1px solid var(--line);
  background: linear-gradient(160deg, #0c1928, #050c15 68%); box-shadow: 24px 0 70px rgba(0, 0, 0, .48);
  transform: translateX(-104%); transition: transform .22s ease;
}
.nav-drawer.open { transform: translateX(0); }
.nav-head { min-height: 62px; display: flex; align-items: flex-start; justify-content: space-between; border-bottom: 1px solid var(--line); }
.nav-head strong { display: block; margin-top: 6px; font-size: 1.05rem; letter-spacing: .12em; }
.nav-close { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); background: transparent; font-size: 1.2rem; }
.nav-list { display: grid; gap: 7px; margin-top: 18px; }
.nav-item {
  display: grid; grid-template-columns: 28px 1fr; gap: 3px 9px; width: 100%; padding: 13px;
  border: 1px solid transparent; border-radius: 9px; color: var(--muted); background: transparent; text-align: left;
}
.nav-item > span { grid-row: 1 / span 2; color: var(--cyan); font: .58rem Consolas, monospace; padding-top: 2px; }
.nav-item strong { color: var(--text); font-size: .76rem; }
.nav-item small { color: var(--muted); font: .56rem Consolas, monospace; }
.nav-item:hover, .nav-item.active { border-color: rgba(66, 232, 216, .18); background: rgba(66, 232, 216, .07); }
.nav-item.active strong { color: var(--cyan); }
.nav-foot { margin: auto 0 0; padding-top: 15px; border-top: 1px solid var(--line); color: var(--amber); font: .55rem Consolas, monospace; letter-spacing: .08em; }
body.menu-open { overflow: hidden; }

.auth-gate { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 18px; overflow-y: auto; background: radial-gradient(circle at 50% 20%, rgba(29, 94, 120, .26), transparent 42%), rgba(3, 9, 16, .97); }
.auth-card { width: min(420px, 100%); padding: 30px; border: 1px solid var(--line); border-radius: 16px; background: linear-gradient(145deg, #0d1b2b, #07111d); box-shadow: 0 28px 80px rgba(0, 0, 0, .45); }
.auth-card h1 { margin: 8px 0; font-size: 1.45rem; letter-spacing: .04em; }
.auth-description { min-height: 42px; margin: 0 0 18px; color: var(--muted); font-size: .72rem; line-height: 1.65; }
.auth-card label { display: block; margin-top: 11px; color: var(--muted); font-size: .68rem; }
.auth-submit { width: 100%; margin: 18px 0 0; min-height: 48px; }
.auth-error { min-height: 20px; margin: 10px 0 0; color: var(--red); font-size: .65rem; }
.auth-note { margin: 12px 0 0; color: var(--muted); font-size: .57rem; line-height: 1.55; }
.auth-server-status { margin-bottom: 16px; padding: 13px; border: 1px solid var(--line); border-radius: 9px; background: rgba(255, 200, 87, .05); font-size: .75rem; line-height: 1.6; }
.auth-server-status strong { color: var(--amber); }
.auth-server-status p { margin: 5px 0 0; color: var(--muted); }
.auth-server-status button { margin-top: 10px; width: 100%; min-height: 40px; }
.auth-server-status[data-connection="offline"] { border-color: var(--red); background: rgba(255, 95, 116, .07); }
.auth-server-status[data-connection="offline"] strong { color: var(--red); }
.auth-server-status[data-connection="online"] strong { color: var(--green); }
.auth-submit:disabled { cursor: not-allowed; opacity: .5; }
.server-notice { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin: 14px; padding: 14px; border: 1px solid var(--red); border-radius: 9px; background: #271522; font-size: .8rem; line-height: 1.6; }
.server-notice strong { color: var(--red); }
.server-notice span { flex: 1 1 250px; }

.workspace {
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(175px, .55fr) minmax(680px, 3fr) minmax(185px, .65fr);
  gap: 12px;
  max-width: 1920px;
  margin: 0 auto;
}
.panel {
  background: linear-gradient(145deg, rgba(13, 27, 43, .96), rgba(7, 16, 27, .97));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 14px 45px rgba(0, 0, 0, .18);
  overflow: hidden;
}
.panel-title { display: flex; justify-content: space-between; align-items: center; padding: 15px 16px; border-bottom: 1px solid var(--line); }
.panel-title > div { display: flex; align-items: center; gap: 9px; }
.panel-title h2 { margin: 0; font-size: .78rem; letter-spacing: .07em; }
.index { font-size: .62rem; color: var(--cyan); font-family: Consolas, monospace; }
.panel-meta { display: flex; align-items: center; gap: 10px; }
.data-source { display: inline-flex; align-items: center; padding: 4px 7px; border: 1px solid rgba(37, 220, 135, .32); border-radius: 99px; color: var(--green); font: .55rem Consolas, monospace; letter-spacing: .04em; }
.data-source.mock { color: var(--amber); border-color: rgba(255, 200, 87, .3); }
.data-source.error { color: var(--red); border-color: rgba(255, 95, 116, .4); }

.watch-panel, .book-panel { min-height: 515px; }
.watchlist-toolbar {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px;
  padding: 10px 10px 8px; border-bottom: 1px solid var(--line);
}
.watchlist-toolbar label { color: var(--muted); font-size: .61rem; white-space: nowrap; }
.watchlist-toolbar select { min-width: 0; padding: 7px 8px; font-size: .7rem; }
.watchlist-toolbar .ghost { padding: 7px 9px; }
.watchlist-status { padding: 8px 10px 0; color: var(--muted); font-size: .61rem; line-height: 1.45; }
.watchlist { padding: 7px; }
.watchlist-empty { padding: 22px 10px; color: var(--muted); font-size: .72rem; line-height: 1.6; text-align: center; }
.watch-row {
  width: 100%; border: 0; border-left: 2px solid transparent; color: var(--text); background: transparent;
  display: grid; grid-template-columns: 1fr auto; gap: 6px; text-align: left; padding: 13px 10px; border-radius: 7px;
}
.watch-row:hover { background: rgba(66, 232, 216, .055); }
.watch-row.active { border-left-color: var(--cyan); background: rgba(66, 232, 216, .09); }
.watch-name { font-size: .82rem; font-weight: 700; }
.watch-symbol { display: block; color: var(--muted); font: .62rem Consolas, monospace; margin-top: 4px; }
.watch-quote { text-align: right; font: .75rem Consolas, monospace; }
.watch-change { display: block; margin-top: 4px; font-size: .63rem; }
.up { color: var(--red) !important; }
.down { color: var(--blue) !important; }

.main-column { display: grid; gap: 14px; min-width: 0; align-content: start; align-self: start; container-type: inline-size; container-name: trade-main; }
.market-panel { min-height: 365px; }
.quote-head { display: flex; align-items: flex-end; justify-content: space-between; padding: 18px 20px 7px; }
.quote-head h2 { display: inline; font-size: 1.04rem; margin: 0 0 0 8px; }
.quote-head .data-source { margin-left: 8px; vertical-align: 2px; }
.symbol { color: var(--muted); font: .68rem Consolas, monospace; }
.quote-price { text-align: right; }
.quote-price strong { display: block; font: 1.75rem Consolas, monospace; }
.quote-price span { font: .75rem Consolas, monospace; }
.chart-tabs { display: flex; align-items: center; gap: 3px; padding: 0 15px; }
.chart-tab, .ghost { border: 1px solid transparent; color: var(--muted); background: transparent; padding: 8px 10px; border-radius: 6px; font-size: .7rem; }
.chart-tab.active { color: var(--cyan); background: rgba(66, 232, 216, .08); border-color: rgba(66, 232, 216, .16); }
.ma-legend { display: inline-flex; align-items: center; gap: 9px; margin-left: 9px; color: var(--muted); font: .6rem Consolas, monospace; }
.ma-item { display: inline-flex; align-items: center; gap: 4px; }
.ma-item i { display: inline-block; width: 13px; height: 2px; border-radius: 2px; background: currentColor; }
.ma5 { color: #ffc857; }
.ma10 { color: #f08cff; }
.ma20 { color: #42e8d8; }
.ma60 { color: #e7eef8; }
.live-mark { margin-left: auto; color: var(--muted); font-size: .58rem; letter-spacing: .08em; }
.pulse { display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: var(--green); margin-right: 5px; animation: pulse 1.3s infinite; }
@keyframes pulse { 50% { opacity: .3; box-shadow: 0 0 10px var(--green); } }
.canvas-wrap { position: relative; height: 300px; padding: 8px 12px 14px; }
#priceChart {
  display: block; width: 100%; height: 100%; touch-action: none; cursor: grab;
  user-select: none; -webkit-user-select: none;
}
#priceChart.chart-dragging { cursor: grabbing; }
.chart-tooltip {
  position: absolute; z-index: 5; min-width: 132px; pointer-events: none;
  padding: 8px 10px; border: 1px solid rgba(66, 232, 216, .48); border-radius: 7px;
  color: var(--text); background: rgba(4, 13, 24, .96); box-shadow: 0 8px 24px rgba(0, 0, 0, .36);
  font: .65rem/1.45 Consolas, monospace; white-space: nowrap;
}
.chart-tooltip strong { display: block; color: var(--cyan); font-size: .78rem; }
.chart-tooltip span { display: block; color: var(--muted); }
.chart-tooltip { max-width: min(460px, calc(100% - 12px)); white-space: normal; overflow-wrap: anywhere; }
.chart-tooltip .chart-signal-detail { margin-top: 6px; color: var(--text); }
.chart-reference-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; padding: 8px 14px 0; font-size: .68rem; color: var(--muted); }
.chart-reference-bar b { font-weight: 500; white-space: nowrap; }
.reference-support { color: #a9c7ff; }
.reference-breakout { color: #ffc857; }
.reference-structure { color: #f08cff; }
.ema-control { display: inline-flex; align-items: center; gap: 5px; color: #a3e635; cursor: pointer; white-space: nowrap; }
.ema-control input { width: 15px; height: 15px; margin: 0; padding: 0; accent-color: #a3e635; }
.ema-control[hidden] { display: none; }
.chart-reference-bar details { max-width: 100%; }
.chart-reference-bar summary { cursor: pointer; color: var(--text); }
.chart-reference-bar p { max-width: 80ch; line-height: 1.7; }
.chart-range { color: var(--cyan); font: .56rem Consolas, monospace; letter-spacing: .04em; white-space: nowrap; }

/* Explanations stay available without reserving three rows below the chart. */
.chart-help { position: relative; margin: 0 14px 8px; color: var(--muted); font-size: .68rem; }
.chart-help summary { cursor: pointer; color: var(--text); padding: 5px 0; }
.chart-help summary span { margin-left: 8px; color: var(--muted); }
.chart-help-content { position: absolute; z-index: 8; bottom: 100%; left: 0; right: 0; max-height: min(280px, 55dvh); overflow-y: auto; background: #091725; border: 1px solid #365366; border-radius: 8px; padding: 10px 14px; box-shadow: 0 -6px 25px #0008; }
.chart-help-content p, .chart-help-content .chart-live-note { margin: 0; padding: 5px 0; font-size: .68rem; line-height: 1.5; }

.order-panel { padding-bottom: 13px; }
.safety-tag { border: 1px solid rgba(255, 200, 87, .32); color: var(--amber); border-radius: 99px; padding: 4px 8px; font-size: .58rem; }
.order-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 9px; padding: 14px; }
.order-grid label { color: var(--muted); font-size: .64rem; }
.help-tip { display: inline-grid; place-items: center; width: 16px; height: 16px; margin-left: 3px; border: 1px solid var(--cyan); border-radius: 50%; color: var(--cyan); font: 800 .58rem sans-serif; cursor: help; }
.order-price-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; align-items: end; }
.order-price-row .compact { height: 39px; margin-top: 6px; padding-inline: 8px; white-space: nowrap; }
.order-price-field small { display: block; min-height: 1em; margin-top: 3px; color: var(--cyan); font-size: .55rem; }
select, input {
  width: 100%; height: 39px; margin-top: 6px; border: 1px solid var(--line); border-radius: 7px;
  color: var(--text); background: #07111d; padding: 0 10px; outline: none;
}
select:focus, input:focus { border-color: var(--cyan); box-shadow: 0 0 0 2px rgba(66, 232, 216, .1); }
.input-suffix { display: flex; position: relative; }
.input-suffix span { position: absolute; right: 10px; bottom: 10px; color: var(--muted); }
.target-return-field #targetReturn {
  padding-right: 48px; font: 800 .8rem Consolas, monospace; color: #f4fbff;
}
.target-return-field .input-suffix span {
  right: 31px; bottom: 9px; color: #f4fbff; font: 800 .76rem Consolas, monospace; pointer-events: none;
}
.buy-button {
  width: calc(100% - 28px); min-height: 54px; margin: 0 14px; border: 0; border-radius: 8px;
  color: #001813; background: linear-gradient(90deg, #20c987, var(--cyan)); font-weight: 900; letter-spacing: .1em;
  transition: transform .14s, filter .14s;
}
.buy-button:hover { transform: translateY(-1px); filter: brightness(1.08); }
.buy-button:disabled { opacity: .5; transform: none; }
.buy-button span { display: block; font-size: 1rem; }
.buy-button small { display: block; font-size: .58rem; opacity: .72; letter-spacing: .03em; }
.policy-note { color: var(--muted); margin: 10px 14px 0; font-size: .61rem; text-align: center; }

.book-header, .book-row { display: grid; grid-template-columns: 1fr 1fr; padding: 7px 15px; font: .68rem Consolas, monospace; }
.book-header { color: var(--muted); font-size: .58rem; }
.book-header span:last-child, .book-row span:last-child { text-align: right; }
.book-row { position: relative; overflow: hidden; }
.book-row::before { content: ""; position: absolute; height: 70%; top: 15%; right: 0; width: var(--depth); opacity: .09; }
.asks .book-row { color: #ff91a0; }
.asks .book-row::before { background: var(--red); }
.bids .book-row { color: #77b8ff; }
.bids .book-row::before { background: var(--blue); }
.mid-price { padding: 14px; border-block: 1px solid var(--line); text-align: center; font: 1.15rem Consolas, monospace; color: var(--cyan); }

.lots-panel { grid-column: 1 / -1; }
.count-chip { color: var(--cyan); font: .62rem Consolas, monospace; }
.lot-list { min-height: 95px; }
.empty-state { padding: 30px; color: var(--muted); text-align: center; font-size: .73rem; }
.lot-row {
  display: grid; grid-template-columns: 1.25fr .9fr .75fr .75fr 1fr auto; align-items: center;
  gap: 10px; padding: 13px 16px; border-top: 1px solid rgba(28, 45, 64, .7); font-size: .7rem;
}
.lot-row:first-child { border-top: 0; }
.lot-id { display: block; color: var(--muted); font: .56rem Consolas, monospace; margin-top: 3px; }
.venue { display: inline-block; margin-left: 6px; color: var(--cyan); font: .54rem Consolas, monospace; }
.state { display: inline-flex; align-items: center; gap: 5px; width: fit-content; padding: 5px 7px; border-radius: 4px; background: rgba(74, 158, 255, .1); color: #8ec2ff; font: .58rem Consolas, monospace; }
.state.OPEN { color: var(--green); background: rgba(37, 220, 135, .1); }
.state.CLOSED, .state.CANCELLED { color: var(--muted); background: rgba(129, 146, 166, .08); }
.lot-metric small { display: block; color: var(--muted); margin-bottom: 3px; }
.actions { display: flex; gap: 6px; justify-content: end; }
.action { border: 1px solid var(--line); border-radius: 5px; padding: 7px 9px; background: #0a1624; color: var(--text); font-size: .62rem; }
.action.cancel:hover { color: var(--amber); border-color: var(--amber); }
.action.sell { color: #ff8fa0; border-color: rgba(255, 95, 116, .35); }
.ghost.compact { padding: 5px 7px; border-color: var(--line); }

.ledger-panel { grid-column: 1 / -1; }
.ledger-summary { display: flex; flex-wrap: wrap; gap: 12px 24px; padding: 11px 16px; border-bottom: 1px solid var(--line); color: var(--muted); font: .58rem Consolas, monospace; }
.ledger-summary strong { color: var(--cyan); margin-left: 5px; }
.ledger-grid { display: grid; grid-template-columns: 1.35fr 1fr; }
.ledger-grid > section + section { border-left: 1px solid var(--line); }
.ledger-head { min-height: 48px; padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border-bottom: 1px solid rgba(28, 45, 64, .7); }
.ledger-head h3 { display: inline; margin: 0; font-size: .67rem; letter-spacing: .07em; }
.ledger-head span { margin-left: 7px; color: var(--muted); font-size: .55rem; }
.auth-actions { display: flex; gap: 6px; }
.auth-actions .action { padding: 6px 8px; }
.auth-actions .action:disabled { opacity: .35; cursor: default; }
.ledger-list { min-height: 160px; }
.ledger-row { display: grid; grid-template-columns: 1fr auto; gap: 7px; padding: 8px 14px; border-top: 1px solid rgba(28, 45, 64, .45); font-size: .63rem; }
.ledger-row:first-child { border-top: 0; }
.ledger-row strong { color: var(--text); }
.ledger-row small { display: block; margin-top: 3px; color: var(--muted); font: .53rem Consolas, monospace; }
.ledger-row time { color: var(--muted); font: .54rem Consolas, monospace; white-space: nowrap; }
.ledger-empty { padding: 30px 14px; color: var(--muted); text-align: center; font-size: .64rem; }

.kiwoom-panel { grid-column: 1 / -1; padding-bottom: 14px; }
.kiwoom-status-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 9px; padding: 14px 14px 0; }
.kiwoom-status-card { min-height: 70px; padding: 11px; border: 1px solid var(--line); border-radius: 8px; background: #07111d; }
.kiwoom-status-card span { display: block; color: var(--muted); font-size: .58rem; }
.kiwoom-status-card strong { display: block; margin-top: 8px; color: var(--text); font: .72rem Consolas, monospace; overflow-wrap: anywhere; }
.kiwoom-status-card strong.connected { color: var(--green); }
.kiwoom-status-card strong.disconnected { color: var(--amber); }
.kiwoom-connection-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 14px; }
.kiwoom-connection-toolbar p { margin: 0; color: var(--muted); font-size: .67rem; line-height: 1.6; }
.kiwoom-form { display: grid; grid-template-columns: .72fr 1fr 1fr .7fr auto; gap: 9px; align-items: end; margin: 0 14px 14px; padding: 14px; border: 1px solid var(--line); border-radius: 9px; }
.kiwoom-edit-note { grid-column: 1 / -1; margin: 0 0 6px; color: var(--amber); font-size: .64rem; line-height: 1.6; }
.kiwoom-form label { min-width: 0; color: var(--muted); font-size: .62rem; }
.kiwoom-buttons { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.kiwoom-buttons .action { min-height: 39px; white-space: nowrap; }
.kiwoom-buttons .kiwoom-primary { color: #001813; border-color: transparent; background: var(--cyan); font-weight: 800; }
.kiwoom-buttons .action:disabled { opacity: .42; cursor: default; }
.kiwoom-positions { margin: 0 14px 13px; border: 1px solid var(--line); border-radius: 9px; background: rgba(3, 10, 18, .42); overflow: hidden; }
.kiwoom-positions-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 12px; border-bottom: 1px solid var(--line); }
.kiwoom-positions-head strong { display: block; font-size: .68rem; }
.kiwoom-positions-head span { display: block; margin-top: 4px; color: var(--muted); font: .54rem Consolas, monospace; }
.kiwoom-positions-head .action:disabled { opacity: .42; cursor: default; }
.kiwoom-position-wrap { max-height: 270px; overflow: auto; }
.kiwoom-position-table { width: 100%; min-width: 860px; border-collapse: collapse; font-size: .6rem; }
.kiwoom-position-table th, .kiwoom-position-table td { padding: 9px 11px; border-bottom: 1px solid rgba(28, 45, 64, .52); text-align: right; font-family: Consolas, monospace; white-space: nowrap; }
.kiwoom-position-table th { position: sticky; top: 0; z-index: 1; color: var(--muted); background: #07111d; font-size: .53rem; }
.kiwoom-position-table th:first-child, .kiwoom-position-table td:first-child { text-align: left; }
.kiwoom-position-table td:first-child strong, .kiwoom-position-table td:first-child small { display: block; }
.kiwoom-position-table td:first-child small { margin-top: 3px; color: var(--muted); }
.kiwoom-notes { margin: 0 14px; padding: 10px 12px; border-left: 2px solid var(--cyan); background: rgba(66, 232, 216, .04); }
.kiwoom-notes p { margin: 0; color: var(--muted); font-size: .59rem; line-height: 1.65; }
.kiwoom-notes strong { color: var(--amber); }
.kiwoom-notes p + p { margin-top: 4px; }

.family-users { margin: 0 14px 13px; border: 1px solid var(--line); border-radius: 12px; background: rgba(7, 17, 31, .7); overflow: hidden; }
.family-users-head { display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.family-users-head strong { display: block; color: var(--text); font-size: .74rem; letter-spacing: .05em; }
.family-users-head span { display: block; margin-top: 3px; color: var(--muted); font-size: .59rem; line-height: 1.5; }
.family-user-form { display: grid; grid-template-columns: minmax(150px, .8fr) minmax(220px, 1.2fr) auto; align-items: end; gap: 9px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.family-user-form label { color: var(--muted); font-size: .62rem; }
.family-user-list { display: grid; }
.family-user-row { display: grid; grid-template-columns: 1fr auto auto minmax(155px, auto); align-items: center; gap: 14px; padding: 10px 14px; border-top: 1px solid rgba(35, 57, 77, .62); }
.family-user-row:first-child { border-top: 0; }
.family-user-row strong { font-size: .68rem; }
.family-user-row small { display: block; margin-top: 2px; color: var(--muted); font-size: .56rem; }
.family-user-role, .family-user-password { padding: 4px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--cyan); font-size: .56rem; }
.family-user-password.required { color: var(--amber); border-color: rgba(255, 190, 69, .36); }
.family-plan-select { min-width: 155px; padding: 7px 9px; font-size: .58rem; }
.family-plan-select:disabled { opacity: .62; }

.ai-view { max-width: 1500px; }
.ai-status-panel, .ai-review-panel { overflow: hidden; }
.ai-status-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; padding: 14px; }
.ai-status-grid article, .ai-score-grid article { min-height: 88px; padding: 13px; border: 1px solid var(--line); border-radius: 10px; background: #07111d; }
.ai-status-grid span, .ai-score-grid span, .ai-score-grid small { display: block; color: var(--muted); font-size: .58rem; }
.ai-status-grid strong, .ai-score-grid strong { display: block; margin-top: 10px; color: var(--text); font: .84rem Consolas, monospace; }
.ai-config-form { display: grid; grid-template-columns: minmax(210px, 1fr) minmax(220px, 1fr) auto; gap: 9px; align-items: end; padding: 0 14px 12px; }
.ai-config-form label, .ai-key-form label, .ai-review-form label { color: var(--muted); font-size: .62rem; }
.ai-key-form { display: grid; grid-template-columns: minmax(280px, 1fr) auto 2fr; gap: 9px; align-items: end; margin: 0 14px 14px; padding: 12px; border: 1px solid rgba(255, 190, 69, .25); border-radius: 9px; background: rgba(255, 190, 69, .035); }
.ai-key-form p { margin: 0 0 4px; color: var(--muted); font-size: .58rem; line-height: 1.55; }
.ai-review-form { display: grid; grid-template-columns: repeat(2, minmax(160px, .7fr)) auto auto auto; gap: 9px; align-items: end; padding: 14px; }
.ai-review-form button { min-height: 39px; white-space: nowrap; }
.ai-score-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; padding: 0 14px 14px; }
.ai-score-grid article.primary { border-color: rgba(66, 232, 216, .4); background: rgba(66, 232, 216, .055); }
.ai-score-grid small { margin-top: 7px; }
.ai-result-box, .ai-history-box { margin: 0 14px 14px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: rgba(3, 10, 18, .48); }
.ai-result-box > div, .ai-history-box > strong { display: flex; justify-content: space-between; gap: 12px; padding: 11px 13px; border-bottom: 1px solid var(--line); font-size: .66rem; }
.ai-result-box > div span { color: var(--muted); font-size: .56rem; }
.ai-result-box pre { min-height: 220px; max-height: 520px; margin: 0; padding: 15px; overflow: auto; color: #c7d6e7; background: transparent; font: .64rem/1.7 Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }

.history-view { width: min(1700px, 100%); margin: 0 auto; padding: 22px 18px 36px; display: grid; gap: 14px; }
.history-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; padding: 8px 3px 3px; }
.history-heading h2 { margin: 5px 0 4px; font-size: 1.45rem; letter-spacing: .04em; }
.history-heading p:last-child { margin: 0; color: var(--muted); font-size: .67rem; }
.history-back { border-color: var(--line); white-space: nowrap; }
.history-filter-panel { padding: 13px 14px 14px; overflow: visible; }
.period-presets { display: flex; gap: 6px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.period-button { padding: 7px 12px; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); background: #07111d; font-size: .64rem; }
.period-button.active { color: var(--cyan); border-color: rgba(66, 232, 216, .42); background: rgba(66, 232, 216, .08); }
.history-basis { margin-left: auto; align-self: center; color: var(--amber); font-size: .58rem; letter-spacing: .02em; }
.history-filters { display: grid; grid-template-columns: repeat(5, minmax(130px, 1fr)) auto; gap: 9px; align-items: end; padding-top: 11px; }
.history-filters label { color: var(--muted); font-size: .6rem; }
.history-filters input, .history-filters select { margin-top: 5px; }
.history-search { min-width: 90px; height: 39px; border: 0; border-radius: 7px; color: #001813; background: var(--cyan); font-weight: 900; font-size: .68rem; }
.history-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; }
.history-kpis article { min-height: 102px; padding: 14px; border: 1px solid var(--line); border-radius: 11px; background: linear-gradient(145deg, rgba(13, 27, 43, .96), rgba(7, 16, 27, .97)); }
.history-kpis article.primary { border-color: rgba(66, 232, 216, .35); background: linear-gradient(145deg, rgba(22, 52, 62, .9), rgba(7, 20, 29, .97)); }
.history-kpis span, .history-kpis small { display: block; color: var(--muted); font-size: .58rem; }
.history-kpis strong { display: block; margin: 9px 0 6px; color: var(--text); font: 1.02rem Consolas, monospace; }
.history-kpis strong b { font: inherit; }
.history-table-panel { overflow: hidden; }
.history-table-meta { display: flex !important; align-items: center; gap: 13px !important; color: var(--muted); font: .57rem Consolas, monospace; }
.history-table-wrap { width: 100%; overflow-x: auto; }
.history-table { width: 100%; min-width: 1600px; border-collapse: collapse; font-size: .63rem; }
.history-table th { padding: 10px 12px; border-bottom: 1px solid var(--line); color: var(--muted); background: #07111d; text-align: right; font-size: .55rem; font-weight: 600; letter-spacing: .04em; white-space: nowrap; }
.history-table th:nth-child(-n+4), .history-table td:nth-child(-n+4) { text-align: left; }
.history-table td { padding: 12px; border-bottom: 1px solid rgba(28, 45, 64, .58); text-align: right; font-family: Consolas, monospace; white-space: nowrap; }
.history-table td > small { display: block; margin-top: 4px; color: var(--muted); font-size: .51rem; }
.history-table tbody tr:hover { background: rgba(66, 232, 216, .035); }
.history-lot strong, .history-symbol strong { display: block; color: var(--text); font-family: inherit; }
.history-lot small, .history-symbol small { display: block; margin-top: 4px; color: var(--muted); font-size: .52rem; }
.history-state { display: inline-block; padding: 5px 7px; border-radius: 5px; color: #8ec2ff; background: rgba(74, 158, 255, .1); font-size: .55rem; }
.history-state.OPEN { color: var(--green); background: rgba(37, 220, 135, .1); }
.history-state.CLOSED, .history-state.CANCELLED { color: var(--muted); background: rgba(129, 146, 166, .08); }
.settlement-state { display: inline-block; min-width: 52px; padding: 5px 7px; border-radius: 5px; text-align: center; font-size: .55rem; font-weight: 800; }
.settlement-state.settled { color: var(--cyan); background: rgba(66, 232, 216, .1); }
.settlement-state.unsettled { color: var(--amber); background: rgba(255, 190, 64, .1); }
.settlement-state.not-entered { color: var(--muted); background: rgba(129, 146, 166, .08); }
.history-empty { height: 130px; color: var(--muted); text-align: center !important; }
.history-cost-note { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 14px; color: var(--muted); font-size: .56rem; }
.history-cost-note strong { color: var(--amber); }

.target-edit { color: var(--cyan); border-color: rgba(66, 232, 216, .4); white-space: nowrap; }
.history-target strong { display: block; }
.history-target .target-edit { display: block; margin: 7px 0 0 auto; }
.target-dialog { width: min(580px, calc(100vw - 28px)); max-height: calc(100dvh - 28px); padding: 24px; border: 1px solid var(--line); border-radius: 14px; color: var(--text); background: #0b1725; overflow-y: auto; box-shadow: 0 24px 100px #0008; }
.target-dialog::backdrop { background: rgba(2, 7, 14, .82); }
.target-dialog h2 { margin: 10px 0 12px; font-size: 1.2rem; }
.target-dialog label { display: block; margin: 15px 0 6px; font-size: .8rem; }
.target-dialog input { font-size: .9rem; }
.target-lot-summary { white-space: pre-line; overflow-wrap: anywhere; color: var(--muted); font-size: .73rem; line-height: 1.7; }
.target-comparison { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.target-comparison > div { padding: 13px; border: 1px solid var(--line); border-radius: 8px; background: #07111d; }
.target-comparison span, .target-comparison small { display: block; color: var(--muted); font-size: .71rem; }
.target-comparison strong { display: block; margin: 9px 0; color: var(--cyan); font-size: 1.14rem; }
.target-note { color: var(--muted); font-size: .7rem; line-height: 1.6; }
.target-loss-notice { padding: 11px; border-left: 3px solid var(--amber); background: #ffbe4510; color: var(--amber); font-size: .74rem; line-height: 1.6; }
.target-dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
.target-dialog-actions button { min-height: 42px; font-size: .77rem; }
.target-dialog-actions button:disabled { opacity: .5; cursor: wait; }
.buy-confirm-dialog { width: min(680px, calc(100vw - 28px)); }
.buy-confirm-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin: 18px 0; }
.buy-confirm-grid > div { min-width: 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: #07111d; }
.buy-confirm-grid dt { color: var(--muted); font-size: .68rem; }
.buy-confirm-grid dd { margin: 7px 0 0; color: var(--text); font: 800 .86rem/1.45 sans-serif; overflow-wrap: anywhere; }
.buy-confirm-grid > div:nth-child(5) dd,
.buy-confirm-grid > div:nth-child(6) dd,
.buy-confirm-grid > div:nth-child(7) dd { color: var(--cyan); }
.buy-confirm-warning { margin: 4px 0 16px; padding: 10px 12px; border-left: 3px solid var(--amber); background: rgba(255, 190, 69, .06); color: var(--amber); font-size: .7rem; line-height: 1.55; }
.target-history { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 15px; font-size: .73rem; }
.target-history summary { cursor: pointer; color: var(--cyan); }
.target-history p { white-space: pre-line; overflow-wrap: anywhere; color: var(--muted); line-height: 1.65; padding-bottom: 8px; border-bottom: 1px solid var(--line); }

.reconciliation-view { max-width: 1700px; }
.reconciliation-separation { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 15px 17px; border: 1px solid rgba(255, 190, 69, .42); border-left: 4px solid var(--amber); border-radius: 11px; background: rgba(255, 190, 69, .055); }
.reconciliation-separation strong { display: block; color: var(--amber); font-size: .78rem; }
.reconciliation-separation span { display: block; margin-top: 5px; color: var(--text); font-size: .65rem; line-height: 1.55; }
.reconciliation-separation button { flex: 0 0 auto; min-width: 145px; }
.reconciliation-separation button:disabled { opacity: .42; cursor: default; }
.reconciliation-table-panel { overflow: hidden; }
.reconciliation-table-wrap { width: 100%; overflow-x: auto; }
.reconciliation-table { width: 100%; border-collapse: collapse; font-size: .64rem; }
.position-comparison-table { min-width: 1050px; }
.order-comparison-table { min-width: 1320px; }
.reconciliation-table th { padding: 10px 12px; border-bottom: 1px solid var(--line); color: var(--muted); background: #07111d; text-align: right; font-size: .55rem; font-weight: 600; white-space: nowrap; }
.reconciliation-table td { padding: 12px; border-bottom: 1px solid rgba(28, 45, 64, .58); text-align: right; font-family: Consolas, monospace; white-space: nowrap; }
.reconciliation-table th:nth-child(-n+2), .reconciliation-table td:nth-child(-n+2) { text-align: left; }
.reconciliation-table td strong, .reconciliation-table td small { display: block; }
.reconciliation-table td small { margin-top: 4px; color: var(--muted); font-size: .52rem; }
.reconciliation-table tbody tr:hover { background: rgba(66, 232, 216, .035); }
.reconciliation-badge { display: inline-block; padding: 5px 8px; border-radius: 6px; color: var(--muted); background: rgba(129, 146, 166, .09); font: 700 .55rem sans-serif; }
.reconciliation-badge.MATCHED, .reconciliation-badge.MY_TRADE_ONLY { color: var(--green); background: rgba(37, 220, 135, .1); }
.reconciliation-badge.EXISTING_HOLDING_ONLY, .reconciliation-badge.BROKER_ONLY { color: var(--amber); background: rgba(255, 190, 69, .1); }
.reconciliation-badge.QUANTITY_MISMATCH, .reconciliation-badge.LATE_FILL_AFTER_CANCEL, .reconciliation-badge.DB_ONLY, .reconciliation-badge.REVIEW_REQUIRED { color: var(--red); background: rgba(255, 81, 113, .1); }
.reconciliation-badge.MY_TRADE_AND_EXISTING { color: #8ec2ff; background: rgba(74, 158, 255, .1); }
.external-quantity { color: var(--amber); font-weight: 800; }
.reconciliation-footnote { margin: 0; padding: 11px 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: .59rem; line-height: 1.6; }
.reconciliation-footnote strong { color: var(--amber); }

.toast { position: fixed; right: 18px; bottom: 18px; max-width: min(620px, calc(100vw - 36px)); padding: 11px 14px; border: 1px solid var(--line); border-radius: 8px; background: #102033; color: var(--text); font-size: .72rem; line-height: 1.55; white-space: pre-line; transform: translateY(30px); opacity: 0; pointer-events: none; transition: .25s; z-index: 50; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { border-color: var(--red); }
.toast.pinned { pointer-events: auto; cursor: pointer; }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 220px 1fr; }
  .book-panel { grid-column: 1; grid-row: 2; min-height: 410px; }
  .main-column { grid-column: 2; grid-row: 1 / span 2; }
  .lots-panel { grid-column: 1 / -1; }
  .order-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .history-filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .history-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kiwoom-status-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kiwoom-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .family-user-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .family-user-form button { grid-column: 1 / -1; }
  .ai-status-grid, .ai-score-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ai-review-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ai-review-form button { width: 100%; }
  .ai-key-form { grid-template-columns: 1fr auto; }
  .ai-key-form p { grid-column: 1 / -1; }
  .kiwoom-buttons { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
  .topbar { position: static; align-items: flex-start; flex-direction: column; gap: 10px; }
  .brand-area { width: 100%; }
  .system-status { width: 100%; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 8px 14px; }
  .workspace { width: 100%; min-width: 0; grid-template-columns: 1fr; padding: 10px; }
  .main-column, .panel { min-width: 0; }
  .chart-tabs { flex-wrap: wrap; }
  .ma-legend { order: 3; width: 100%; margin: 2px 0 0 8px; }
  .canvas-wrap { height: 270px; }
  .chart-range { order: 4; margin-left: 8px; }
  .watch-panel, .book-panel, .main-column, .lots-panel, .ledger-panel, .kiwoom-panel { grid-column: 1; grid-row: auto; min-height: auto; }
  .watchlist { display: flex; overflow-x: auto; }
  .watch-row { min-width: 150px; }
  .main-column { grid-row: 1; }
  .watch-panel { grid-row: 2; }
  .book-panel { grid-row: 3; }
  .lots-panel { grid-row: 4; }
  .ledger-panel { grid-row: 5; }
  .kiwoom-panel { grid-row: 6; }
  .ledger-grid { grid-template-columns: 1fr; }
  .ledger-grid > section + section { border-left: 0; border-top: 1px solid var(--line); }
  .lot-row { grid-template-columns: 1.2fr .8fr .8fr; }
  .lot-row .lot-metric:nth-of-type(3) { display: none; }
  .actions { grid-column: 1 / -1; justify-content: stretch; }
  .actions .action { flex: 1; }
  .history-view { padding: 14px 10px 28px; }
  .history-heading { align-items: flex-start; flex-direction: column; }
  .history-back { width: 100%; border-color: var(--line); }
  .period-presets { overflow-x: auto; }
  .period-button { flex: 0 0 auto; }
  .history-basis { flex: 0 0 auto; }
  .history-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .history-filters label:nth-of-type(3), .history-search { grid-column: 1 / -1; }
  .history-kpis { grid-template-columns: 1fr 1fr; }
  .history-kpis article { min-height: 96px; padding: 12px; }
  .kiwoom-status-grid, .kiwoom-form { grid-template-columns: 1fr; }
  .family-user-form { grid-template-columns: 1fr; }
  .family-user-row { grid-template-columns: 1fr auto; }
  .family-user-password { grid-column: 1 / -1; justify-self: start; }
  .family-plan-select { grid-column: 1 / -1; width: 100%; }
  .ai-status-grid, .ai-score-grid, .ai-config-form, .ai-key-form, .ai-review-form { grid-template-columns: 1fr; }
  .ai-key-form p { grid-column: auto; }
  .ai-result-box > div { flex-direction: column; }
  .kiwoom-buttons { display: grid; grid-template-columns: 1fr; }
  .reconciliation-separation { align-items: stretch; flex-direction: column; }
  .reconciliation-separation button { width: 100%; }
  .buy-confirm-grid { grid-template-columns: 1fr; }
}

@media (max-width: 430px) {
  .history-kpis { grid-template-columns: 1fr; }
}
.execution-notifications { margin: 12px 18px; padding: 14px 18px; border: 1px solid #294657; border-radius: 10px; background: #091725; }
.execution-notifications summary { cursor: pointer; font-size: 17px; font-weight: 700; }
.execution-notifications summary span { color: #35ddd4; margin-left: 16px; font-size: 14px; }
.execution-notifications p { color: #9bafc1; font-size: 14px; }
.execution-notifications ol { padding-left: 0; list-style: none; max-height: 320px; overflow-y: auto; }
.execution-notifications li { padding: 12px 0; border-top: 1px solid #243847; overflow-wrap: anywhere; }
.execution-notifications li strong { display: block; font-size: 16px; line-height: 1.6; }
.execution-notifications li small { display: block; color: #9bafc1; margin-top: 5px; }
.lot-row .state small { display: block; margin-top: 6px; }

/* PC: chart stays above the single order surface. BUY remains below the chart. */
@media (min-width: 1000px) {
  .main-column { gap: 14px; }
  .market-panel { min-height: 0; }
  .canvas-wrap { height: clamp(300px, 42vh, 440px); }
  .quote-head { padding: 10px 14px 4px; }
  .chart-stream-toolbar { padding: 4px 14px; gap: 6px 10px; }
  .chart-stream-toolbar > span { flex: 1 1 auto; }
  .chart-stream-toolbar > .mono { flex: 0 0 auto; }
  .chart-reference-bar { padding-top: 4px; }
  .order-panel { display: grid; grid-template-columns: minmax(0, 1fr) 156px; align-items: center; padding-bottom: 6px; }
  .order-panel .panel-title { grid-column: 1 / -1; padding: 6px 12px; }
  .order-grid { grid-column: 1; grid-row: 2; grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 8px 12px; gap: 6px 9px; }
  .order-panel > .buy-button { grid-column: 2; grid-row: 2; align-self: stretch; min-height: 60px; width: auto; margin: 8px 12px 8px 0; padding: 7px 9px; }
  .order-panel > .policy-note { grid-column: 1 / -1; margin: 0 12px 2px; }
  .watch-panel, .book-panel { align-self: start; }
}
@container trade-main (min-width: 840px) {
  .order-grid { grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(0, 1.18fr); }
}
