/* ══════════════════════════════════════════════════════════
   discipline.css — 投資紀律計畫頁（Day 25B 骨架 + Day 25C 表單）
   風格與 AI 股票白話分析頁 / 投資白話字典頁保持同一產品家族：
   淡藍綠背景、白色卡片、大留白、冷靜可信。
   ══════════════════════════════════════════════════════════ */

body.discipline-page {
  display: block;
  padding: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 8% 12%, rgba(147, 197, 253, 0.30), transparent 34%),
    radial-gradient(circle at 92% 10%, rgba(187, 247, 208, 0.28), transparent 32%),
    radial-gradient(circle at 50% 85%, rgba(219, 234, 254, 0.18), transparent 42%),
    linear-gradient(135deg, #eaf6ff 0%, #f4fbf8 42%, #f6f8fb 100%);
  background-attachment: fixed;
  background-repeat: no-repeat;
  color: #1a1a2e;
}

.discipline-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 36px;
}

/* ══════════════════════════════════════════════════════════
   ★ Day 25 下一輪：全面性長文字防呆
   ══════════════════════════════════════════════════════════
   🧒 小孩版：前幾輪都是「使用者回報一個欄位跑版→修一個欄位」，
   修了代碼、修了名稱、修了子類別……永遠修不完，因為這個問題不是
   單一欄位的錯，而是同一種瀏覽器行為（沒有空白的長字串預設不能從
   中間被切開換行）在「任何」顯示使用者輸入文字的地方都會發生。
   與其繼續一個個補，這裡直接對整個紀律計畫頁「所有」會顯示文字的
   地方下一條通用規則：不管是標題、段落、清單項目、多行輸入框，
   遇到過長且沒有空白的字串，一律強制換行，不會撐開版面。
   這樣不管之後又冒出哪個沒被個別處理過的欄位，都天生免疫。 */
.discipline-shell h1,
.discipline-shell h2,
.discipline-shell h3,
.discipline-shell h4,
.discipline-shell p,
.discipline-shell span,
.discipline-shell div,
.discipline-shell li,
.discipline-shell label,
.discipline-shell textarea,
.discipline-shell button {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* 多行輸入框（備註類欄位）：明確限制最高高度＋超過高度改用捲軸上下捲動，
   不會隨著使用者一直打字而無限往下（或往右）撐開 */
.discipline-form textarea {
  max-height: 220px;
  overflow-y: auto;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: pre-wrap;
}

/* 單行輸入框、下拉選單：文字本來就是靠瀏覽器原生的內部捲動處理，
   不會撐開外框，這裡額外加保險，避免極端情況下仍撐開版面 */
.discipline-form input,
.discipline-form select {
  min-width: 0;
  overflow-wrap: anywhere;
}

.discipline-top-nav {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 18px;
}

.discipline-nav-link {
  text-decoration: none;
  color: #4b5563;
  font-size: 0.92rem;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(226, 232, 240, 0.9);
}

.discipline-nav-link--active {
  color: #1d4ed8;
  background: #eff6ff;
  border-color: #bfdbfe;
  font-weight: 700;
}

.discipline-hero-inner,
.discipline-toolbar,
.discipline-filter-card,
.discipline-empty-card,
.discipline-plan-card,
.discipline-editor {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 22px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.07);
}

.discipline-hero {
  margin-bottom: 18px;
}

.discipline-hero-inner {
  padding: 30px;
}

.discipline-eyebrow {
  color: #2563eb;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.discipline-hero h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 1.15;
  margin-bottom: 12px;
}

.discipline-hero-subtitle {
  color: #64748b;
  line-height: 1.8;
  font-size: 1.02rem;
}

.discipline-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.discipline-toolbar {
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.discipline-toolbar h2 {
  color: #0f172a;
  font-size: 1.2rem;
  margin-bottom: 6px;
}

.discipline-toolbar p {
  color: #64748b;
  line-height: 1.6;
  font-size: 1.02rem;
}

.discipline-primary-btn {
  border: none;
  border-radius: 14px;
  background: #2563eb;
  color: #fff;
  font-weight: 800;
  padding: 13px 18px;
  cursor: pointer;
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.22);
}

.discipline-primary-btn:hover {
  background: #1d4ed8;
}

.discipline-filter-card {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.discipline-filter-top-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.discipline-filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ★ Day 25 通用化：市場列／持有策略列／自訂標籤列 共用的區塊樣式 */
.discipline-tag-filter-section {
  border-top: 1px solid #e2e8f0;
  padding-top: 10px;
}

.discipline-tag-filter-title {
  color: #64748b;
  font-size: 0.8rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.discipline-tag-filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  overflow: hidden;
  max-height: 76px; /* 約兩排晶片的高度，超過的部分收合隱藏 */
}

.discipline-tag-filter-chips--expanded {
  max-height: none;
}

.discipline-filter-chip {
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #475569;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.discipline-filter-chip.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #ffffff;
}

.discipline-tag-filter-toggle {
  border: none;
  background: transparent;
  color: #2563eb;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  margin-top: 6px;
  padding: 0;
}

/* ★ Day 25 通用化：表單內的自訂標籤（子類別）輸入 UI */
.discipline-custom-tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.discipline-custom-tags-list:empty {
  margin-top: 0;
}

.discipline-custom-tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  padding: 5px 8px 5px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.discipline-custom-tag-remove-btn {
  border: none;
  background: transparent;
  color: #1d4ed8;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 2px;
}

/* ★ Day 25 通用化第三輪 (b)：子類別輸入框改成自己畫下拉建議清單，
   視覺上盡量貼近 <select> 的樣子（輸入框右側加一個裝飾用的下拉箭頭）。 */
.discipline-tag-input-combo {
  position: relative;
}

.discipline-tag-input-combo input {
  padding-right: 32px;
  background-image: linear-gradient(45deg, transparent 50%, #64748b 50%),
    linear-gradient(135deg, #64748b 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.discipline-tag-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.12);
  max-height: 220px;
  overflow-y: auto;
}

.discipline-tag-dropdown li {
  margin: 0;
}

.discipline-tag-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 8px 10px;
  border-radius: 8px;
  font: inherit;
  color: #0f172a;
  cursor: pointer;
}

.discipline-tag-dropdown button:hover {
  background: #eff6ff;
  color: #1d4ed8;
}

/* ★ Day 25C.5：排序下拉選單 */
.discipline-sort-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.discipline-sort-row span {
  color: #64748b;
  font-size: 0.85rem;
  font-weight: 800;
  white-space: nowrap;
}

.discipline-sort-row select {
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 8px 10px;
  background: #ffffff;
  color: #0f172a;
  font: inherit;
}

.discipline-filter-tab {
  border: 1px solid #e2e8f0;
  background: #ffffff;
  color: #64748b;
  border-radius: 999px;
  padding: 9px 14px;
  font-weight: 800;
  cursor: pointer;
}

.discipline-filter-tab.active {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #ffffff;
}

.discipline-status {
  color: #64748b;
  font-size: 0.92rem;
  padding: 0 4px;
}

.discipline-loading {
  min-height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: #94a3b8;
}

.discipline-loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #e2e8f0;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: disciplineSpin 0.8s linear infinite;
}

@keyframes disciplineSpin {
  to { transform: rotate(360deg); }
}

.discipline-empty {
  text-align: center;
}

.discipline-empty-card {
  padding: 42px 24px;
}

.discipline-empty-icon {
  font-size: 2.4rem;
  margin-bottom: 12px;
}

.discipline-empty h2 {
  margin-bottom: 10px;
}

.discipline-empty p {
  color: #64748b;
  line-height: 1.8;
  max-width: 560px;
  margin: 0 auto 18px;
}

.discipline-cards-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.discipline-plan-card {
  padding: 18px;
}

.discipline-plan-card-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

/* ★ Day 25 通用化第二輪 (h)(i) 修正：flex 子項目預設不會縮小到比內容還窄
   （瀏覽器的 min-width:auto 預設行為），子類別一多、副標題文字變長時，
   標題區塊會硬撐開、把右邊的星星／狀態徽章往外推到快要溢出。
   加上 min-width:0 讓標題區塊可以正常換行縮小；右邊固定不縮小，
   維持星星／徽章永遠有足夠空間、不被擠壓。 */
.discipline-plan-card-top > div:first-child {
  min-width: 0;
  flex: 1 1 auto;
}

.discipline-plan-card-top > div:last-child {
  flex-shrink: 0;
}

.discipline-plan-card h3 {
  font-size: 1.15rem;
  color: #0f172a;
  margin-bottom: 4px;
  overflow-wrap: anywhere;
}

/* ★ Day 25 通用化：代碼跟名稱同色系、較淺，做出深淺區隔而不是換色相 */
.discipline-plan-code {
  color: #94a3b8;
  font-weight: 600;
}

/* ★ Day 25 下一輪 (e) 修正：中文字天生逐字可換行，但沒有空格的長串英數字
   （例如極端測試字串）瀏覽器預設當成一個不能從中間切斷的完整單字，
   超出容器寬度就會硬撐開版面。加上 overflow-wrap: anywhere 讓這類長字串
   也能被強制換行，不再撐破卡片。 */
.discipline-plan-symbol {
  color: #64748b;
  font-size: 0.9rem;
  margin-bottom: 14px;
  overflow-wrap: anywhere;
}

.discipline-status-badge {
  flex-shrink: 0;
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.78rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  border: 1px solid transparent;
}

/* ★ Day 25C.5：加深對比、加細邊框，文字用 flex 置中（不貼底色上緣） */
.discipline-status-badge--draft {
  background: #e2e8f0;
  color: #334155;
  border-color: #cbd5e1;
}

/* ★ Day 25C.5 第三輪：進行中/已完成配色對調（藍=進行中、綠=完成，符合通用介面慣例）；
   已封存改用琥珀色系（沿用「封存」按鈕的顏色，兩者概念相關） */
.discipline-status-badge--active {
  background: #dbeafe;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.discipline-status-badge--completed {
  background: #d1fae5;
  color: #047857;
  border-color: #a7f3d0;
}

.discipline-status-badge--archived {
  background: #fffbeb;
  color: #92400e;
  border-color: #fde68a;
}

.discipline-plan-block {
  background: #f8fafc;
  border-radius: 14px;
  padding: 12px;
  color: #475569;
  line-height: 1.7;
  margin-bottom: 14px;
}

/* ★ Day 25C.5：卡片上的買入/停損/停利數量標籤（固定長度，不受規則內容影響） */
.discipline-plan-rule-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.discipline-plan-rule-badges span {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 700;
}

.discipline-plan-label {
  font-size: 0.78rem;
  color: #94a3b8;
  font-weight: 800;
  margin-bottom: 4px;
}

.discipline-plan-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.discipline-plan-metrics div {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 12px;
}

.discipline-plan-metrics span {
  display: block;
  color: #94a3b8;
  font-size: 0.78rem;
  margin-bottom: 4px;
}

.discipline-plan-metrics strong {
  color: #0f172a;
  font-size: 0.95rem;
}

/* ★ Day 25C.5：卡片底部改成兩個按鈕並排（查看/編輯 + 封存） */
.discipline-plan-actions {
  display: flex;
  gap: 10px;
}

.discipline-secondary-btn {
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #475569;
  border-radius: 12px;
  padding: 10px 13px;
  font-weight: 800;
  cursor: pointer;
  flex: 1 1 auto;
}

.discipline-secondary-btn:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.discipline-archive-btn {
  border: 1px solid #fde68a;
  background: #fffbeb;
  color: #92400e;
  border-radius: 12px;
  padding: 10px 13px;
  font-weight: 800;
  cursor: pointer;
  flex: 0 0 auto;
  white-space: nowrap;
}

.discipline-archive-btn:hover {
  background: #fef3c7;
}

/* ★ Day 25C.5 第四輪：完成按鈕改用綠色系，跟「已完成」狀態徽章的顏色呼應 */
.discipline-complete-btn {
  border: 1px solid #a7f3d0;
  background: #ecfdf5;
  color: #047857;
  border-radius: 12px;
  padding: 10px 13px;
  font-weight: 800;
  cursor: pointer;
  flex: 0 0 auto;
  white-space: nowrap;
}

.discipline-complete-btn:hover {
  background: #d1fae5;
}

.discipline-footer {
  margin-top: 24px;
  text-align: center;
  color: #94a3b8;
  font-size: 0.86rem;
}

/* ══════════════════════════════════════════════════════════
   ★ Day 25C：計畫編輯表單（Editor Panel）
   ══════════════════════════════════════════════════════════ */

.discipline-editor {
  padding: 22px;
}

.discipline-editor-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.discipline-editor-eyebrow {
  color: #2563eb;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.discipline-icon-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 999px;
  background: #e2e8f0;
  color: #334155; /* ★ Day 25D.5：加深顏色，原本 #64748b 配上淺底對長輩來說不夠明顯 */
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

/* ★ Day 25C.5 第三輪：表單標題列右側（收藏星星 + 關閉按鈕）並排 */
.discipline-editor-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.discipline-icon-btn:hover {
  background: #e2e8f0;
}

.discipline-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.discipline-form-section {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 18px;
  padding: 18px;
}

.discipline-form-section h3 {
  color: #0f172a;
  font-size: 1.05rem;
  margin-bottom: 14px;
}

/* ★ Day 25C.5 第六輪修正：補上跟 .discipline-full-field 一致的上邊距，
   避免連續兩個雙欄輸入框區塊（例如「前高點/前低點」接著「最多可承受損失」）
   彼此貼在一起、卻跟旁邊的單欄文字框區塊間距不一致。 */
.discipline-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.discipline-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.discipline-form label span {
  color: #475569;
  font-size: 0.88rem;
  font-weight: 800;
}

.discipline-form input,
.discipline-form select,
.discipline-form textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 11px 12px;
  font: inherit;
  background: #ffffff;
  color: #0f172a;
}

/* ★ Day 25 通用化第二輪 (b)(iii)：Chrome 選了自己記住的建議值後，
   會強制套用內建的淺藍/淺黃底色，且只有重新整理頁面才會消失——
   這是瀏覽器自己的行為，不是我們的樣式造成的，用這個標準寫法蓋掉即可。 */
.discipline-form input:-webkit-autofill,
.discipline-form input:-webkit-autofill:hover,
.discipline-form input:-webkit-autofill:focus {
  -webkit-text-fill-color: #0f172a;
  -webkit-box-shadow: 0 0 0 100px #ffffff inset;
  transition: background-color 9999s ease-in-out 0s;
}

.discipline-form textarea {
  resize: vertical;
}

/* ★ Day 25C.5 第三輪：補上方留白，不管前面接的是提醒文字還是其他輸入框，
   都有一致的呼吸空間（原本只有下方留白，緊接在提醒文字後面時中間會沒有間距） */
.discipline-full-field {
  margin-top: 16px;
  margin-bottom: 14px;
  display: block;
  position: relative;
}

/* ★ Day 25C.5 第四輪修正：在兩欄式規則網格（.discipline-rule-fields）裡，
   讓「自訂條件說明」真正橫跨整行，不要只佔一欄——
   之前它雖然叫 full-field，但沒有真的 grid-column: 1/-1，
   導致跟旁邊的「出場數量」共用同一列時，因為多了上邊距而看起來對不齊。
   加上這行之後，它會自己獨佔一整列，其餘欄位排到下一列，兩邊都不會再互相干擾。
   ★ 第六輪修正：margin-bottom 也要歸零——網格本身已經有統一的 gap（列間距），
   這裡如果還留著自己的下邊距，會疊加造成「出場數量」離它特別遠。 */
.discipline-rule-fields .discipline-full-field {
  grid-column: 1 / -1;
  margin-top: 0;
  margin-bottom: 0;
}

.discipline-full-field > span {
  display: block;
  color: #475569;
  font-size: 0.88rem;
  font-weight: 800;
  margin-bottom: 6px;
}

.discipline-form-hint {
  color: #64748b;
  font-size: 0.85rem;
  line-height: 1.6;
  margin-top: 14px;
}

/* ★ Day 25C.5 第四輪：視覺上隱藏但螢幕報讀器讀得到的標準寫法，
   用來讓隱藏欄位（如 timeHorizonInput）符合無障礙檢查要求，
   同時不會讓文字憑空出現在畫面上 */
.discipline-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ★ Day 25C.5：必填標示 */
.discipline-required-mark {
  color: #dc2626 !important; /* ★ Day 25D.2：確保無論在什麼容器（含 <label>）裡都維持紅色，
                                 蓋過 .discipline-form label span 的深灰色設定，比照樣式表既有的
                                 .discipline-field-invalid input 同一種「驗證狀態優先」做法 */
  font-weight: 900;
  margin-left: 2px;
}

/* ★ Day 25C.5：驗證失敗時，第一個沒過關的欄位加紅框 */
.discipline-field-invalid {
  outline: 2px solid #ef4444;
  outline-offset: 2px;
  border-radius: 12px;
}

.discipline-field-invalid input,
.discipline-field-invalid select,
.discipline-field-invalid textarea {
  border-color: #ef4444 !important;
}

/* ★ Day 25C.5：非阻擋式溫馨提醒（軟性警告，跟紅字錯誤區分開） */
.discipline-soft-warning {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.85rem;
  line-height: 1.6;
  margin-top: 10px;
}

.discipline-cost-preview {
  margin-top: 14px;
  background: #ffffff;
  border: 1px solid #dbeafe;
  border-radius: 14px;
  padding: 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.discipline-cost-preview span {
  color: #64748b;
  display: flex;
  align-items: center;
  gap: 6px;
}

.discipline-cost-preview strong {
  color: #1d4ed8;
}

/* ★ Day 25D：執行檢查與復盤（第 7 節）
   進度清單（進行中／已完成皆顯示）：每個區塊一個小標籤，未完整用中性灰、
   已完整用綠色，跟「紀律完成度」分數（沿用 .discipline-cost-preview 樣式）分開呈現，
   避免混用兩種不同語意的視覺重量。 */
.discipline-review-progress {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.discipline-progress-chip {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  color: #64748b;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 700;
}

.discipline-progress-chip.complete {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #047857;
}

/* 自評星等：跟收藏星星（.discipline-favorite-btn）同一種「灰底/亮色」邏輯，
   但這裡是 1~5 顆一起點擊，用透明度區分已選/未選，不需要另外畫圖示 */
.discipline-stars {
  display: flex;
  gap: 4px;
}

.discipline-star-btn {
  background: none;
  border: none;
  font-size: 1.6rem;
  line-height: 1;
  color: #f59e0b;
  opacity: 0.28;
  cursor: pointer;
  padding: 2px;
}

.discipline-star-btn.active {
  opacity: 1;
}

/* 規則卡片內的執行狀態區塊，跟上面備註欄位隔出一點呼吸空間
   （.discipline-exec-block 是 .discipline-rule-card 的一般區塊子元素，不在
   .discipline-rule-fields 的 grid 容器內，所以不需要 grid-column 設定） */
.discipline-exec-block {
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px dashed #e2e8f0;
}

.discipline-exec-block .discipline-pill-group {
  margin-bottom: 10px;
}

.discipline-exec-block .discipline-pill {
  padding: 7px 12px;
  font-size: 0.82rem;
}

/* ★ Day 25D.2 新增 CSS ──────────────────────────────────────── */

/* 非必填但會扣分的欄位，用琥珀色框跟「必填未填」的紅框區分開 */
.discipline-field-warning {
  outline: 2px solid #f59e0b;
  outline-offset: 2px;
  border-radius: 12px;
}

.discipline-field-warning input,
.discipline-field-warning select,
.discipline-field-warning textarea {
  border-color: #f59e0b !important;
}

/* 未完整的進度標籤可以點擊跳轉，滑鼠移過去給個提示 */
.discipline-progress-chip.clickable {
  cursor: pointer;
}

.discipline-progress-chip.clickable:hover {
  background: #f1f5f9;
}

/* 紀律完成度那一行＋ⓘ說明按鈕 */
.discipline-score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.discipline-info-btn {
  background: #f1f5f9;
  border: none;
  border-radius: 999px;
  color: #64748b;
  font-size: 0.86rem;
  width: 24px;
  height: 24px;
  min-width: 24px;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.discipline-score-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.discipline-info-btn:hover {
  background: #dbeafe;
  color: #1d4ed8;
}

/* ★ Day 25D.3：#reviewScoreDisplay 沿用 .discipline-cost-preview 的樣式，但那個 class
   預設是左右並排（flex-direction: row），只有窄螢幕的既有 media query才會變成上下堆疊，
   導致寬螢幕下說明文字意外貼在右邊。這裡強制不管螢幕寬度都用上下堆疊，不依賴那個
   既有的響應式規則（避免这个元件被其他地方的響應式調整意外影響到）。 */
#reviewScoreDisplay {
  flex-direction: column;
  align-items: stretch;
}

/* ★ Day 25D.3：已完成計畫鎖定第 1~6 節時，用背景色/游標樣式讓使用者一眼看出
   這個欄位是唯讀的（執行狀態按鈕/執行備註不受影響，維持原本的互動樣式）。
   用瀏覽器原生的 :read-only/:disabled 偽類，不需要額外掛 class，欄位一旦被
   加上 readOnly/disabled 屬性就會自動套用，不會漏掉。 */
.discipline-form input:read-only,
.discipline-form textarea:read-only {
  background: #f8fafc;
  color: #64748b;
  cursor: default;
}

.discipline-form select:disabled,
.discipline-form button:disabled {
  background: #f1f5f9;
  color: #475569; /* ★ Day 25D.4：原本用更淺的 #94a3b8，瀏覽器對 disabled select 原生
                      還會再疊加一層透明度，兩者相加導致文字太淡看不清楚，改深一階，
                      跟 readOnly input 用同一色階，確保鎖定狀態下內容仍清楚可讀 */
  opacity: 1; /* 不疊加瀏覽器原生的額外透明度，鎖定用背景色/游標區分即可 */
  cursor: not-allowed;
  -webkit-text-fill-color: #475569; /* Safari 對 disabled select 有時會忽略 color，需要這個 */
}

/* ★ Day 25D.4：第 1~6 節展開/收合。
   做法：只隱藏 <section> 底下「第一個子元素以外」的所有內容——每個 section 的
   第一個子元素固定是標題列（<h3> 本身，或包住 <h3>＋新增按鈕的 .discipline-section-title-row），
   收合鈕本身就放在標題列裡面，所以永遠不會被這條規則誤藏。這樣不需要另外幫每個
   section 的內容包一層 wrapper div，改動範圍最小。 */
.discipline-form-section.discipline-collapsed > *:not(:first-child) {
  display: none !important; /* ★ Day 25D.5：部分欄位（子類別滿額、預期持有時間等）
    的顯示/隱藏是由 JS 直接設定 inline style 控制，優先權比一般樣式表規則高，
    沒有 !important 蓋不過去，會導致收合時這些欄位殘留沒有一起隱藏。 */
}

.discipline-section-toggle-btn {
  background: #e2e8f0; /* ★ Day 25D.5：加上淺灰底＋加深文字色，比純文字符號更明顯是可點擊的按鈕 */
  border: none;
  border-radius: 999px;
  color: #334155;
  font-weight: 700;
  font-size: 0.85rem;
  width: 24px;
  height: 24px;
  min-width: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  vertical-align: middle;
}

.discipline-section-toggle-btn:hover {
  background: #cbd5e1;
  color: #1d4ed8;
}

.discipline-principle-explainer {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed #e2e8f0;
  font-size: 0.82rem;
  line-height: 1.7;
  color: #475569;
}

.discipline-principle-explainer p {
  margin: 4px 0;
}

/* ★ Day 25C.5：預計平均成本價 — 自動/手動標籤 + 改用自動按鈕 */
.discipline-avgcost-tag {
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
}

.discipline-avgcost-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.discipline-avgcost-controls input {
  width: 130px;
  max-width: 100%;
  text-align: right;
}

.discipline-section-title-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.discipline-small-btn {
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 800;
  cursor: pointer;
}

.discipline-small-btn:hover {
  background: #dbeafe;
}

.discipline-rules-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.discipline-rule-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 14px;
}

.discipline-rule-card-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.discipline-rule-card-top select {
  flex: 1;
}

.discipline-rule-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

/* ★ Day 25C.5 第四輪：三種換算文字依位置給不同間距——
   --price 緊貼在輸入框正下方（維持原本的負邊距，視覺上像是輸入框的附屬說明）；
   --quantity 是在整個欄位區塊結束後才出現的，需要比較大的留白，不然會貼著單位選單；
   --note（自訂條件「不計入成本」提醒）緊貼在說明欄位下方，比照 --price 的間距。 */
.discipline-rule-preview {
  grid-column: 1 / -1;
  color: #64748b;
  font-size: 0.85rem;
}

.discipline-rule-preview--price,
.discipline-rule-preview--note {
  margin: -2px 0 0;
}

.discipline-rule-preview--quantity {
  margin: 10px 0 0;
}

.discipline-remove-rule-btn {
  border: none;
  background: #fee2e2;
  color: #b91c1c;
  border-radius: 999px;
  padding: 6px 10px;
  font-weight: 800;
  cursor: pointer;
  flex-shrink: 0;
}

.discipline-remove-rule-btn:hover {
  background: #fecaca;
}

/* ★ Day 25C.5：情緒檢查分三組（情緒與判斷／資訊來源／風險承受） */
.discipline-checklist-group {
  margin-bottom: 16px;
}

.discipline-checklist-group-title {
  color: #1d4ed8;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.discipline-checklist {
  display: grid;
  gap: 10px;
}

.discipline-checklist label {
  flex-direction: row;
  align-items: center;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 10px 12px;
  line-height: 1.6;
}

.discipline-checklist input {
  width: auto;
  margin-right: 8px;
  flex-shrink: 0;
}

.discipline-form-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  border-radius: 14px;
  padding: 12px 14px;
  line-height: 1.7;
}

.discipline-form-error p {
  margin: 0;
}

.discipline-form-error p + p {
  margin-top: 6px;
}

/* ★ Day 25C：持有週期按鈕（當沖／短期／中期／長期持有／觀察中） */
.discipline-pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.discipline-pill {
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #475569;
  border-radius: 999px;
  padding: 9px 16px;
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
}

.discipline-pill:hover {
  border-color: #93c5fd;
}

.discipline-pill.active {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #ffffff;
}

/* ★ Day 25C：Autosave 狀態指示（只在編輯模式顯示） */
.discipline-autosave-indicator {
  font-size: 0.85rem;
  font-weight: 700;
  padding: 2px 2px 0;
}

.discipline-autosave-indicator--typing,
.discipline-autosave-indicator--saving {
  color: #94a3b8;
}

.discipline-autosave-indicator--saved {
  color: #16a34a;
}

.discipline-autosave-indicator--demoted {
  color: #b45309;
  font-weight: 800;
}

.discipline-autosave-indicator--error {
  color: #dc2626;
}

.discipline-editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

/* ★ Day 25C.5 第三輪：密集按鈕群拿掉光暈陰影，避免看起來髒髒的；
   獨立的「＋新增計畫」等單顆按鈕維持原本的光暈效果 */
.discipline-editor-actions .discipline-primary-btn {
  box-shadow: none;
}

.discipline-secondary-action {
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #475569;
  border-radius: 14px;
  padding: 12px 18px;
  font-weight: 800;
  cursor: pointer;
}

.discipline-secondary-action:hover {
  background: #f8fafc;
}

.discipline-danger-btn {
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: #b91c1c;
  border-radius: 12px;
  padding: 10px 13px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.discipline-danger-btn:hover {
  background: #fee2e2;
}

/* ★ Day 25C.5 第二輪：收藏星星圖示 */
.discipline-favorite-btn {
  border: none;
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: #cbd5e1;
  padding: 2px 6px;
  flex-shrink: 0;
}

.discipline-favorite-btn.active {
  color: #f59e0b;
}

/* ★ Day 25C.5 第二輪：卡片「上次更新」時間 */
/* ★ Day 25C.5 第三輪：補下方留白，避免文字太貼近下方按鈕 */
.discipline-updated-at {
  color: #94a3b8;
  font-size: 0.78rem;
  margin-top: 6px;
  margin-bottom: 12px;
}

/* ══════════════════════════════════════════════════════════
   ★ Day 25C.5：自訂確認對話框（取代瀏覽器原生 confirm）
   ══════════════════════════════════════════════════════════ */

.discipline-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 20px;
}

.discipline-modal-card {
  background: #ffffff;
  border-radius: 20px;
  padding: 26px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
}

.discipline-modal-message {
  color: #0f172a;
  font-size: 1rem;
  line-height: 1.7;
  margin-bottom: 20px;
  text-align: center;
}

.discipline-modal-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.discipline-modal-actions button {
  flex: 1 1 0;
}

/* ══════════════════════════════════════════════════════════
   響應式
   ══════════════════════════════════════════════════════════ */

/* ★ Day 25 收尾：原本 900px 以下就把「+新增計畫」按鈕擠到文字下方（滿版寬度），
   但在文字精簡過後，實測發現這個按鈕跟文字其實在寬到 480px 都還放得下、不會擠壓，
   900px 這個門檻明顯太保守，把很多平板尺寸的畫面都不必要地擠成上下堆疊、
   浪費掉右側大片空白。改成 520px 以下才切換成上下堆疊，平板寬度（700px 以上）
   維持文字在左、按鈕在右的橫向排列，跟桌面版一致，只有真正窄的手機畫面才會堆疊。 */
@media (max-width: 520px) {
  .discipline-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .discipline-primary-btn {
    width: 100%;
  }

  /* ★ Day 25C.5 第四輪修正：「儲存並啟用/儲存變更」共用 .discipline-primary-btn，
     排除表單按鈕群組，不要被上面那條規則拉成滿版寬度——
     這條規則原本是為了獨立的「＋新增計畫」按鈕寫的，761~900px 之間
     曾經因為這個衝突讓表單裡的按鈕跑版。 */
  .discipline-editor-actions .discipline-primary-btn {
    width: auto;
  }
}

/* ★ Day 25C.5 第七輪：卡片改成 700px 才切成單欄，不是 900px——
   實測過在這張卡片的實際內容（買入/停損/停利徽章、預估成本/紀律完成度）下，
   705px 以上兩欄排版都還能維持單行不換行，900px、768px 這種寬度切成單欄
   反而會顯得每張卡片過寬、空白太多。700px 是實測抓到的換行臨界點。 */
@media (max-width: 700px) {
  .discipline-cards-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  .discipline-form-grid,
  .discipline-rule-fields {
    grid-template-columns: minmax(0, 1fr);
  }

  .discipline-section-title-row,
  .discipline-cost-preview,
  .discipline-filter-card {
    flex-direction: column;
    align-items: stretch;
  }

  .discipline-avgcost-controls {
    justify-content: space-between;
  }

  .discipline-avgcost-controls input {
    flex: 1 1 auto;
    width: auto;
  }

  .discipline-sort-row {
    justify-content: flex-start;
  }

  .discipline-plan-actions {
    flex-wrap: wrap;
  }

  /* ★ Day 25C.5 第四輪：「查看/編輯計畫」獨占一整行（主要動作），
     「封存」「刪除」並排在下一行（次要動作），不要三個都各自佔一整行 */
  .discipline-plan-actions .discipline-secondary-btn {
    flex: 1 1 100%;
  }

  .discipline-plan-actions .discipline-archive-btn,
  .discipline-plan-actions .discipline-danger-btn {
    flex: 1 1 calc(50% - 5px);
    min-width: 0;
  }

  /* ★ Day 25C.5 第四輪：表單按鈕群組改用 2 欄網格，不管目前狀態顯示
     幾顆按鈕都自動排成 2x2、2x1 等，不會再變成每顆各自佔一整行、
     過度佔用垂直空間 */
  .discipline-editor-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  /* ★ Day 25C.5 第五輪修正：CSS Grid 預設不會把格子縮小到比裡面文字還窄，
     「封存/完成/刪除」又設定文字不換行，兩者疊加會撐爆容器，
     在連續拖曳調整視窗寬度時特別容易造成畫面暫時跑版。
     加上 min-width:0 讓格子真正能縮小；文字改回可換行，
     極窄狀況下寧可按鈕變兩行，也不要撐破版面。 */
  .discipline-editor-actions button {
    width: 100%;
    min-width: 0;
    white-space: normal;
    padding: 11px 10px;
    font-size: 0.92rem;
  }
}

/* ★ Day 25C.5 第二輪：320px 極窄螢幕，成本價輸入框強制單獨一行 */
@media (max-width: 340px) {
  .discipline-avgcost-controls {
    width: 100%;
    justify-content: space-between;
  }

  .discipline-avgcost-controls input {
    flex: 1 1 auto;
    width: auto;
  }
}

@media (max-width: 560px) {
  .discipline-shell {
    width: min(100% - 24px, 460px);
    padding-top: 12px;
  }

  .discipline-top-nav {
    justify-content: center;
    flex-wrap: wrap;
  }

  .discipline-hero-inner {
    padding: 22px;
  }

  .discipline-hero h1 {
    font-size: 1.85rem;
  }

  .discipline-filter-tab {
    flex: 1 1 calc(50% - 8px);
  }

  .discipline-plan-metrics {
    grid-template-columns: minmax(0, 1fr);
  }

  .discipline-editor {
    padding: 18px;
  }

  .discipline-form-section {
    padding: 14px;
  }
}
