* {
  box-sizing: border-box;
}

:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #dc2626;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --header-bg: #f9fafb;
  --today: #fef3c7;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
    "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  text-align: center;
  padding: 24px 16px 8px;
}

header h1 {
  margin: 0 0 12px;
  font-size: 26px;
}

.team-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 900px;
  margin: 0 auto;
}

.team-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  color: #fff;
  font-weight: 500;
  white-space: nowrap;
}

.team-chip .leader {
  opacity: 0.85;
  font-weight: 400;
}

main {
  flex: 1;
  display: grid;
  gap: 16px;
  padding: 16px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* ----- Calendar toolbar ----- */
.calendar-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.nav-group {
  display: flex;
  gap: 6px;
}

.calendar-toolbar h2 {
  margin: 0;
  font-size: 18px;
  flex: 1;
  text-align: center;
}

button {
  font-family: inherit;
  cursor: pointer;
  font-size: 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  padding: 8px 14px;
  color: var(--text);
  transition: background 0.12s ease, border-color 0.12s ease;
}

button:hover {
  background: var(--header-bg);
  border-color: #d1d5db;
}

#prev-week,
#next-week {
  font-size: 18px;
  width: 38px;
  padding: 4px;
}

/* ----- Calendar grid ----- */
.calendar-grid {
  display: grid;
  grid-template-columns: 64px repeat(5, minmax(0, 1fr));
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.cal-cell {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  min-height: 42px;
  padding: 4px 6px;
  font-size: 13px;
  position: relative;
}

.cal-header {
  background: var(--header-bg);
  font-weight: 600;
  text-align: center;
  padding: 10px 4px;
  font-size: 13px;
  line-height: 1.4;
}

.cal-header .dow {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.cal-header.today {
  background: var(--today);
  color: #92400e;
}

.cal-header.today .dow {
  color: #b45309;
}

.cal-time {
  background: var(--header-bg);
  color: var(--muted);
  text-align: right;
  padding: 6px 8px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.cal-slot {
  cursor: pointer;
  background: #fff;
  transition: background 0.1s ease;
}

.cal-slot:hover {
  background: var(--header-bg);
}

.cal-slot.past:not(.taken) {
  background: repeating-linear-gradient(
    45deg,
    #f9fafb,
    #f9fafb 6px,
    #f3f4f6 6px,
    #f3f4f6 12px
  );
  cursor: not-allowed;
  pointer-events: none;
}

.cal-slot.taken.past {
  opacity: 0.55;
}

.cal-slot.holiday:not(.taken) {
  background: repeating-linear-gradient(
    45deg,
    #fef2f2,
    #fef2f2 6px,
    #fee2e2 6px,
    #fee2e2 12px
  );
  cursor: not-allowed;
  pointer-events: none;
}

.cal-header.holiday {
  background: #fef2f2;
  color: #b91c1c;
}

.cal-header.holiday .dow {
  color: #dc2626;
}

.cal-slot.today-col {
  background: rgba(254, 243, 199, 0.35);
}

.cal-slot.today-col:hover {
  background: rgba(254, 243, 199, 0.6);
}

.cal-slot.taken {
  cursor: pointer;
  color: #fff;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4px;
  line-height: 1.25;
}

.cal-slot.taken .reserver {
  font-size: 11px;
  font-weight: 400;
  opacity: 0.92;
}

.cal-slot.taken:hover {
  filter: brightness(0.92);
}

/* ----- Modal ----- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  animation: fadeIn 0.12s ease;
}

.modal.hidden {
  display: none;
}

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

.modal-content {
  background: #fff;
  border-radius: 12px;
  padding: 22px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.modal-content h3 {
  margin: 0 0 6px;
  font-size: 18px;
}

.modal-when {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
}

.modal-content label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}

.modal-content input[type="text"],
.modal-content input[type="url"],
.modal-content select,
.modal-content textarea {
  width: 100%;
  padding: 9px 12px;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  font-family: inherit;
}

.modal-content textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.45;
}

.modal-content input:focus,
.modal-content select:focus,
.modal-content textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

#detail-memo {
  white-space: pre-wrap;
  word-break: break-word;
}

#detail-memo-row {
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

#detail-memo-row strong {
  min-width: 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.modal-actions button {
  padding: 8px 16px;
}

#submit-btn,
#edit-save {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

#submit-btn:hover,
#edit-save:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.detail-row a {
  color: var(--primary);
  text-decoration: underline;
  word-break: break-all;
}

.required {
  color: var(--primary);
  font-weight: 500;
}

button.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

button.danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

button.danger:hover {
  background: #b91c1c;
  border-color: #b91c1c;
}

.detail-row {
  margin: 6px 0;
  font-size: 14px;
  display: flex;
  gap: 8px;
}

.detail-row strong {
  color: var(--muted);
  font-weight: 500;
  min-width: 56px;
}

.detail-row.hidden {
  display: none;
}

.message {
  margin: 8px 0 0;
  font-size: 13px;
  min-height: 18px;
}

.message.error {
  color: var(--danger);
}

.message.success {
  color: #047857;
}

footer {
  text-align: center;
  padding: 16px;
  color: var(--muted);
}

@media (max-width: 640px) {
  .calendar-grid {
    grid-template-columns: 50px repeat(5, minmax(0, 1fr));
  }
  .cal-cell {
    font-size: 11px;
    min-height: 36px;
  }
  .cal-header {
    padding: 6px 2px;
    font-size: 12px;
  }
  .cal-time {
    font-size: 11px;
    padding: 4px;
  }
  .cal-slot.taken .reserver {
    font-size: 10px;
  }
}
