:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --border: #e2e6ee;
  --text: #1b2333;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --ok: #16a34a;
  --ok-soft: #e8f8ee;
  --warn: #b45309;
  --warn-soft: #fef3e2;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10131b;
    --surface: #171b26;
    --surface-2: #1e2330;
    --border: #2a2f3d;
    --text: #e7eaf1;
    --text-muted: #9aa1b1;
    --accent: #5b8def;
    --accent-soft: #1c2a49;
    --ok: #4ade80;
    --ok-soft: #123423;
    --warn: #fbbf24;
    --warn-soft: #3a2a10;
    --danger: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 10px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.5;
  padding-bottom: 3rem;
}

.wrap {
  max-width: 920px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 0;
}

header.app-header {
  padding: 0.5rem 0 1.25rem;
}

header.app-header h1 {
  font-size: 1.5rem;
  margin: 0 0 0.35rem;
}

header.app-header p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.app-header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
}

.app-header-row > div:first-child {
  min-width: 0;
  flex: 1 1 auto;
}

header.app-header h1 {
  white-space: nowrap;
}

.settings-btn {
  white-space: nowrap;
  flex-shrink: 0;
}

@media (max-width: 420px) {
  header.app-header h1 {
    font-size: 1.3rem;
  }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 20, 30, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal h2 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}

.modal-hint {
  color: var(--text-muted);
  font-size: 0.82rem;
  margin: 0 0 0.6rem;
}

#settings-textarea {
  width: 100%;
  min-height: 220px;
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: space-between;
  margin-top: 0.75rem;
}

.modal-actions-right {
  display: flex;
  gap: 0.5rem;
}

@media (max-width: 480px) {
  .modal-actions {
    flex-direction: column;
  }
  .modal-actions-right {
    flex-direction: column;
  }
}

.tab-nav {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 999px;
  padding: 0.55rem 1rem;
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--text-muted);
  cursor: pointer;
}

.tab-btn.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow);
}

.tab-footnote {
  color: var(--text-muted);
  font-size: 0.82rem;
  margin: -0.5rem 0 1.25rem;
}

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

.card h2 {
  font-size: 1.05rem;
  margin: 0 0 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.5rem;
}

.card h2 .badge {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
}

.field {
  margin-bottom: 0.9rem;
}

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
  color: var(--text-muted);
}

select, input[type="file"] {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
  background: var(--surface-2);
  transition: border-color 0.15s, background 0.15s;
}

.dropzone.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.file-picked {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--text);
}

button {
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: 10px;
  border: none;
  padding: 0.65rem 1.1rem;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.05s;
}

button:active { transform: scale(0.98); }

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) { opacity: 0.92; }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border: 1px solid transparent;
  padding: 0.3rem 0.6rem;
  font-size: 0.82rem;
}

.btn-danger-ghost:hover { background: rgba(220, 38, 38, 0.08); }

.status-msg {
  margin-top: 0.75rem;
  font-size: 0.88rem;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  display: none;
}

.status-msg.show { display: block; }

.status-msg.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.status-msg.error {
  background: var(--warn-soft);
  color: var(--warn);
}

.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.9rem;
}

.progress-count {
  font-weight: 700;
  font-size: 1.05rem;
}

.progress-bar-track {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  margin-bottom: 1rem;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  font-size: 0.82rem;
  padding: 0.32rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--surface-2);
  white-space: nowrap;
}

.chip.done {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: transparent;
  font-weight: 600;
}

.chip.done::before {
  content: "✓ ";
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead th {
  text-align: right;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.4rem;
  white-space: nowrap;
}

thead th:first-child, tbody td:first-child {
  text-align: left;
}

tbody td {
  padding: 0.55rem 0.4rem;
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: none; }

tr.region-row td {
  background: var(--surface-2);
  font-weight: 700;
  color: var(--accent);
}

td.congregation-name {
  padding-left: 1.2rem;
  color: var(--text-muted);
  font-weight: 400;
}

.table-scroll {
  overflow-x: auto;
}

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

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.9rem;
}

.stat-tile {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 1rem;
  text-align: center;
}

.stat-tile .stat-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.stat-tile .stat-value {
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.summary-warn {
  margin-top: 0.9rem;
  font-size: 0.85rem;
  color: var(--warn);
  background: var(--warn-soft);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
}

.card-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.upload-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.upload-actions button {
  flex: 1 1 auto;
}

.join-room-row {
  display: flex;
  gap: 0.5rem;
}

.join-room-row button {
  white-space: nowrap;
  flex-shrink: 0;
}

.join-room-row input {
  flex: 1 1 auto;
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  min-width: 0;
}

.room-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}

.room-bar strong {
  color: var(--accent);
  letter-spacing: 0.05em;
}

.room-bar-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.6rem;
}

.room-name {
  font-weight: 700;
}

.room-name.unnamed {
  font-weight: 400;
  color: var(--text-muted);
  font-style: italic;
}

.room-rename-btn {
  font-size: 0.78rem;
  padding: 0.15rem 0.5rem;
}

.room-bar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.room-bar-actions button {
  font-size: 0.82rem;
  padding: 0.4rem 0.7rem;
}

footer.app-footer {
  max-width: 920px;
  margin: 0 auto;
  padding: 0.5rem 1.25rem 2rem;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-align: center;
}

@media (max-width: 560px) {
  .summary-grid { grid-template-columns: 1fr; }
  thead th, tbody td { font-size: 0.82rem; }
}

/* ---------- 雲嘉月報表系統 ---------- */
.wrap { max-width: 1180px; }

a { color: var(--accent); }

.source-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}

.source-info {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.8rem;
  min-width: 0;
}

.source-info a { font-weight: 700; word-break: break-all; }

.source-time { color: var(--text-muted); font-size: 0.82rem; }

.source-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.source-actions button, .file-btn {
  font-size: 0.82rem;
  padding: 0.4rem 0.7rem;
}

.file-btn {
  display: inline-block;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
}

#status-msg { margin: -0.5rem 0 1.25rem; }

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}

@media (max-width: 640px) {
  .settings-grid { grid-template-columns: 1fr; }
}

.inline-row { display: flex; gap: 0.5rem; align-items: center; }
.inline-row select { flex: 1 1 auto; min-width: 0; }
.inline-row button { white-space: nowrap; flex-shrink: 0; padding: 0.55rem 0.8rem; }

.field-hint { font-weight: 400; margin-left: 0.4rem; }

.seg {
  display: inline-flex;
  flex-wrap: wrap;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.2rem;
  gap: 0.2rem;
}

.seg button {
  background: transparent;
  color: var(--text-muted);
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
}

.seg button.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow);
}

.check-row { display: flex; flex-wrap: wrap; gap: 0.5rem 1.2rem; }

.check {
  display: inline-flex !important;
  align-items: center;
  gap: 0.35rem;
  font-weight: 500 !important;
  color: var(--text) !important;
  margin: 0 !important;
  cursor: pointer;
}

.picker-group { margin-bottom: 0.8rem; }

.picker-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.link-btn {
  background: none;
  color: var(--accent);
  padding: 0;
  font-size: 0.78rem;
  font-weight: 500;
}

.chip-check {
  display: inline-flex !important;
  align-items: center;
  margin: 0 !important;
  font-size: 0.85rem !important;
  font-weight: 500 !important;
  padding: 0.32rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted) !important;
  cursor: pointer;
  user-select: none;
}

.chip-check input { display: none; }

.chip-check.on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent) !important;
  font-weight: 700 !important;
}

.report-sub {
  margin: -0.6rem 0 0.9rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.report-table th.group-th {
  text-align: center;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.report-table thead tr:nth-child(2) th { font-size: 0.76rem; }

.sticky-col {
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 1;
}

tr.region-row td.sticky-col, tr.total-row td.sticky-col { background: var(--surface-2); }

tr.total-row td {
  background: var(--surface-2);
  font-weight: 800;
  border-top: 2px solid var(--text-muted);
}

td.ok {
  background: var(--ok-soft) !important;
  color: var(--ok);
  font-weight: 700;
}

td.sub { color: var(--text-muted); font-size: 0.82rem; }
td.up { color: var(--ok); }
td.down { color: var(--danger); }

.cell-sub {
  display: block;
  font-size: 0.74rem;
  color: var(--text-muted);
  font-weight: 400;
}

tr.current-row td { font-weight: 700; }
tr.current-row td:first-child { color: var(--accent); }

footer.app-footer { max-width: 1180px; line-height: 1.7; }

@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; color: #000; padding: 0; }
  .no-print, footer.app-footer, header.app-header p { display: none !important; }
  .wrap { max-width: none; padding: 0; }
  .card { box-shadow: none; border: none; padding: 0; margin-bottom: 1rem; break-inside: avoid; }
  .card:not(.report-card) { display: none; }
  .table-scroll { overflow: visible; }
  table { font-size: 9pt; }
  thead th, tbody td { padding: 2px 4px; border-bottom: 1px solid #ccc; color: #000; }
  .sticky-col { position: static; }
  td.ok { background: #d9f2e1 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
