:root {
      --primary: #2563eb;
      --primary-hover: #1d4ed8;
      --danger: #ef4444;
      --danger-hover: #dc2626;
      --bg: #f8fafc;
      --card-bg: #ffffff;
      --text: #1e293b;
      --text-muted: #64748b;
      --border: #e2e8f0;
      --accent: #eff6ff;
    }

    * { box-sizing: border-box; margin: 0; padding: 0; }
    body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--text); padding: 16px; }
    .container { max-width: 800px; margin: 0 auto; }
    
    header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
    h1 { font-size: 1.4rem; color: #0f172a; }
    .auth-badge { background: #e0f2fe; color: #0369a1; border: 1px solid #bae6fd; padding: 6px 14px; border-radius: 20px; font-size: 0.85rem; font-weight: 600; display: flex; align-items: center; gap: 6px; }
    .auth-badge::before { content: "●"; color: #0284c7; }
    .auth-badge.edit-unlocked { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
    .auth-badge.edit-unlocked::before { color: #16a34a; }
    .auth-badge.viewer { background: #f1f5f9; color: #64748b; border-color: #e2e8f0; }
    .auth-badge.viewer::before { color: #94a3b8; }
    .password-message { font-size: 0.85rem; line-height: 1.6; color: #475569; background: #f8fafc; padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; }
    .password-error { color: #dc2626; font-size: 0.8rem; min-height: 18px; margin-top: 6px; }

    .card { background: var(--card-bg); border-radius: 16px; padding: 20px; margin-bottom: 16px; box-shadow: 0 4px 12px rgba(0,0,0,0.03); border: 1px solid var(--border); }
    .card-title { font-size: 0.95rem; font-weight: 600; color: var(--text-muted); margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 4px; }
    
    /* 上方最新數據區塊 */
    .dashboard { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
    .stat-box { background: var(--accent); padding: 12px 8px; border-radius: 12px; text-align: center; border: 1px solid #dbeafe; }
    .stat-label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 4px; }
    .stat-value { font-size: 1.5rem; font-weight: 700; color: #0f172a; line-height: 1.1; }
    .stat-unit { font-size: 0.75rem; font-weight: 400; color: var(--text-muted); margin-left: 2px; }
    
    .stat-diff { font-size: 0.75rem; font-weight: 600; margin-top: 6px; }
    .diff-up { color: #dc2626; }    /* 上升：紅色 */
    .diff-down { color: #2563eb; }  /* 下降：藍色 */
    .diff-equal { color: #64748b; } /* 無變化：灰色 */

    /* 初次施打至今 & 施打劑量統計區塊共用 */
    .baseline-section { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); }
    .baseline-title { font-size: 0.85rem; font-weight: 700; color: #334155; margin-bottom: 8px; display: flex; align-items: center; justify-content: space-between; }
    .baseline-title.clickable { cursor: pointer; user-select: none; }
    
    .baseline-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
    
    /* 單排強制的劑量統計 Grid */
    .dose-stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
    /* 舒適柔和的紅色系標題 */
    .phase-sub-title { font-size: 0.78rem; font-weight: 600; color: #c2410c; margin-top: 12px; margin-bottom: 4px; text-align: center; }
    
    .baseline-box { background: #f1f5f9; padding: 8px 4px; border-radius: 8px; text-align: center; }
    .baseline-label { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 2px; }
    .baseline-value { font-size: 1.1rem; font-weight: 700; }
    .baseline-unit { font-size: 0.75rem; font-weight: 400; color: var(--text-muted); margin-left: 2px; }
    .baseline-percent { display: block; font-size: 0.68rem; font-weight: 500; margin-top: 3px; margin-left: 0; white-space: nowrap; }

    /* 操作區塊 */
    .action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px; }
    
    .btn { padding: 12px; border: none; border-radius: 10px; font-size: 0.95rem; font-weight: 600; cursor: pointer; transition: all 0.2s; display: flex; align-items: center; justify-content: center; gap: 6px; }
    .btn-primary { background: var(--primary); color: white; }
    .btn-primary:hover { background: var(--primary-hover); }
    .btn-danger { background: var(--danger); color: white; }
    .btn-danger:hover { background: var(--danger-hover); }
    .btn-outline { background: white; border: 1px solid var(--primary); color: var(--primary); }
    .btn-outline:hover { background: var(--accent); }
    .btn-lot-info { background: #CE0000; color: white; }
    .btn-lot-info:hover { background: #CE0000; }
    .btn:disabled { opacity: 0.65; cursor: not-allowed; }
    .btn-sm { padding: 6px 12px; font-size: 0.8rem; border-radius: 6px; }
    
    /* 檢視者禁用按鈕樣式 */
    .btn-disabled {
      background-color: #94a3b8 !important;
      color: #ffffff !important;
      border-color: #94a3b8 !important;
      cursor: not-allowed !important;
      opacity: 0.7;
      box-shadow: none !important;
    }
    
    /* 彈出視窗 Modal */
    .modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(4px); justify-content: center; align-items: center; z-index: 100; padding: 16px; }
    .modal-content { background: white; padding: 24px; border-radius: 16px; width: 95%; max-width: 650px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1); }
    .modal-header { font-size: 1.2rem; font-weight: 700; margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center; }

    .form-group { margin-bottom: 14px; }
    label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; color: #334155; }
    input, select { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 1rem; color: var(--text); outline: none; transition: border 0.2s; }
    input:focus, select:focus { border-color: var(--primary); }
    select { appearance: none; background: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2064748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e") no-repeat right 12px center/16px; }

    /* 表單預設提示文字（Placeholder）設定 */
    input::placeholder {
      color: #cbd5e1;
      opacity: 1;
    }

    /* 月份選擇控制器 */
    .month-picker { display: flex; align-items: center; justify-content: space-between; background: #f1f5f9; padding: 8px 12px; border-radius: 10px; margin-bottom: 16px; }
    .month-title { font-weight: 700; color: #334155; font-size: 1.05rem; letter-spacing: 0.5px; }

    /* 歷史明細標題與排序按鈕 */
    .history-header { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; }
    .sort-btn { background: #f1f5f9; border: 1px solid var(--border); color: #475569; padding: 4px 10px; border-radius: 6px; font-size: 0.75rem; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 4px; }
    .sort-btn:hover { background: #e2e8f0; }

    /* 歷史明細列表與左滑右滑樣式 */
    .history-list { max-height: 280px; overflow-y: auto; overflow-x: hidden; margin-top: 8px; border: 1px solid var(--border); border-radius: 8px; }
    
    .swipe-wrapper {
      position: relative;
      overflow: hidden;
      border-bottom: 1px solid #f1f5f9;
      background-color: #f8fafc;
    }
    .swipe-wrapper:last-child { border-bottom: none; }

    /* 背景操作按鈕底色層 */
    .swipe-actions {
      position: absolute;
      top: 0; bottom: 0; left: 0; right: 0;
      display: flex;
      justify-content: space-between;
      align-items: center;
      z-index: 1;
    }
    .swipe-action-btn {
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      width: 75px;
      color: white;
      font-size: 0.85rem;
      font-weight: 600;
      cursor: pointer;
      user-select: none;
    }
    .swipe-action-edit { background-color: var(--primary); }
    .swipe-action-delete { background-color: var(--danger); }

    /* 前景卡片內容層 */
    .history-item {
      position: relative;
      z-index: 2;
      background: #ffffff;
      padding: 10px 12px;
      font-size: 0.85rem;
      user-select: none;
      touch-action: pan-y;
    }
    .history-item.dosed { background-color: #f0f4ff; }
    .history-item-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
    .history-date { font-weight: 700; color: #0f172a; font-size: 0.9rem; }
    .history-dose { display: inline-flex; align-items: center; gap: 4px; background: #3b82f6; color: white; padding: 2px 10px; border-radius: 12px; font-size: 0.75rem; font-weight: 600; }
    
    /* 明細對齊排版 */
    .history-details { display: flex; flex-direction: column; gap: 4px; color: #475569; font-size: 0.82rem; background: rgba(255,255,255,0.6); padding: 6px 8px; border-radius: 6px; }
    .history-row { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
    .detail-tag { font-weight: 600; color: #1e293b; }

    /* 單獨圖表卡片 */
    .sub-chart-card { background: #fafafa; border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
    .sub-chart-title { font-size: 0.85rem; font-weight: 700; color: #475569; margin-bottom: 8px; }

    @media (max-width: 600px) {
      .dashboard, .baseline-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
      .dose-stats-grid { grid-template-columns: repeat(4, 1fr); gap: 4px; }
      .dose-stats-grid .baseline-label { font-size: 0.7rem; }
      .dose-stats-grid .baseline-value { font-size: 0.95rem; }
      .action-grid { grid-template-columns: 1fr; }
    }
/* 搬遷第一階段：明確標示尚未接通資料 */
.preview-notice { margin-bottom: 12px; padding: 12px; border: 1px solid #fcd34d; border-radius: 10px; background: #fffbeb; color: #92400e; font-size: 0.85rem; line-height: 1.5; }

.preview-notice.read-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
