/* PickleTrader — mobile-first dark UI (iPhone)
   화면: ① 차트/시세 ② 오늘 매수 TOP5 ③ 자동 상투 */

:root {
  --bg: #0b0f17;
  --bg-2: #0e1520;
  --card: #121a26;
  --card-2: #16202e;
  --line: #22303f;
  --txt: #e8eef7;
  --muted: #8698ad;
  --emerald: #10b981;
  --emerald-dim: rgba(16, 185, 129, 0.14);
  --purple: #7c3aed;
  --red: #f0506e;
  --red-dim: rgba(240, 80, 110, 0.14);
  --amber: #f5b942;
  --amber-dim: rgba(245, 185, 66, 0.14);
  --sky: #38bdf8;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 58px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard",
    "Malgun Gothic", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* ── 상단 바 ─────────────────────────────── */
.appbar {
  flex: 0 0 auto;
  padding-top: calc(var(--safe-top) + 6px);
  background: linear-gradient(180deg, rgba(14, 21, 32, 0.98), rgba(11, 15, 23, 0.92));
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.appbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 16px 8px;
}
.brand { display: flex; align-items: center; gap: 7px; }
.brand-name { font-weight: 700; letter-spacing: -0.02em; font-size: 16px; }
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18), 0 0 12px rgba(16, 185, 129, 0.7);
}
.pill {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  background: rgba(255, 255, 255, 0.02);
}

/* ── 본문 ───────────────────────────────── */
main {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px calc(var(--tabbar-h) + var(--safe-bottom) + 22px);
}
.panel { display: none; }
.panel.is-active { display: block; animation: fade 0.18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

h2.card-title {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 14px; font-weight: 700; margin: 0 0 10px; letter-spacing: -0.01em;
}
.muted { color: var(--muted); font-weight: 500; font-size: 12px; }
.hint { color: var(--muted); font-size: 11.5px; line-height: 1.5; margin: 8px 2px 0; }
.hint code { font-size: 11px; color: #a8bcd2; background: rgba(255, 255, 255, 0.04); padding: 1px 4px; border-radius: 4px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 12px;
}

/* ── 관심종목 스트립 ─────────────────────── */
.watch-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 10px;
  margin: 0 -2px;
  scrollbar-width: none;
}
.watch-strip::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--txt);
  border-radius: 11px;
  padding: 8px 12px;
  font-size: 13px; font-weight: 650; letter-spacing: 0.01em;
  transition: all 0.15s ease;
}
.chip.is-on {
  border-color: rgba(16, 185, 129, 0.55);
  background: var(--emerald-dim);
  color: #b9f5dc;
  box-shadow: 0 0 0 1px rgba(16, 185, 129, 0.12) inset;
}
.chip .x {
  border: 0; background: transparent; color: var(--muted);
  font-size: 15px; line-height: 1; padding: 0 0 0 2px; margin-left: 1px;
}
.chip-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--emerald); flex: 0 0 auto;
}
.chip-dot.warn { background: var(--amber); }
.chip-dot.danger { background: var(--red); }

.add-row { display: flex; gap: 8px; margin-bottom: 12px; }
.add-input {
  flex: 1 1 auto; min-width: 0;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--txt);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 16px; /* iOS 자동 확대 방지 */
  font-family: inherit;
}
.add-input::placeholder { color: #5a6b7f; }
.btn-ghost {
  border: 1px solid rgba(16, 185, 129, 0.45);
  background: var(--emerald-dim);
  color: #a8f0d2;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 13.5px; font-weight: 650;
  font-family: inherit;
  flex: 0 0 auto;
  text-decoration: none;
  text-align: center;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-ghost:active { transform: scale(0.98); }
.btn-ghost:disabled { opacity: 0.55; }

/* ── 차트 ───────────────────────────────── */
.chart-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 10px 10px;
  overflow: hidden;
}
.chart-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 0 4px 8px;
}
.chart-id { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.chart-id .sym { font-size: 19px; font-weight: 800; letter-spacing: -0.02em; }
.chart-id .cname { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart-head-right { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.tv-link {
  font-size: 11px; color: var(--muted); text-decoration: none;
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px;
  flex: 0 0 auto;
}
.tf-row { display: flex; gap: 6px; padding: 0 4px 9px; }
.tf {
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  border-radius: 8px; padding: 4px 10px; font-size: 11.5px; font-family: inherit; font-weight: 600;
}
.tf.is-on { color: #b9f5dc; border-color: rgba(16, 185, 129, 0.5); background: var(--emerald-dim); }

/* 지표 ON/OFF 버튼 — 누를 때마다 그 지표만 사라지고/나타난다 */
.ind-row { display: flex; flex-wrap: wrap; gap: 5px; padding: 0 4px 9px; }
.ind {
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  border-radius: 999px; padding: 4px 10px; font-size: 11px; font-family: inherit; font-weight: 600;
  line-height: 1.2;
}
.ind.is-on { color: #cfe9ff; border-color: rgba(79, 195, 247, 0.45); background: rgba(79, 195, 247, 0.1); }
.ind.is-off { color: #5b6b7d; border-style: dashed; background: transparent; opacity: 0.75; }
.ind:active { transform: scale(0.97); }

.chart-legend {
  display: flex; flex-wrap: wrap; align-items: baseline;
  gap: 3px 10px;
  padding: 0 6px 7px;
  font-size: 11px; color: var(--muted);
}
.chart-legend .lg-px { font-weight: 800; font-size: 12.5px; color: var(--txt); }
.chart-legend .lg-ma { display: inline-flex; align-items: center; gap: 4px; }
.chart-legend .lg-ma i { width: 9px; height: 2px; border-radius: 1px; display: inline-block; }
.chart-legend .lg-ma.is-off { opacity: 0.4; }
.chart-legend .lg-tf { color: #64778c; }
.chart-legend .lg-gex { display: inline-flex; gap: 6px; align-items: baseline; }
.chart-legend .lg-gex.is-off { opacity: 0.45; text-decoration: line-through; }
.chart-legend .lg-gex-c { color: #f0506e; }
.chart-legend .lg-gex-p { color: #26a69a; }
.chart-legend .lg-gex-z { color: #b39ddb; }

.lwchart {
  width: 100%;
  height: 58vh;
  min-height: 300px;
  max-height: 520px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg);
  position: relative;
  touch-action: pan-y;   /* 세로 스크롤은 페이지에 넘기고, 차트는 가로 드래그만 받는다 */
}
.chart-empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12.5px; text-align: center; padding: 24px;
}
.chart-tip {
  position: absolute; z-index: 4; top: 8px; left: 8px;
  background: rgba(18, 26, 38, 0.95);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 9px; max-width: 150px;
  font-size: 10.5px; line-height: 1.55; color: #cfdae8;
  pointer-events: none;
  display: flex; flex-direction: column; gap: 1px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
.chart-tip[hidden] { display: none; }
.chart-tip b { color: var(--txt); }
.chart-tip .tip-ma20 { color: #4fc3f7; }
.chart-tip .tip-ma50 { color: #f5b942; }
.tv-fallback {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12.5px; text-align: center; padding: 24px;
  line-height: 1.6;
}

/* ── 펀더멘털 셀 (PER · FCF · 자사주 · 실적일) ── */
.fund-row {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 9px 0 3px;
}
.fund-cell {
  flex: 1 1 44%; min-width: 0;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 5px 7px;
}
.fund-cell span {
  display: block; font-size: 9.5px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fund-cell b {
  display: block; font-size: 11.5px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fund-cell b i { font-style: normal; font-weight: 600; font-size: 9.5px; color: var(--muted); }
.fund-row.is-empty {
  align-items: center; justify-content: space-between;
  border: 1px dashed var(--line); border-radius: 10px;
  padding: 6px 9px; font-size: 10.5px;
}
.fund-btn {
  border: 1px solid var(--line); background: transparent; color: #9fb3c8;
  border-radius: 999px; padding: 3px 10px; font-size: 10px; font-family: inherit; font-weight: 650;
  flex: 0 0 auto;
}
.fund-btn:active { border-color: rgba(56, 189, 248, 0.45); color: #9fe6ff; }

/* ── 뱃지 · 공통 ────────────────────────── */
.up { color: var(--emerald); }
.down { color: var(--red); }

.badge {
  font-size: 11.5px; font-weight: 800; padding: 5px 11px; border-radius: 999px;
  background: var(--emerald-dim); color: #7de8bf; border: 1px solid rgba(16, 185, 129, 0.35);
  white-space: nowrap;
}
.badge.small { font-size: 10px; padding: 3px 8px; }
.badge.warn { background: var(--amber-dim); color: var(--amber); border-color: rgba(245, 185, 66, 0.35); }
.badge.danger { background: var(--red-dim); color: #ff92a6; border-color: rgba(240, 80, 110, 0.4); }
.badge.live {
  background: rgba(56, 189, 248, 0.14); color: #8fe0ff; border-color: rgba(56, 189, 248, 0.45);
  font-size: 10.5px; padding: 4px 9px;
}
.badge.live::before {
  content: ""; display: inline-block; width: 5px; height: 5px; border-radius: 50%;
  background: var(--sky); margin-right: 5px; vertical-align: 1px;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}
.badge.cache {
  background: rgba(255, 255, 255, 0.05); color: #a8b8ca; border-color: var(--line);
  font-size: 10.5px; padding: 4px 9px;
}

.verdict { font-size: 12.5px; line-height: 1.55; color: #c8d6e6; margin: 0 0 10px; padding: 10px 12px;
  background: rgba(255, 255, 255, 0.03); border-radius: 10px; border: 1px solid var(--line); }
.verdict b { color: #e8eef7; font-weight: 700; }

/* ── 상투 게이지 (탭2·탭3 공용 카드) ───── */
.gauge-card { background: linear-gradient(160deg, #121a26, #131a2c); }
.gauge-top { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 12px; gap: 8px; }
.acc-label { font-size: 11.5px; color: var(--muted); letter-spacing: 0.01em; }
.gauge-num { display: block; font-size: 26px; font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.gauge-num em { font-style: normal; font-size: 14px; color: var(--muted); font-weight: 600; margin-left: 4px; }

.status-counts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; }
.sc {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 7px 4px;
}
.sc span { font-size: 10px; color: var(--muted); }
.sc b { font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; }
.sc.normal b { color: var(--emerald); }
.sc.warn b { color: var(--amber); }
.sc.danger b { color: var(--red); }

.meter-scale { display: flex; justify-content: space-between; font-size: 9.5px; color: var(--muted); margin-top: 6px; }

/* 분할 매수 가이드 */
.guide {
  display: flex; flex-direction: column; gap: 3px;
  background: rgba(255, 255, 255, 0.03); border: 1px dashed var(--line);
  border-radius: 10px; padding: 9px 11px; margin-bottom: 10px;
}
.guide:empty { display: none; }
.guide-t { font-size: 11.5px; font-weight: 800; color: #b9f5dc; }
.guide-t.warn { color: var(--amber); }
.guide-t.danger { color: #ff92a6; }
.guide-d { font-size: 11.5px; color: #b8c9da; line-height: 1.5; }

/* ── 조작 ───────────────────────────────── */
.control-row { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 10px; }
.control-row .btn-ghost { width: 100%; }

/* ── 오늘 매수 TOP5 ─────────────────────── */
.sig-list { display: flex; flex-direction: column; gap: 10px; }

.buy-card {
  margin-bottom: 0; padding: 12px 13px;
  background: linear-gradient(158deg, #101d1a, #121a26 60%);
  border-color: rgba(16, 185, 129, 0.22);
}
.buy-card.is-warn { border-color: rgba(245, 185, 66, 0.3); }
.buy-card.is-danger { border-color: rgba(240, 80, 110, 0.34); }

.buy-head { display: flex; align-items: center; gap: 9px; }
.rank {
  flex: 0 0 auto;
  width: 26px; height: 26px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums;
  background: rgba(16, 185, 129, 0.16); color: #7de8bf; border: 1px solid rgba(16, 185, 129, 0.35);
}
.rank.top { background: rgba(245, 185, 66, 0.18); color: var(--amber); border-color: rgba(245, 185, 66, 0.45); }
.buy-id { display: flex; flex-direction: column; min-width: 0; }
.buy-id b { font-size: 15.5px; font-weight: 800; letter-spacing: -0.01em; }
.buy-id small { font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.buy-px { margin-left: auto; text-align: right; padding-right: 2px; }
.buy-px b { font-size: 13.5px; font-variant-numeric: tabular-nums; }
.buy-px small { display: block; font-size: 10.5px; font-variant-numeric: tabular-nums; }

.buy-score { display: flex; align-items: center; gap: 9px; margin: 10px 0 9px; }
.buy-score em { font-style: normal; font-size: 9.5px; color: var(--muted); flex: 0 0 auto; }
.buy-score > b { font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 24px; text-align: right; }

.why { list-style: none; margin: 9px 0 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.why li { font-size: 11.8px; color: #d3dfec; line-height: 1.45; padding-left: 11px; position: relative; }
.why li::before { content: ""; position: absolute; left: 2px; top: 6px; width: 4px; height: 4px; border-radius: 50%; background: rgba(16, 185, 129, 0.75); }

.more { margin-top: 7px; }
.more summary {
  font-size: 10.5px; color: var(--muted); cursor: pointer; list-style: none;
  padding: 3px 0;
}
.more summary::-webkit-details-marker { display: none; }
.more summary::before { content: "▸ "; }
.more[open] summary::before { content: "▾ "; }
.more .why { margin-top: 4px; }
.more .why li { font-size: 11.2px; color: #b8c9da; }

.note {
  margin-top: 9px; padding-top: 8px; border-top: 1px dashed var(--line);
  font-size: 10.8px; color: #9fb2c6; line-height: 1.5;
}
.note b { color: #7de8bf; font-size: 9.5px; letter-spacing: 0.04em; margin-right: 4px; }

/* 오늘 제외 목록 */
.skip-list { display: flex; flex-direction: column; gap: 6px; }
.skip {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto;
  column-gap: 8px; align-items: baseline;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
}
.skip b { font-size: 13px; font-weight: 750; grid-row: 1; }
.skip .muted { font-size: 10.5px; grid-row: 1; }
.skip small { grid-column: 1 / span 2; grid-row: 2; font-size: 10.8px; color: #9fb2c6; line-height: 1.45; margin-top: 3px; }

/* ── 자동 상투 ──────────────────────────── */
.sig-card { margin-bottom: 0; padding: 12px 13px; }
.sig-card.is-warn { border-color: rgba(245, 185, 66, 0.32); }
.sig-card.is-danger { border-color: rgba(240, 80, 110, 0.38); background: linear-gradient(160deg, #1a141c, #121a26); }
.sig-head { display: flex; align-items: center; gap: 8px; }
.sig-idb { display: flex; flex-direction: column; min-width: 0; }
.sig-idb b { font-size: 15px; font-weight: 800; letter-spacing: -0.01em; }
.sig-idb small { font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sig-px { margin-left: auto; text-align: right; padding-right: 2px; }
.sig-x {
  flex: 0 0 auto; width: 24px; height: 24px; border-radius: 8px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03);
  color: var(--muted); font-size: 15px; line-height: 1; font-family: inherit;
  display: inline-flex; align-items: center; justify-content: center;
  margin-left: 2px; padding: 0;
}
.sig-x:active { color: #ff92a6; border-color: rgba(240, 80, 110, 0.4); }
.sig-px b { font-size: 13.5px; font-variant-numeric: tabular-nums; }
.sig-px small { display: block; font-size: 10.5px; font-variant-numeric: tabular-nums; }

.score-row { display: flex; align-items: center; gap: 9px; margin: 9px 0 8px; }
.score-bar {
  position: relative; flex: 1 1 auto; height: 8px; border-radius: 999px;
  background: #1b2634; overflow: hidden;
}
.score-bar i {
  display: block; height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, #10b981, #f5b942 55%, #f0506e);
  transition: width 0.3s cubic-bezier(0.3, 0.9, 0.3, 1);
}
.score-bar i.warn { background: linear-gradient(90deg, #10b981, #f5b942); }
.score-bar i.danger { background: linear-gradient(90deg, #f5b942, #f0506e); }
.score-bar.buy { height: 9px; flex: 0 1 68%; }
.score-bar.buy i { background: linear-gradient(90deg, #10b981, #38bdf8); }
.score-bar .tick { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(11, 15, 23, 0.9); }
.score-bar .t30 { left: 30%; }
.score-bar .t60 { left: 60%; }
.score-row > b { font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 26px; text-align: right; }

.sig-metrics { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; padding: 8px 0; border-top: 1px dashed var(--line); border-bottom: 1px dashed var(--line); }
.sig-metrics > div { display: flex; flex-direction: column; gap: 1px; }
.sig-metrics span { font-size: 9.5px; color: var(--muted); }
.sig-metrics b { font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums; }

.reasons { list-style: none; margin: 9px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.reasons li { display: flex; align-items: flex-start; gap: 8px; font-size: 11.5px; color: #d3dfec; line-height: 1.4; }
.reasons .pts {
  flex: 0 0 auto; min-width: 26px; text-align: center; font-size: 10px; font-weight: 800;
  color: #ffb3c0; background: var(--red-dim); border-radius: 5px; padding: 1px 4px; margin-top: 1px;
}
.reasons li:last-child .pts { color: #7de8bf; background: var(--emerald-dim); }
.reasons small { display: block; font-size: 10.5px; color: var(--muted); margin-top: 1px; }

/* ── 규칙 설명 ──────────────────────────── */
.rules { border-top: 1px solid var(--line); padding: 9px 0; }
.rules:first-of-type { border-top: 0; padding-top: 0; }
.rules summary { font-size: 12.5px; font-weight: 700; color: #c8d6e6; cursor: pointer; list-style: none; }
.rules summary::-webkit-details-marker { display: none; }
.rules summary::before { content: "▸ "; color: var(--muted); }
.rules[open] summary::before { content: "▾ "; }
.rules ul { margin: 8px 0 0; padding-left: 16px; font-size: 11.5px; color: #b8c9da; line-height: 1.6; }
.rules li { margin-bottom: 3px; }
.rules b { color: #e8eef7; }

.empty { color: var(--muted); font-size: 12.5px; text-align: center; padding: 16px 6px; line-height: 1.5; }

/* ── AI 1초 진단 (Groq) ─────────────────── */
.ai-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.ai-btn {
  flex: 1 1 auto;
  border: 1px solid rgba(56, 189, 248, 0.4);
  background: rgba(56, 189, 248, 0.12);
  color: #9fe6ff;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 11.5px; font-weight: 700; font-family: inherit;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  white-space: nowrap;
}
.ai-btn:active { transform: scale(0.98); }
.ai-btn.shield {
  flex: 1 1 100%;
  border-color: rgba(245, 185, 66, 0.46);
  background: var(--amber-dim); color: var(--amber);
  font-size: 12px;
}

.ai-slot:empty { display: none; }
.ai-box {
  margin-top: 9px; padding: 10px 11px; border-radius: 11px;
  background: rgba(56, 189, 248, 0.06);
  border: 1px solid rgba(56, 189, 248, 0.26);
  font-size: 11.8px; color: #d3dfec; line-height: 1.45;
}
.ai-box.is-loading { display: flex; align-items: center; gap: 8px; color: #9fe6ff; }
.ai-box.is-error {
  display: flex; flex-direction: column; gap: 4px;
  background: var(--red-dim); border-color: rgba(240, 80, 110, 0.34);
}
.ai-box.is-error b { color: #ff92a6; font-size: 11.5px; }
.ai-spin {
  width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto;
  border: 2px solid rgba(56, 189, 248, 0.3); border-top-color: var(--sky);
  animation: aiSpin 0.8s linear infinite;
}
@keyframes aiSpin { to { transform: rotate(360deg); } }

.ai-lines { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.ai-lines li { display: flex; gap: 7px; }
.ai-lines li b {
  flex: 0 0 auto; min-width: 28px; padding-top: 1px;
  font-size: 10.5px; font-weight: 800; color: #9fe6ff; letter-spacing: 0.02em;
}
.ai-lines li span { min-width: 0; }

.ai-verdict {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 800; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--line); margin-bottom: 8px;
}
.ai-verdict.noise { color: #b9f5dc; background: var(--emerald-dim); border-color: rgba(16, 185, 129, 0.4); }
.ai-verdict.moat { color: #ff92a6; background: var(--red-dim); border-color: rgba(240, 80, 110, 0.45); }
.ai-verdict.hold { color: #c8d6e6; background: rgba(255, 255, 255, 0.05); }

.ai-src {
  display: block; margin-top: 7px; font-size: 10.3px; line-height: 1.4;
  color: #8fe0ff; text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ai-src.muted { color: var(--muted); }
.ai-foot { margin-top: 6px; font-size: 9.5px; color: var(--muted); }
.ai-guide {
  margin: 6px 0 0; padding: 8px 9px; border-radius: 8px;
  border: 1px dashed var(--line); background: rgba(255, 255, 255, 0.04);
  font-size: 11px; color: #c8d6e6; line-height: 1.5;
}
.ai-guide b { color: #b9f5dc; display: block; margin-bottom: 2px; }

/* 팩트체크 카드(접힘) */
.ai-fact { padding: 0; overflow: hidden; }
.ai-fact-sum {
  display: flex; align-items: baseline; gap: 8px;
  padding: 12px 14px; cursor: pointer; list-style: none;
  font-size: 13px; font-weight: 700;
}
.ai-fact-sum::-webkit-details-marker { display: none; }
.ai-fact-sum::after { content: "▾"; margin-left: auto; color: var(--muted); font-size: 12px; }
.ai-fact[open] .ai-fact-sum::after { content: "▴"; }
.ai-fact-sum .muted { font-weight: 500; font-size: 10.5px; }
.ai-fact-body { padding: 0 14px 12px; }
.ai-textarea {
  width: 100%; min-height: 76px;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--txt);
  border-radius: 11px; padding: 10px 11px;
  font-size: 16px; font-family: inherit; line-height: 1.45; resize: vertical;
}
.ai-textarea::placeholder { color: #5a6b7f; font-size: 12.5px; }
.ai-fact-btn { width: 100%; margin-top: 8px; }

/* ── 하단 탭바 ──────────────────────────── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(12, 18, 27, 0.94);
  backdrop-filter: blur(18px) saturate(140%);
  border-top: 1px solid var(--line);
  z-index: 50;
}
.tab {
  border: 0; background: transparent; color: #64788e;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 10px; font-weight: 700; font-family: inherit;
  padding: 6px 0 4px; white-space: nowrap;
}
.tab svg {
  width: 22px; height: 22px; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.tab.is-on { color: var(--emerald); }
.tab.is-on svg { filter: drop-shadow(0 0 6px rgba(16, 185, 129, 0.5)); }

/* ── AI 채팅 ─────────────────────────────── */
.panel#panel-chat.is-active {
  display: flex; flex-direction: column;
  min-height: calc(100dvh - 150px);   /* 입력창이 화면 아래에 붙는다 */
}
.chat-log { flex: 1 1 auto; }
.chat-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 2px 2px 10px;
}
.chat-title { font-size: 14px; font-weight: 800; letter-spacing: -0.01em; }
.chat-title .muted { font-size: 10px; font-weight: 600; margin-left: 3px; }
.chat-clear {
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03);
  color: var(--muted); border-radius: 999px; padding: 5px 11px;
  font-size: 11px; font-weight: 650; font-family: inherit;
}
.chat-clear:active { color: #ff92a6; border-color: rgba(240, 80, 110, 0.4); }

.chat-log { display: flex; flex-direction: column; gap: 9px; padding-bottom: 4px; }
.chat-empty {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--card); border: 1px dashed var(--line); border-radius: 14px;
  padding: 14px; font-size: 12px; color: #b8c9da; line-height: 1.5;
}
.chat-empty b { font-size: 13px; color: var(--txt); }

.chat-msg { display: flex; flex-direction: column; max-width: 88%; }
.chat-msg.me { align-self: flex-end; align-items: flex-end; }
.chat-msg.ai { align-self: flex-start; align-items: flex-start; }
.chat-bubble {
  padding: 9px 12px; border-radius: 14px;
  font-size: 13.5px; line-height: 1.5; word-break: break-word;
  border: 1px solid var(--line); background: var(--card); color: #e2ebf6;
}
.chat-msg.me .chat-bubble {
  background: rgba(16, 185, 129, 0.16);
  border-color: rgba(16, 185, 129, 0.38);
  color: #d9fbea;
  border-bottom-right-radius: 5px;
}
.chat-msg.ai .chat-bubble {
  background: rgba(56, 189, 248, 0.07);
  border-color: rgba(56, 189, 248, 0.24);
  border-bottom-left-radius: 5px;
}
.chat-msg.ai.is-error .chat-bubble {
  background: var(--red-dim); border-color: rgba(240, 80, 110, 0.34); color: #ffc4d0;
}
.chat-bubble.is-typing { display: flex; align-items: center; gap: 8px; color: #9fe6ff; font-size: 12px; }
.chat-src {
  display: block; margin-top: 4px; font-size: 9.8px; color: #8fe0ff; text-decoration: none;
  max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-src.muted { color: var(--muted); }
.chat-foot { margin-top: 3px; font-size: 9.2px; color: var(--muted); }

.chat-composer {
  position: sticky;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) - 4px);
  z-index: 12;
  margin: 10px -6px -6px;
  padding: 8px 6px 6px;
  background: linear-gradient(180deg, rgba(11, 15, 23, 0.35), rgba(11, 15, 23, 0.96) 38%);
  backdrop-filter: blur(10px);
}
.chat-chips {
  display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px;
  scrollbar-width: none;
}
.chat-chips::-webkit-scrollbar { display: none; }
.chip-q {
  flex: 0 0 auto;
  border: 1px solid var(--line); background: var(--card);
  color: #b8c9da; border-radius: 999px; padding: 6px 11px;
  font-size: 11px; font-weight: 650; font-family: inherit; white-space: nowrap;
}
.chip-q:active { border-color: rgba(56, 189, 248, 0.45); color: #9fe6ff; }
.chat-form { display: flex; gap: 7px; align-items: center; }
.chat-input {
  flex: 1 1 auto; min-width: 0;
  background: var(--card); border: 1px solid var(--line); color: var(--txt);
  border-radius: 12px; padding: 11px 12px;
  font-size: 16px; /* iOS 자동 확대 방지 */
  font-family: inherit;
}
.chat-input::placeholder { color: #5a6b7f; font-size: 13px; }
.chat-send {
  flex: 0 0 auto;
  border: 1px solid rgba(16, 185, 129, 0.45); background: var(--emerald-dim);
  color: #a8f0d2; border-radius: 12px; padding: 11px 15px;
  font-size: 13.5px; font-weight: 700; font-family: inherit;
}
.chat-send:active { transform: scale(0.98); }
.chat-send:disabled { opacity: 0.55; }

@media (min-width: 620px) {
  main { max-width: 560px; margin: 0 auto; width: 100%; }
  .tabbar { max-width: 560px; left: 50%; transform: translateX(-50%); border-radius: 16px 16px 0 0; }
  .tvchart { height: 480px; }
  .lwchart { height: 460px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
