:root {
  color-scheme: light dark;
  --bg: #f0f2f5;
  --card: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --ok: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --chip: #eef2ff;
  --chip-active: #2563eb;
  --chip-active-ink: #ffffff;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #1a1d24;
    --ink: #f3f4f6;
    --muted: #9ca3af;
    --line: #2d323c;
    --accent: #3b82f6;
    --chip: #1e293b;
    --chip-active: #3b82f6;
    --shadow: 0 2px 16px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang HK", "Noto Sans TC",
    "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  padding-bottom: calc(5rem + var(--safe-bottom));
  min-height: 100dvh;
}

/* ===== Header ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.header .sub {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0;
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 0.4rem;
  padding: 0.75rem 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex-shrink: 0;
  border: none;
  background: var(--chip);
  color: var(--ink);
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: 0.15s;
}

.tab.active {
  background: var(--chip-active);
  color: var(--chip-active-ink);
}

/* ===== List ===== */
.list {
  padding: 0 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: border-color 0.15s;
}

.card:active {
  border-color: var(--accent);
}

.card-title {
  font-weight: 650;
  font-size: 1rem;
  margin: 0 0 0.25rem;
}

.card-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.card-status {
  font-size: 0.95rem;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.65rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.badge {
  display: inline-block;
  background: var(--chip);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 3rem 1rem;
  font-size: 0.95rem;
}

/* ===== FAB ===== */
.fab {
  position: fixed;
  right: 1.25rem;
  bottom: calc(1.25rem + var(--safe-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  font-size: 1.75rem;
  line-height: 1;
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.4);
  cursor: pointer;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fab:active {
  transform: scale(0.95);
}

/* ===== Detail page ===== */
.detail-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.back-btn {
  border: none;
  background: var(--chip);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
}

.detail-body {
  padding: 1rem;
}

.detail-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
}

.detail-loc {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.status-box {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.status-box h3 {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}

.status-text {
  font-size: 1.05rem;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.progress-text {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0.4rem 0 0;
}

.action-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-size: 0.875rem;
  font-weight: 550;
  cursor: pointer;
  transition: 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-secondary {
  background: var(--chip);
  color: var(--ink);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.section-title {
  font-size: 0.9rem;
  font-weight: 650;
  margin: 0 0 0.65rem;
  color: var(--muted);
}

/* Timeline */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 1.5rem;
}

.tl-item {
  position: relative;
  padding-left: 1.25rem;
  padding-bottom: 1rem;
  border-left: 2px solid var(--line);
  margin-left: 0.4rem;
}

.tl-item:last-child {
  border-left-color: transparent;
  padding-bottom: 0;
}

.tl-item::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 0.35rem;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.tl-author {
  font-weight: 600;
  font-size: 0.85rem;
}

.tl-time {
  font-size: 0.75rem;
  color: var(--muted);
  margin-left: 0.4rem;
}

.tl-status {
  margin: 0.2rem 0 0;
  font-size: 0.9rem;
  white-space: pre-wrap;
}

.tl-note {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Notes */
.note-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.note-card {
  background: var(--card);
  border-radius: 10px;
  padding: 0.75rem;
  box-shadow: var(--shadow);
}

.note-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.note-content {
  margin: 0;
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

@media (min-width: 640px) {
  .modal-overlay {
    align-items: center;
  }
}

.modal {
  background: var(--card);
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 1.25rem;
  padding-bottom: calc(1.25rem + var(--safe-bottom));
}

@media (min-width: 640px) {
  .modal {
    border-radius: 16px;
  }
}

.modal h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}

.form-group {
  margin-bottom: 0.85rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 550;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font-size: 0.95rem;
  font-family: inherit;
}

.form-group textarea {
  min-height: 80px;
  resize: vertical;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.form-actions .btn {
  flex: 1;
  padding: 0.7rem;
}

.hidden {
  display: none !important;
}

/* Loading */
.loading {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
}

/* Desktop tweak */
@media (min-width: 768px) {
  .list {
    max-width: 720px;
    margin: 0 auto;
  }
  .detail-body {
    max-width: 720px;
    margin: 0 auto;
  }
  .header,
  .tabs,
  .detail-header {
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
  }
}
