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

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #dde3ec;
  --text: #1a2332;
  --text-muted: #5c6b7a;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #059669;
  --success-bg: #ecfdf5;
  --error: #dc2626;
  --error-bg: #fef2f2;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
}

.header-inner {
  max-width: 800px;
  margin: 0 auto;
}

.header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.back-link {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
}

.back-link a {
  color: var(--primary);
  text-decoration: none;
}

.back-link a:hover {
  text-decoration: underline;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 1.5rem;
}

.step {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.step.disabled {
  opacity: 0.55;
  pointer-events: none;
}

.step h2 {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.hint {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.provider-grid,
.appt-type-grid,
.slots-grid {
  display: grid;
  gap: 0.75rem;
}

.provider-grid {
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

.appt-type-grid {
  grid-template-columns: 1fr;
}

.slots-grid {
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}

.card-btn {
  display: block;
  width: 100%;
  padding: 0.875rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.card-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-light);
}

.card-btn.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.card-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.card-btn .meta {
  display: block;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

select {
  width: 100%;
  max-width: 320px;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: var(--surface);
}

.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

#calendar-month-label {
  font-weight: 600;
}

.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-header {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0.25rem;
}

.cal-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: transparent;
  color: var(--text-muted);
  cursor: default;
}

.cal-day.empty {
  visibility: hidden;
}

.cal-day.available {
  color: var(--text);
  background: var(--primary-light);
  border-color: var(--border);
  cursor: pointer;
  font-weight: 500;
}

.cal-day.available:hover {
  border-color: var(--primary);
}

.cal-day.selected {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.cal-day.unavailable {
  color: #c5cdd8;
}

.selected-date {
  font-weight: 500;
  margin: 0 0 0.75rem;
}

.search-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.search-row input {
  flex: 1;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
}

.patient-results {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.patient-result {
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.patient-result:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.patient-result .email {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.new-patient-form {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}

.new-patient-form summary {
  cursor: pointer;
  font-weight: 500;
  color: var(--primary);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.form-grid input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
}

.form-grid button {
  grid-column: 1 / -1;
  justify-self: start;
}

.selected-patient {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--success-bg);
  border-radius: var(--radius);
  color: var(--success);
}

.summary {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.summary dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 1rem;
}

.summary dt {
  font-weight: 500;
  color: var(--text-muted);
}

.summary dd {
  margin: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg);
}

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  padding: 0;
  margin-left: 0.5rem;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
}

.success {
  background: var(--success-bg);
  border: 1px solid #a7f3d0;
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.success h2 {
  margin: 0 0 0.75rem;
  color: var(--success);
}

.toast {
  position: fixed;
  top: 1rem;
  right: 1rem;
  max-width: 360px;
  padding: 0.875rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.toast.error {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid #fecaca;
}

.toast.success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid #a7f3d0;
}

.hidden {
  display: none !important;
}

.loading {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

@media (max-width: 600px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .provider-grid {
    grid-template-columns: 1fr;
  }
}
