/* ============================================================
   響應式排版
   ── < 760px   手機：維持原本單欄（本檔不影響）
   ── ≥ 760px   平板／小視窗：內容放寬、分頁改雙欄、彈窗置中
   ── ≥ 1100px  電腦：底部導覽改成左側欄
   頁面內的雙欄容器（.two-cols / .bk-layout / .cal-layout）在手機上
   只是普通的區塊，不會改變原本的排版。
   ============================================================ */

@media (min-width: 760px) {
  .phone { max-width: 1000px; }
  .cal-wd-br { display: none; } /* 手機版「國定假日未計入」換行；寬螢幕放得下就不換 */
  :root { --page-pad: 24px; }
  .topbar { padding: 20px 24px 12px; }

  /* 底部導覽：不要拉滿整個寬螢幕 */
  .nav {
    max-width: 560px; border: 0.5px solid var(--border); border-bottom: none;
    border-radius: 20px 20px 0 0;
  }

  /* 共用雙欄（固定收支、每月帳目） */
  .two-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 16px; align-items: start; }

  /* 主頁：Hero＋本月消費並排，KPI、時間軸滿版 */
  #page-home.active {
    display: grid; padding: 4px 24px 110px; column-gap: 12px; align-items: stretch;
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
    grid-template-areas: "hero insight" "kpis kpis" "tl tl";
  }
  #home-hero    { grid-area: hero; display: flex; flex-direction: column; }
  #home-hero .hero-bar { margin-top: auto; }
  #home-insight { grid-area: insight; }
  #home-kpis    { grid-area: kpis; }
  .home-tl-card { grid-area: tl; }

  /* 存款藍圖：總覽固定在左，清單在右（清單維持單欄，拖曳排序才順） */
  .bk-layout { display: grid; grid-template-columns: minmax(240px, 320px) minmax(0, 1fr); gap: 24px; align-items: start; }
  .bk-side { position: sticky; top: 72px; }
  .bk-side .bucket-overview { flex-direction: column; text-align: center; padding: 20px 16px; }
  .bk-side .bo-ring { width: 120px; height: 120px; }
  .bk-main > .bucket-group-head:first-child { margin-top: 0; }

  /* 行事曆：月曆在左，節日清單在右 */
  .cal-layout { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(220px, 1fr); gap: 20px; align-items: start; }
  #cal-holiday-list > .section-label:first-child { margin-top: 0; }
  .cal-table td { height: 76px; }
  .cal-hol-label { font-size: 0.625rem; max-height: 40px; }

  /* 帳目分析：摘要滿版，下面兩張圖並排 */
  #page-analysis.active { padding: 0 8px 24px; }
  #page-analysis { --page-pad: 8px; }
  .analysis-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; align-items: start; }
  .analysis-body > .an-card { margin-bottom: 0; }
  /* 清單和走勢圖兩兩包在一起：走勢圖黏在畫面上，但最多只跟到旁邊清單的底線，不會滑到下一組後面 */
  .an-pair { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; align-items: start; }
  .an-pair > .an-card { margin-bottom: 0; }
  .analysis-body > .an-summary, .analysis-body > .an-rec-card { grid-column: 1 / -1; }
  /* 走勢圖固定在畫面上，左邊清單捲動時仍看得到 */
  #an-trend-card, #an-fx-chart { position: sticky; top: calc(var(--topbar-h, 60px) + var(--an-sticky-h, 0px) + 12px); }
  #page-home.active { grid-template-areas: "hero insight" "kpis kpis" "an an" "tl tl"; }
  .home-an-link { grid-area: an; }

  /* 設定：左欄一般設定（捲動時固定），右欄配色 */
  .settings-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); align-items: start; }
  .settings-col:first-child { position: sticky; top: 72px; padding-right: 32px; }
  .settings-col + .settings-col { border-left: 0.5px solid var(--border); padding-left: 32px; }
  .settings-tabs { max-width: 380px; margin-bottom: 36px; }
  .theme-cards { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }

  /* 彈窗：從底部抽屜改成畫面中央的對話框 */
  .overlay, .edit-overlay { align-items: center; padding: 24px; }
  .modal {
    max-width: 480px; max-height: 86dvh; border-radius: var(--r-lg);
    box-shadow: 0 24px 60px -12px rgba(0,0,0,.35);
    animation: modal-in .18s cubic-bezier(.2,.8,.2,1);
  }
  @keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }

  /* 主頁快速記帳鈕：對齊內容區右下角 */
  .home-quick-btn-wrap { max-width: 1000px; bottom: 92px; }
  .home-quick-btn { margin-right: 24px; }
}

@media (min-width: 1100px) {
  body { padding-bottom: 32px; }
  .phone { max-width: none; padding-left: 220px; }
  .phone > .topbar, .phone > .page { max-width: 1120px; margin-left: auto; margin-right: auto; }

  /* 左側導覽欄 */
  .nav {
    top: 0; bottom: 0; left: 0; right: auto; width: 220px; max-width: none; margin: 0;
    flex-direction: column; justify-content: flex-start; gap: 4px;
    padding: 76px 14px 24px; border: none; border-right: 0.5px solid var(--border); border-radius: 0;
  }
  .nav-item {
    width: 100%; flex-direction: row; justify-content: flex-start; gap: 12px;
    padding: 11px 14px; border-radius: 12px; font-size: 0.875rem; font-weight: 500;
    color: var(--text2-on-bg-base); transition: background .15s, color .15s;
  }
  .nav-item:hover { background: var(--bg-surface2); color: var(--text-on-bg-surface2); }
  .nav-item.active { background: var(--accent-bg); color: var(--accent); }
  .nav-item.active .nav-icon, .nav-home.active .nav-home-bubble svg { transform: none; }
  .nav-home { order: -1; margin-bottom: 8px; }
  .nav-home-bubble { width: 22px; height: 22px; margin: 0; background: none; box-shadow: none; }
  .nav-home.active .nav-home-bubble { background: none; }
  .nav-home.active { color: var(--accent); }
  .nav-home span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  :root { --page-pad: 32px; }
  .topbar { padding: 24px 32px 14px; }
  #page-home.active { padding: 4px 32px 110px; column-gap: 16px; }
  .two-cols { gap: 0 20px; }
  .cal-table td { height: 92px; }

  /* 快速記帳：浮在內容區右下角（扣掉左側欄），按鈕放大 */
  .home-quick-btn-wrap { left: calc(50% + 110px); width: calc(100% - 220px); max-width: 1120px; bottom: 32px; }
  .home-quick-btn { margin-right: 32px; padding: 16px 30px; font-size: 1.0625rem; border-radius: 30px; gap: 10px; }
  .home-quick-btn svg { width: 22px; height: 22px; }
  .toast-stack { bottom: 40px; left: calc(50% + 110px); }
}
