:root {
    --bg: #f3f5f8;
    --panel: #ffffff;
    --line: #e2e7ef;
    --text: #172033;
    --muted: #738096;
    --primary: #315efb;
    --up: #e53935;
    --down: #1976d2;
    --ask-bg: #fff2f2;
    --bid-bg: #eef6ff;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", sans-serif; }
button, input { font: inherit; }
.topbar { display: flex; justify-content: space-between; gap: 20px; align-items: center; padding: 22px 28px; background: #111827; color: #fff; }
.topbar h1 { margin: 0; font-size: 1.45rem; }
.topbar p { margin: 5px 0 0; color: #aab4c6; font-size: .86rem; }
.top-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn { border: 0; border-radius: 8px; padding: 9px 13px; cursor: pointer; font-weight: 700; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.secondary { background: #283346; color: #fff; }
.btn.danger { background: #fff0f0; color: #cf2e2e; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .55; cursor: wait; }
.notice { margin: 14px 28px 0; padding: 12px 15px; border-radius: 9px; background: #e8f0ff; color: #2349b9; font-weight: 700; }
.notice.error { background: #ffecec; color: #bb2525; }
.hidden { display: none !important; }
.layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; padding: 18px 28px 28px; }
.sidebar, .content { min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 13px; padding: 16px; margin-bottom: 14px; box-shadow: 0 3px 14px rgba(31, 46, 78, .05); }
.panel h2 { margin: 0; font-size: 1rem; }
.panel-title-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.count { min-width: 27px; padding: 3px 8px; background: #eef2f8; color: #56647a; border-radius: 999px; text-align: center; font-size: .75rem; }
.watch-form { display: grid; gap: 7px; margin-bottom: 12px; }
.watch-form input { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; outline: none; }
.watch-form input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(49,94,251,.1); }
.stock-list { display: grid; gap: 7px; }
.stock-item { position: relative; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; align-items: center; padding: 10px 9px; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; transition: .15s; }
.stock-item:hover, .stock-item.active { border-color: var(--primary); background: #f4f7ff; }
.stock-item .name { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stock-item .code { color: var(--muted); font-size: .74rem; }
.stock-item .price { text-align: right; font-weight: 800; }
.stock-item .rate { display: block; font-size: .75rem; }
.stock-item .delete { position: absolute; top: -7px; right: -7px; width: 21px; height: 21px; border-radius: 50%; border: 0; color: #fff; background: #9aa5b5; display: none; cursor: pointer; }
.stock-item:hover .delete { display: block; }
.up { color: var(--up) !important; }
.down { color: var(--down) !important; }
.flat { color: var(--muted) !important; }
.portfolio-summary { margin-bottom: 10px; padding: 10px; border-radius: 9px; background: #f7f9fc; font-size: .78rem; line-height: 1.65; }
.worker-row { display: flex; justify-content: space-between; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: .76rem; }
.worker-row:last-child { border-bottom: 0; }
.worker-state { font-weight: 800; }
.selected-header { display: flex; justify-content: space-between; align-items: center; min-height: 105px; }
.stock-code { color: var(--muted); font-size: .82rem; margin-bottom: 5px; }
.selected-header h2 { font-size: 1.3rem; }
.price-block { text-align: right; }
.price-block > strong { display: block; font-size: 2rem; }
.price-block > span { display: block; font-weight: 800; }
.price-block small { display: block; color: var(--muted); margin-top: 5px; }
.stats-grid { display: grid; grid-template-columns: repeat(6, minmax(0,1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.stat span { display: block; color: var(--muted); font-size: .75rem; margin-bottom: 5px; }
.stat strong { font-size: .95rem; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(310px, .75fr); gap: 14px; }
.chart-panel, .orderbook-panel { margin-bottom: 0; }
.chart-wrap { position: relative; height: 500px; }
.muted { color: var(--muted); font-size: .75rem; }
.orderbook-head, .order-row { display: grid; grid-template-columns: 1fr 1fr; align-items: center; text-align: right; }
.orderbook-head { color: var(--muted); font-size: .7rem; padding: 0 8px 5px; }
.order-row { min-height: 31px; padding: 5px 9px; border-bottom: 1px solid rgba(0,0,0,.035); font-size: .82rem; }
.asks .order-row { background: var(--ask-bg); }
.bids .order-row { background: var(--bid-bg); }
.asks .order-row .price { color: var(--up); font-weight: 800; }
.bids .order-row .price { color: var(--down); font-weight: 800; }
.current-line { display: flex; justify-content: space-between; align-items: center; padding: 11px 9px; border-top: 2px solid #dfe5ed; border-bottom: 2px solid #dfe5ed; }
.current-line span { color: var(--muted); font-size: .75rem; }
.orderbook-total { display: flex; justify-content: space-between; gap: 10px; padding-top: 10px; color: var(--muted); font-size: .72rem; }
footer { padding: 16px 28px 28px; color: var(--muted); font-size: .75rem; text-align: center; }
@media (max-width: 1100px) {
    .layout { grid-template-columns: 285px minmax(0,1fr); }
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
    .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
    .topbar { align-items: flex-start; flex-direction: column; padding: 18px; }
    .layout { grid-template-columns: 1fr; padding: 14px; }
    .sidebar { order: 2; }
    .content { order: 1; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .selected-header { align-items: flex-start; }
    .chart-wrap { height: 330px; }
    .notice { margin: 12px 14px 0; }
}

/* v3 실시간 수신 상태 */
.selected-code-row { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.live-badge { display:inline-flex; align-items:center; gap:5px; border-radius:999px; padding:3px 9px; font-size:.72rem; font-weight:800; border:1px solid transparent; }
.live-badge::before { content:""; width:7px; height:7px; border-radius:50%; background:currentColor; }
.live-badge.live { color:#146c43; background:#d1e7dd; border-color:#a3cfbb; }
.live-badge.rest { color:#664d03; background:#fff3cd; border-color:#ffecb5; }
.live-badge.delayed { color:#842029; background:#f8d7da; border-color:#f5c2c7; }
.live-badge.waiting { color:#495057; background:#e9ecef; border-color:#dee2e6; }
