/* 午餐剩食追蹤 — 校園友善樣式 */
:root {
  --bg: #f0f7f4;
  --card: #ffffff;
  --primary: #2d8a6e;
  --primary-dark: #1f6b54;
  --primary-light: #e6f5ef;
  --accent: #f4a261;
  --accent-soft: #fff3e6;
  --danger: #e76f51;
  --danger-soft: #fde8e4;
  --success: #2a9d8f;
  --success-soft: #e6f7f5;
  --text: #1a2e28;
  --muted: #5a7269;
  --border: #d0e4db;
  --shadow: 0 4px 16px rgba(45, 138, 110, 0.12);
  --radius: 16px;
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(ellipse at top left, #d8f0e6 0%, transparent 50%),
    radial-gradient(ellipse at bottom right, #ffe8cc 0%, transparent 45%),
    var(--bg);
  line-height: 1.55;
}

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

header.site-header {
  text-align: center;
  margin-bottom: 1.5rem;
  padding: 1.25rem 1rem;
  background: linear-gradient(135deg, var(--primary) 0%, #3aa882 100%);
  color: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

header.site-header h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.35rem, 4vw, 1.85rem);
  font-weight: 700;
  letter-spacing: 0.02em;
}

header.site-header .subtitle {
  margin: 0;
  opacity: 0.95;
  font-size: 0.95rem;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.75rem;
}

.page-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.9rem;
}

.page-nav-link {
  text-decoration: none;
  color: #fff;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.4);
  padding: 0.4rem 0.95rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.92rem;
}

.page-nav-link:hover {
  background: rgba(255, 255, 255, 0.28);
}

.page-nav-link.is-current {
  background: #fff;
  color: var(--primary-dark);
  border-color: #fff;
}

.footer-note a {
  color: var(--primary-dark);
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: rgba(255, 255, 255, 0.2);
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
}

main {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

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

.card h2 {
  margin: 0 0 1rem;
  font-size: 1.2rem;
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.card h2 .emoji {
  font-size: 1.35rem;
}

.form-grid {
  display: grid;
  gap: 1rem;
}

label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.hint {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.8rem;
}

select,
input[type="number"] {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

select:focus,
input[type="number"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45, 138, 110, 0.2);
}

.date-display {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 0.85rem;
  background: var(--primary-light);
  border-radius: 12px;
  font-weight: 600;
  color: var(--primary-dark);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.8rem 1.4rem;
  border: none;
  border-radius: 12px;
  font-size: 1.05rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, box-shadow 0.15s;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  width: 100%;
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(45, 138, 110, 0.35);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.btn-secondary:hover:not(:disabled) {
  background: #d0ebe0;
}

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

.feedback {
  display: none;
  margin-top: 1rem;
  padding: 1rem 1.1rem;
  border-radius: 12px;
  animation: fadeIn 0.35s ease;
}

.feedback.visible {
  display: block;
}

.feedback.success {
  background: var(--success-soft);
  border: 2px solid #9dd9d1;
}

.feedback.error {
  background: var(--danger-soft);
  border: 2px solid #f5b8a8;
}

.feedback.encourage {
  background: var(--accent-soft);
  border: 2px solid #f5c99a;
}

.feedback .title {
  font-weight: 700;
  font-size: 1.05rem;
  margin: 0 0 0.4rem;
}

.feedback .msg {
  margin: 0;
  white-space: pre-line;
}

.feedback .stats-line {
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px dashed rgba(0, 0, 0, 0.12);
  font-size: 0.95rem;
}

.leaderboard {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  min-width: 480px;
}

th,
td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 700;
  white-space: nowrap;
}

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

tr:hover td {
  background: #f8fcfa;
}

.medal {
  font-size: 1.1rem;
}

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

.footer-note {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.5rem;
}

.mock-banner {
  display: none;
  background: #fff8e1;
  border: 1px solid #ffe082;
  color: #7a5c00;
  text-align: center;
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.mock-banner.visible {
  display: block;
}

.loading {
  display: inline-block;
  width: 1em;
  height: 1em;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 560px) {
  .wrap {
    padding: 0.85rem 0.65rem 2.5rem;
  }

  .card {
    padding: 1rem;
  }

  th,
  td {
    padding: 0.5rem 0.45rem;
    font-size: 0.85rem;
  }
}

/* ——— 本月特別統計 ——— */
.extra-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.stat-tile {
  border-radius: 14px;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  background: var(--primary-light);
}

.stat-tile.stat-missed {
  background: #fff8e8;
  border-color: #f0d9a8;
}

.stat-tile.stat-high-avg {
  background: #fdeeea;
  border-color: #f0c4b8;
}

.stat-tile-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.stat-tile-value {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--primary-dark);
  letter-spacing: 0.01em;
  word-break: break-word;
  line-height: 1.3;
}

.stat-tile.stat-high-avg .stat-tile-value {
  color: #b54a32;
}

.stat-tile.stat-missed .stat-tile-value {
  color: #8a6a20;
}

.stat-tile-detail {
  margin-top: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
}

@media (max-width: 560px) {
  .extra-stats-grid {
    grid-template-columns: 1fr;
  }

  .stat-tile-value {
    font-size: 1.25rem;
  }
}

/* ——— 循環日徽章 ——— */
#cycle-day-badge {
  font-weight: 700;
}

#cycle-day-badge.is-off {
  opacity: 0.85;
  background: rgba(255, 255, 255, 0.12);
}


/* ——— 今日尚未登記 ——— */
.today-missing-status {
  margin: 0 0 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary-dark);
  border: 1px solid var(--border);
}

.today-missing-status.is-off {
  background: #f0f2f1;
  color: var(--muted);
  border-color: #d8ddd9;
}

.today-missing-status.is-ok {
  background: var(--success-soft);
  color: var(--success);
  border-color: #9dd9d1;
}

.today-missing-status.is-warn {
  background: #fff8e8;
  color: #8a6a20;
  border-color: #f0d9a8;
}

.today-missing-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.missing-chip,
.submitted-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.4rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.92rem;
}

.missing-chip {
  background: #fff3e6;
  border: 1px solid #f0d9a8;
  color: #8a6a20;
}

.submitted-chip {
  background: var(--success-soft);
  border: 1px solid #9dd9d1;
  color: var(--success);
}

.today-group-label {
  margin: 0.85rem 0 0.4rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
}

.today-submitted-status {
  margin: 0 0 0.45rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.today-missing-list + .today-group-label {
  margin-top: 1rem;
}

/* ——— 近兩月柱狀圖（純 CSS） ——— */
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem 1.25rem;
  margin-bottom: 0.85rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
}

.chart-swatch {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 3px;
  display: inline-block;
}

.swatch-prev {
  background: #7eb8a4;
}

.swatch-curr {
  background: var(--primary);
}

.chart-body {
  display: flex;
  align-items: flex-end;
  gap: 0.35rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 180px;
  padding: 0.25rem 0.15rem 0.5rem;
  border-top: 1px dashed var(--border);
}

.chart-group {
  flex: 0 0 auto;
  width: 3.1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0.18rem;
  height: 140px;
  width: 100%;
}

.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  width: 1.15rem;
  gap: 0.15rem;
}

.bar {
  width: 100%;
  border-radius: 4px 4px 2px 2px;
  min-height: 2px;
  transition: height 0.25s ease;
}

.bar-prev {
  background: #7eb8a4;
}

.bar-curr {
  background: var(--primary);
}

.bar.is-empty {
  background: #e2ebe6;
  opacity: 0.7;
}

.bar-val {
  font-size: 0.62rem;
  color: var(--muted);
  line-height: 1;
  white-space: nowrap;
}

.bar-val.is-null {
  opacity: 0.55;
}

.chart-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary-dark);
}

@media (max-width: 560px) {
  .chart-group {
    width: 2.7rem;
  }

  .chart-bars {
    height: 120px;
  }

  .bar-col {
    width: 1rem;
  }
}
