/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f5f5f5;
  color: #333;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

a { color: #4a90d9; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Nav */
.nav {
  background: #2c3e50;
  color: white;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-brand { font-size: 1.1rem; font-weight: 600; }
.nav-links { display: flex; gap: 0.75rem; }
.nav-link { color: #ecf0f1; padding: 0.25rem 0.5rem; border-radius: 4px; font-size: 0.9rem; }
.nav-link:hover { background: rgba(255,255,255,0.1); text-decoration: none; }

/* Container */
.container { max-width: 1200px; margin: 0 auto; padding: 1rem; }

h1 { font-size: 1.5rem; margin-bottom: 1rem; }

/* Alerts */
.alert { padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: 0.9rem; }
.alert-success { background: #d4edda; color: #155724; }
.alert-error { background: #f8d7da; color: #721c24; }

/* Filters */
.filter-form { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filter-form select {
  padding: 0.5rem 0.75rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: white;
  font-size: 0.85rem;
  flex: 1;
  min-width: 100px;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}
.type-badge { background: #e8f4fd; color: #1a73e8; }
.status-待處理 { background: #fff3cd; color: #856404; }
.status-進行中 { background: #cce5ff; color: #004085; }
.status-待確認 { background: #e2d5f1; color: #6f42c1; }
.status-已完成 { background: #d4edda; color: #155724; }
.status-已發佈 { background: #d1ecf1; color: #0c5460; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  background: #4a90d9;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  text-align: center;
}
.btn:hover { background: #357abd; text-decoration: none; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-secondary { background: #6c757d; }
.btn-secondary:hover { background: #5a6268; }
.btn-danger { background: #dc3545; }
.btn-danger:hover { background: #c82333; }
.action-cell { white-space: nowrap; }
.action-cell form { display: inline; }

/* Inline edit */
.inline-edit {
  padding: 0.25rem 0.4rem;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  max-width: 100%;
}
.inline-edit:hover { border-color: #ddd; background: white; }
.inline-edit:focus { outline: none; border-color: #4a90d9; background: white; box-shadow: 0 0 0 2px rgba(74,144,217,0.2); }
select.inline-status { font-weight: 500; }

.empty-state { text-align: center; padding: 3rem; color: #999; }

/* ===== Desktop: Table view ===== */
.task-table-wrap { overflow-x: auto; }
.task-table { width: 100%; border-collapse: collapse; background: white; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.task-table thead { background: #f8f9fa; }
.task-table th { padding: 0.75rem 0.75rem; text-align: left; font-weight: 600; font-size: 0.8rem; color: #666; border-bottom: 2px solid #dee2e6; white-space: nowrap; }
.task-table td { padding: 0.6rem 0.75rem; border-bottom: 1px solid #f0f0f0; font-size: 0.85rem; }
.task-table tbody tr:hover { background: #f8f9fa; }
.task-table input.inline-edit { width: 130px; }

/* ===== Mobile: Card view ===== */
.task-cards { display: none; }

.task-card {
  background: white;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  margin-bottom: 0.75rem;
  overflow: hidden;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.75rem;
  background: #f8f9fa;
  border-bottom: 1px solid #f0f0f0;
}
.card-body { padding: 0.75rem; }
.card-desc { font-size: 0.95rem; font-weight: 500; margin-bottom: 0.5rem; }
.card-desc a { color: #333; }
.card-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: #888;
  margin-bottom: 0.4rem;
}
.card-id { color: #aaa; }
.card-dates {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: #666;
}
.card-dates input.inline-edit { width: 120px; font-size: 0.8rem; }
.card-actions {
  padding: 0.5rem 0.75rem;
  border-top: 1px solid #f0f0f0;
  display: flex;
  justify-content: flex-end;
}

/* Task Detail */
.task-detail h1 { margin-bottom: 1rem; font-size: 1.3rem; }
.detail-grid { background: white; border-radius: 8px; padding: 1rem; box-shadow: 0 1px 3px rgba(0,0,0,0.1); margin-bottom: 1rem; }
.detail-row { display: flex; padding: 0.6rem 0; border-bottom: 1px solid #f0f0f0; }
.detail-row:last-child { border-bottom: none; }
.detail-label { width: 90px; font-weight: 600; color: #666; flex-shrink: 0; font-size: 0.85rem; }
.links { display: flex; flex-direction: column; gap: 0.25rem; }
.links a { word-break: break-all; font-size: 0.85rem; }
.detail-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Edit Form */
.edit-form { background: white; border-radius: 8px; padding: 1rem; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.form-group { margin-bottom: 0.75rem; }
.form-group label { display: block; font-weight: 600; color: #666; margin-bottom: 0.25rem; font-size: 0.85rem; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 16px; /* prevents iOS zoom on focus */
  font-family: inherit;
}
.form-group textarea { resize: vertical; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: #4a90d9;
  box-shadow: 0 0 0 2px rgba(74,144,217,0.2);
}
.form-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }

/* Calendar */
.calendar-nav { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.calendar { background: white; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); overflow: hidden; }
.calendar-header { display: grid; grid-template-columns: repeat(7, 1fr); background: #f8f9fa; }
.calendar-day-name { padding: 0.5rem 0.25rem; text-align: center; font-weight: 600; font-size: 0.75rem; color: #666; }
.calendar-body { display: grid; grid-template-columns: repeat(7, 1fr); }
.calendar-cell { min-height: 70px; border: 1px solid #f0f0f0; padding: 0.25rem; }
.calendar-cell.empty { background: #fafafa; }
.calendar-cell.today { background: #eff6ff; }
.calendar-cell.has-tasks { background: #fefce8; }
.calendar-date { font-weight: 600; font-size: 0.75rem; margin-bottom: 0.15rem; }
.calendar-task {
  display: block;
  padding: 0.15rem 0.25rem;
  margin-bottom: 0.15rem;
  border-radius: 3px;
  font-size: 0.65rem;
  background: #e8f4fd;
  color: #1a73e8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.calendar-task:hover { text-decoration: none; opacity: 0.8; }
.calendar-task-type { font-weight: 600; }
.calendar-task-desc { display: none; }

/* ===== RWD: Mobile (< 768px) ===== */
@media (max-width: 767px) {
  .container { padding: 0.75rem; }
  h1 { font-size: 1.25rem; }

  /* Hide table, show cards */
  .task-table-wrap { display: none; }
  .task-cards { display: block; }

  /* Calendar cells smaller */
  .calendar-cell { min-height: 55px; padding: 0.2rem; }
  .calendar-date { font-size: 0.7rem; }
  .calendar-task { font-size: 0.6rem; padding: 0.1rem 0.2rem; }

  /* Detail page */
  .detail-row { flex-direction: column; gap: 0.2rem; }
  .detail-label { width: auto; }

  /* Nav */
  .nav { padding: 0.6rem 0.75rem; }
  .nav-brand { font-size: 1rem; }
  .nav-link { font-size: 0.8rem; padding: 0.2rem 0.4rem; }
}

/* ===== Safe area for notch/Dynamic Island ===== */
@supports (padding-top: env(safe-area-inset-top)) {
  .nav {
    padding-top: calc(0.75rem + env(safe-area-inset-top));
    padding-left: calc(0.75rem + env(safe-area-inset-left));
    padding-right: calc(0.75rem + env(safe-area-inset-right));
  }
  .container {
    padding-left: calc(0.75rem + env(safe-area-inset-left));
    padding-right: calc(0.75rem + env(safe-area-inset-right));
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
  }
}
