:root {
  --coach-color: #039BE5;
  --coach-color-bg: rgba(3,155,229,0.08);
  --bg:      #f0f2f8;
  --bg-card: #ffffff;
  --bg-cell: #ffffff;
  --border:  #e4e6f0;
  --text:    #1a1a2e;
  --text-secondary: #44446a;
  --text-muted:     #9090aa;
  --accent:  #00c07a;
  --danger:  #ff4757;
  --shadow:  0 2px 14px rgba(0,0,0,0.07);
}

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

body {
  font-family: 'Noto Sans TC', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100svh;
  overflow-x: hidden;
}

/* ── Widget Header ── */
#widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-card);
  border-bottom: 2px solid var(--coach-color);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}

#coach-name {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--coach-color);
  letter-spacing: 0.02em;
}

#coach-switcher {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 12px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}

.coach-chip {
  flex: 0 0 auto;
  color: var(--text-secondary);
  background: #f7f8fc;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.75rem;
  font-weight: 800;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.coach-chip:hover,
.coach-chip.is-active {
  color: var(--chip-color);
  background: #ffffff;
  border-color: var(--chip-color);
}

#week-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

#week-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 120px;
  text-align: center;
  font-weight: 500;
}

.nav-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.nav-btn:hover:not(:disabled) {
  background: var(--coach-color-bg);
  border-color: var(--coach-color);
  color: var(--coach-color);
}
.nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Legend ── */
#legend {
  display: flex;
  gap: 16px;
  padding: 8px 16px;
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-dot  { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.busy-dot    { background: var(--coach-color); }
.free-dot    { background: #ffffff; border: 1.5px solid var(--border); }
.full-dot    {
  background: #f0f2f8;
  border: 1.5px solid var(--border);
  position: relative;
}
.full-dot::after {
  content: '✕';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #e04050;
  font-size: 8px;
  font-weight: 700;
  line-height: 1;
}
.nonwork-dot {
  background-image: repeating-linear-gradient(
    -45deg, #e8eaf0, #e8eaf0 3px, #f4f5fa 3px, #f4f5fa 7px
  );
  border: 1px solid var(--border);
}

/* ── Calendar Wrap ── */
#calendar-wrap {
  overflow-x: auto;
  padding: 12px 12px 24px;
  -webkit-overflow-scrolling: touch;
}

/* ── Grid ── */
.grid-container {
  display: grid;
  grid-template-columns: 54px repeat(7, minmax(42px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: visible;
  min-width: 380px;
  box-shadow: var(--shadow);
}

.grid-cell {
  background: var(--bg-cell);
  min-height: 28px;
}

/* Header */
.time-header {
  background: #f7f8fc;
  position: sticky;
  left: 0;
  z-index: 5;
  box-shadow: 1px 0 0 var(--border);
}

.day-header {
  background: #f7f8fc;
  text-align: center;
  padding: 6px 2px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-secondary);
  line-height: 1.5;
}
.day-header.today {
  background: var(--coach-color-bg);
  color: var(--coach-color);
}
.date-num { font-size: 0.62rem; font-weight: 500; color: var(--text-muted); }
.day-header.today .date-num { color: var(--coach-color); }

.is-dayoff { color: #cc3344 !important; }
.is-dayoff .date-num { color: #cc3344 !important; }

/* Time label */
.time-label {
  background: #f7f8fc;
  font-size: 0.58rem;
  color: var(--text-muted);
  padding: 4px 5px 0;
  display: flex;
  align-items: flex-start;
  white-space: nowrap;
  font-weight: 500;
  position: sticky;
  left: 0;
  z-index: 4;
  box-shadow: 1px 0 0 var(--border);
}
.time-label.hour-mark {
  background: #eef1f7;
  color: var(--text-secondary);
  font-weight: 700;
}
.time-label.half-mark {
  color: #a6a6bb;
}

.grid-cell.hour-row {
  box-shadow: inset 0 1px 0 #cfd3de;
}
.grid-cell.row-hover {
  outline: 1px solid rgba(3, 155, 229, 0.34);
  outline-offset: -1px;
}
.time-label.row-hover {
  background: #e7eef8;
  color: var(--text-secondary);
}

/* Busy */
.busy-cell {
  background: var(--coach-color);
  opacity: 0.88;
}

/* Free (bookable) */
.free-cell {
  background: #ffffff;
  cursor: pointer;
  transition: background 0.1s;
}
.free-cell:hover {
  background: var(--coach-color-bg);
}

/* Past */
.past-cell {
  background: #f4f5fa;
}

/* 當天已達上限 → 聯繫 LINE */
.full-cell {
  background: #f4f5fa;
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
}
.full-cell::after {
  content: '✕';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #e04050;
  font-size: 14px;
  font-weight: 700;
  opacity: 0.5;
}
.full-cell:hover {
  background: #ecedf5;
}
.full-cell:hover::after {
  opacity: 0.8;
}

/* 排休 */
.badge-off {
  display: inline-block;
  background: rgba(204,51,68,0.1);
  color: #cc3344;
  border-radius: 4px;
  font-size: 0.58rem;
  padding: 1px 4px;
  font-weight: 700;
}
.dayoff-cell {
  background: #fff5f5;
  cursor: not-allowed;
}

/* 非上班時間 */
.nonwork-cell {
  background-color: #f4f5fa;
  background-image: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 5px,
    rgba(0,0,0,0.025) 5px,
    rgba(0,0,0,0.025) 10px
  );
  cursor: pointer;
  transition: background-color 0.1s;
}
.nonwork-cell:hover { background-color: #ebebf4; }

/* Loading / Error */
.grid-msg {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ── Modal ── */
#modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20,20,40,0.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
}
#modal-overlay.active { display: flex; }

#modal {
  background: #ffffff;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 90svh;
  overflow-y: auto;
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 16px);
  box-shadow: 0 -4px 30px rgba(0,0,0,0.12);
}

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

#modal-header {
  padding: 14px 20px 12px;
  border-bottom: 1px solid var(--border);
}
#modal-title      { font-size: 1.05rem; font-weight: 800; color: var(--text); }
#modal-datetime   { font-size: 0.8rem; color: var(--coach-color); margin-top: 3px; font-weight: 600; }

/* ── Form ── */
#booking-form { padding: 14px 20px 8px; }

.form-section   { margin-bottom: 14px; }
.form-label     { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 5px; font-weight: 600; }
.required       { color: var(--danger); }

.form-input,
.form-select {
  width: 100%;
  background: #f8f9fc;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 0.88rem;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
}
.form-input:focus,
.form-select:focus  { border-color: var(--coach-color); background: #fff; }
.form-select        { appearance: none; cursor: pointer; }
.form-textarea      { min-height: 68px; resize: vertical; }

.form-divider {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--coach-color);
  margin: 18px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1.5px solid var(--coach-color-bg);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Goal chips */
.goal-chips    { display: flex; flex-wrap: wrap; gap: 7px; }
.goal-chip {
  background: #f4f5fa;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 0.76rem;
  cursor: pointer;
  transition: all 0.13s;
  color: var(--text-secondary);
  user-select: none;
  font-weight: 500;
}
.goal-chip.selected {
  background: var(--coach-color);
  border-color: var(--coach-color);
  color: #fff;
  font-weight: 700;
}

.detail-input { margin-top: 7px; }

.error-msg {
  color: var(--danger);
  font-size: 0.78rem;
  margin-bottom: 8px;
  min-height: 16px;
}

.btn-submit {
  width: 100%;
  background: var(--coach-color);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  margin-bottom: 8px;
  font-family: inherit;
  letter-spacing: 0.03em;
  transition: opacity 0.15s, transform 0.1s;
}
.btn-submit:active:not(:disabled) { transform: scale(0.98); }
.btn-submit:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-cancel {
  width: 100%;
  background: #f4f5fa;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  font-size: 0.88rem;
  cursor: pointer;
  font-family: inherit;
  margin-bottom: 4px;
  transition: background 0.13s;
}
.btn-cancel:hover { background: var(--border); }

/* Form hint */
.form-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 5px;
  line-height: 1.5;
}

/* Contact modal */
.contact-body {
  padding: 28px 20px 24px;
  text-align: center;
}
.contact-icon  { font-size: 2.8rem; margin-bottom: 10px; }
.contact-title { font-size: 1rem; font-weight: 800; color: var(--text); margin-bottom: 10px; }
.contact-msg   { font-size: 0.85rem; color: var(--text-muted); line-height: 1.7; margin-bottom: 20px; }

.btn-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: #06C755;
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  margin-bottom: 4px;
  font-family: inherit;
  text-decoration: none;
  transition: opacity 0.15s;
}
.btn-line:hover { opacity: 0.88; }

/* Success state */
#booking-success {
  text-align: center;
  padding: 36px 20px 24px;
}
#booking-success .success-icon {
  font-size: 3.5rem;
  margin-bottom: 12px;
}
#booking-success .success-title {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 8px;
}
#booking-success .success-msg {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 24px;
}
