/* 包子管家 - 全域樣式 */
* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  background: #f0f2f5;
}

#sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: 240px; background: linear-gradient(180deg, #1e3a5f 0%, #0f2744 100%);
  z-index: 100; transition: transform 0.3s ease;
  display: flex; flex-direction: column;
}
#sidebar .logo { padding: 20px 18px 16px; border-bottom: 1px solid rgba(255,255,255,0.1); }
#sidebar .logo h1 { color: #fff; font-size: 20px; font-weight: 700; margin: 0; display: flex; align-items: center; gap: 8px; }
#sidebar .logo .version { color: rgba(255,255,255,0.4); font-size: 11px; margin-top: 2px; }
#sidebar nav { flex: 1; overflow-y: auto; padding: 8px 0; }
#sidebar nav .nav-section { padding: 10px 18px 4px; color: rgba(255,255,255,0.4); font-size: 11px; font-weight: 600; letter-spacing: 0.5px; text-transform: uppercase; }
#sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 10px 18px; color: rgba(255,255,255,0.75); text-decoration: none; font-size: 14px; cursor: pointer; transition: all 0.2s; border-left: 3px solid transparent; }
#sidebar nav a:hover { background: rgba(255,255,255,0.08); color: #fff; }
#sidebar nav a.active { background: rgba(59,130,246,0.25); color: #60a5fa; border-left-color: #60a5fa; }
#sidebar nav a i { width: 18px; text-align: center; font-size: 14px; }
#sidebar .sidebar-footer { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,0.1); color: rgba(255,255,255,0.4); font-size: 12px; }

#main-content { margin-left: 240px; min-height: 100vh; display: flex; flex-direction: column; }
#topbar { background: #fff; height: 56px; padding: 0 24px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #e5e7eb; position: sticky; top: 0; z-index: 50; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
#topbar h2 { font-size: 18px; font-weight: 600; color: #1f2937; margin: 0; }
#topbar .topbar-actions { display: flex; align-items: center; gap: 10px; }
#page-content { flex: 1; padding: 24px; }

.stat-card { background: #fff; border-radius: 12px; padding: 20px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); border: 1px solid #f0f0f0; display: flex; align-items: center; gap: 16px; }
.stat-card .stat-icon { width: 52px; height: 52px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0; }
.stat-card .stat-info { flex: 1; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: #1f2937; line-height: 1; }
.stat-card .stat-label { font-size: 13px; color: #6b7280; margin-top: 4px; }
.stat-card .stat-sub { font-size: 12px; color: #9ca3af; margin-top: 3px; }

.card { background: #fff; border-radius: 12px; padding: 20px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); border: 1px solid #f0f0f0; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid #f3f4f6; }
.card-header h3 { font-size: 15px; font-weight: 600; color: #374151; margin: 0; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th { background: #f9fafb; padding: 10px 14px; text-align: left; font-weight: 600; color: #6b7280; border-bottom: 2px solid #e5e7eb; white-space: nowrap; }
.data-table td { padding: 11px 14px; border-bottom: 1px solid #f3f4f6; color: #374151; vertical-align: middle; }
.data-table tr:hover td { background: #f9fafb; }
.data-table tr:last-child td { border-bottom: none; }

.badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge-green  { background: #dcfce7; color: #166534; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-gray   { background: #f3f4f6; color: #4b5563; }
.badge-purple { background: #f3e8ff; color: #6b21a8; }
.badge-orange { background: #ffedd5; color: #9a3412; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 8px; font-size: 13.5px; font-weight: 500; cursor: pointer; border: none; transition: all 0.15s; text-decoration: none; white-space: nowrap; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary   { background: #2563eb; color: #fff; }
.btn-primary:hover   { background: #1d4ed8; }
.btn-success   { background: #16a34a; color: #fff; }
.btn-success:hover   { background: #15803d; }
.btn-danger    { background: #dc2626; color: #fff; }
.btn-danger:hover    { background: #b91c1c; }
.btn-warning   { background: #d97706; color: #fff; }
.btn-warning:hover   { background: #b45309; }
.btn-secondary { background: #6b7280; color: #fff; }
.btn-secondary:hover { background: #4b5563; }
.btn-outline   { background: #fff; color: #374151; border: 1px solid #d1d5db; }
.btn-outline:hover   { background: #f9fafb; border-color: #9ca3af; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 6px; }
.btn-xs { padding: 3px 8px; font-size: 11.5px; border-radius: 5px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: #374151; margin-bottom: 6px; }
.form-control { width: 100%; padding: 9px 12px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px; color: #1f2937; outline: none; transition: border-color 0.15s, box-shadow 0.15s; background: #fff; }
.form-control:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.form-control::placeholder { color: #9ca3af; }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: grid; gap: 16px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

.search-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.search-input-wrap { position: relative; flex: 1; min-width: 220px; }
.search-input-wrap i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: #9ca3af; font-size: 14px; }
.search-input-wrap input { width: 100%; padding: 9px 12px 9px 34px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px; outline: none; background: #fff; }
.search-input-wrap input:focus { border-color: #2563eb; }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 600px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.25); animation: modalIn 0.2s ease; }
.modal-lg { max-width: 780px; }
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(-10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal-header { padding: 18px 22px 14px; border-bottom: 1px solid #e5e7eb; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: #fff; z-index: 1; }
.modal-header h3 { font-size: 17px; font-weight: 700; color: #1f2937; margin: 0; }
.modal-header .close-btn { width: 30px; height: 30px; border-radius: 8px; border: none; background: #f3f4f6; color: #6b7280; cursor: pointer; font-size: 16px; display: flex; align-items: center; justify-content: center; }
.modal-header .close-btn:hover { background: #e5e7eb; }
.modal-body { padding: 20px 22px; }
.modal-footer { padding: 14px 22px 18px; display: flex; gap: 10px; justify-content: flex-end; border-top: 1px solid #f3f4f6; }

.toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1f2937; color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 14px; min-width: 220px; box-shadow: 0 4px 12px rgba(0,0,0,0.2); display: flex; align-items: center; gap: 10px; animation: toastIn 0.3s ease; }
.toast.success { background: #16a34a; }
.toast.error   { background: #dc2626; }
.toast.warning { background: #d97706; }
@keyframes toastIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: translateX(0); } }

.empty-state { text-align: center; padding: 60px 20px; color: #9ca3af; }
.empty-state i { font-size: 48px; margin-bottom: 14px; display: block; }
.empty-state p { font-size: 15px; margin: 0; }

.chart-wrap { position: relative; height: 220px; }
.progress-bar { background: #e5e7eb; border-radius: 99px; height: 7px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 99px; transition: width 0.4s ease; }

.detail-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 20px; }
.detail-item label { font-size: 12px; color: #6b7280; display: block; margin-bottom: 2px; }
.detail-item span { font-size: 14px; color: #1f2937; font-weight: 500; }

.mono { font-family: 'Courier New', monospace; font-size: 13px; color: #2563eb; }
.amount { font-weight: 600; }
.amount-positive { color: #16a34a; }
.amount-negative { color: #dc2626; }

.slide-up { animation: slideUp 0.3s ease; }
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 768px) {
  /* 側邊欄：預設隱藏，.open 時滑入 */
  #sidebar {
    transform: translateX(-100%);
    z-index: 150;
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
  }
  #sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,0.35); }
  #main-content { margin-left: 0; }

  /* 漢堡選單按鈕 */
  #menu-toggle { display: flex !important; }

  /* 頂部列 */
  #topbar { padding: 0 12px 0 64px; }
  #topbar h2 { font-size: 15px; }
  #topbar .topbar-actions { gap: 6px; }

  /* 頁面內容 */
  #page-content { padding: 10px; }

  /* ===== 表單欄位：手機一欄 ===== */
  .form-row.cols-2, .form-row.cols-3 { grid-template-columns: 1fr; }

  /* ===== 統計卡片 ===== */
  .stat-card .stat-value { font-size: 22px; }
  .stat-card { padding: 12px; gap: 10px; }
  .stat-card .stat-icon { width: 44px; height: 44px; font-size: 18px; }

  /* ===== inline grid 雙欄自動轉單欄 ===== */
  /* 捕捉所有 1fr 1fr / 1fr 2fr inline style grid */
  div[style*="grid-template-columns:1fr 1fr"],
  div[style*="grid-template-columns: 1fr 1fr"],
  div[style*="grid-template-columns:1fr 2fr"],
  div[style*="grid-template-columns: 1fr 2fr"],
  div[style*="grid-template-columns:1fr 380px"],
  div[style*="grid-template-columns:repeat(3,1fr)"],
  div[style*="grid-template-columns: repeat(3, 1fr)"] {
    grid-template-columns: 1fr !important;
  }
  /* auto 1fr (detail grid) 改為完整寬度 */
  div[style*="grid-template-columns:auto 1fr"] {
    grid-template-columns: auto 1fr !important;
  }

  /* ===== 表格橫向捲動 ===== */
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 8px 8px; white-space: nowrap; }
  /* 讓所有 overflow-x:auto 的 div 正確捲動 */
  div[style*="overflow-x:auto"],
  div[style*="overflow-x: auto"] { -webkit-overflow-scrolling: touch; }

  /* ===== detail-list 手機單欄 ===== */
  .detail-list { grid-template-columns: 1fr; gap: 8px 0; }

  /* ===== 搜尋列 ===== */
  .search-bar { gap: 6px; }
  .search-input-wrap { min-width: 0; flex: 1 1 100%; }
  /* 搜尋列內按鈕換行 */
  .search-bar > .btn,
  .search-bar > button { flex: 1 1 auto; justify-content: center; }

  /* ===== card-header 內按鈕群組 ===== */
  .card-header { flex-wrap: wrap; gap: 8px; }
  .card-header > div[style*="display:flex"],
  .card-header > div { flex-wrap: wrap; gap: 6px !important; }

  /* ===== Modal 底部滑入 ===== */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    border-radius: 16px 16px 0 0;
    max-height: 94vh;
    max-width: 100% !important;
    animation: modalInMobile 0.25s ease;
  }
  .modal-lg { max-width: 100% !important; }
  @keyframes modalInMobile {
    from { opacity: 0; transform: translateY(60px); }
    to   { opacity: 1; transform: translateY(0); }
  }
  /* Modal body 內 grid 轉單欄 */
  .modal-body div[style*="grid-template-columns:1fr 1fr"],
  .modal-body div[style*="grid-template-columns: 1fr 1fr"],
  .modal-body div[style*="grid-template-columns:repeat(3,1fr)"],
  .modal-body div[style*="grid-template-columns: repeat(3, 1fr)"] {
    grid-template-columns: 1fr !important;
  }
  /* Modal footer 按鈕換行 */
  .modal-footer { flex-wrap: wrap; padding: 12px 16px 16px; }
  .modal-footer .btn { flex: 1 1 auto; justify-content: center; min-width: 80px; }
  /* Modal body padding 縮小 */
  .modal-body { padding: 14px 16px; }
  .modal-header { padding: 14px 16px 12px; }

  /* ===== 按鈕字體 ===== */
  .btn { font-size: 13px; }
  .btn-sm { padding: 7px 10px; font-size: 12px; }

  /* ===== 照片格 ===== */
  #pp-grid, #rph-grid,
  div[style*="grid-template-columns:repeat(auto-fill"] {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)) !important;
  }

  /* ===== 儀表板快速連結區 ===== */
  div[style*="grid-template-columns:repeat(auto-fit,minmax(160"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* ===== 側邊欄 PWA 安裝按鈕 ===== */
  #pwa-install-btn { display: flex !important; }

  /* ===== toast 手機版 ===== */
  .toast-container { top: auto; bottom: 72px; right: 10px; left: 10px; }
  .toast { min-width: 0; font-size: 13px; }

  /* ===== 安全區域（iPhone notch）===== */
  body { padding-bottom: env(safe-area-inset-bottom); }
  #sidebar { padding-bottom: env(safe-area-inset-bottom); }

  /* ===== 報修/交屋 modal 雙格標籤 ===== */
  .modal-body div[style*="grid-template-columns:1fr 1fr;gap:10px"],
  .modal-body div[style*="grid-template-columns:1fr 1fr;gap:12px"] {
    grid-template-columns: 1fr !important;
  }

  /* ===== 記帳報表圖表 ===== */
  .chart-wrap { height: 180px; }
}

/* iPad 橫式 */
@media (min-width: 768px) and (max-width: 1024px) {
  #sidebar { width: 200px; }
  #main-content { margin-left: 200px; }
}

/* PWA 獨立模式（安裝到主畫面後）*/
@media (display-mode: standalone) {
  #topbar { padding-top: env(safe-area-inset-top, 0px); height: calc(56px + env(safe-area-inset-top, 0px)); }
  #sidebar { padding-top: env(safe-area-inset-top, 0px); }
  #menu-toggle { top: calc(12px + env(safe-area-inset-top, 0px)); }
}

/* 離線指示器動畫 */
#online-indicator { transition: all 0.3s ease; }
.offline-banner {
  background: #fef2f2;
  border-bottom: 2px solid #fca5a5;
  color: #dc2626;
  padding: 6px 16px;
  font-size: 13px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* 安裝按鈕動畫 */
#pwa-install-btn {
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.75; }
}

/* 表格操作欄位 */
.data-table td .btn + .btn { margin-left: 2px; }

/* 金額輸入欄 */
input[type="number"].form-control { font-variant-numeric: tabular-nums; }

/* 卡片懸停 */
.card[onclick] { cursor: pointer; }
.card[onclick]:hover { border-color: #d1d5db; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }

/* 進度條 */
.progress-bar { background: #e5e7eb; border-radius: 99px; height: 7px; overflow: hidden; margin-top: 6px; }
.progress-fill { height: 100%; border-radius: 99px; transition: width 0.5s ease; }

/* 表格空白佔位符 */
.data-table tbody td[colspan] { text-align: center; color: #9ca3af; padding: 32px; }

/* 手機版隱藏次要欄位 */
@media (max-width: 640px) {
  .hide-mobile { display: none !important; }
  .data-table th:nth-child(n+5):not(:last-child) { display: none; }
  .data-table td:nth-child(n+5):not(:last-child) { display: none; }

  /* 搜尋列按鈕文字隱藏，只顯示圖示 */
  .search-bar .btn .btn-label { display: none; }

  /* 卡片 padding 縮小 */
  .card { padding: 14px 12px; }
  .card-header { margin-bottom: 12px; padding-bottom: 10px; }

  /* 統計卡片文字再縮小 */
  .stat-card .stat-value { font-size: 20px; }
  .stat-card .stat-label { font-size: 12px; }

  /* page-content 更緊湊 */
  #page-content { padding: 8px; }

  /* Modal body 更緊湊 */
  .modal-body { padding: 12px 14px; }
  .modal-header { padding: 12px 14px 10px; }
  .modal-footer { padding: 10px 14px 14px; gap: 8px; }

  /* 表格字體再縮 */
  .data-table { font-size: 11.5px; }
  .data-table th, .data-table td { padding: 7px 6px; }
}

/* 側邊欄滑動時防止背景滾動 */
body.sidebar-open { overflow: hidden; }

/* ===== 行事曆響應式佈局 ===== */

/* 桌面：左月曆 + 右側欄 雙欄 */
.cal-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 16px;
  align-items: start;
}
.cal-side-panel { display: block; }

/* 月曆格 wrapper */
.cal-grid-wrap { padding: 12px 16px 16px; }

/* 星期標頭 */
.cal-week-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  text-align: center;
}
.cal-weekday {
  font-size: 13px;
  font-weight: 700;
  color: #6b7280;
  padding: 6px 0;
}
.cal-weekday-sun { color: #dc2626; }
.cal-weekday-sat { color: #2563eb; }

/* 日期格 */
.cal-day-cell {
  cursor: pointer;
  padding: 6px 2px 4px;
  border-radius: 8px;
  border: 1.5px solid transparent;
  background: transparent;
  transition: all 0.15s;
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.cal-day-today  { background: #dbeafe; border-color: #2563eb; }
.cal-day-selected { background: #1e3a5f; border-color: #1e3a5f; }

/* 日期數字 */
.cal-day-num {
  font-size: 14px;
  font-weight: 500;
  color: #1f2937;
  line-height: 1.4;
}
.cal-day-num-sun   { color: #dc2626; }
.cal-day-num-sat   { color: #2563eb; }
.cal-day-num-today { font-weight: 700; }
.cal-day-num-sel   { color: #fff !important; font-weight: 700; }

/* 事件小點列 */
.cal-dots {
  display: flex;
  justify-content: center;
  gap: 3px;
  margin-top: 3px;
}
.cal-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

/* 圖例 */
.cal-legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #f3f4f6;
  font-size: 11px;
  color: #9ca3af;
}
.cal-legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

/* 手機版 ≤ 768px：單欄堆疊，放大日期 */
@media (max-width: 768px) {
  .cal-layout {
    grid-template-columns: 1fr !important;
  }
  .cal-side-panel { margin-top: 0; }
  .cal-grid-wrap { padding: 10px 10px 14px; }

  /* 星期標頭更大 */
  .cal-weekday { font-size: 14px; padding: 8px 0; }

  /* 日期格更大更好點擊 */
  .cal-day-cell {
    min-height: 58px;
    padding: 6px 2px 4px;
    border-radius: 10px;
  }

  /* 日期數字放大、加粗 */
  .cal-day-num { font-size: 16px; font-weight: 600; }

  /* 事件點放大 */
  .cal-dot { width: 7px; height: 7px; }

  /* 圖例 */
  .cal-legend { font-size: 12px; gap: 10px; }
  .cal-legend-dot { width: 9px; height: 9px; }
}

/* 超小螢幕 ≤ 390px（iPhone SE / 小型 Android）*/
@media (max-width: 390px) {
  .cal-grid-wrap { padding: 8px 6px 12px; }
  .cal-week-grid { gap: 2px; }
  .cal-weekday { font-size: 13px; }
  .cal-day-cell { min-height: 52px; border-radius: 8px; }
  .cal-day-num { font-size: 15px; }
}


