/* oc-cash-cow dashboard — design tokens & components (vanilla, offline) */

:root {
  --crust: #0f0f17;
  --mantle: #15151f;
  --base: #1a1a25;
  --surface0: #23232f;
  --surface1: #2d2d3c;
  --surface2: #393949;

  --text: #e4e6f1;
  --subtext: #a8acc4;
  --muted: #6c7086;
  --faint: #45475a;

  --accent: #89b4fa;
  --accent-hover: #a3c4fb;
  --accent-subtle: rgba(137, 180, 250, .12);
  --accent-border: rgba(137, 180, 250, .32);
  --success: #a6e3a1;
  /* 경고색은 주황이다. 기존 노랑(#f9e2af)은 성공 초록과 구분이 안 됐다
     — 적록색약 ΔE 2.9, 일반 시야도 11.0 으로 기준(15) 미달.
     주문 상태 배지(미확인/일부체결 ↔ 체결완료)가 같은 열에 나란히 뜨므로 실제 문제다.
     #ff9e64 는 CVD 8.1 · 일반 19.2 로 통과한다 (dataviz 검증기). */
  --warning: #ff9e64;
  --danger: #f38ba8;
  --danger-hover: #f7a5bb;
  /* 채운 위험 버튼용. 파스텔 분홍은 '위험'이 아니라 '귀여움'으로 읽히고, 모바일에서
     '매매 시작' 옆에 같은 채도로 서 있어 잘못 누르기 쉬웠다. 한국 관행상 빨강이 이미
     '상승'이라 색상만으로는 안 갈리므로 명도와 채움으로 가른다 — 상승은 밝은 글자색,
     위험은 진한 배경 + 흰 글자. */
  --danger-solid: #c4303f;
  --danger-solid-hover: #d8404f;
  --info: #74c7ec;
  --surface0-a45: rgba(35, 35, 47, .45);

  /* Korean market: rising=red, falling=blue */
  --up: #e64553;
  --down: #74c7ec;
  --up-subtle: rgba(230, 69, 83, .13);
  --down-subtle: rgba(116, 199, 236, .13);

  --border: rgba(228, 230, 241, .06);
  --border-strong: rgba(228, 230, 241, .12);
  --border-subtle: rgba(228, 230, 241, .03);
  --scrim: rgba(0, 0, 0, .55);

  --success-subtle: rgba(166, 227, 161, .13);
  --warning-subtle: rgba(255, 158, 100, .14);
  --danger-subtle: rgba(243, 139, 168, .13);
  --info-subtle: rgba(116, 199, 236, .13);

  /* 본문은 Noto Sans KR (자체 호스팅). CSP 가 default-src 'self' 라 외부 폰트 CDN 은
     차단되고, 회선이 끊겨도 화면이 같아야 하므로 파일을 직접 서빙한다.
     폴백은 기기별 한글 기본 폰트 — 폰트가 뜨기 전에도 글자가 깨지지 않는다. */
  --font: "Noto Sans KR", "Nanum Gothic", "Apple SD Gothic Neo", "Malgun Gothic",
          -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  /* 금액·수량은 본문과 같은 산세리프로 쓰고 자릿수만 tabular-nums 로 맞춘다.
     고정폭 폰트는 금융앱이 아니라 개발자 콘솔로 읽힌다 — 주린이가 보는 화면이라
     숫자가 무섭게 보이면 안 된다. 게다가 "JetBrains Mono" 는 자체 호스팅한 적이
     없고 CSP(default-src 'self')가 외부 폰트를 막으므로 로드된 적도 없다.
     실제로 뜨던 건 시스템 기본 모노스페이스였다. */
  --mono: var(--font);
  /* 진짜 코드 조각(도움말의 <code>)에만 쓴다 */
  --code: ui-monospace, "D2Coding", Menlo, monospace;

  --ease: cubic-bezier(0.2, 0, 0, 1);
  --t: 120ms;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-modal: 0 12px 40px rgba(0, 0, 0, .45);

  --topbar-h: 48px;
}

/* 본문 한글 — 자체 호스팅 서브셋 (한글 음절 전체 + 라틴/숫자/기호).
   swap: 다운로드 전에는 폴백으로 즉시 그리고, 받으면 바꿔 끼운다. */
@font-face {
  font-family: "Noto Sans KR";
  src: url("../fonts/NotoSansKR-subset.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--base);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* 페이지는 브라우저가 직접 스크롤한다. 예전엔 body 를 잠그고 .main-col 이 내부
     스크롤을 맡았는데, 그러면 스크롤바가 오버레이(레이아웃 폭 0)로 떠서 사실상
     안 보였다 — 실측 offsetWidth-clientWidth = 0.
     scroll 로 고정해 트랙을 항상 띄우고, 내용이 짧아도 폭이 안 흔들리게 한다. */
  overflow-y: scroll;
  overflow-x: hidden;
}

[hidden] { display: none !important; }

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
button:disabled { cursor: not-allowed; }

:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

.mono, .num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--subtext); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface1); border-radius: 5px; border: 2px solid var(--base); }
::-webkit-scrollbar-thumb:hover { background: var(--surface2); }

/* ---------- app frame ---------- */

.app { display: flex; min-height: 100dvh; }

/* ---------- left rail ---------- */

.rail {
  width: 156px;
  flex: none;
  background: var(--crust);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 10px 10px 12px;
  gap: 2px;
  z-index: 20;
  /* 페이지가 통째로 스크롤되므로 레일은 sticky 로 붙여둔다 — 장중에 "지금 정상인가"
     를 여기만 보고 판단해야 하니 스크롤을 내려도 사라지면 안 된다. */
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100dvh;
}

/* 엔진 상태 패널 — 스크롤과 무관하게 항상 보인다.
   장중에 "지금 정상인가" 를 여기만 보고 판단할 수 있어야 한다. */
.rs { margin: 0; display: flex; flex-direction: column; gap: 1px; }
.rs-row {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 8px; padding: 5px 2px;
}
.rs-row dt { font-size: 11px; color: var(--muted); flex: none; }
.rs-v {
  margin: 0; font-size: 12px; color: var(--text);
  font-variant-numeric: tabular-nums; text-align: right;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rs-sep { height: 1px; background: var(--border); margin: 6px 2px; }
/* 이상 상태는 색으로 즉시 드러낸다 */
.rs-v.ok { color: var(--green); }
.rs-v.warn { color: var(--yellow, #f9e2af); }
.rs-v.bad { color: var(--red); }

.rail-brand {
  height: 30px;
  display: grid; place-items: center start;
  color: var(--accent);
  padding-left: 2px;
}
.rail-brand .ic { display: block; }

.rail-sep {
  height: 1px;
  background: var(--border-strong);
  margin: 6px 2px 8px;
}

.rail-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  color: var(--subtext);
  transition: color var(--t) var(--ease);
}
/* 터치 기기(아이패드 가로 등 레일 노출 시) — 손가락 히트 영역 44px+ 확보 */
@media (pointer: coarse) and (min-width: 768px) {
  .rail-btn { width: 44px; height: 44px; }
  .rail-btn .rail-ic { width: 32px; height: 32px; }
}
.rail-btn .rail-ic {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 5px;
  transition: background var(--t) var(--ease);
}
.rail-btn:hover { color: var(--text); }
.rail-btn:hover .rail-ic { background: var(--surface0); }
.rail-btn.is-active { color: var(--accent); }
.rail-btn.is-active .rail-ic { background: var(--surface1); }

/* ---------- main column / topbar ---------- */

.main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: var(--mantle);
  border-bottom: 1px solid var(--border);
}

.tb-group { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tb-right { margin-left: auto; }

.tb-detail {
  display: flex;
  align-items: center;
  border-radius: 5px;
  padding: 4px 6px;
  margin-left: auto;
}

.session-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--subtext);
  white-space: nowrap;
}
.session-badge .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); flex: none; }
.session-badge.tone-success .dot { background: var(--success); }
.session-badge.tone-warning .dot { background: var(--warning); }
.session-badge.tone-info .dot { background: var(--info); }
.session-badge.tone-muted .dot { background: var(--muted); }

.tb-time {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.tb-time .ic { color: var(--faint); }

.tb-pnl {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  white-space: nowrap;
  color: var(--subtext);
}

/* chips */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .01em;
  white-space: nowrap;
  flex: none;
}
.chip-muted { background: var(--surface0); color: var(--muted); }
.chip-accent { background: var(--accent-subtle); color: var(--accent); }
.chip-info { background: var(--info-subtle); color: var(--info); }
.chip-success { background: var(--success-subtle); color: var(--success); }
.chip-warning { background: var(--warning-subtle); color: var(--warning); }
.chip-danger { background: var(--danger-subtle); color: var(--danger); }
.chip-buy { background: var(--up-subtle); color: var(--up); }
.chip-sell { background: var(--down-subtle); color: var(--down); }

.chip.pulsing { animation: chip-pulse 1.3s var(--ease) infinite; }
@keyframes chip-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }

/* toggle switch */

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 5px;
  color: var(--muted);
  font-size: 11px;
  transition: color var(--t) var(--ease);
}
.toggle:hover { color: var(--subtext); }
.toggle[aria-checked="true"] { color: var(--success); }
.toggle-track {
  width: 30px; height: 18px;
  border-radius: 999px;
  background: var(--surface1);
  border: 1px solid var(--border-strong);
  position: relative;
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease);
}
.toggle-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform var(--t) var(--ease), background var(--t) var(--ease);
}
.toggle[aria-checked="true"] .toggle-track { background: var(--success); border-color: transparent; }
.toggle[aria-checked="true"] .toggle-thumb { transform: translateX(12px); background: var(--crust); }

/* buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface1);
  transition: transform var(--t) var(--ease), background var(--t) var(--ease), border-color var(--t) var(--ease), color var(--t) var(--ease);
  white-space: nowrap;
  user-select: none;
}
.btn:hover { background: var(--surface2); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-sm { height: 26px; padding: 0 10px; font-size: 11.5px; border-radius: 6px; gap: 5px; }

.btn-accent { background: var(--accent); color: var(--crust); font-weight: 700; box-shadow: 0 2px 8px var(--accent-subtle); }
.btn-accent:hover { background: var(--accent-hover); }

.btn-danger { background: var(--danger-solid); color: #fff; font-weight: 700; box-shadow: 0 2px 8px rgba(196, 48, 63, .3); }
.btn-danger:hover { background: var(--danger-solid-hover); }

.btn-ghost { background: var(--surface0); border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--surface1); color: var(--text); }

.btn-ghost-danger { background: transparent; border-color: rgba(243, 139, 168, .35); color: var(--danger); }
.btn-ghost-danger:hover { background: var(--danger-subtle); border-color: rgba(243, 139, 168, .5); }

/* connection state */

.conn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: .03em;
  white-space: nowrap;
}
.conn .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.conn.is-ok .dot { background: var(--success); }
.conn.is-ok .conn-label { color: var(--muted); }
.conn.is-bad .dot { background: var(--danger); }
.conn.is-bad .conn-label { color: var(--danger); }
.conn.is-wait .dot { background: var(--warning); animation: chip-pulse 1s var(--ease) infinite; }
.conn.is-wait .conn-label { color: var(--warning); }

/* ---------- halt banner ---------- */

.halt-banner {
  position: sticky;
  top: var(--topbar-h);
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  background: var(--danger-subtle);
  border-bottom: 1px solid rgba(243, 139, 168, .28);
  color: var(--danger);
  font-size: 13px;
}
.halt-banner .ic { flex: none; }
.halt-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.halt-banner .btn { margin-left: auto; flex: none; }

/* ---------- content grid ---------- */

.content-grid {
  width: 100%;
  max-width: 1460px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-width: 0;
}

.sec { min-width: 0; scroll-margin-top: 8px; }

.sec-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
/* 제목은 본문보다 커야 한다. 이전엔 13px·subtext 라 본문(13px·text)보다 흐려서
   훑어읽기가 안 됐다 — 어디서 어디까지가 한 덩어리인지 눈으로 안 잡혔다. */
.sec-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--text);
}

.panel {
  background: var(--mantle);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .2);
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 10px;
}
.panel-title { font-size: 13px; font-weight: 700; color: var(--text); }

.live-flag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .06em;
  color: var(--muted);
}
.live-flag .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); animation: chip-pulse 1.6s var(--ease) infinite; }

/* ---------- summary cards ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: 12px;
}

/* 헤드라인 하나는 크게. 대시보드를 열었을 때 제일 먼저 읽어야 하는 값은
   '당일 손익' 하나뿐이다 — 다섯 칸을 같은 무게로 두면 위계가 없다. */
.card.is-hero { grid-column: span 2; }
.card.is-hero .card-value { font-size: 32px; font-weight: 800; letter-spacing: -.03em; line-height: 1.15; }
.card.is-hero .card-label { font-size: 12.5px; font-weight: 600; }
@media (max-width: 767px) { .card.is-hero { grid-column: span 2; } }

/* 한도 대비 사용량 — 숫자만으로는 '7/200 이 여유인지' 가 안 읽힌다.
   가는 막대 하나가 즉시 알려준다. */
.meter {
  margin-top: 8px;
  height: 4px;
  border-radius: 2px;
  background: var(--surface1);
  overflow: hidden;
}
.meter > i {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: var(--subtext);
  transition: width var(--t) var(--ease), background var(--t) var(--ease);
}
.meter.warn > i { background: var(--warning); }
.meter.bad > i { background: var(--danger); }

.card {
  background: var(--mantle);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  min-width: 0;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .2);
  transition: border-color var(--t) var(--ease);
}
.card-label { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.card-value {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-sub {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- grid tables ---------- */

.grid-table { overflow: hidden; }

.gr {
  display: grid;
  gap: 0 10px;
  padding: 8px 14px 6px;
  border-bottom: 1px solid var(--border-subtle);
}
.h {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: .04em;
  white-space: nowrap;
}
.h.num { text-align: right; }

.grid-row {
  min-height: 46px;
  display: grid;
  gap: 0 10px;
  align-items: center;
  padding: 9px 14px;
  border-top: 1px solid var(--border-subtle);
  transition: background var(--t) var(--ease);
}
.grid-row:first-child { border-top: 0; }
.grid-row:hover { background: var(--surface0-a45); }

/* 용어 안내 버튼 — 주식을 모르는 사람도 화면을 읽을 수 있게.
   hover 툴팁이 아니라 클릭 모달이다 (폰에는 hover 가 없다). */
.help-btn {
  width: 17px; height: 17px;
  margin-left: 6px;
  display: inline-grid; place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 10px; font-weight: 700; line-height: 1;
  cursor: pointer; flex: none;
  transition: color var(--t) var(--ease), border-color var(--t) var(--ease);
}
.help-btn:hover { color: var(--accent); border-color: var(--accent); }
.help-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* 터치 기기에서 누르기 쉽게 히트 영역 확대 (보이는 크기는 그대로) */
@media (pointer: coarse) {
  .help-btn { position: relative; }
  .help-btn::after { content: ""; position: absolute; inset: -11px; }
}
.rail-help { align-self: flex-end; margin: 0 2px 0 0; }
.modal-detail .v code {
  font-family: var(--code); font-size: 11px;
  background: var(--surface0-a45); padding: 1px 4px; border-radius: 3px;
}

/* 종목 표시 — 이름을 앞세우고 코드는 보조로 */
.sym { display: inline-flex; align-items: baseline; gap: 6px; min-width: 0; }
.sym-name {
  font-weight: 600; font-size: 13px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sym-name.mono { font-family: var(--mono); font-weight: 500; }
.sym-code {
  font-family: var(--mono); font-size: 10px; color: var(--muted);
  flex: none; letter-spacing: -.02em;
}

.r { display: contents; }

/* 데스크톱 열 정렬 — DOM 순서는 모바일 카드(제목줄에 종목·청산 버튼)에 맞춰져 있어
   헤더 순서와 다르다. 그대로 두면 값이 한 칸씩 밀리고, 좁은 열에 청산 버튼이
   안 들어가 행이 두 줄로 터진다. order 로 표시 순서만 헤더에 맞춘다. */
.t-pos .c-symbol { order: 1; }
.t-pos .c-qty    { order: 2; }
.t-pos .c-avg    { order: 3; }
.t-pos .c-cur    { order: 4; }
.t-pos .c-pnl    { order: 5; }
.t-pos .c-tgt    { order: 6; }
.t-pos .c-exit   { order: 7; }

.t-ord .c-time   { order: 1; }
.t-ord .c-symbol { order: 2; }
.t-ord .c-side   { order: 3; }
.t-ord .c-qty    { order: 4; }
.t-ord .c-price  { order: 5; }
.t-ord .c-status { order: 6; }
.t-ord .c-reason { order: 7; }

.t-fill .c-time   { order: 1; }
.t-fill .c-symbol { order: 2; }
.t-fill .c-side   { order: 3; }
.t-fill .c-qtyp   { order: 4; }
.t-fill .c-fee    { order: 5; }

.c { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; font-size: 13px; }
/* 셀 라벨은 모바일 카드 레이아웃 전용 — 데스크톱은 헤더가 있어 중복이다.
   숫자 셀은 .num-c 라서 .c 선택자에 걸리지 않았고, 그래서 헤더와 행에
   같은 라벨이 두 번 보였다. */
.c .cl, .num-c .cl { display: none; }

.num-c {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  text-align: right;
}
.vsub { font-size: 11px; color: var(--muted); font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* desktop column placement — positions */
.t-pos .gr, .t-pos .grid-row {
  min-height: 46px; grid-template-columns: minmax(120px, 1.4fr) 56px 92px 92px minmax(120px, 1fr) 84px 68px; }
.t-pos .c-symbol { grid-column: 1; }
.t-pos .c-qty { grid-column: 2; }
.t-pos .c-avg { grid-column: 3; }
.t-pos .c-cur { grid-column: 4; }
.t-pos .c-pnl { grid-column: 5; }
.t-pos .c-tgt { grid-column: 6; }
.t-pos .c-exit { grid-column: 7; }

/* orders */
.t-ord .gr, .t-ord .grid-row {
  min-height: 46px; grid-template-columns: 66px minmax(120px, 1.2fr) 56px 78px 96px 84px minmax(100px, 1fr); }
.t-ord .c-time { grid-column: 1; }
.t-ord .c-symbol { grid-column: 2; }
.t-ord .c-side { grid-column: 3; }
.t-ord .c-qty { grid-column: 4; }
.t-ord .c-price { grid-column: 5; }
.t-ord .c-status { grid-column: 6; }
.t-ord .c-reason { grid-column: 7; align-items: flex-start; }

/* fills */
.t-fill .gr, .t-fill .grid-row {
  min-height: 46px; grid-template-columns: 66px minmax(120px, 1.2fr) 56px minmax(120px, 1fr) 158px; }
.t-fill .c-time { grid-column: 1; }
.t-fill .c-symbol { grid-column: 2; }
.t-fill .c-side { grid-column: 3; }
.t-fill .c-qtyp { grid-column: 4; }
.t-fill .c-fee { grid-column: 5; }

.c-symbol {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--text);
  letter-spacing: .01em;
}
.c-time { color: var(--muted); font-size: 12px; }

.pair { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.pair .stopv { color: var(--danger); opacity: .85; }

.reason {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--muted);
}

/* tick flash */
@keyframes tick-flash {
  from { background: var(--accent-subtle); }
  to { background: transparent; }
}
.grid-row.flash .c-cur, .ticker-row.flash {
  animation: tick-flash 300ms var(--ease);
}

/* empty states */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 32px 16px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
.empty .ic, .empty-ic { color: var(--faint); }
.empty-ic { display: grid; place-items: center; }

/* ---------- ticker panel ---------- */

.ticker-panel { min-width: 0; }
/* 시세가 아직 없으면 패널째 감춘다. 개장 전에는 항상 비어 있는데, 데스크톱에선
   우측 한 칸을, 모바일에선 첫 화면 최상단을 빈 상자가 통째로 차지하고 있었다.
   맨 처음 보이는 것이 "기다리는 중입니다" 여서는 안 된다. */
.ticker-panel:has(.empty) { display: none; }
.ticker-body { display: flex; flex-direction: column; }

.ticker-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 62px;
  gap: 8px;
  align-items: center;
  padding: 7px 14px;
  border-top: 1px solid var(--border-subtle);
  border-radius: 0;
}
.ticker-row:first-child { border-top: 0; }
.tk-sym { font-family: var(--mono); font-size: 13px; color: var(--subtext); }
.tk-price { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 13px; color: var(--text); }
.tk-chg { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 11px; text-align: right; }

/* ---------- risk panel ---------- */

.risk-panel { padding: 6px 14px; }

.risk-row { padding: 10px 0 12px; border-top: 1px solid var(--border-subtle); }
.risk-row:first-child { border-top: 0; }

.risk-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
}
.risk-label { font-size: 12px; color: var(--subtext); white-space: nowrap; }
.risk-val {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
}
.risk-val.muted { color: var(--muted); }

.risk-bar {
  position: relative;
  height: 6px;
  border-radius: 3px;
  background: var(--surface0);
  overflow: hidden;
}
.risk-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 3px;
  transition: width 240ms var(--ease);
}
.risk-fill.ok { background: var(--success); }
.risk-fill.warn { background: var(--warning); }
.risk-fill.bad { background: var(--danger); }

.risk-mark {
  position: absolute;
  top: -1px; bottom: -1px;
  width: 2px;
  background: var(--warning);
  opacity: .7;
}
.risk-hint { margin-top: 6px; font-size: 10px; color: var(--muted); }

/* ---------- mobile controls row (overview, mobile only) ---------- */

.mobile-controls { display: none; }

/* ---------- modal (Toss Securities style) ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10001;
  background: var(--scrim, rgba(0, 0, 0, .6));
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  width: 100%;
  max-width: 500px;
  max-height: min(88dvh, 740px);
  display: flex;
  flex-direction: column;
  background: var(--base);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow-modal);
  overflow: hidden;
  animation: modal-in 160ms var(--ease);
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: none; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.modal-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1.35;
}
.modal-title.t-danger { color: var(--danger); }
.modal-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin-right: -6px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--t) var(--ease), color var(--t) var(--ease);
}
.modal-close-btn:hover {
  background: var(--surface0);
  color: var(--text);
}
.modal-close-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.modal-body {
  padding: 16px 20px;
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.modal-msg {
  margin: 0;
  font-size: 14px;
  color: var(--subtext);
  line-height: 1.6;
  overflow-wrap: anywhere;
  word-break: keep-all;
}

/* Modal Detail (Glossary / Help / State Cards) */
.modal-detail {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-detail .kv {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
  padding: 12px 14px;
  background: var(--surface0);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: background var(--t) var(--ease);
}
.modal-detail .kv:hover {
  background: var(--surface1);
}
.modal-detail .k {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}
.modal-detail .v {
  font-size: 13px;
  color: var(--subtext);
  line-height: 1.6;
  font-family: var(--font);
  word-break: keep-all;
  overflow-wrap: break-word;
}
.modal-detail .v b {
  color: var(--text);
  font-weight: 600;
}
.modal-detail .v code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--surface1);
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

/* Status Detail Modal (Short key-value pairs) */
.modal-detail.is-compact .kv {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
}
.modal-detail.is-compact .v {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
  flex: none;
  background: var(--base);
}
.modal-actions .btn {
  min-width: 80px;
  height: 38px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 7px;
}

/* ---------- toasts ---------- */

.toast-root {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 20px;
  z-index: 10002;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 9px 14px;
  border-radius: 7px;
  background: var(--surface2);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-1);
  font-size: 12px;
  color: var(--text);
  animation: toast-in 160ms var(--ease);
}
.toast .ic { flex: none; }
.toast.leaving { opacity: 0; transition: opacity 200ms var(--ease); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.toast.t-success .ic { color: var(--success); }
.toast.t-danger .ic { color: var(--danger); }
.toast.t-warning .ic { color: var(--warning); }
.toast.t-info .ic { color: var(--info); }

/* ---------- tab bar (mobile) ---------- */


/* ================================================================
   Wide desktop: ticker becomes right column
   ================================================================ */

@media (min-width: 1280px) {
  .content-grid {
    grid-template-columns: minmax(0, 1fr) 300px;
  }
  /* 시세 패널이 숨으면 300px 칸이 빈 채로 남아 본문만 좁아진다 — 한 칸으로 접는다.
     다만 그대로 두면 표의 유동 열(종목·평가손익)이 화면 끝까지 벌어져 행 가운데가
     텅 빈다. 열 비율은 본문 약 1,100px 기준으로 잡혀 있으므로 거기서 묶고 가운데 정렬. */
  .content-grid:has(.ticker-panel .empty) {
    grid-template-columns: minmax(0, 1120px);
    justify-content: center;
  }
  .content { grid-column: 1; grid-row: 1; }
  .ticker-panel {
    grid-column: 2;
    grid-row: 1;
    position: sticky;
    top: calc(var(--topbar-h) + 16px);
    max-height: calc(100dvh - var(--topbar-h) - 32px);
    display: flex;
    flex-direction: column;
  }
  .ticker-body { overflow-y: auto; min-height: 0; }
}

/* ================================================================
   Tablet / small desktop (768–1279): ticker full width
   ================================================================ */

@media (min-width: 768px) and (max-width: 1279px) {
  .ticker-body {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1px 0;
  }
}

/* ================================================================
   Mobile (<768): no rail, cards instead of tables, bottom tabs
   ================================================================ */

@media (max-width: 767px) {
  .rail { display: none; }

  .topbar { padding: 0 12px; gap: 8px; }
  .tb-time, #brokerChip, #tradingToggle, #haltBtn, #tradingOffChip, .conn .conn-label { display: none; }
  .tb-detail { margin-left: auto; padding: 6px 8px; }
  .tb-pnl { font-size: 13px; }
  .conn { margin-left: 0; }

  .halt-banner { top: var(--topbar-h); flex-wrap: nowrap; font-size: 12px; padding: 6px 12px; }

  .content-grid { padding: 12px; gap: 12px; }

  /* ticker → horizontal strip */
  .ticker-panel { border-radius: 7px; }
  .panel-head { padding: 8px 12px 6px; }
  .ticker-body {
    flex-direction: row;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 12px 10px;
    -webkit-overflow-scrolling: touch;
  }
  .ticker-row {
    flex: none;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    border: 0;
    border-radius: 5px;
    padding: 6px 10px;
    background: var(--surface0);
  }
  .tk-chg { text-align: left; }

  .cards { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  /* 히어로가 2칸을 먹으므로 나머지가 홀수 개면 마지막 하나가 왼쪽에 혼자 남아
     오른쪽이 빈다. 짝수 번째가 마지막이면 그때가 그 경우다 — 한 줄을 다 쓰게 한다. */
  .cards > .card:last-child:nth-child(even) { grid-column: span 2; }
  .card { padding: 12px; }
  .card-value { font-size: 18px; }

  /* controls visible in overview */
  .mobile-controls {
    display: flex;
    gap: 8px;
    margin-top: 12px;
  }
  .mobile-controls .btn { flex: 1; height: 40px; }

  /* grid tables → card list */
  .gr { display: none; }
  .grid-row {
    min-height: 48px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    margin: 0 12px 10px;
    background: var(--surface0);
    box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
    transition: background var(--t) var(--ease);
  }
  .grid-row:first-child { margin-top: 12px; }
  .grid-row:hover { background: var(--surface1); }
  .grid-table { padding-bottom: 4px; }

  .r { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
  .c, .num-c { flex-direction: row; align-items: baseline; gap: 6px; text-align: left; }
  .c .cl, .num-c .cl { display: inline; font-size: 10.5px; color: var(--muted); flex: none; font-weight: 600; }

  .c-symbol { font-size: 14px; font-weight: 700; }
  .c-time { font-size: 11px; margin-left: auto; color: var(--muted); }
  .c-side { flex: none; }

  .t-ord .c-symbol { font-size: 14px; font-weight: 700; }
  .t-ord .r2 .c-reason { flex: 1 1 100%; }

  .t-pos .c-exit { margin-left: auto; }
  .t-pos .btn-ghost-danger { height: 28px; padding: 0 12px; border-radius: 6px; font-size: 12px; font-weight: 600; }
  .r1 { flex-wrap: nowrap; }
  /* 카드 레이아웃은 DOM 순서 그대로 — 데스크톱용 order 를 무효화한다 */
  .t-pos .c, .t-pos .num-c, .t-ord .c, .t-ord .num-c, .t-fill .c, .t-fill .num-c { order: 0; }
  .r2 .num-c { flex: 1; justify-content: flex-start; }

  /* 포지션 카드: 수량·매입가·현재가를 3열로 고르게 놓고 평가손익만 한 줄을 다 쓴다. */
  .t-pos .r2 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px 12px;
    align-items: start;
  }
  /* 데스크톱 열 배치(.t-pos .c-qty{grid-column:2} …)가 카드까지 따라와서 2·3·4번
     열을 만들어 버렸다. 그래서 1번 열이 통째로 비고 숫자 셋이 오른쪽에 몰렸다.
     카드에서는 배치를 흐름에 맡긴다. */
  .t-pos .r2 > .num-c { grid-column: auto; }
  /* 라벨을 값 위에 쌓는다. 한 줄에 '라벨 값' 을 나란히 두면 좁은 칸에서 옆 칸
     라벨과 붙어 읽히고(실측: 셀 65px 인데 '매입가 107,500' 이 더 넓다),
     무엇보다 주린이가 어느 라벨이 어느 숫자인지 헷갈린다. */
  .t-pos .r2 .num-c {
    flex: none;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 3px;
  }
  /* .vsub(등락률 등 보조값)는 원래 크기를 지킨다 */
  .t-pos .r2 .num-c > span:not(.cl):not(.vsub) { font-size: 14px; font-weight: 600; }
  .t-pos .r2 .c-pnl {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: row;
    align-items: baseline;
    gap: 6px;
  }
  /* 금액과 단위가 갈라지지 않게 */
  .t-pos .c-pnl [data-f="pnl"] { white-space: nowrap; font-weight: 700; }
  .t-pos .c-pnl [data-f="pnlp"] { margin-left: auto; white-space: nowrap; font-weight: 700; }
  .pair { flex-direction: row; align-items: baseline; gap: 8px; }

  .t-fill .c-fee { margin-left: auto; }

  .risk-panel { padding: 6px 14px; }

  /* 하단 탭바는 걷어냈다. 섹션 5개는 한 장에 이어져 있으므로 그냥 스크롤하면 된다 —
     탭으로 같은 문서 안을 점프시키면 지금 어디를 보는지가 흐려지고, 화면 아래
     56px 을 상시로 잡아먹는다. */
  .main-col { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }

  .toast-root { bottom: calc(env(safe-area-inset-bottom) + 16px); }

  /* Mobile Modal (Toss-style bottom sheet) */
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }
  .modal {
    max-width: 100%;
    max-height: 85dvh;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    border-top: 1px solid var(--border-strong);
    animation: modal-sheet-up 200ms var(--ease);
  }
  @keyframes modal-sheet-up {
    from { opacity: 0; transform: translateY(100%); }
    to { opacity: 1; transform: translateY(0); }
  }
  .modal-header {
    padding: 16px 18px 12px;
  }
  .modal-title {
    font-size: 15px;
  }
  .modal-body {
    padding: 14px 18px;
    max-height: calc(85dvh - 125px);
  }
  .modal-detail {
    gap: 8px;
  }
  .modal-detail .kv {
    padding: 11px 13px;
    border-radius: 8px;
    gap: 4px;
  }
  .modal-detail .k {
    font-size: 13px;
  }
  .modal-detail .v {
    font-size: 12.5px;
    line-height: 1.55;
  }
  .modal-actions {
    padding: 12px 18px calc(14px + env(safe-area-inset-bottom));
  }
  .modal-actions .btn {
    flex: 1;
    height: 44px;
    font-size: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
