/* 台股分析網站 — 基礎樣式（乾淨白色風格）
   階段 1 先放骨架與導覽列，響應式細修在階段 9。 */

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

:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --up: #d85a30;
  --down: #1d9e75;
}

body {
  font-family: "Segoe UI", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* 導覽列 */
.navbar {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.nav-brand {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}
.nav-links {
  display: flex;
  gap: 8px;
  margin-left: auto;
}
.nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 15px;
}
.nav-links a:hover { background: var(--bg); color: var(--text); }
.nav-links a.active { background: var(--accent); color: #fff; }

.nav-user { display: inline-flex; align-items: center; gap: 4px; color: var(--text-muted); font-size: 14px; padding: 6px 8px; }
.nav-user-icon { font-style: normal; }
.nav-logout { color: var(--text-muted) !important; font-size: 14px; }
.nav-logout:hover { color: #b91c1c !important; }

/* ===== 登入／註冊頁 ===== */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card {
  width: 100%; max-width: 360px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; padding: 32px 28px;
}
.auth-brand { font-size: 15px; color: var(--text-muted); margin-bottom: 4px; }
.auth-title { font-size: 24px; font-weight: 600; margin-bottom: 20px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card input {
  padding: 12px 14px; font-size: 16px; border: 1px solid var(--border);
  border-radius: 10px; outline: none;
}
.auth-card input:focus { border-color: var(--accent); }
.auth-card button {
  padding: 12px; font-size: 16px; font-weight: 500; color: #fff;
  background: var(--accent); border: none; border-radius: 10px; cursor: pointer; margin-top: 4px;
}
.auth-card button:hover { background: #1d4ed8; }
.auth-error {
  background: #fcebeb; color: #b91c1c; font-size: 14px;
  padding: 10px 12px; border-radius: 10px; margin-bottom: 16px;
}
.auth-switch { font-size: 14px; color: var(--text-muted); text-align: center; margin-top: 18px; }
.auth-switch a { color: var(--accent); text-decoration: none; }

/* 漢堡按鈕（手機才顯示） */
.nav-toggle {
  display: none;
  margin-left: auto;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text);
}

/* 主內容 */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px;
}
h1 { font-size: 24px; font-weight: 600; margin-bottom: 12px; }
.placeholder {
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

/* ===== 查詢頁 ===== */
.hidden { display: none !important; }

.search-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.search-bar input {
  flex: 1; padding: 10px 14px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 8px; outline: none;
}
.search-bar input:focus { border-color: var(--accent); }
.search-bar button {
  padding: 10px 20px; font-size: 15px; color: #fff; background: var(--accent);
  border: none; border-radius: 8px; cursor: pointer;
}
.search-bar button:hover { background: #1d4ed8; }

.status { min-height: 22px; font-size: 14px; color: var(--text-muted); margin-bottom: 8px; }
.status.error { color: #b91c1c; }

/* 股票標頭 */
.stock-head {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 18px; margin-bottom: 14px;
}
.r-name { font-size: 18px; font-weight: 600; }
.r-code { font-size: 14px; color: var(--text-muted); margin-left: 8px; }
.r-price-box { text-align: right; }
.r-price { font-size: 22px; font-weight: 600; }
.r-change { display: block; font-size: 14px; }
.up { color: var(--up); }
.down { color: var(--down); }

/* 分頁 */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab-btn {
  padding: 10px 16px; font-size: 15px; background: none; border: none;
  border-bottom: 2px solid transparent; color: var(--text-muted); cursor: pointer;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }

/* 指標卡片 */
.metric-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px; margin-bottom: 16px;
}
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.m-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.m-value { font-size: 18px; font-weight: 600; }

/* 建議橫幅 */
.advice-banner { border-radius: 10px; padding: 14px 16px; margin-bottom: 16px; }
.advice-banner .advice-label { font-size: 16px; font-weight: 600; display: block; margin-bottom: 4px; }
.advice-banner .advice-reason { font-size: 14px; }
.advice-buy  { background: #e1f5ee; color: #085041; }
.advice-hold { background: #faeeda; color: #633806; }
.advice-sell { background: #fcebeb; color: #791f1f; }

/* 標籤 */
.tags-section { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.tags-label { font-size: 13px; color: var(--text-muted); margin-bottom: 8px; }
.tags-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tag {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px;
  background: #eef2ff; color: #3730a3; padding: 4px 10px; border-radius: 20px;
}
.tag-x { cursor: pointer; font-weight: bold; opacity: 0.6; }
.tag-x:hover { opacity: 1; }
.tag-empty { font-size: 13px; color: var(--text-muted); }
.auto-hint { font-size: 11px; color: var(--text-muted); margin-left: 8px; font-weight: 400; }
.tag.auto-tag { background: #e1f5ee; color: #085041; }
.preset-label { font-size: 12px; color: var(--text-muted); margin: 10px 0 6px; }
.preset-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.preset-chip {
  font-size: 13px; padding: 4px 10px; border-radius: 20px; cursor: pointer;
  border: 1px solid var(--border); color: var(--text-muted); background: var(--surface);
}
.preset-chip:hover { border-color: var(--accent); color: var(--accent); }
.preset-chip.on { background: #eef2ff; color: #3730a3; border-color: #c7d2fe; }
.tag-add { display: flex; gap: 6px; }
.tag-add input { flex: 1; padding: 7px 12px; border: 1px solid var(--border); border-radius: 8px; outline: none; }
.tag-add button { padding: 7px 14px; background: var(--accent); color: #fff; border: none; border-radius: 8px; cursor: pointer; }

/* 1年/5年 切換 */
.range-toggle { display: flex; gap: 6px; margin-bottom: 14px; }
.range-btn {
  padding: 6px 16px; font-size: 14px; cursor: pointer;
  background: var(--surface); color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 8px;
}
.range-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* 公司產業別 */
.company-box { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; }
.industry-label { font-size: 13px; color: var(--text-muted); }
.industry-pill { font-size: 14px; font-weight: 500; background: #eef2ff; color: #3730a3; padding: 4px 14px; border-radius: 20px; }

/* 圖表 */
.chart-block { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; }
.chart-title {
  font-size: 14px; font-weight: 500; margin-bottom: 10px;
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; user-select: none;
}
.chart-arrow { font-size: 12px; color: var(--text-muted); transition: transform 0.2s; }
.chart-block.collapsed .chart-title { margin-bottom: 0; }
.chart-block.collapsed .chart-arrow { transform: rotate(-90deg); }
.chart-block.collapsed > *:not(.chart-title) { display: none; }
.chart-wrap { position: relative; height: 260px; }
.chart-wrap.chart-sm { height: 150px; }
.note { font-size: 12px; color: var(--text-muted); }
.mops-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.mops-text { font-size: 13px; color: var(--text-muted); }
.mops-link { display: inline-block; font-size: 14px; color: var(--accent); text-decoration: none; padding: 6px 12px; border: 1px solid #c7d2fe; border-radius: 8px; }
.mops-link:hover { background: #eef2ff; }

/* 填息 */
.fill-rate { font-size: 15px; margin-bottom: 10px; }
.fill-events { display: flex; flex-direction: column; gap: 6px; }
.fill-event { display: flex; justify-content: space-between; font-size: 13px; padding: 6px 10px; background: var(--bg); border-radius: 8px; }
.filled-yes { color: var(--down); font-weight: 500; }
.filled-no { color: var(--up); font-weight: 500; }

/* ===== 自動選股頁 ===== */
.screener-intro { color: var(--text-muted); font-size: 14px; margin-bottom: 16px; }

.conditions { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px 16px; margin-bottom: 16px; }
.cond-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.cond-row:last-child { border-bottom: none; }
.cond-label { flex: 1; font-size: 15px; }
.cond-op { color: var(--text-muted); font-size: 15px; min-width: 24px; text-align: center; }
.cond-threshold { width: 70px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; text-align: right; }
.cond-unit { font-size: 14px; color: var(--text-muted); min-width: 24px; }
.cond-row.cond-off .cond-label,
.cond-row.cond-off .cond-op,
.cond-row.cond-off .cond-unit { color: #c0c0c0; }
.cond-row.cond-off .cond-threshold { opacity: 0.5; }

/* 開關 switch */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { display: none; }
.slider {
  position: absolute; inset: 0; cursor: pointer; background: #ccc;
  border-radius: 22px; transition: 0.2s;
}
.slider::before {
  content: ""; position: absolute; height: 16px; width: 16px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: 0.2s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* 標籤篩選 */
.filter-section { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-bottom: 16px; }
.filter-label { font-size: 13px; color: var(--text-muted); margin-bottom: 10px; }
.filter-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.filter-chip {
  font-size: 13px; padding: 5px 12px; border-radius: 20px; cursor: pointer;
  border: 1px solid var(--border); color: var(--text-muted); background: var(--surface);
}
.filter-chip:hover { border-color: var(--accent); color: var(--accent); }
.filter-chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* 結果卡片的自動標籤 */
.match-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }

/* 執行按鈕 */
.screener-actions { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.sample-label { font-size: 15px; color: var(--text); display: inline-flex; align-items: center; gap: 6px; }
.sample-label input { width: 72px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; text-align: center; }
.run-btn {
  padding: 11px 24px; font-size: 16px; font-weight: 500; color: #fff;
  background: var(--accent); border: none; border-radius: 10px; cursor: pointer;
}
.run-btn:hover { background: #1d4ed8; }
.run-btn:disabled { background: #9bb8e8; cursor: not-allowed; }
.screener-hint { font-size: 13px; color: var(--text-muted); }

/* 選股結果 */
.no-match { color: var(--text-muted); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.match-card {
  display: block; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px; margin-bottom: 10px; text-decoration: none; color: var(--text);
}
.match-card:hover { border-color: var(--accent); }
.match-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.match-name { font-size: 16px; font-weight: 600; }
.match-code { font-size: 13px; color: var(--text-muted); }
.match-price { margin-left: auto; font-size: 16px; font-weight: 600; }
.match-checks { display: flex; flex-wrap: wrap; gap: 6px; }
.check-pill { font-size: 12px; background: #e1f5ee; color: #085041; padding: 3px 9px; border-radius: 20px; }

/* ===== 我的持股頁 ===== */
.port-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.add-btn {
  padding: 8px 16px; font-size: 14px; color: #fff; background: var(--accent);
  border: none; border-radius: 8px; cursor: pointer;
}
.add-btn:hover { background: #1d4ed8; }

.add-form {
  display: flex; flex-wrap: wrap; gap: 8px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-bottom: 16px;
}
.add-form input { padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; outline: none; }
.add-form #f-code { flex: 1; min-width: 160px; }
.add-form #f-cost, .add-form #f-shares { width: 110px; }
.add-form #f-submit { padding: 8px 20px; color: #fff; background: var(--accent); border: none; border-radius: 8px; cursor: pointer; }

/* 損益摘要 */
.summary-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.sum-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.sum-label { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.sum-val { font-size: 22px; font-weight: 600; }

.no-holding { color: var(--text-muted); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }

/* 可折疊卡片 */
.stock-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px; overflow: hidden; }
.stock-card:hover { border-color: #d0d5dd; }
.card-header { display: flex; align-items: center; gap: 10px; padding: 14px 16px; cursor: pointer; user-select: none; }
.stock-name { font-size: 16px; font-weight: 600; }
.stock-code { font-size: 12px; color: var(--text-muted); }
.card-arrow { font-size: 12px; color: var(--text-muted); transition: transform 0.2s; flex-shrink: 0; }
.stock-card.open .card-arrow { transform: rotate(180deg); }
.header-price { text-align: right; flex-shrink: 0; }
.cur-price { font-size: 16px; font-weight: 600; }
.price-chg { font-size: 12px; }
.card-err { color: var(--text-muted); font-size: 13px; margin-left: auto; }

/* 建議徽章 */
.badge { font-size: 12px; font-weight: 500; padding: 3px 10px; border-radius: 20px; flex-shrink: 0; }
.badge-buy { background: #e1f5ee; color: #085041; }
.badge-hold { background: #faeeda; color: #633806; }
.badge-sell { background: #fcebeb; color: #791f1f; }

/* 卡片展開內容（預設收起） */
.card-body { display: none; border-top: 1px solid var(--border); padding: 14px 16px; }
.stock-card.open .card-body { display: block; }
.detail-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 12px; }
.det-item { background: var(--bg); border-radius: 8px; padding: 10px 12px; }
.det-label { font-size: 11px; color: var(--text-muted); margin-bottom: 3px; }
.det-val { font-size: 15px; font-weight: 600; }

.advice-box { border-radius: 8px; padding: 12px 14px; font-size: 14px; margin-bottom: 10px; }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.card-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.act-btn { padding: 6px 14px; font-size: 13px; color: var(--accent); background: none; border: 1px solid #c7d2fe; border-radius: 8px; cursor: pointer; }
.act-btn:hover { background: #eef2ff; }
.link-btn { font-size: 14px; color: var(--accent); text-decoration: none; margin-left: auto; }
.link-btn:hover { text-decoration: underline; }
.del-btn { padding: 6px 12px; font-size: 13px; color: #b91c1c; background: none; border: 1px solid #f0c0c0; border-radius: 8px; cursor: pointer; }
.del-btn:hover { background: #fcebeb; }

/* 補倉/減倉/編輯 表單 */
.act-form { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; padding: 12px; background: var(--bg); border-radius: 8px; }
.act-form input { width: 120px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; outline: none; }
.act-form .af-submit { padding: 7px 16px; color: #fff; background: var(--accent); border: none; border-radius: 8px; cursor: pointer; }

/* ===== 觀察中 ===== */
.notify-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: #eef2ff; border: 1px solid #c7d2fe; color: #3730a3; border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; font-size: 14px; }
.notify-btn { padding: 6px 14px; font-size: 13px; color: #fff; background: var(--accent); border: none; border-radius: 8px; cursor: pointer; }
.watch-card { padding: 14px 16px; }
.watch-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.watch-head .header-price { margin-left: auto; }
.watch-card.reached { border-color: #1d9e75; background: #f0fbf7; }
.watch-form { display: flex; gap: 8px; margin-bottom: 8px; }
.watch-form .w-dir { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
.watch-form .w-target { flex: 1; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
.watch-form .w-save { padding: 8px 16px; color: #fff; background: var(--accent); border: none; border-radius: 8px; cursor: pointer; }
.w-note { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; outline: none; margin-bottom: 10px; box-sizing: border-box; }

/* 手機響應式（階段 9 會再細修） */
@media (max-width: 640px) {
  /* 導覽列收成漢堡選單 */
  .nav-toggle { display: block; }
  .nav-links {
    display: none;
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    flex-direction: column;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 8px 20px;
    margin-left: 0;
    z-index: 20;
  }
  .nav-links.open { display: flex; }
  .container { padding: 16px 14px; }
  h1 { font-size: 21px; }

  /* 指標卡片：手機 2 欄 */
  .metric-grid { grid-template-columns: repeat(2, 1fr); }

  /* 圖表：手機降低高度 */
  .chart-wrap { height: 220px; }
  .chart-wrap.chart-sm { height: 130px; }

  /* 股票標頭 */
  .r-name { font-size: 16px; }
  .r-price { font-size: 20px; }

  /* 分頁按鈕縮小一點，三個剛好排得下 */
  .tab-btn { padding: 10px 12px; font-size: 14px; }

  /* 自動選股：條件列縮小間距，標籤可換行 */
  .cond-row { gap: 8px; }
  .cond-label { font-size: 14px; min-width: 0; }
  .cond-threshold { width: 56px; }
  .cond-op, .cond-unit { min-width: 18px; font-size: 13px; }
  .screener-actions { flex-wrap: wrap; }
  .screener-hint { font-size: 12px; }

  /* 我的持股：損益摘要縮小字、卡片明細改 2 欄 */
  .summary-row { gap: 8px; }
  .sum-card { padding: 12px 10px; }
  .sum-val { font-size: 17px; }
  .detail-grid { grid-template-columns: repeat(2, 1fr); }

  /* 持股卡片標頭：股名換行、價格不擠 */
  .card-header { gap: 8px; flex-wrap: wrap; }
  .badge { font-size: 11px; }
  .card-actions { gap: 6px; }
  .act-btn, .del-btn { padding: 6px 10px; font-size: 12px; }
  .link-btn { font-size: 13px; }

  /* 表單：輸入框在手機放大好點，整排塞滿 */
  .add-form input, .add-form #f-cost, .add-form #f-shares,
  .add-form #f-code { width: 100%; flex: 1 1 100%; }
  .add-form #f-submit { flex: 1 1 100%; }
  .act-form input { width: 100%; flex: 1 1 100%; }
  .act-form .af-submit { flex: 1 1 100%; }
}

/* 自動選股：跑步動畫＋進度條 */
.screening { display: flex; flex-direction: column; gap: 10px; align-items: center; padding: 18px 0; }
.spinner {
  width: 34px; height: 34px; border: 4px solid #d9e6f2;
  border-top-color: #378add; border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.screening-text { font-size: 15px; color: #333; }
.screening-bar {
  width: 100%; max-width: 360px; height: 8px;
  background: #e8eef4; border-radius: 5px; overflow: hidden;
}
.screening-bar-fill {
  height: 100%; width: 0; border-radius: 5px;
  background: linear-gradient(90deg, #378add, #54c0e8);
  transition: width 0.35s ease;
}
.screening-meta { font-size: 13px; color: #777; }
