/* ===== 主題變數(深色;紅漲綠跌為台股慣例,勿反轉)===== */
:root {
  --bg:        #0f172a;
  --surface:   #1e293b;
  --border:    #334155;
  --text:      #e2e8f0;
  --muted:     #64748b;
  --accent:    #2dd4bf;
  --accent-dk: #0f766e;
  --up:        #f87171;   /* 漲/獲利 = 紅 */
  --down:      #4ade80;   /* 跌/虧損 = 綠 */
  --danger:    #f87171;
  --danger-bg: #7f1d1d;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* ===== 版面骨架 ===== */
.shell   { min-height: 100dvh; display: flex; flex-direction: column; }
.content { flex: 1; padding: 12px 12px calc(76px + env(safe-area-inset-bottom)); max-width: 640px; width: 100%; margin: 0 auto; }

.page-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 0 12px;
}
.page-header h1 { font-size: 20px; font-weight: 700; }

/* ===== 底部 Tab Bar ===== */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; background: var(--bg);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; text-align: center; padding: 8px 0 10px;
  color: var(--muted); text-decoration: none; font-size: 12px;
}
.tab.active { color: var(--accent); font-weight: 700; }
.tab-icon { display: block; font-size: 18px; line-height: 1.2; }

/* ===== 卡片與列 ===== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 10px;
}
.row { display: flex; justify-content: space-between; align-items: baseline; padding: 2px 0; }
.muted-row { font-size: 13px; }
.muted { color: var(--muted); }
.up   { color: var(--up);   font-weight: 700; }
.down { color: var(--down); font-weight: 700; }

.summary-card {
  background: linear-gradient(135deg, #134e4a, var(--surface));
  border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; margin-bottom: 14px;
}
.summary-big { font-size: 26px; font-weight: 800; letter-spacing: .5px; margin: 2px 0 8px; }

.history { border-top: 1px dashed var(--border); margin-top: 8px; padding-top: 6px; }
.empty { color: var(--muted); text-align: center; padding: 32px 0; }

/* ===== 分段切換(seg)===== */
.seg {
  display: flex; border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; margin-bottom: 12px;
}
.seg-item {
  flex: 1; padding: 8px 0; background: none; border: none;
  color: var(--muted); font-size: 14px; cursor: pointer;
}
.seg-item.active { background: var(--accent-dk); color: #fff; font-weight: 700; }
.seg-item.active-buy  { background: var(--danger-bg); color: #fecaca; font-weight: 700; }
.seg-item.active-sell { background: #14532d; color: #bbf7d0; font-weight: 700; }

.chip-buy, .chip-sell {
  display: inline-block; font-size: 12px; border-radius: 4px;
  padding: 1px 6px; margin-right: 4px; font-weight: 700;
}
.chip-buy  { background: var(--danger-bg); color: #fecaca; }
.chip-sell { background: #14532d; color: #bbf7d0; }

/* ===== 表單 ===== */
.field { margin-bottom: 10px; }
.field label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.input {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px; color: var(--text); font-size: 16px;
}
.input:focus { outline: none; border-color: var(--accent); }
.input.invalid { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 12px; margin-top: 4px; }

.btn {
  border: none; border-radius: 10px; padding: 12px;
  font-size: 15px; font-weight: 700; cursor: pointer;
}
.btn-primary { background: var(--accent-dk); color: #fff; }
.btn-danger  { background: none; color: var(--danger); border: 1px solid var(--danger); }
.btn-block   { display: block; width: 100%; }
.btn:disabled { opacity: .5; }

.icon-btn {
  background: none; border: none; color: var(--muted);
  font-size: 20px; cursor: pointer; padding: 4px 8px;
}

/* ===== FAB ===== */
.fab {
  position: fixed; right: 18px; bottom: calc(76px + env(safe-area-inset-bottom));
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent-dk); color: #fff; font-size: 26px;
  border: none; cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,.4);
}

/* ===== Bottom Sheet ===== */
.sheet-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20;
  display: flex; align-items: flex-end;
}
.sheet {
  width: 100%; max-width: 640px; margin: 0 auto;
  background: var(--surface); border-radius: 16px 16px 0 0;
  border-top: 1px solid var(--border);
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: 88dvh; overflow-y: auto;
}
.sheet-handle {
  width: 36px; height: 4px; background: var(--muted);
  border-radius: 2px; margin: 0 auto 12px;
}

/* 錯誤警示條(sheet 內操作級錯誤,醒目) */
.banner-error {
  background: var(--danger-bg); color: #fecaca;
  border: 1px solid var(--danger); border-radius: 8px;
  padding: 10px 12px; margin-bottom: 10px; font-size: 14px; font-weight: 700;
}

/* 費用明細試算區 */
.cost-box {
  background: var(--bg); border: 1px dashed var(--border);
  border-radius: 8px; padding: 8px 12px; margin-bottom: 12px;
}
.cost-line { display: flex; justify-content: space-between; font-size: 13px;
             color: var(--muted); padding: 2px 0; }
.cost-line.total { color: var(--text); font-weight: 700; font-size: 14px; }

/* ===== Toast(全域錯誤/成功提示,醒目)===== */
.toast {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  max-width: 90%; z-index: 50;
  background: var(--danger-bg); color: #fecaca;
  border: 1px solid var(--danger); border-radius: 10px;
  padding: 12px 18px; font-weight: 700; cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
}
.toast.ok { background: #134e4a; color: #99f6e4; border-color: var(--accent); }

/* ===== 登入頁 ===== */
.login {
  min-height: 100dvh; display: flex; flex-direction: column;
  justify-content: center; padding: 0 32px; max-width: 400px; margin: 0 auto;
}
.login-title { text-align: center; font-size: 28px; font-weight: 800; margin-bottom: 24px; }
.login .input { margin-bottom: 12px; }
