/* ============== Reset & Base ============== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: #f2f2f7;
  color: #1c1c1e;
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  user-select: none;
  -webkit-user-select: none;
}
input, textarea, select { font-family: inherit; font-size: inherit; user-select: text; -webkit-user-select: text; }

/* ============== Layout ============== */
#app {
  min-height: 100vh;
  max-width: 640px;
  margin: 0 auto;
  background: #f2f2f7;
  position: relative;
  padding-bottom: 80px;
}

/* ============== Header ============== */
.app-header {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  color: white;
  padding: 20px 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.app-header-title { display: flex; align-items: center; gap: 12px; }
.app-logo { font-size: 32px; }
.app-header h1 { font-size: 20px; font-weight: 700; }
.app-header .subtitle { font-size: 12px; opacity: 0.85; margin-top: 2px; }
.header-stats { display: flex; gap: 8px; }
.badge-pending {
  background: #fbbf24;
  color: #78350f;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
}

/* ============== Pages ============== */
.page {
  display: none;
  padding: 16px;
}
.page-active { display: block; }
.page h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 12px;
  color: #1c1c1e;
}
.count-badge {
  background: #ef4444;
  color: white;
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 14px;
  font-weight: 700;
  margin-left: 8px;
}
.section-h {
  font-size: 14px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 16px 0 8px;
}

/* ============== Hero (Capture) ============== */
.hero {
  text-align: center;
  padding: 32px 16px;
}
.hero-icon { font-size: 64px; margin-bottom: 12px; }
.hero h2 { font-size: 24px; margin-bottom: 8px; }
.hero p { color: #6b7280; }

/* ============== Action Grid ============== */
.action-grid { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.action-card {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}
.action-card:active { transform: scale(0.98); box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.action-icon {
  width: 56px; height: 56px;
  border-radius: 12px;
  background: rgba(79, 70, 229, 0.1);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
}
.action-card:nth-child(2) .action-icon { background: rgba(59, 130, 246, 0.1); }
.action-card:nth-child(3) .action-icon { background: rgba(20, 184, 166, 0.1); }
.action-card:nth-child(4) .action-icon { background: rgba(245, 158, 11, 0.1); }
.action-content { flex: 1; }
.action-title { font-size: 16px; font-weight: 600; color: #1c1c1e; }
.action-subtitle { font-size: 13px; color: #6b7280; margin-top: 2px; }
.chevron { color: #cbd5e1; font-size: 24px; }

/* ============== OCR Section ============== */
.ocr-section { margin: 16px 0; }
.ocr-progress {
  background: white;
  border-radius: 14px;
  padding: 24px;
  text-align: center;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid #e5e7eb;
  border-top-color: #4f46e5;
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress-bar {
  height: 6px; background: #e5e7eb; border-radius: 3px;
  margin-top: 12px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: #4f46e5;
  width: 0%; transition: width 0.3s;
}
.ocr-preview {
  background: white;
  border-radius: 14px;
  padding: 16px;
  margin-top: 12px;
}
.ocr-preview h3 { font-size: 16px; margin-bottom: 8px; }
.ocr-image-wrap {
  max-height: 250px;
  overflow: hidden;
  border-radius: 8px;
  margin: 8px 0;
}
.ocr-image-wrap img { width: 100%; display: block; }
.ocr-text {
  background: #f9fafb;
  padding: 10px;
  border-radius: 8px;
  font-size: 13px;
  color: #4b5563;
  max-height: 120px;
  overflow-y: auto;
  white-space: pre-wrap;
}
.muted { color: #9ca3af; font-size: 13px; }

/* ============== Tomorrow Preview ============== */
.tomorrow-preview {
  background: white;
  border-radius: 14px;
  padding: 16px;
  margin: 16px 0;
}
.tomorrow-preview h3 { font-size: 16px; margin-bottom: 12px; }
.tomorrow-item {
  background: #fef3c7;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 8px;
  display: flex;
  gap: 10px;
  align-items: center;
}

/* ============== Confirm List ============== */
.notice-card {
  background: white;
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  cursor: pointer;
  transition: transform 0.1s;
  border-left: 4px solid #fbbf24;
  position: relative;
}
.notice-card:active { transform: scale(0.99); }
.notice-card.status-confirmed { border-left-color: #3b82f6; }
.notice-card.status-scheduled { border-left-color: #10b981; }
.notice-card.status-archived { border-left-color: #9ca3af; opacity: 0.6; }
.notice-status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #fbbf24; flex-shrink: 0; margin-top: 6px;
}
.notice-card.status-confirmed .notice-status-dot { background: #3b82f6; }
.notice-card.status-scheduled .notice-status-dot { background: #10b981; }
.notice-card.status-archived .notice-status-dot { background: #9ca3af; }
.notice-content { flex: 1; }
.notice-title { font-size: 15px; font-weight: 600; line-height: 1.4; }
.notice-meta {
  display: flex;
  gap: 10px;
  margin-top: 6px;
  flex-wrap: wrap;
  font-size: 12px;
  color: #6b7280;
}
.notice-meta-item { display: flex; align-items: center; gap: 3px; }
.notice-warning {
  color: #f59e0b;
  font-size: 18px;
  flex-shrink: 0;
}
.notice-assignees {
  margin-top: 6px;
  display: flex;
  gap: 4px;
}
.notice-assignee-emoji { font-size: 18px; }

/* ============== Empty State ============== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: #6b7280;
}
.empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty-state small { display: block; margin-top: 4px; color: #9ca3af; }

/* ============== Calendar ============== */
.calendar-date {
  width: 100%;
  padding: 12px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: white;
  font-size: 16px;
  margin-bottom: 16px;
}
.calendar-day-section {
  background: white;
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
}
.day-notice {
  display: flex;
  gap: 12px;
  padding: 10px;
  background: #f9fafb;
  border-radius: 10px;
  margin-bottom: 8px;
}
.day-badge {
  background: rgba(79, 70, 229, 0.1);
  color: #4f46e5;
  border-radius: 8px;
  padding: 6px;
  text-align: center;
  font-weight: 700;
  font-size: 14px;
  min-width: 50px;
  flex-shrink: 0;
}
.day-notice-content { flex: 1; }
.day-notice-title { font-size: 14px; font-weight: 600; }
.day-notice-meta { font-size: 12px; color: #6b7280; margin-top: 4px; }
.upcoming-section {
  background: white;
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
}
.upcoming-section h3 { font-size: 16px; margin-bottom: 12px; }

/* ============== Family ============== */
.family-row {
  background: white;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 8px;
  display: flex;
  gap: 12px;
  align-items: center;
}
.family-emoji { font-size: 28px; }
.family-content { flex: 1; }
.family-name { font-size: 15px; font-weight: 600; }
.family-detail { font-size: 12px; color: #6b7280; }
.color-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
}
.add-btn {
  width: 100%;
  background: white;
  border: 2px dashed #d1d5db;
  border-radius: 12px;
  padding: 12px;
  color: #6b7280;
  font-size: 14px;
  cursor: pointer;
  margin-bottom: 16px;
}
.add-btn:active { background: #f9fafb; }
.privacy-notice {
  background: #ecfdf5;
  border-radius: 12px;
  padding: 12px;
  margin: 16px 0;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.privacy-icon { font-size: 24px; }
.privacy-notice strong { color: #065f46; }
.privacy-notice p { font-size: 12px; color: #047857; margin-top: 4px; line-height: 1.5; }

/* ============== Settings ============== */
.setting-row {
  background: white;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #f3f4f6;
}
.setting-row:first-of-type { border-radius: 12px 12px 0 0; }
.setting-row:last-of-type { border-radius: 0 0 12px 12px; border-bottom: none; }
.setting-row:only-child { border-radius: 12px; }
.btn-mini {
  background: #4f46e5;
  color: white;
  border: none;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.btn-mini:active { opacity: 0.85; }
.btn-mini.danger { background: #ef4444; }
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.stat-card {
  background: white;
  border-radius: 12px;
  padding: 14px;
  text-align: center;
}
.stat-value { font-size: 24px; font-weight: 700; color: #4f46e5; }
.stat-label { font-size: 12px; color: #6b7280; margin-top: 4px; }

/* ============== Bottom Nav ============== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 640px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  border-top: 1px solid #e5e7eb;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 100;
}
.nav-item {
  flex: 1;
  background: none;
  border: none;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  color: #6b7280;
  position: relative;
}
.nav-item.active { color: #4f46e5; }
.nav-icon { font-size: 22px; }
.nav-label { font-size: 11px; font-weight: 500; }
.nav-badge {
  position: absolute;
  top: 4px;
  right: 25%;
  background: #ef4444;
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 8px;
  min-width: 16px;
  text-align: center;
}

/* ============== Modal ============== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: none;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-content {
  background: white;
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  animation: slideUp 0.25s;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e5e7eb;
}
.modal-header h3 { font-size: 17px; font-weight: 600; flex: 1; text-align: center; }
.btn-cancel {
  background: none; border: none; color: #6b7280; font-size: 16px; cursor: pointer;
}
.btn-confirm {
  background: #4f46e5; color: white; border: none;
  padding: 8px 16px; border-radius: 8px; font-weight: 600; cursor: pointer;
}
.manual-content { display: flex; flex-direction: column; height: 90vh; }
.manual-content textarea {
  flex: 1; padding: 12px; border: none; outline: none;
  font-size: 15px; line-height: 1.6; resize: none;
}
.form-content input, .form-content select {
  width: 100%; padding: 12px; border: 1px solid #e5e7eb;
  border-radius: 10px; margin-bottom: 10px; font-size: 15px;
}

/* ============== Confirm Sheet Form ============== */
.confirm-section {
  background: white;
  margin-bottom: 12px;
  border-radius: 12px;
  padding: 12px 16px;
}
.confirm-section-title {
  font-size: 13px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  margin-bottom: 8px;
  letter-spacing: 0.3px;
}
.confirm-row {
  display: flex;
  align-items: center;
  padding: 8px 0;
  gap: 10px;
  border-bottom: 1px solid #f3f4f6;
}
.confirm-row:last-child { border-bottom: none; }
.confirm-row label { flex: 1; font-size: 14px; }
.confirm-row input, .confirm-row textarea {
  flex: 2; padding: 8px 10px; border: 1px solid #e5e7eb;
  border-radius: 8px; font-size: 14px;
}
.confirm-row input[type="checkbox"] { flex: 0; width: 20px; height: 20px; }
.item-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; color: #047857;
}
.confirm-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
  padding-bottom: env(safe-area-inset-bottom);
}
.btn-primary {
  background: #4f46e5; color: white;
  border: none; padding: 14px; border-radius: 12px;
  font-size: 16px; font-weight: 600; cursor: pointer;
}
.btn-secondary {
  background: #10b981; color: white;
  border: none; padding: 14px; border-radius: 12px;
  font-size: 16px; font-weight: 600; cursor: pointer;
}
.btn-danger {
  background: white; color: #ef4444;
  border: 1px solid #ef4444;
  padding: 14px; border-radius: 12px;
  font-size: 16px; font-weight: 600; cursor: pointer;
}
.btn-link {
  background: none; border: none;
  color: #4f46e5; font-size: 14px; padding: 8px; cursor: pointer;
}
.privacy-badge {
  background: #fef3c7;
  color: #92400e;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  display: inline-block;
  margin-top: 4px;
}

/* ============== Toast ============== */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.85);
  color: white;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 300;
  animation: fadeIn 0.2s;
}

/* OCR 低信心行高亮 */
mark.ocr-low-conf {
  background: #fef3c7;
  color: #92400e;
  padding: 1px 3px;
  border-radius: 3px;
  border-bottom: 2px dashed #f59e0b;
  font-weight: 500;
}

/* OCR preview 區塊加信心燈號 */
.ocr-confidence-meter {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  margin-left: 6px;
}
.ocr-confidence-meter.high { background: #d1fae5; color: #065f46; }
.ocr-confidence-meter.mid  { background: #fef3c7; color: #92400e; }
.ocr-confidence-meter.low  { background: #fee2e2; color: #991b1b; }

/* Feature badge(設定頁新功能) */
.feature-badge {
  display: inline-block;
  background: linear-gradient(135deg, #8b5cf6, #ec4899);
  color: white;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 9px;
  font-weight: 700;
  margin-left: 6px;
  letter-spacing: 0.5px;
  vertical-align: middle;
}