/* === 台股技術分析儀表板 — 一頁解讀版 === */

:root {
  --bg-page: #020613;
  --bg-panel: #060f24;
  --bg-panel2: #0a1733;
  --bg-cell:  #08122a;
  --border: #1d3b6e;
  --border-bright: #2b62c2;
  --text: #e0eaff;
  --text-dim: #6e89bd;
  --cyan: #4dd6ff;
  --yellow: #ffd84a;
  --green: #29e87a;     /* 台股：跌綠 */
  --red: #ff4d4d;       /* 台股：漲紅 */
  --orange: #ff9d3a;
  --magenta: #ff66cc;
  --purple: #c191ff;
  --warn: #ff8a3a;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; background: var(--bg-page); color: var(--text);
  font-family: "Microsoft JhengHei", "Noto Sans TC", "Segoe UI", sans-serif;
  font-size: 12px;
  width: 100vw; height: 100vh; overflow: hidden;
}

/* === 控制列 (24px) === */
#control-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 10px; background: var(--bg-panel2); border-bottom: 1px solid var(--border);
  height: 26px; flex-shrink: 0;
}
.ctrl-label { color: var(--text-dim); }
#symbol-input, #period-select {
  background: var(--bg-page); color: var(--text);
  border: 1px solid var(--border); padding: 2px 8px; font: inherit;
}
#load-btn {
  background: var(--border-bright); color: white; border: 0;
  padding: 3px 14px; cursor: pointer; font: inherit; border-radius: 2px;
}
#load-btn:hover { background: #4084e8; }
#status-text { margin-left: auto; color: var(--text-dim); font-size: 10px; }

/* === Page wrapper grid (整頁 100vh) === */
body {
  display: grid;
  grid-template-rows: 26px 70px 1fr 130px;
  grid-template-areas:
    "ctrl"
    "hdr"
    "main"
    "bot";
}
#control-bar { grid-area: ctrl; }
#hdr { grid-area: hdr; }
#main { grid-area: main; }
#bottom-row { grid-area: bot; }

/* ====================== HEADER ====================== */
#hdr {
  display: grid;
  grid-template-columns: 1.7fr 1.4fr 0.9fr 1fr 1.1fr 1.1fr 1.4fr 1.2fr;
  gap: 4px;
  padding: 4px 6px;
  background: var(--bg-page);
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.hdr-block {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 4px 8px;
  height: 60px;
  display: flex; flex-direction: column; justify-content: center;
}
.hdr-name-block {
  background: linear-gradient(90deg, #0c1a3a 0%, #060f24 100%);
}
#hdr-name {
  font-size: 26px; font-weight: bold; color: var(--yellow);
  letter-spacing: 4px; line-height: 1;
}
#hdr-code {
  font-size: 22px; color: var(--cyan); font-weight: bold;
  margin-left: 8px; letter-spacing: 2px;
}
.hdr-industry { color: var(--text-dim); font-size: 10px; margin-top: 4px; letter-spacing: 1px; }
.hdr-price-block { text-align: center; align-items: center; }
#hdr-price {
  font-size: 38px; font-weight: bold; color: var(--green);
  font-family: "Consolas", "Courier New", monospace; line-height: 1;
}
#hdr-change { font-size: 13px; color: var(--green); margin-top: 4px; font-family: "Consolas", monospace; }
.hdr-cell { text-align: center; align-items: center; gap: 1px; }
.hdr-cell.two { gap: 1px; }
.hdr-cell.two > div { display: flex; justify-content: space-between; gap: 4px; }
.cl { color: var(--text-dim); font-size: 10px; }
.cv { font-size: 17px; color: var(--cyan); font-weight: bold; font-family: "Consolas", monospace; line-height: 1.1; }
.cv.big { font-size: 22px; }
.cv.green { color: var(--green); }
.cv.red { color: var(--red); }
.cp { font-size: 11px; line-height: 1; }
.cp.green { color: var(--green); }
.cp.red { color: var(--red); }

.hdr-bar-wrap { padding: 2px 6px; gap: 4px; justify-content: center; }
.hdr-bar { display: flex; height: 16px; border: 1px solid var(--border); border-radius: 2px; overflow: hidden; }
.hdr-bar-in  { background: var(--green); height: 100%; transition: flex 0.5s; }
.hdr-bar-out { background: var(--red);   height: 100%; transition: flex 0.5s; }
.hdr-time { color: var(--text-dim); font-size: 11px; font-family: "Consolas", monospace; text-align: center; margin-top: 2px; }

.hdr-alert { text-align: center; align-items: center; }
.alert-stars { font-size: 18px; color: var(--yellow); letter-spacing: 2px; line-height: 1.1; }
.alert-level { color: var(--yellow); font-size: 12px; }

/* ====================== MAIN GRID ====================== */
#main {
  display: grid;
  grid-template-columns: 1.85fr 1fr 1fr 0.85fr;
  gap: 4px;
  padding: 4px 6px;
  min-height: 0;
}
.col {
  display: flex; flex-direction: column; gap: 4px;
  min-height: 0; min-width: 0;
}

/* === 通用 panel === */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 5px 8px;
  position: relative;
  min-height: 0;
  display: flex; flex-direction: column;
}
.ptitle {
  color: var(--cyan); font-weight: bold; font-size: 13px;
  border-bottom: 1px solid var(--border);
  padding: 1px 0 3px 0; margin-bottom: 4px;
  letter-spacing: 2px; text-align: center; flex-shrink: 0;
}
.muted { color: var(--text-dim); }
.green { color: var(--green); }
.red   { color: var(--red); }
.warn-text { color: var(--warn); }
.cyan-text { color: var(--cyan); }

/* ====================== K 線圖 ====================== */
.kline-panel { padding: 2px 4px; flex: 1.55; min-height: 0; }
.tab-row {
  display: flex; gap: 14px; padding: 3px 8px 4px 8px;
  border-bottom: 1px solid var(--border); align-items: center;
}
.tab { color: var(--text-dim); font-size: 13px; cursor: pointer; padding-bottom: 2px; }
.tab.active { color: var(--cyan); border-bottom: 2px solid var(--cyan); }
.kline-side-title {
  margin-left: auto;
  background: rgba(77, 214, 255, 0.1);
  border: 1px solid var(--cyan);
  color: var(--cyan); padding: 1px 8px; font-size: 10px; border-radius: 2px;
}
.ma-legend {
  padding: 3px 10px; display: flex; gap: 14px;
  font-family: "Consolas", monospace; font-size: 11px; flex-shrink: 0;
}
.ma-tag.ma5  { color: var(--orange); }
.ma-tag.ma20 { color: var(--cyan); }
.ma-tag.ma60 { color: var(--purple); }
#kline-chart { flex: 1; min-height: 0; width: 100%; }

/* ====================== 型態分析 (W底/M頭) ====================== */
.pattern-panel { flex: 0.85; min-height: 0; }
.pattern-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; flex: 1; min-height: 0; }
.pcard {
  border: 1px solid var(--border); border-radius: 3px; padding: 4px 6px;
  background: var(--bg-panel2); display: flex; flex-direction: column;
}
.pcard-head { text-align: center; font-size: 12px; padding-bottom: 2px; }
.pcard-w .pcard-head b { color: var(--orange); font-size: 14px; }
.pcard-m .pcard-head b { color: var(--magenta); font-size: 14px; }
.pcard-row { display: flex; gap: 8px; align-items: center; flex: 1; min-height: 0; }
.pcard-svg { width: 70px; height: 35px; flex-shrink: 0; }
.check { list-style: none; padding-left: 0; margin: 0; font-size: 11px; flex: 1; }
.check li { padding: 1px 0; line-height: 1.3; }
.check li.ok::before { content: "✓ "; color: var(--green); font-weight: bold; }
.check li.no::before { content: "✗ "; color: var(--red); font-weight: bold; }
.pcard-verdict {
  color: var(--warn); font-size: 11px; text-align: center; margin-top: 2px;
  letter-spacing: 1px;
}

/* ====================== K 線型態表 ====================== */
.kpattern-panel { flex: 0.7; min-height: 0; }
.kpat { width: 100%; border-collapse: collapse; font-size: 11px; flex: 1; }
.kpat th, .kpat td {
  padding: 1px 4px; border: 1px solid var(--border);
  text-align: center; color: var(--text); line-height: 1.4;
}
.kpat th { background: var(--bg-panel2); color: var(--cyan); font-weight: normal; font-size: 10px; }
.kpat td.hit { background: rgba(255, 216, 74, 0.12); color: var(--yellow); font-weight: bold; }
.kpat td.icon { font-family: "Consolas", monospace; font-size: 12px; letter-spacing: 1px; }
.kpat td.icon.bull { color: var(--red); }
.kpat td.icon.bear { color: var(--green); }
.kpat td.icon.neu  { color: var(--yellow); }

/* ====================== 中欄技術分析總覽 ====================== */
.col-mid > .panel:first-child { flex: 1; }
.ind-tbl { width: 100%; border-collapse: collapse; flex: 1; }
.ind-tbl td {
  padding: 4px 6px; border-bottom: 1px solid var(--border);
  font-size: 12px; line-height: 1.2;
}
.ind-tbl tr:last-child td { border-bottom: 0; }
.ind-tbl tr td:first-child { color: var(--text-dim); width: 45%; }
.ind-tbl tr td:nth-child(2) {
  color: var(--cyan); font-family: "Consolas", monospace;
  font-weight: bold; text-align: right;
}
.ind-tbl tr td:nth-child(3) { width: 18px; text-align: center; font-weight: bold; }

/* ====================== 中欄技術指標 mini ====================== */
.ti-panel { flex: 1; }
.ti-block { display: flex; flex-direction: column; flex: 1; min-height: 0; padding: 2px 0; }
.ti-block + .ti-block { border-top: 1px solid var(--border); margin-top: 2px; padding-top: 4px; }
.ti-head {
  display: flex; justify-content: space-between; padding: 0 2px 2px 2px;
  font-size: 11px; color: var(--cyan); flex-shrink: 0;
}
.ti-vals { color: var(--text); font-family: "Consolas", monospace; font-size: 10px; }
.ti-block > div[id^="mini-"] { flex: 1; min-height: 0; }
.ti-note { font-size: 10px; text-align: center; padding: 2px 0; flex-shrink: 0; }

/* ====================== 右欄 (產業/公司/籌碼) ====================== */
.col-right > .panel { flex: 1; }
.bul { list-style: none; padding-left: 0; margin: 0; }
.bul li {
  padding: 4px 0 4px 16px; position: relative; font-size: 12px; line-height: 1.4;
  color: var(--text);
}
.bul li::before {
  content: "•"; color: var(--cyan); position: absolute; left: 4px; font-size: 14px; line-height: 1.2;
}
.bul.advice li::before { color: var(--orange); }

.chip { list-style: none; padding-left: 0; margin: 0; }
.chip li {
  padding: 5px 4px; display: flex; justify-content: space-between;
  border-bottom: 1px dashed var(--border); font-size: 12px;
}
.chip li:last-child { border-bottom: 0; }
.chip li .who { color: var(--text-dim); }
.chip li .v.buy  { color: var(--red); font-weight: bold; }
.chip li .v.sell { color: var(--green); font-weight: bold; }
.chip li .v.flat { color: var(--text-dim); }

/* ====================== 最右欄 ====================== */
.gauge-panel { flex: 1.3; }
#winrate-gauge { flex: 1; min-height: 0; }
.gauge-label { color: var(--orange); font-size: 14px; font-weight: bold;
  text-align: center; margin-top: -8px; letter-spacing: 2px; }

.col-far > .panel { flex: 1; }

.vol-panel { flex: 1; }
#mini-vol { flex: 1; min-height: 0; }

.rule-panel { text-align: center; flex: 0.6; justify-content: center; align-items: center; }
.rule-line { padding: 2px 0; font-size: 13px; }
.rule-line.dn { color: var(--green); font-weight: bold; font-size: 14px; }
.rule-mini { font-size: 10px; }

/* ====================== 底部 (近期訊號 + 整體結論) ====================== */
#bottom-row {
  display: grid;
  grid-template-columns: 1.4fr 4fr;
  gap: 4px;
  padding: 0 6px 4px 6px;
  min-height: 0;
}
.signals-panel { padding: 4px 8px; }
.sig { list-style: none; padding-left: 0; margin: 0; flex: 1; overflow: hidden; }
.sig li {
  padding: 3px 4px 3px 18px; position: relative;
  display: flex; justify-content: space-between; font-size: 11px;
  border-bottom: 1px dashed var(--border); line-height: 1.4;
}
.sig li:last-child { border-bottom: 0; }
.sig li::before {
  content: ""; position: absolute; left: 4px; top: 8px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--cyan);
}
.sig li.dot-green::before  { background: var(--green); }
.sig li.dot-red::before    { background: var(--red); }
.sig li.dot-yellow::before { background: var(--yellow); }
.sig li.dot-orange::before { background: var(--orange); }
.sig li.dot-white::before  { background: white; }
.sig li .desc { color: var(--text-dim); }

.conclusion-panel {
  background: linear-gradient(180deg, #0a1a3a 0%, #060f24 100%);
  border: 1px solid var(--cyan);
}
.conclusion-panel .ptitle { color: var(--cyan); font-size: 14px; }
.conc-text {
  text-align: center; padding: 3px 8px;
  flex: 1; display: flex; flex-direction: column; justify-content: center;
  line-height: 1.35;
}
.conc-text .conc-line { font-weight: bold; letter-spacing: 3px; line-height: 1.3; }
.conc-text .conc-l1 { font-size: 24px; color: var(--orange); }
.conc-text .conc-l2 { font-size: 18px; color: var(--text); margin: 2px 0; }
.conc-text .conc-l3 { font-size: 26px; color: var(--yellow); }
.conc-text .key-bear  { color: var(--green); }
.conc-text .key-bull  { color: var(--red); }
.conc-text .key-warn  { color: var(--orange); }
.conc-text .key-pop   { color: var(--yellow); }

/* ====================== 響應式 ====================== */
@media (max-width: 1500px) {
  #main { grid-template-columns: 1.7fr 1fr 1fr 0.8fr; }
  #hdr { grid-template-columns: 1.5fr 1.3fr 0.9fr 0.9fr 1fr 1fr 1.2fr 1.1fr; }
  #hdr-name { font-size: 22px; }
  #hdr-price { font-size: 32px; }
}
@media (max-width: 1280px) {
  body { font-size: 11px; overflow: auto; height: auto; }
  #main { grid-template-columns: 1.6fr 1fr 1fr; }
  .col-far { display: none; }
}

/* ====================== 手機版 (≤768px) ====================== */
@media (max-width: 768px) {
  html, body {
    font-size: 13px;
    overflow-y: auto; overflow-x: hidden;
    width: 100%; height: auto;
  }
  body {
    grid-template-rows: auto auto auto auto;
    grid-template-areas:
      "ctrl"
      "hdr"
      "main"
      "bot";
  }

  /* 控制列 */
  #control-bar {
    flex-wrap: wrap; height: auto; padding: 6px 8px; gap: 4px;
  }
  #control-bar input, #control-bar select { font-size: 14px; padding: 6px 8px; }
  #load-btn { font-size: 14px; padding: 6px 14px; min-height: 36px; }
  #status-text { width: 100%; margin-left: 0; font-size: 11px; }

  /* === Header 改成 3x2 grid，緊湊 === */
  #hdr {
    grid-template-columns: 1.4fr 1fr;
    grid-auto-rows: auto;
    gap: 4px; padding: 4px;
  }
  .hdr-block { height: auto; min-height: 50px; padding: 6px 8px; }
  .hdr-name-block { grid-column: 1 / 3; }
  #hdr-name { font-size: 22px; letter-spacing: 2px; }
  #hdr-code { font-size: 18px; }
  .hdr-industry { font-size: 11px; }
  .hdr-price-block { grid-column: 1 / 2; }
  #hdr-price { font-size: 32px; }
  #hdr-change { font-size: 12px; }
  .hdr-alert { grid-column: 2 / 3; }
  .hdr-cell { display: none; }   /* 內外盤 / 單量等放底部單獨面板 */
  .hdr-bar-wrap { grid-column: 1 / 3; padding: 4px 8px; min-height: 32px; }
  .hdr-bar { height: 12px; }
  .hdr-time { font-size: 10px; }

  /* === Main 全部單欄堆疊 === */
  #main {
    grid-template-columns: 1fr;
    gap: 6px; padding: 6px;
  }
  .col { gap: 6px; }
  .col-far { display: flex; }   /* 重新顯示 */

  /* K 線圖 */
  .kline-panel { flex: none; }
  #kline-chart { height: 50vh; min-height: 320px; }

  /* 型態分析 */
  .pattern-panel { flex: none; }
  .pcard-svg { width: 60px; height: 30px; }
  .check { font-size: 12px; }

  /* K線型態表 */
  .kpattern-panel { flex: none; }
  .kpat th, .kpat td { padding: 3px 4px; font-size: 11px; }

  /* 中欄 */
  .col-mid > .panel:first-child { flex: none; }
  .ti-panel { flex: none; }
  .ti-block > div[id^="mini-"] { height: 90px; }
  .ind-tbl td { padding: 6px 8px; font-size: 13px; }

  /* 右欄 */
  .col-right > .panel { flex: none; }
  .bul li { font-size: 13px; padding: 6px 0 6px 18px; }
  .chip li { font-size: 13px; padding: 7px 4px; }

  /* 最右欄 */
  .col-far > .panel { flex: none; }
  .gauge-panel { flex: none; }
  #winrate-gauge { height: 180px; }
  .vol-panel #mini-vol { height: 100px; }

  /* === Bottom 結論 === */
  #bottom-row {
    grid-template-columns: 1fr;
    gap: 6px; padding: 6px;
  }
  .conclusion-panel { padding: 8px 10px; }
  .conc-text .conc-l1 { font-size: 18px; letter-spacing: 1px; }
  .conc-text .conc-l2 { font-size: 14px; letter-spacing: 1px; }
  .conc-text .conc-l3 { font-size: 20px; letter-spacing: 1px; }

  /* Tab row 不要超出 */
  .tab-row { flex-wrap: wrap; gap: 8px; padding: 4px; }
  .tab { font-size: 14px; padding: 4px 0; }
  .kline-side-title { font-size: 9px; padding: 2px 6px; }
  .ma-legend { font-size: 11px; padding: 4px 8px; gap: 10px; flex-wrap: wrap; }
}

/* ====================== 超小螢幕 (≤480px) ====================== */
@media (max-width: 480px) {
  #hdr-name { font-size: 18px; }
  #hdr-price { font-size: 26px; }
  .pattern-grid { grid-template-columns: 1fr; }   /* W 底 / M 頭 上下排 */
  .conc-text .conc-l1 { font-size: 16px; }
  .conc-text .conc-l3 { font-size: 18px; }
  #kline-chart { height: 40vh; min-height: 260px; }
}
