/* Q_fin mini app — layout and components. Values come from tokens.css. */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.mute { color: var(--faint); }
.dim { color: var(--dim); }

/* app shell */
.app {
  max-width: 480px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) 0 calc(env(safe-area-inset-bottom, 0px) + 84px);
}
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px 10px; }
.logo { font-weight: 600; font-size: 15px; letter-spacing: .3px; }
.live {
  font-size: 11px; color: var(--text-2); background: var(--chip);
  padding: 4px 10px 4px 8px; border-radius: var(--r-pill);
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
}
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--pos); box-shadow: 0 0 0 3px var(--pos-bg); }
.live.warn i { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.live.bad i { background: var(--neg); box-shadow: 0 0 0 3px var(--neg-bg); }
.live.busy i { animation: live-pulse 1.2s ease-in-out infinite; }
@keyframes live-pulse { 50% { opacity: .35; transform: scale(.7); } }

.panel { margin: 0 12px 10px; background: var(--surface); border-radius: var(--r-panel); padding: 14px 16px 12px; }
.section-label { font-size: 11.5px; color: var(--dim); padding: 2px 26px 7px; }
.label { font-size: 11.5px; color: var(--dim); }
.caption { font-size: 10.5px; color: var(--faint); margin-top: 8px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* notice strip (stale data) */
.notice {
  margin: 0 12px 10px; padding: 8px 12px; border-radius: var(--r-box);
  background: var(--accent-soft); color: var(--text-2); font-size: 12px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.notice button { color: var(--accent); font-weight: 600; font-size: 12px; }

/* hero */
.hero-top { display: flex; justify-content: space-between; align-items: flex-end; }
.big { font-size: 30px; font-weight: 400; letter-spacing: -1px; line-height: 1.2; }
.hero-dd { text-align: right; }
.hero-dd .v { font-size: 13px; color: var(--text-2); }
.hero-dd .v.pos { color: var(--pos); }
.hero-dd .v.neg { color: var(--neg); }

/* allocation bar */
.alloc-bar { display: flex; gap: 2px; height: 6px; margin-top: 14px; }
.alloc-bar > div { border-radius: var(--r-pill); min-width: 2px; }
.alloc-legend { display: flex; justify-content: space-between; margin-top: 8px; font-size: 11px; color: var(--dim); }
.alloc-legend > span { display: flex; flex-direction: column; gap: 2px; }
.alloc-legend em { font-style: normal; display: flex; align-items: center; gap: 5px; }
.alloc-legend b { color: var(--text); font-weight: 500; font-size: 12.5px; padding-left: 12px; }
.swatch { width: 7px; height: 7px; border-radius: var(--r-pill); display: inline-block; flex: none; }
.c-engine { background: var(--c-engine); }
.c-fuel { background: var(--c-fuel); }
.c-main { background: var(--c-main); }
.c-subf { background: var(--c-subf); }

/* exchange list */
.group { margin: 0 12px 10px; background: var(--surface); border-radius: var(--r-panel); overflow: hidden; }
.mrow { padding: 12px 16px 10px; display: block; width: 100%; text-align: left; }
.mrow + .mrow, .collapse + .mrow { border-top: 1px solid var(--hairline); }
.mrow-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ex-name { font-weight: 600; font-size: 13.5px; }
.ex-sym { font-size: 11px; color: var(--faint); margin-left: 4px; }
.pill { font-size: 10px; font-weight: 600; letter-spacing: .3px; margin-left: 6px; padding: 2px 8px; border-radius: var(--r-pill); vertical-align: 1px; }
.pill.long { color: var(--pos); background: var(--pos-bg); }
.pill.short { color: var(--neg); background: var(--neg-bg); }
.pill.idle { color: var(--dim); background: var(--hairline); }
.pill.warn { color: var(--accent); background: var(--accent-bg); }
.pill.bad { color: var(--neg); background: var(--neg-bg); }
.pnl { font-size: 14px; font-weight: 600; white-space: nowrap; }
.row-msg { font-size: 12px; margin-top: 6px; }

/* expand / collapse */
.row-right { display: flex; align-items: center; gap: 8px; }
.chev { flex: none; color: var(--faint); transition: transform .2s ease; }
.chev.open { transform: rotate(180deg); }
.collapse { display: grid; grid-template-rows: 0fr; opacity: 0; transition: grid-template-rows .2s ease, opacity .2s ease; }
.collapse.open { grid-template-rows: 1fr; opacity: 1; }
.collapse-inner { overflow: hidden; min-height: 0; }

/* stop gauge */
.gauge { position: relative; height: 38px; margin-top: 6px; }
.g-track { position: absolute; left: 0; right: 0; top: 24px; height: 4px; border-radius: var(--r-pill); background: var(--track); }
.g-risk { position: absolute; top: 24px; height: 4px; border-radius: var(--r-pill); background: var(--risk); }
.g-dot { position: absolute; top: 21px; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: var(--text); box-shadow: 0 0 0 3px var(--surface); }
.g-tag {
  position: absolute; top: 0; font-size: 11.5px; font-weight: 600; color: var(--bg); background: var(--text);
  padding: 1px 8px; border-radius: var(--r-pill); white-space: nowrap;
}
.g-tag.center { transform: translateX(-50%); }
.g-tag.right { transform: translateX(-100%); }
/* z-index: the stop stays visible when the price dot or forecast ring sits on top of it */
.g-stop { position: absolute; top: 20px; width: 3px; height: 12px; margin-left: -1.5px; border-radius: var(--r-pill); background: var(--neg); z-index: 2; }
.g-stop.up { background: var(--pos); }
.g-tp { position: absolute; top: 22px; width: 2px; height: 8px; margin-left: -1px; border-radius: var(--r-pill); background: var(--pos); opacity: .7; }
.g-entry { position: absolute; top: 22px; width: 2px; height: 8px; margin-left: -1px; border-radius: var(--r-pill); background: var(--dim); }
.g-fc { position: absolute; top: 21px; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; border: 2px solid var(--accent); background: var(--surface); }
.g-axis { position: relative; height: 14px; font-size: 10.5px; color: var(--dim); }
.g-axis > span { position: absolute; white-space: nowrap; }
.g-axis .left { left: 0; }
.g-axis .right { right: 0; }
.g-axis .mid { transform: translateX(-50%); }
.g-axis .risk-label { color: var(--neg); }
.g-warn { font-size: 11.5px; color: var(--neg); font-weight: 600; margin-top: 4px; }

/* expanded detail */
.detail { padding: 2px 16px 14px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; background: var(--surface-2); border-radius: var(--r-box); padding: 12px 14px; }
.stats .k { font-size: 11px; color: var(--dim); }
.stats .v { font-size: 13.5px; margin-top: 1px; }
.stats .s { font-size: 11px; color: var(--dim); }
.box { margin-top: 10px; background: var(--surface-2); border-radius: var(--r-box); padding: 10px 14px 11px; font-size: 12px; }
.box .alloc-bar { margin-top: 8px; height: 5px; }
.box .alloc-legend { margin-top: 7px; }
.fc { margin-top: 10px; background: var(--accent-soft); border-radius: var(--r-box); padding: 10px 12px; font-size: 12px; line-height: 1.5; color: var(--text-2); }
.fc-title { color: var(--accent); font-size: 11px; font-weight: 600; margin-bottom: 2px; }
.fc-alt { color: var(--dim); font-size: 11.5px; margin-top: 4px; }
.fc-warn { color: var(--neg); font-size: 11.5px; margin-top: 4px; }
.fc-note { color: var(--faint); font-size: 10.5px; margin-top: 6px; }
.legs { line-height: 1.55; color: var(--text-2); }
.legs .leg-title { color: var(--accent); font-size: 11px; font-weight: 600; }
.legs .leg-sub { color: var(--dim); font-size: 11.5px; }
.legs .leg-sec { margin-top: 4px; }
.legs .leg-child { padding-left: 10px; }
.legs .leg-child2 { padding-left: 22px; }
.legs .leg-orders, .legs .leg-log { margin-top: 6px; }
.legs .leg-log div { color: var(--faint); font-size: 10.5px; }
.foot { margin-top: 10px; font-size: 11px; color: var(--faint); display: flex; justify-content: space-between; }

/* segmented / chips */
.seg { display: inline-flex; background: var(--bg); border-radius: var(--r-pill); padding: 3px; font-size: 11px; }
.seg button { padding: 3px 10px; border-radius: var(--r-pill); color: var(--faint); min-height: 24px; }
.seg button.on { background: rgba(230, 165, 60, 0.14); color: var(--accent); font-weight: 600; }
.chips { display: flex; gap: 6px; padding: 0 12px 10px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { font-size: 12px; padding: 6px 12px; border-radius: var(--r-pill); background: var(--surface); color: var(--dim); white-space: nowrap; }
.chips button.on { background: var(--text); color: var(--bg); font-weight: 600; }

/* charts */
.chart { position: relative; touch-action: none; user-select: none; -webkit-user-select: none; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-axis { display: flex; justify-content: space-between; font-size: 10px; color: var(--faint); margin-top: 6px; }
.tip {
  position: absolute; top: -4px; background: #262522; border-radius: 10px; padding: 6px 9px; font-size: 10.5px;
  line-height: 1.5; color: var(--text-2); white-space: nowrap; box-shadow: 0 4px 14px rgba(0, 0, 0, .35); pointer-events: none; z-index: 2;
}
.tip b { color: var(--text); font-weight: 600; font-size: 11.5px; }
.tip .swatch { border-radius: 2px; margin-right: 4px; }
.grid-label { position: absolute; right: 0; font-size: 9.5px; color: var(--faint); transform: translateY(-100%); }
.value-line { display: flex; align-items: baseline; gap: 8px; margin: 6px 0 10px; flex-wrap: wrap; }
.value-line b { font-size: 24px; font-weight: 400; letter-spacing: -.8px; }
.value-line .chg { font-size: 12.5px; font-weight: 600; }
.value-line .per { font-size: 11px; color: var(--faint); }
.chart-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; gap: 8px; }
.legend { display: flex; gap: 10px; font-size: 11px; color: var(--dim); flex-wrap: wrap; }
.legend span { display: flex; align-items: center; gap: 4px; }
.legend .swatch { width: 8px; height: 8px; border-radius: 3px; }

/* records */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 0 12px; }
.kpis > div { background: var(--surface-2); border-radius: var(--r-kpi); padding: 8px 10px; }
.kpis .k { font-size: 10.5px; color: var(--dim); }
.kpis .v { font-size: 14px; margin-top: 1px; }
.kpis .s { font-size: 10px; color: var(--faint); }
.trow { padding: 11px 16px; display: block; width: 100%; text-align: left; }
.trow + .trow, .collapse + .trow { border-top: 1px solid var(--hairline); }
.trow-sub { display: flex; justify-content: space-between; margin-top: 4px; font-size: 11.5px; color: var(--dim); gap: 8px; }
.dv { font-size: 10.5px; padding: 1px 7px; border-radius: var(--r-pill); background: var(--hairline); color: var(--text-2); white-space: nowrap; }
.dv.none { color: var(--faint); }
.trow-sub.cf { justify-content: flex-start; color: var(--text-2); }
.cfbox { margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--hairline); }
.tag { font-size: 10px; padding: 1px 6px; border-radius: var(--r-pill); background: var(--hairline); color: #a8a398; margin-left: 4px; }
.tid { font-size: 11px; color: var(--faint); margin-left: 4px; }
.tdetail { padding: 0 16px 12px; }
.drow { display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; padding: 4px 0; align-items: baseline; }
.drow .k { color: var(--dim); font-size: 11px; }
.drow .sl { font-size: 11px; }
.cmp { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--hairline); }
.cbar { display: grid; grid-template-columns: 34px 1fr 70px; gap: 8px; align-items: center; padding: 3px 0; font-size: 11px; color: var(--dim); }
.cbar .b { height: 6px; border-radius: var(--r-pill); }
.cbar .b.exp { background: transparent; border: 1.5px dashed currentColor; height: 8px; }
.cbar .n { text-align: right; color: var(--text); }
.more { display: block; width: 100%; text-align: center; font-size: 12px; color: var(--dim); padding: 11px; border-top: 1px solid var(--hairline); }
.empty { text-align: center; color: var(--faint); font-size: 12.5px; padding: 26px 12px; }

/* skeleton */
.skeleton {
  background: linear-gradient(100deg, var(--surface) 40%, var(--track) 50%, var(--surface) 60%) var(--surface);
  background-size: 250% 100%; animation: shimmer 1.6s linear infinite;
  border-radius: var(--r-panel); margin: 0 12px 10px; height: 120px; opacity: .6;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
.skeleton.tall { height: 240px; }

/* tab bar */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
  width: calc(100% - 24px); max-width: 456px; display: flex; gap: 4px; background: var(--surface);
  border-radius: var(--r-pill); padding: 5px; box-shadow: 0 8px 28px rgba(0, 0, 0, .45); z-index: 10;
}
.tabbar button { flex: 1; text-align: center; padding: 10px 0; font-size: 12.5px; color: var(--faint); border-radius: var(--r-pill); min-height: 40px; }
.tabbar button.on { color: var(--accent); background: var(--accent-bg); font-weight: 600; }

/* auth overlay */
.overlay {
  position: fixed; inset: 0; background: rgba(16, 16, 15, .94); z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px; text-align: center;
}
.overlay p { color: var(--text-2); font-size: 14px; }
.overlay button { background: var(--accent-bg); color: var(--accent); font-weight: 600; padding: 10px 22px; border-radius: var(--r-pill); }

/* iOS "동작 줄이기": no shimmer; the busy dot dims instead of pulsing */
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
  .live.busy i { animation: none; opacity: .45; }
}
.strategy-seg { margin: 8px 0 2px; }

/* research tab — portfolio cards (demo account · shadows), strategy slider, comparison chart */
.research-head { display: flex; justify-content: flex-end; padding: 0 16px 8px; }
.section-label.rs { display: flex; justify-content: space-between; align-items: baseline; padding: 8px 26px 6px; }
.section-label.rs b { color: var(--text-2); font-weight: 600; font-size: 12.5px; }
.baseline { margin: 0 12px 4px; background: var(--surface-2); border-radius: var(--r-box); padding: 9px 14px;
  font-size: 12px; color: var(--dim); display: flex; justify-content: space-between; gap: 8px; }
.baseline b { color: var(--text-2); font-weight: 500; }
.pf-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.pf { margin: 0 12px; background: var(--surface); border-radius: var(--r-panel); overflow: hidden; }
.pf.hero { margin-bottom: 4px; }
.pf-total { padding: 14px 16px 12px; display: flex; flex-direction: column; gap: 9px; }
.pf-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.pf .title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; min-width: 0; }
.pf .sub { font-size: 11.5px; color: var(--dim); margin-top: 3px; }
.pf.hero .big { font-size: 28px; font-weight: 600; letter-spacing: -.5px; margin-top: 4px; }
.pf .ret { text-align: right; flex: none; }
.pf .ret .v { font-size: 17px; font-weight: 600; }
.pf .ret .d { font-size: 11px; color: var(--dim); margin-top: 2px; }
.pf .badges { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.pf .pill { margin-left: 0; }
.pill.real { color: var(--accent); background: var(--accent-bg); }
.pill.shadow { color: var(--dim); background: var(--hairline); }
.pill.cut { color: var(--c-s2); background: rgba(184, 121, 178, .14); }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.metrics div { background: var(--surface-2); border-radius: 10px; padding: 6px 8px; min-width: 0; }
.metrics .k2 { font-size: 10.5px; color: var(--faint); }
.metrics .m { font-size: 12.5px; color: var(--text-2); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; }
.pf .swatch { width: 9px; height: 9px; border-radius: 3px; flex: none; display: inline-block; }
.pf-status { font-size: 10.5px; color: var(--faint); }
.pf .toggle { font-size: 12.5px; color: var(--text-2); border-top: 1px solid var(--hairline); width: 100%;
  padding: 10px 16px; display: flex; justify-content: space-between; align-items: center; }
.pf .toggle .cnt { color: var(--dim); margin-left: 6px; }
.pf .toggle .chev { color: var(--dim); transition: transform .2s; }
.pf .toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }
.slider-wrap { padding: 0 0 12px; }
.slider { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; padding: 0 16px; }
.slider::-webkit-scrollbar { display: none; }
.slide { flex: 0 0 88%; scroll-snap-align: center; background: var(--surface-2); border-radius: var(--r-box);
  padding: 12px 14px 10px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.slide-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.slide .name { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13.5px; min-width: 0; }
.slide .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.slide .metrics div { background: var(--surface); }
.pf-chk { font-size: 11px; color: var(--dim); background: var(--surface-2); border-radius: var(--r-pill); padding: 3px 9px; }
.pf-chk[aria-pressed="true"] { color: var(--bg); background: var(--text-2); }
.research-legend { gap: 4px 12px; margin: 6px 0 8px; }
.log > div { display: grid; grid-template-columns: 3.4em minmax(0, 1fr); gap: 8px; padding: 6px 0; font-size: 12px;
  border-top: 1px solid var(--hairline); }
.log > div:first-child { border-top: 0; }
.log time { color: var(--faint); }
.log p { color: var(--text-2); min-width: 0; overflow-wrap: anywhere; }
@media (prefers-reduced-motion: reduce) { .pf .toggle .chev { transition: none; } }
