/* ── Reset & Base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #FAF7F2;
  --surface:    #FFFFFF;
  --border:     #EDE8E0;
  --text:       #1A1614;
  --text-muted: #8A7F76;

  --dad:    #6B8FAF;
  --mom:    #D4837A;
  --sister: #7ABEBF;
  --holiday: #E8A838;
  --birthday: #E07B6A;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;

  --shadow-sm: 0 1px 4px rgba(0,0,0,0.06), 0 2px 8px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.10), 0 2px 8px rgba(0,0,0,0.05);
}

html, body {
  font-family: 'Noto Sans Thai', 'Noto Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

/* ── Hero Card ────────────────────────────────────────────────────────── */
.hero-section {
  background: linear-gradient(135deg, #6B9FD4 0%, #9B6FB0 100%);
  color: #fff;
  padding: 20px 24px 18px;
  text-align: center;
  border-radius: 0 0 20px 20px;
  margin: 0 0 12px;
}

.hero-month {
  font-family: 'Nunito', 'Noto Sans Thai', sans-serif;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin-bottom: 10px;
  text-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.hero-stats {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.hero-stat {
  background: rgba(255,255,255,0.22);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

/* ── Header ───────────────────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(250, 247, 242, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-title {
  font-family: 'Nunito', 'Noto Sans Thai', sans-serif;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.3px;
  color: var(--text);
  white-space: nowrap;
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.month-nav button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.month-nav button:active {
  transform: scale(0.92);
  background: var(--border);
}

.month-label {
  font-family: 'Nunito', 'Noto Sans Thai', sans-serif;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  min-width: 120px;
  text-align: center;
}

/* ── Main ────────────────────────────────────────────────────────────── */
main {
  padding: 0 0 32px;
}

/* ── Week Strip ──────────────────────────────────────────────────────── */
.week-section {
  padding: 16px 16px 12px;
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.week-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 4px;
}

.week-scroll::-webkit-scrollbar { display: none; }

.day-card {
  flex: 0 0 auto;
  width: 76px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  scroll-snap-align: start;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.day-card:active {
  transform: scale(0.95);
  box-shadow: var(--shadow-md);
}

.day-card.today {
  border-color: var(--dad);
  border-width: 2px;
}

.day-card-header {
  padding: 8px 6px 6px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.day-dow {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.day-date {
  font-family: 'Nunito', sans-serif;
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
  margin-top: 2px;
}

.day-card.today .day-date {
  color: var(--dad);
}

.day-card-body {
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0; /* collapse when empty */
}

.member-status {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
}

.member-status .emoji {
  font-size: 12px;
  flex-shrink: 0;
}

.member-status .label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.member-status.dad   { background: rgba(107,143,175,0.15); color: #4A6E8A; }
.member-status.mom   { background: rgba(212,131,122,0.15); color: #A85F57; }
.member-status.sister { background: rgba(122,190,191,0.15); color: #4A8A8B; }

.status-off {
  background: rgba(232,168,56,0.12);
  color: #9A6820;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 20px;
  text-align: center;
}

/* ── Monthly Grid ────────────────────────────────────────────────────── */
.month-section {
  padding: 8px 16px 16px;
}

.month-grid {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}

.month-dow-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--border);
}

.month-dow {
  padding: 8px 4px;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.month-grid-body {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.month-cell {
  min-height: 52px;
  padding: 4px 3px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.month-cell:nth-child(7n) { border-right: none; }

.month-cell:empty { cursor: default; }
.month-cell:active { background: rgba(0,0,0,0.03); }

.month-cell.empty { background: var(--bg); cursor: default; }
.month-cell.empty:active { background: var(--bg); }

.month-cell.today { background: rgba(107,143,175,0.06); }

.month-day-num {
  font-family: 'Nunito', sans-serif;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
}

.month-cell.today .month-day-num {
  background: var(--dad);
  color: white;
}

.month-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-top: 1px;
}

.month-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.month-dot.dad   { background: var(--dad); }
.month-dot.mom   { background: var(--mom); }
.month-dot.sister{ background: var(--sister); }
.month-dot.holiday { background: var(--holiday); }
.month-dot.birthday { background: var(--birthday); }
.month-dot.note { background: #6B9FD4; }

/* ── Legend ──────────────────────────────────────────────────────────── */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Modal ───────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26,22,20,0.45);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: fadeIn 0.2s ease;
}

.modal-overlay[hidden] {
  display: none;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 70dvh;
  overflow-y: auto;
  animation: slideUp 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: var(--shadow-lg);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 12px auto 0;
}

.modal-header {
  padding: 16px 20px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-date {
  font-family: 'Nunito', 'Noto Sans Thai', sans-serif;
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
}

.modal-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.modal-events {
  list-style: none;
  padding: 4px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-event {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  color: white;
  box-shadow: var(--shadow-sm);
}

.modal-event-icon { font-size: 16px; flex-shrink: 0; }
.modal-event-label { flex: 1; }
.modal-event-sub   { font-size: 11px; opacity: 0.85; font-weight: 500; }

.modal-delete-btn {
  background: rgba(255,255,255,0.25);
  border: none;
  border-radius: 50%;
  width: 26px;
  height: 26px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  padding: 0;
}
.modal-delete-btn:active { background: rgba(255,255,255,0.45); }

/* ── Loading ─────────────────────────────────────────────────────────── */
.loading-skeleton {
  animation: shimmer 1.4s infinite linear;
  background: linear-gradient(90deg, var(--border) 25%, var(--bg) 50%, var(--border) 75%);
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* ── FAB ────────────────────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: 28px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6B9FD4 0%, #9B6FB0 100%);
  color: #fff;
  border: none;
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 4px 16px rgba(107, 159, 212, 0.45);
  cursor: pointer;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.fab:active {
  transform: scale(0.92);
  box-shadow: 0 2px 8px rgba(107, 159, 212, 0.3);
}

/* ── Member Filter (Legend Toggle) ────────────────────────────────────── */
.member-filter {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.member-filter::-webkit-scrollbar { display: none; }

.filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1.5px solid transparent;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  background: transparent;
  opacity: 0.45;
  white-space: nowrap;
}

.filter-btn.on {
  opacity: 1;
  transform: scale(1.06);
  box-shadow: 0 3px 10px rgba(0,0,0,0.18);
  color: #fff;
}

.filter-btn.on .filter-emoji { filter: brightness(0) invert(1); }
.filter-btn .filter-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Faded dots when filter is active (some members hidden) */
.month-dot.faded {
  opacity: 0.12;
}

/* ── Note Modal ────────────────────────────────────────────────────── */
.note-body {
  padding: 8px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.note-member-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.note-member-btn {
  flex: 1;
  padding: 10px 4px;
  border: 2.5px solid #D0C9C0;
  border-radius: var(--radius-md);
  background: var(--surface);
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  transition: all 0.18s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  -webkit-tap-highlight-color: transparent;
  min-width: 0;
}

.note-member-btn.selected {
  color: #fff;
  transform: scale(1.06);
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}

.note-member-btn.selected .emoji { filter: brightness(0) invert(1); }
.note-member-btn.selected .label { color: #fff; font-weight: 700; }

.note-input {
  width: 100%;
  box-sizing: border-box;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}

.note-input:focus {
  border-color: #6B9FD4;
}

.note-textarea {
  resize: none;
  line-height: 1.5;
}

.note-save-btn {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #6B9FD4 0%, #9B6FB0 100%);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.note-save-btn:active { opacity: 0.85; }

/* ── Reduced motion ─────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
