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

:root {
  --primary: #0f6a8a;
  --primary-dark: #0b546d;
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #18202a;
  --text-muted: #5f6b7a;
  --border: #e0e4ea;
  --success: #1b7b45;
  --success-bg: #e8f5ee;
  --error: #b23a2c;
  --error-bg: #fdecea;
  --radius-card: 14px;
  --radius-btn: 8px;
  --shadow-card: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-modal: 0 8px 32px rgba(0,0,0,0.18);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --ppm: 2.5; /* pixels per minute */
}

html {
  font-family: var(--font);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
}

a { color: var(--primary); }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}

.hidden { display: none !important; }

/* ===== Header ===== */
.header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
}

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

.header-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon { flex-shrink: 0; }

.header-title {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.2;
}

.header-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ===== Main ===== */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-btn);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 10px 20px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  line-height: 1.4;
}

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

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

.btn-outline {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline:hover:not(:disabled) {
  background: var(--bg);
}

.btn-danger {
  background: var(--error);
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  background: #922e22;
}

.btn-full { width: 100%; }

.btn-nav {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 1.4rem;
  font-weight: 400;
}

/* ===== Select ===== */
.select-field {
  font-family: var(--font);
  font-size: 0.9rem;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  min-width: 200px;
}

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

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

.week-label {
  font-size: 0.95rem;
  font-weight: 600;
  margin-left: 8px;
  white-space: nowrap;
}

/* ===== Day Tabs (mobile) ===== */
.day-tabs {
  display: none;
  gap: 4px;
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.day-tabs::-webkit-scrollbar { display: none; }

.day-tab {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: var(--radius-btn);
  border: 1px solid var(--border);
  background: var(--card);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.day-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ===== Calendar Grid ===== */
.calendar-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.calendar-grid {
  display: grid;
  position: relative;
  min-width: 600px;
}

.calendar-header-row {
  display: contents;
}

.calendar-col-header {
  text-align: center;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 10px 4px;
  background: var(--card);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
}

.calendar-col-header .day-name {
  display: block;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.5px;
}

.calendar-col-header .day-date {
  display: block;
  font-size: 0.95rem;
  margin-top: 2px;
}

.calendar-col-header.today .day-date {
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.time-axis {
  grid-column: 1;
  position: relative;
  width: 56px;
  min-width: 56px;
}

.time-label {
  position: absolute;
  right: 8px;
  font-size: 0.72rem;
  color: var(--text-muted);
  transform: translateY(-50%);
  white-space: nowrap;
}

.day-column {
  position: relative;
  border-left: 1px solid var(--border);
  min-height: calc(600 * var(--ppm) * 1px); /* 10h * 60min */
}

.hour-line {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px solid var(--border);
}

.half-hour-line {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px dashed #eceef2;
}

/* ===== Slot Card ===== */
.slot-card {
  position: absolute;
  left: 4px;
  right: 4px;
  background: var(--primary);
  color: #fff;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.78rem;
  cursor: pointer;
  overflow: hidden;
  transition: background 0.15s, box-shadow 0.15s;
  z-index: 1;
  line-height: 1.3;
}

.slot-card:hover {
  background: var(--primary-dark);
  box-shadow: 0 2px 8px rgba(15,106,138,0.3);
}

.slot-card .slot-time {
  font-weight: 600;
  display: block;
}

.slot-card .slot-therapeut {
  font-weight: 400;
  opacity: 0.9;
  display: block;
  font-size: 0.72rem;
  margin-top: 2px;
}

/* ===== Loading ===== */
.loading-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.modal .loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.85);
  z-index: 10;
  border-radius: var(--radius-card);
}

.spinner {
  width: 32px;
  height: 32px;
  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); }
}

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  overflow-y: auto;
}

.modal {
  background: var(--card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-modal);
  width: 100%;
  max-width: 480px;
  padding: 28px 24px;
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.6rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 4px;
}
.modal-close:hover { color: var(--text); }

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.slot-summary {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

/* ===== Toggle Tabs ===== */
.toggle-tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  overflow: hidden;
  margin-bottom: 20px;
}

.toggle-tab {
  flex: 1;
  padding: 10px 8px;
  background: var(--card);
  border: none;
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  color: var(--text-muted);
}

.toggle-tab.active {
  background: var(--primary);
  color: #fff;
}

.toggle-tab:not(.active):hover {
  background: var(--bg);
}

/* ===== Forms ===== */
.patient-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.form-group label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-group input,
.form-group select {
  font-family: var(--font);
  font-size: 0.92rem;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  background: var(--card);
  color: var(--text);
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15,106,138,0.12);
}

.form-group input.invalid {
  border-color: var(--error);
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-group-wide { flex: 2; }
.form-group-small { flex: 0 0 100px; }

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  margin-top: 2px;
  flex-shrink: 0;
}

.form-message {
  padding: 10px 14px;
  border-radius: var(--radius-btn);
  font-size: 0.85rem;
  line-height: 1.4;
}

.form-message.error {
  background: var(--error-bg);
  color: var(--error);
}

.form-message.success {
  background: var(--success-bg);
  color: var(--success);
}

/* ===== Verify / Code ===== */
.verify-info {
  font-size: 0.9rem;
  margin-bottom: 16px;
  line-height: 1.5;
}

.code-input {
  text-align: center;
  font-size: 1.5rem !important;
  letter-spacing: 8px;
  font-weight: 700;
}

/* ===== Confirmation ===== */
.confirmation-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--success-bg);
  color: var(--success);
  font-size: 1.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  font-weight: 700;
}

#step-confirmation {
  text-align: center;
}

#step-confirmation h3 {
  font-size: 1.1rem;
  margin-bottom: 8px;
}

#step-confirmation p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 20px;
  line-height: 1.5;
}

/* ===== Cancel View ===== */
.cancel-card {
  background: var(--card);
  border-radius: var(--radius-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  padding: 28px 24px;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

.cancel-card h2 {
  font-size: 1.15rem;
  margin-bottom: 16px;
}

.cancel-details {
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 20px;
}

.cancel-details p {
  margin-bottom: 4px;
}

.cancel-success {
  text-align: center;
  padding: 20px 0;
}

.cancel-success .confirmation-icon {
  background: var(--error-bg);
  color: var(--error);
}

/* ===== Fallback ===== */
.fallback-card {
  background: var(--card);
  border-radius: var(--radius-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  padding: 32px 24px;
  max-width: 480px;
  margin: 40px auto;
  text-align: center;
}

.fallback-card h2 {
  font-size: 1.1rem;
  margin-bottom: 12px;
}

.fallback-contact {
  margin-top: 16px;
  text-align: left;
}

.fallback-contact p {
  margin-bottom: 6px;
  font-size: 0.9rem;
}

/* ===== No Slots ===== */
.no-slots-message {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ===== Responsive ===== */

/* Tablet */
@media (max-width: 900px) {
  .calendar-grid {
    min-width: 500px;
  }
}

/* Mobile */
@media (max-width: 760px) {
  .header { padding: 12px 16px; }
  .header-title { font-size: 1.1rem; }
  .main { padding: 12px 10px 30px; }

  .calendar-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .week-nav {
    justify-content: center;
  }

  .filter-row {
    width: 100%;
  }

  .select-field {
    width: 100%;
    min-width: unset;
  }

  .day-tabs {
    display: flex;
  }

  .calendar-grid {
    min-width: unset;
  }

  .day-column.mobile-hidden {
    display: none;
  }

  .calendar-col-header.mobile-hidden {
    display: none;
  }

  .modal {
    padding: 20px 16px;
    max-height: 95vh;
  }

  .form-row {
    flex-direction: column;
    gap: 14px;
  }

  .form-group-small { flex: 1; }
}
