:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: #0f172a;
  background: #f1f5f9;
  --bg-color: #f1f5f9;
  --card-bg: #ffffff;
  --card-border: #e2e8f0;
  --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-label: #475569;
  --primary-accent: #2563eb;
}

* { box-sizing: border-box; }
body { margin: 0; overflow-x: hidden; background: var(--bg-color); }
main { width: min(1200px, 100%); margin: auto; padding: 24px 16px 48px; }

h1 {
  font-size: 1.75rem;
  margin-top: 0;
  margin-bottom: 16px;
  color: var(--text-main);
}

/* Nav Tabs */
nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-bottom: 2px solid #e2e8f0;
  margin-bottom: 24px;
}

button { padding: 8px 16px; cursor: pointer; border-radius: 6px; font-size: 0.9375rem; }
nav button {
  border: 0;
  background: transparent;
  padding: 10px 18px;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 3px solid transparent;
  border-radius: 0;
  margin-bottom: -2px;
  transition: all 0.15s ease;
}

nav button:hover {
  color: var(--text-main);
}

nav button.active {
  border-bottom: 3px solid var(--primary-accent);
  color: var(--primary-accent);
  font-weight: 700;
}

/* GM Dashboard Styles */
.gm-container {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.gm-header {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 20px 24px;
  box-shadow: var(--card-shadow);
}

.gm-header-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.gm-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
  color: var(--text-main);
}

.report-date-container {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.gm-card-meta-group {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.gm-card-author {
  font-size: 0.875rem;
  font-weight: 600;
  color: #334155;
  text-align: right;
  padding-right: 2px;
}

.date-label {
  white-space: nowrap;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
}

.report-date-select {
  padding: 6px 12px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
  background-color: #f8fafc;
  border: 1.5px solid var(--card-border);
  border-radius: 8px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s, background-color 0.15s;
}

.report-date-select:hover, .report-date-select:focus {
  border-color: var(--primary-accent);
  background-color: #ffffff;
}

.history-note {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.history-table-wrapper {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  box-shadow: var(--card-shadow);
  overflow-x: auto;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
  text-align: left;
}

.history-table th {
  background: #f8fafc;
  color: var(--text-label);
  font-weight: 700;
  padding: 12px 16px;
  border-bottom: 1px solid var(--card-border);
  white-space: nowrap;
}

.history-table th small {
  display: block;
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.history-table td {
  padding: 14px 16px;
  border-bottom: 1px solid #f1f5f9;
  color: var(--text-main);
  white-space: nowrap;
}

.history-table tbody tr {
  cursor: pointer;
  transition: background-color 0.15s;
}

.history-table tbody tr:hover {
  background-color: #f1f5f9;
}

.history-table tbody tr.active-row {
  background-color: #e0f2fe;
  font-weight: 600;
}

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

.badge-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-source {
  background: #e2e8f0;
  color: #334155;
}

.badge-missing {
  background: #fee2e2;
  color: #991b1b;
}

.daily-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.section-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 6px 0 0 0;
}

.missing-notice {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-style: italic;
  margin: 8px 4px 0 4px;
}

.gm-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
}

.t2-total-badge {
  font-size: 1.0625rem;
  color: var(--text-label);
  background: #f8fafc;
  border: 1.5px solid var(--card-border);
  padding: 6px 16px;
  border-radius: 9999px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.t2-total-badge strong {
  color: var(--primary-accent);
  font-size: 1.625rem;
  font-weight: 800;
}

.section-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-label);
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.section-title::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 1rem;
  background-color: var(--primary-accent);
  border-radius: 2px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.card-label {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-label);
  margin-bottom: 8px;
}

.card-value {
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text-main);
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.kpi-card {
  padding: 24px 28px;
}

.kpi-card .card-label {
  font-size: 1.0625rem;
  color: var(--text-label);
}

.hero-value {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.total-card,
.t2-total-card {
  border-left: 5px solid var(--primary-accent);
}

.recovered-card {
  border-left: 5px solid #64748b;
}
.pending-card {
  border-left: 5px solid #64748b;
}

/* T2 Grid (4 cards scaled down) */
.grid-t2 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.sub-card {
  padding: 12px 14px;
  border-radius: 8px;
}

.sub-card .card-label {
  font-size: 0.8125rem;
  margin-bottom: 4px;
  color: var(--text-muted);
}

.sub-card .card-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.grid-status-rows {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.row-card {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
}

.row-card .card-label {
  margin-bottom: 0;
  font-size: 1.0625rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.label-sub {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  background: #f1f5f9;
  border: 1px solid var(--card-border);
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: 0.02em;
}

/* Charts & Manage Tab Styles (Preserved) */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(400px, 100%), 1fr)); gap: 20px; margin-top: 16px; }
.charts > article { min-width: 0; }
.charts canvas { max-width: 100%; }
article, form, #pc-list, #preview-result { background: white; padding: 16px; border-radius: 8px; border: 1px solid var(--card-border); box-shadow: var(--card-shadow); }
textarea { width: 100%; box-sizing: border-box; font-family: ui-monospace, monospace; border: 1px solid var(--card-border); border-radius: 6px; padding: 10px; }
.summary { display: flex; flex-wrap: wrap; gap: 16px; font-weight: 700; }
.bad { color: #b42318; }
#pc-list table, #preview-result table { width: 100%; min-width: 560px; border-collapse: collapse; margin-top: 12px; }
#pc-list th, #pc-list td, #preview-result th, #preview-result td { padding: 7px; border-bottom: 1px solid #e3e7ef; text-align: left; }
#pc-list { max-height: 600px; overflow: auto; }
input[type=number] { width: 80px; }
.forecast { display: inline-flex; margin-right: 12px; gap: 6px; align-items: center; }
.pc-filter { display: inline-flex; gap: 8px; align-items: center; margin-bottom: 8px; }
#forecast-inputs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

/* Responsive adjustments */
@media (max-width: 820px) {
  .grid-t2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  main {
    padding: 16px 12px 32px;
  }

  nav button {
    flex: 1 1 auto;
    text-align: center;
    padding: 8px 12px;
  }

  .gm-container {
    gap: 18px;
  }

  .gm-header {
    padding: 16px 18px;
  }

  .gm-title {
    font-size: 1.375rem;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .kpi-card {
    padding: 20px;
  }

  .hero-value {
    font-size: 2.5rem;
  }

  .grid-t2 {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .sub-card {
    padding: 16px;
  }

  .sub-card .card-value {
    font-size: 1.875rem;
  }

  .row-card {
    padding: 14px 18px;
  }

  .row-card .card-label {
    font-size: 1rem;
  }

  .row-card .card-value {
    font-size: 1.875rem;
  }

  .charts { grid-template-columns: 1fr; gap: 12px; }
  article, form, #pc-list, #preview-result { padding: 12px; }
  .forecast { flex: 1 1 calc(50% - 8px); margin-right: 0; }
  .forecast input { min-width: 0; width: 100%; }
  .pc-filter { width: 100%; justify-content: space-between; }
  .pc-filter select { min-width: 8rem; }
}

.records-filter-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.records-count {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* ==========================================================================
   GM 直式表格版面 (真 GM 版)
   ========================================================================== */
.gm-v-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 4px 0 24px;
}

.gm-v-wrapper {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.gm-v-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 10px;
  padding: 0 2px 6px;
}

.gm-v-header-left {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.gm-v-title {
  font-size: 1.4rem;
  font-weight: 800;
  color: #0f172a;
  margin: 0;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.gm-v-meta-badge {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #334155;
  background: #ffffff;
  border: 1px solid var(--card-border);
  padding: 5px 10px;
  border-radius: 6px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  line-height: 1.4;
  flex-shrink: 0;
  margin-left: auto;
}

.gm-v-meta-row {
  white-space: nowrap;
  text-align: right;
}

.gm-v-meta-badge strong,
.gm-v-meta-badge span {
  color: #0f172a;
  font-weight: 700;
}

.gm-v-block {
  background: #ffffff;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.gm-v-blue {
  border: 2px solid #0047ba;
}

.gm-v-purple {
  border: 2px solid #6a1b9a;
}

.gm-v-table {
  width: 100%;
  min-width: 0;
  margin-top: 0;
  border-collapse: collapse;
  table-layout: fixed;
  box-sizing: border-box;
}

.gm-v-table th,
.gm-v-table td {
  box-sizing: border-box;
}

.gm-v-table tr:not(:last-child) {
  border-bottom: 1.5px solid #cbd5e1;
}

/* Header Rows */
.gm-v-header-row th.gm-v-header-label {
  background: #0047ba;
  color: #ffffff;
  font-size: 1.2rem;
  font-weight: 800;
  padding: 10px 14px;
  text-align: left;
  vertical-align: middle;
  border-right: 1.5px solid #cbd5e1;
}

.gm-v-purple-header th.gm-v-header-label {
  background: #6a1b9a;
  border-right: 1.5px solid #cbd5e1;
}

.gm-v-header-val {
  background: #ffffff;
  text-align: center;
  vertical-align: middle;
  padding: 8px 6px;
  font-size: 2.1rem;
  font-weight: 800;
  border-left: 1.5px solid #cbd5e1;
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Regular Data Rows */
.gm-v-label {
  font-size: 1.15rem;
  font-weight: 800;
  color: #0f172a;
  padding: 10px 14px;
  text-align: left;
  vertical-align: middle;
  border-right: 1.5px solid #cbd5e1;
}

.gm-v-code {
  font-size: 1.15rem;
  font-weight: 800;
  color: #0f172a;
  padding: 8px 6px;
  text-align: center;
  vertical-align: middle;
  border-right: 1.5px solid #cbd5e1;
  background: #ffffff;
}

.gm-v-name {
  font-size: 1.15rem;
  font-weight: 800;
  color: #0f172a;
  padding: 8px 10px;
  text-align: left;
  vertical-align: middle;
  border-right: 1.5px solid #cbd5e1;
}

.gm-v-val {
  text-align: center;
  vertical-align: middle;
  padding: 6px 6px;
  font-size: 1.9rem;
  font-weight: 800;
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.gm-v-unit {
  font-size: 1.05rem;
  font-weight: 700;
  margin-left: 3px;
  display: inline-block;
  color: inherit;
}

/* Color Accents */
.gm-v-blue-val {
  color: #0047ba;
}

.gm-v-green-val {
  color: #16a34a;
}

.gm-v-orange-val {
  color: #ea580c;
}

.gm-v-purple-val {
  color: #6a1b9a;
}

/* T3 Cell Specifics */
.gm-v-t3-left {
  padding: 10px 14px;
  vertical-align: middle;
  border-right: 1.5px solid #cbd5e1;
}

.gm-v-t3-line {
  font-size: 1.05rem;
  font-weight: 700;
  color: #0f172a;
  margin: 4px 0;
  white-space: nowrap;
}

.gm-v-t3-line strong {
  font-size: 1.15rem;
  font-weight: 800;
}

.gm-v-t3-right {
  padding: 8px 6px;
  text-align: center;
  vertical-align: middle;
}

.gm-v-t3-total-line {
  font-size: 1.1rem;
  font-weight: 700;
  color: #0f172a;
}

.gm-v-t3-total-line strong {
  font-size: 1.75rem;
  font-weight: 800;
  color: #6a1b9a;
  margin: 0 2px;
}

.gm-v-t3-sub-note {
  font-size: 0.8125rem;
  font-weight: 700;
  color: #6a1b9a;
  margin-top: 4px;
  white-space: nowrap;
}

@media (max-width: 480px) {
  .gm-v-title {
    font-size: 1.35rem;
  }
  .gm-v-header-label, .gm-v-label, .gm-v-name, .gm-v-code {
    font-size: 1rem;
    padding: 8px 10px;
  }
  .gm-v-header-val, .gm-v-val {
    font-size: 1.75rem;
    padding: 6px 8px;
  }
  .gm-v-t3-line {
    font-size: 0.9375rem;
  }
  .gm-v-t3-sub-note {
    font-size: 0.75rem;
  }
}
