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

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --header: #12243a;
  --accent: #0077cc;
  --accent2: #00a878;
  --muted: #6b7a8d;
  --border: #dde1e8;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --text: #1a2332;
  --text2: #4a5568;
  --mono: "IBM Plex Mono", monospace;
  --sans: "Noto Sans TC", sans-serif;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.06);
}

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  background: var(--header);
  color: #fff;
  padding: 28px 40px;
  border-bottom: 3px solid var(--accent);
}
header h1 {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
header p {
  margin-top: 6px;
  font-size: 0.82rem;
  color: #a0b0c4;
  font-weight: 300;
}

main {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 36px 24px 60px;
}

.section-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 14px;
}

/* ── Tool cards（首頁）── */
.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
  margin-bottom: 40px;
}

.tool-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  transition:
    border-color 0.2s,
    transform 0.15s,
    box-shadow 0.15s;
}
.tool-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1), 0 8px 20px rgba(0, 0, 0, 0.08);
}

.card-tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 10px;
  background: #e8f0fe;
  color: var(--accent);
}

.card-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text);
}
.card-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 16px;
  font-family: var(--mono);
  line-height: 1.6;
}

.card-arrow {
  margin-top: 16px;
  font-size: 0.78rem;
  font-family: var(--mono);
  color: var(--accent);
}

/* Placeholder card（首頁，未來工具）*/
.tool-card.placeholder {
  cursor: default;
  opacity: 0.55;
}
.tool-card.placeholder:hover {
  border-color: var(--border);
  transform: none;
  box-shadow: var(--shadow);
}
.tool-card.placeholder .card-tag {
  background: #f1f5f9;
  color: var(--muted);
}
.tool-card.placeholder .card-arrow {
  color: var(--muted);
}

/* ── Reference / data-source section（首頁）── */
.ref-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.ref-header {
  background: var(--header);
  color: #a0b0c4;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 10px 20px;
}

.ref-body {
  padding: 20px;
  font-size: 0.82rem;
  color: var(--text2);
  line-height: 1.7;
}
.ref-body a {
  color: var(--accent);
  font-weight: 500;
  word-break: break-all;
}
.ref-body a:hover {
  text-decoration: none;
}
.ref-warning {
  margin-top: 10px;
  font-size: 0.78rem;
  color: var(--warning);
}

/* ── Notice banner（首頁）── */
.notice-banner {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-left: 4px solid var(--warning);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 32px;
  font-size: 0.82rem;
  color: #78350f;
  line-height: 1.7;
}
.notice-banner .notice-icon {
  font-size: 1rem;
  flex-shrink: 0;
}
.notice-banner strong {
  color: #92400e;
}

/* ── Upload grid / card（分析工具頁）── */
.upload-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.upload-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  transition: border-color 0.2s;
}
.upload-card.ready {
  border-color: var(--success);
}
.upload-card.ready .card-tag {
  background: #dcfce7;
  color: var(--success);
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 6px;
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition:
    border-color 0.2s,
    background 0.2s;
  position: relative;
}
.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: #f0f7ff;
}
.upload-card.ready .dropzone {
  border-color: var(--success);
  background: #f0fdf4;
}

.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.drop-icon {
  font-size: 1.6rem;
  display: block;
  margin-bottom: 8px;
}
.drop-icon::before {
  content: "⬆";
}
.upload-card.ready .drop-icon::before {
  content: "✓";
}
.upload-card:not(.ready) .drop-icon::before {
  content: "⬆";
}

.drop-text {
  font-size: 0.78rem;
  color: var(--muted);
  display: block;
}
.upload-card.ready .drop-text {
  color: var(--success);
  font-weight: 500;
}

.file-name {
  display: block;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text2);
  word-break: break-all;
}

/* ── Action bar / buttons ── */
.action-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.btn {
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 10px 28px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition:
    opacity 0.15s,
    transform 0.1s;
}
.btn:active {
  transform: scale(0.98);
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: #005fa3;
}

.btn-download {
  background: var(--accent2);
  color: #fff;
}
.btn-download:hover:not(:disabled) {
  background: #008a62;
}

.btn-small {
  font-size: 0.72rem;
  padding: 5px 14px;
  font-family: var(--mono);
}

/* ── Status ── */
#status-bar {
  display: none;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  color: var(--text2);
}
#status-bar.visible {
  display: flex;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Stats / result panel ── */
#stats-panel,
#result-panel {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 24px;
}
#stats-panel.visible,
#result-panel.visible {
  display: block;
}

.stats-header,
.result-header {
  background: var(--header);
  color: #a0b0c4;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 10px 20px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  border-bottom: 1px solid var(--border);
}
.stat-cell {
  padding: 16px 20px;
  border-right: 1px solid var(--border);
}
.stat-cell:last-child {
  border-right: none;
}
.stat-label {
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 4px;
}
.stat-value {
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text);
}
.stat-value.hi {
  color: var(--danger);
}
.stat-sub {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 2px;
  font-family: var(--mono);
}

.stats-section {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.stats-section:last-child {
  border-bottom: none;
}
.stats-section-title {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.stats-row {
  display: flex;
  gap: 32px;
  flex-wrap: wrap;
}
.stats-item {
  font-size: 0.78rem;
  color: var(--text2);
}
.stats-item strong {
  font-family: var(--mono);
  color: var(--text);
}

.stats-section.warn {
  background: #fffbeb;
}
.stats-section.warn .stats-section-title {
  color: var(--warning);
}
.stats-section.warn .stats-item {
  color: #78350f;
}

/* ── Preview / result table ── */
#preview-wrap {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
#preview-wrap.visible {
  display: block;
}

.preview-header {
  background: var(--header);
  color: #a0b0c4;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 10px 20px;
}

.table-scroll {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 0.72rem;
}
th {
  background: #f7f9fc;
  border-bottom: 2px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.65rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  color: var(--text);
  vertical-align: top;
}
tr:last-child td {
  border-bottom: none;
}
tr:hover td {
  background: #f7f9fc;
}

td.ok {
  color: var(--success);
  font-weight: 500;
}
td.err {
  color: var(--danger);
  font-weight: 600;
}
td.neg {
  color: var(--danger);
  font-weight: 600;
}

.ext-detail {
  white-space: normal;
  max-width: 320px;
  color: var(--warning);
  line-height: 1.6;
}

.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.68rem;
}
.badge-holiday {
  background: #fef3c7;
  color: #92400e;
}
.badge-weekday {
  background: #eff6ff;
  color: #1d4ed8;
}
.badge-night {
  background: #f3e8ff;
  color: #6d28d9;
}
.badge-day {
  background: #f0fdf4;
  color: #15803d;
}
.badge-true {
  background: #dcfce7;
  color: #15803d;
}
.badge-false {
  background: #f1f5f9;
  color: #64748b;
}
.badge-major {
  background: #fee2e2;
  color: #b91c1c;
  font-weight: 600;
}

footer {
  text-align: center;
  padding: 20px;
  font-size: 0.72rem;
  color: var(--muted);
  font-family: var(--mono);
  letter-spacing: 0.04em;
}

@media (max-width: 900px) {
  .tool-grid {
    grid-template-columns: 1fr;
  }
  header {
    padding: 20px;
  }
  main {
    padding: 24px 16px 48px;
  }
}
