* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #0d9488;
  --primary-light: #ccfbf1;
  --primary-dark: #0f766e;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --gray: #6b7280;
  --gray-light: #f3f4f6;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #4b5563;
  --nav-h: 82px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Noto Sans TC', sans-serif;
  font-size: 20px;
  color: var(--text);
  background: #fff;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 600px;
  margin: 0 auto;
}

/* ─── Tab Content ─── */
.tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
}
.tab-top-pad { height: 16px; }

/* ─── Bottom Nav ─── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 600px;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: #fff;
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--gray);
  font-size: 18px;
  padding: 8px 0;
  transition: color 0.15s;
}
.nav-btn .icon { font-size: 30px; line-height: 1; }
.nav-btn.active { color: var(--primary); font-weight: 700; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 52px;
  padding: 0 20px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-size: 18px;
  font-weight: 600;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:active { opacity: 0.8; transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-outline { background: #fff; color: var(--primary); border: 2px solid var(--primary); }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-gray    { background: var(--gray-light); color: var(--text); border: 1px solid var(--border); }
.btn-sm      { min-height: 40px; padding: 0 14px; font-size: 16px; border-radius: 8px; }
.btn-full    { width: 100%; }

/* ─── Cards / Sections ─── */
.section-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text);
}

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
}

.card-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ─── Calendar ─── */
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.cal-title { font-size: 20px; font-weight: 700; }
.cal-nav { background: none; border: none; font-size: 22px; cursor: pointer; padding: 6px 12px; color: var(--primary); }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 14px;
}
.cal-weekday {
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 0;
}
.cal-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  border: none;
  background: none;
  transition: background 0.1s;
}
.cal-day:active { opacity: 0.7; }
.cal-day.selected {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}
.cal-day.today { border: 2px solid var(--primary); }
.cal-day:empty { cursor: default; }

.selected-dates-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  font-size: 17px;
  color: var(--text-muted);
}
.date-tag {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-radius: 20px;
  padding: 3px 12px;
  font-size: 16px;
  font-weight: 600;
}

/* ─── Date Nav ─── */
.date-nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  overflow-x: auto;
  margin: 0 -16px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}
.date-nav::-webkit-scrollbar { display: none; }
.date-nav-chip {
  flex-shrink: 0;
  background: none;
  border: none;
  border-radius: 0;
  padding: 10px 14px;
  font-size: 18px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s;
}
.date-nav-chip.active {
  color: #f97316;
  font-weight: 700;
}
.date-nav-chip:active { opacity: 0.7; }

/* ─── Schedule Results ─── */
.schedule-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.day-block {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 12px;
}

.day-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--gray-light);
  padding: 10px 14px;
}
.day-title { font-size: 20px; font-weight: 700; }

.route-row {
  display: flex;
  align-items: flex-start;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  gap: 10px;
}
.route-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary-dark);
  min-width: 70px;
  flex-shrink: 0;
  padding-top: 4px;
}
.staff-drag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1;
  min-height: 36px;
}
.staff-chip {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-radius: 20px;
  padding: 4px 14px;
  font-size: 18px;
  font-weight: 600;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.staff-chip:active { cursor: grabbing; opacity: 0.8; }
.staff-chip.sortable-ghost { opacity: 0.4; }
.staff-chip.sortable-chosen { transform: scale(1.05); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }

/* ─── Trash Zone ─── */
.trash-zone {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 20px);
  right: 20px;
  width: 68px;
  height: 68px;
  background: var(--danger-light);
  border: 2px dashed var(--danger);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  z-index: 150;
  transition: transform 0.15s, background 0.15s;
}
/* v-show 隱藏時不攔截事件 */
.trash-zone[style*="display: none"] { pointer-events: none; }
.trash-zone.drag-over {
  background: var(--danger);
  transform: scale(1.12);
}

.route-count {
  display: inline-block;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray);
  background: var(--gray-light);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  margin-right: 6px;
}

/* ─── Staff Tab ─── */
.staff-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 8px;
}
.staff-item-top {
  display: flex;
  align-items: center;
  gap: 10px;
}
.staff-name {
  flex: 1;
  font-size: 22px;
  font-weight: 600;
}
.constraint-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.constraint-tag {
  background: #fef3c7;
  color: #92400e;
  border-radius: 14px;
  padding: 2px 10px;
  font-size: 15px;
}

/* ─── Routes Tab ─── */
.route-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 8px;
}
.route-item-name {
  flex: 1;
  font-size: 22px;
  font-weight: 600;
}
.count-input {
  width: 56px;
  height: 44px;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  border: 2px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}
.count-input:focus { outline: none; border-color: var(--primary); }
.count-label { font-size: 17px; color: var(--text-muted); }

/* ─── Saved Tab ─── */
.saved-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 10px;
}
.saved-item-header {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  gap: 10px;
  cursor: pointer;
  background: #fff;
}
.saved-item-title {
  flex: 1;
  font-size: 20px;
  font-weight: 700;
}
.saved-item-meta {
  font-size: 15px;
  color: var(--text-muted);
}
.saved-item-body {
  border-top: 1px solid var(--border);
  padding: 14px;
  background: var(--gray-light);
}
.saved-content-text {
  font-size: 17px;
  white-space: pre-wrap;
  line-height: 1.7;
  margin-bottom: 12px;
}
.saved-item-actions {
  display: flex;
  gap: 8px;
}

/* ─── Toggle Checkbox ─── */
.toggle {
  position: relative;
  width: 52px;
  height: 30px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 15px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle input:checked + .toggle-track { background: var(--primary); }
.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.toggle input:checked + .toggle-track::after { transform: translateX(22px); }

/* ─── Input ─── */
.input {
  width: 100%;
  height: 52px;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 0 14px;
  font-size: 20px;
  color: var(--text);
  background: #fff;
}
.input:focus { outline: none; border-color: var(--primary); }

.input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

/* ─── Modal ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-box {
  background: #fff;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 85dvh;
  overflow-y: auto;
  padding: 20px 16px;
  padding-bottom: calc(20px + var(--safe-bottom));
}
.modal-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 16px;
}
.modal-section-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 14px 0 8px;
}
.modal-check-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
  max-height: 180px;
  overflow-y: auto;
}
.check-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 2px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  font-size: 18px;
  background: #fff;
  transition: all 0.1s;
}
.check-chip input { display: none; }
.check-chip.checked { background: var(--primary); border-color: var(--primary); color: #fff; }
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

/* ─── Toast ─── */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #111;
  color: #fff;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 17px;
  z-index: 300;
  white-space: nowrap;
  pointer-events: none;
  animation: fadeInOut 2.5s ease forwards;
}
@keyframes fadeInOut {
  0%   { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  15%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-8px); }
}

/* ─── Empty State ─── */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 18px;
  line-height: 1.8;
}

/* ─── Loading ─── */
.loading-row {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 18px;
  gap: 10px;
}
.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Divider ─── */
.divider { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

/* ─── Status Badge ─── */
.status-badge {
  font-size: 16px;
  font-weight: 700;
  border-radius: 10px;
  padding: 2px 9px;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}
.badge-active {
  background: #d1fae5;
  color: #065f46;
}
.badge-inactive {
  background: #f3f4f6;
  color: #9ca3af;
}

/* ─── Delete text button (小灰文字，不顯眼） ─── */
.delete-text-btn {
  background: none;
  border: none;
  color: #9ca3af;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  flex-shrink: 0;
}
.delete-text-btn:hover, .delete-text-btn:active { color: var(--danger); }

/* ─── Utils ─── */
.flex-center { display: flex; align-items: center; gap: 8px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.text-muted { color: var(--text-muted); font-size: 16px; }
.mb-12 { margin-bottom: 12px; }
.mt-12 { margin-top: 12px; }
