/* ─────────────────────────────────────────
   responsive.css
   響應式排版、設定抽屜、手機 Tab Bar
───────────────────────────────────────── */

/* ─────────────────────────────────────────
   設定按鈕（齒輪）
───────────────────────────────────────── */
.settings-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 16px;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
  margin-left: 4px;
}
.settings-btn:hover {
  color: var(--text);
  background: var(--bg3);
}

/* ─────────────────────────────────────────
   設定抽屜遮罩
───────────────────────────────────────── */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.settings-overlay.open {
  opacity: 1;
  pointer-events: all;
}

/* ─────────────────────────────────────────
   設定抽屜本體（右側滑出）
───────────────────────────────────────── */
.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  height: 100%;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  z-index: 201;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  /* overflow: hidden 移除 — 會裁掉 drawer-footer，改由 drawer-body overflow-y:auto 控制捲動 */
}
.settings-drawer.open {
  transform: translateX(0);
}

/* 抽屜標題 */
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.drawer-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}
.drawer-close:hover { color: var(--text); background: var(--bg3); }

/* 抽屜內容捲動區 */
.drawer-body {
  flex: 1;
  min-height: 0;   /* 關鍵：讓 flex 子項目不撐破容器 */
  overflow-y: auto;
  padding: 12px 0;
}
.drawer-body::-webkit-scrollbar { width: 3px; }
.drawer-body::-webkit-scrollbar-thumb { background: var(--border2); }

/* Section */
.drawer-section {
  padding: 0 16px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.drawer-section:last-child { border-bottom: none; }

.drawer-section-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--hint);
  padding: 12px 0 8px;
}

/* 設定列 */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  gap: 12px;
}
.setting-label {
  font-size: 13px;
  color: var(--text);
  flex: 1;
}
.setting-hint {
  font-size: 11px;
  color: var(--hint);
  margin-top: 2px;
}

/* Radio 群組 */
.radio-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.radio-option {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 20px;
  transition: all 0.15s;
  user-select: none;
}
.radio-option input[type="radio"] { display: none; }
.radio-option:has(input:checked) {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(59,130,246,0.08);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}
.toggle-switch input { display: none; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: var(--muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.toggle-switch input:checked + .toggle-track {
  background: rgba(59,130,246,0.25);
  border-color: var(--accent);
}
.toggle-switch input:checked + .toggle-track::after {
  transform: translateX(16px);
  background: var(--accent);
}

/* Token 輸入 */
.token-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.token-row input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 12px;
  color: var(--text);
  font-family: monospace;
  outline: none;
}
.token-row input:focus { border-color: var(--accent); }
.token-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}
.token-toggle:hover { border-color: var(--border2); color: var(--text); }

/* FinMind 區塊（預設隱藏） */
#finmindSection { margin-top: 8px; }

/* 滑桿 */
.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  height: 4px;
  cursor: pointer;
}
.slider-display {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  min-width: 20px;
  text-align: right;
}

/* Select */
.setting-select {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-size: 12px;
  color: var(--text);
  font-family: inherit;
  outline: none;
  cursor: pointer;
}
.setting-select:focus { border-color: var(--accent); }

/* 抽屜底部按鈕 */
.drawer-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.drawer-footer button {
  flex: 1;
  padding: 8px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border2);
  background: none;
  color: var(--muted);
  transition: all 0.15s;
}
.drawer-footer button:hover { color: var(--text); border-color: var(--border2); background: var(--bg3); }
.drawer-footer .btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}
.drawer-footer .btn-primary:hover { background: var(--accent2); border-color: var(--accent2); color: #fff; }

/* ─────────────────────────────────────────
   手機 Tab Bar
───────────────────────────────────────── */
.mobile-tabbar {
  display: none; /* 桌面隱藏 */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  z-index: 50;
  flex-direction: row;
  align-items: stretch;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  color: var(--hint);
  font-size: 10px;
  border: none;
  background: none;
  font-family: inherit;
  transition: color 0.15s;
  padding: 6px 4px;
  -webkit-tap-highlight-color: transparent;
}
.tab-item .tab-icon { font-size: 18px; line-height: 1; }
.tab-item.active    { color: var(--accent); }
.tab-item:hover     { color: var(--text); }

/* ─────────────────────────────────────────
   Tab 內容面板
───────────────────────────────────────── */
.tab-panel { display: none; }
.tab-panel.active { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow-y: auto; }

/* ─────────────────────────────────────────
   桌面：主 Tab Bar（看盤 / 選股 / 型態）
───────────────────────────────────────── */
.main-tabbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 12px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.main-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.main-tab:hover  { color: var(--text); }
.main-tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 500; }

/* ─────────────────────────────────────────
   響應式：手機 (≤ 768px)
───────────────────────────────────────── */
@media (max-width: 768px) {

  /* App layout → v2 flex，不需要 grid 覆蓋 */
  .app {
    padding-bottom: 56px;
  }

  /* 手機版 .main 左右 padding 縮回 0 */
  .main {
    padding-left: 0;
    padding-right: 0;
  }

  /* sidebar 是 absolute 抽屜，不需要 display:none */

  /* Topbar 精簡 */
  .search-box { max-width: none; }
  .data-source { display: none; }

  /* 主 Tab Bar 隱藏（改用底部 Tab Bar） */
  .main-tabbar { display: none; }

  /* 手機 Tab Bar 顯示 */
  .mobile-tabbar { display: flex; }

  /* 設定抽屜 → 全寬底部滑出 */
  .settings-drawer {
    width: 100%;
    height: 85%;
    top: auto;
    bottom: 0;
    right: 0;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
  }
  .settings-drawer.open { transform: translateY(0); }

  /* Chart Toolbar → 橫向捲動 */
  .chart-toolbar {
    overflow-x: auto;
    flex-wrap: nowrap;
    gap: 4px;
    padding: 6px 10px;
    -webkit-overflow-scrolling: touch;
  }
  .chart-toolbar::-webkit-scrollbar { display: none; }

  /* Stock Header 精簡 */
  .stock-header { padding: 10px 12px; }
  .sh-stats {
    gap: 12px;
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .sh-stats::-webkit-scrollbar { display: none; }
  .stat-item { flex-shrink: 0; }
}

/* ─────────────────────────────────────────
   響應式：平板 (769px – 1024px)
───────────────────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
  .main {
    padding-left: 160px;
    padding-right: 160px;
  }
  .settings-drawer { width: 300px; }
}
