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

:root {
  --sidebar-width: 220px;
  --header-height: 56px;
  --color-bg: #f4f6f9;
  --color-sidebar: #1e2a3a;
  --color-sidebar-hover: #2d3f56;
  --color-sidebar-active: #3a5276;
  --color-text: #1a1a2e;
  --color-text-light: #6b7280;
  --color-border: #e0e4ea;
  --color-white: #ffffff;
  --color-danger: #e53e3e;
  --color-success: #38a169;
  --color-warning: #d97706;

  /* 8 pastel specialist colors */
  --pastel-0: #f9c6c6;
  --pastel-1: #b8d8f8;
  --pastel-2: #b8f0d8;
  --pastel-3: #d8c6f8;
  --pastel-4: #fdd9b5;
  --pastel-5: #a8cba8;
  --pastel-6: #faf3b0;
  --pastel-7: #9eacee;

  --pastel-0-dark: #c97a7a;
  --pastel-1-dark: #5a9ad4;
  --pastel-2-dark: #5abf8a;
  --pastel-3-dark: #8a6abf;
  --pastel-4-dark: #d4944a;
  --pastel-5-dark: #6a9a6a;
  --pastel-6-dark: #c8b830;
  --pastel-7-dark: #5aaad4;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  height: 100vh;
  display: flex;
  overflow: hidden;
}

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-width);
  background: var(--color-sidebar);
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  overflow-y: auto;
}
#sidebar .logo {
  padding: 20px 18px 16px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
#sidebar nav { padding: 12px 0; }
#sidebar nav button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: rgba(255,255,255,0.82);
  padding: 11px 18px;
  font-size: 0.92rem;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s;
}
#sidebar nav button:hover { background: var(--color-sidebar-hover); color: #fff; }
#sidebar nav button.active { background: var(--color-sidebar-active); color: #fff; border-left-color: #7eb8f7; }

/* ── Main ── */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* ── Views ── */
.view { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.view.active { display: flex; }

/* ── View header ── */
.view-header {
  height: var(--header-height);
  background: var(--color-white);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  flex-shrink: 0;
}
.view-header h2 { font-size: 1rem; font-weight: 600; flex: 1; }

/* ── Buttons ── */
.btn {
  padding: 7px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: #3a5276; color: #fff; }
.btn-secondary { background: var(--color-border); color: var(--color-text); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }

/* ── Specialist / Therapist lists ── */
#view-specialists .content,
#view-therapists .content { flex: 1; overflow-y: auto; padding: 20px; }

.specialist-card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.specialist-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); border-color: #b0bcd4; }
.specialist-card.suspended { opacity: 0.55; }
.specialist-color-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.specialist-info { flex: 1; }
.specialist-info .name { font-weight: 600; font-size: 0.95rem; }
.specialist-info .meta { font-size: 0.8rem; color: var(--color-text-light); margin-top: 2px; }

/* ── Edit panels ── */
#view-specialist-edit .content,
#view-therapist-edit .content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-section { max-width: 560px; display: flex; flex-direction: column; gap: 16px; }
.form-section-sm { max-width: 400px; }

.form-group { display: flex; flex-direction: column; gap: 4px; max-width: 400px; }
.form-group-full { max-width: none; }
.form-group label { font-size: 0.85rem; font-weight: 500; color: var(--color-text-light); }
.form-group input,
.form-group select,
.form-group textarea {
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.9rem;
  background: var(--color-white);
  color: var(--color-text);
  font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { outline: none; border-color: #3a5276; }
.form-group input[readonly] { background: #f4f6f9; color: var(--color-text-light); }

.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }

.checkbox-group { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; margin-top: 4px; }
.checkbox-group input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }

/* ── Color picker ── */
.color-picker { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.color-swatch {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.1s;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { border-color: #1a1a2e; }

/* ── Availability mini-calendar ── */
#availability-section { max-width: 760px; }
#availability-section h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 12px; }
.avail-calendar-nav { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.avail-calendar-nav span { font-weight: 600; font-size: 0.92rem; flex: 1; text-align: center; }
.avail-calendar-nav button {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 0.85rem;
}
.avail-calendar-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.avail-day-header { text-align: center; font-size: 0.75rem; font-weight: 600; color: var(--color-text-light); padding: 4px 0; }
.avail-day-cell {
  min-height: 64px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 4px 5px;
  background: var(--color-white);
  cursor: pointer;
  position: relative;
  transition: background 0.1s;
}
.avail-day-cell:hover { background: #f0f4ff; }
.avail-day-cell.other-month { background: #f8f9fb; cursor: default; }
.avail-day-cell.other-month .day-number { color: #ccc; }
.avail-day-cell.today { border-color: #3a5276; }
.day-number { font-size: 0.78rem; font-weight: 600; color: var(--color-text-light); margin-bottom: 3px; }
.avail-chip {
  font-size: 0.7rem;
  border-radius: 4px;
  padding: 1px 4px;
  margin-bottom: 2px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 3px;
}
.avail-chip .chip-del { font-size: 0.65rem; opacity: 0.7; flex-shrink: 0; }
.avail-chip .chip-del:hover { opacity: 1; }

/* ── Therapist edit ── */
.therapist-appts-section { margin-top: 24px; max-width: 680px; }
.section-title { font-size: 0.95rem; font-weight: 600; margin-bottom: 12px; }
.therapist-appt-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.85rem;
}
.therapist-appt-row:last-child { border-bottom: none; }
.therapist-appt-date { min-width: 160px; font-weight: 500; }
.therapist-appt-hours { min-width: 110px; color: var(--color-text-light); }
.therapist-appt-info { flex: 1; }

/* ── Agenda ── */
#view-agenda .content { flex: 1; overflow-y: auto; padding: 0; display: flex; flex-direction: column; }
.agenda-body { flex: 1; overflow: auto; display: flex; flex-direction: column; }

.agenda-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: var(--color-white);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.view-toggle { display: flex; border: 1px solid var(--color-border); border-radius: 6px; overflow: hidden; }
.view-toggle button {
  padding: 6px 14px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.85rem;
  border-right: 1px solid var(--color-border);
}
.view-toggle button:last-child { border-right: none; }
.view-toggle button.active { background: #3a5276; color: #fff; }
.agenda-nav { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.agenda-nav span { font-weight: 600; font-size: 0.9rem; min-width: 180px; text-align: center; }
.filter-select {
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.85rem;
  background: var(--color-white);
  color: var(--color-text);
  min-width: 160px;
}
.filter-select:focus { outline: none; border-color: #3a5276; }

/* ── Day view ── */
.agenda-day-grid { flex: 1; overflow-y: auto; display: flex; }
.time-col { width: 56px; flex-shrink: 0; padding-top: 32px; }
.time-slot-label {
  height: 60px;
  font-size: 0.72rem;
  color: var(--color-text-light);
  text-align: right;
  padding-right: 8px;
  padding-top: 2px;
  flex-shrink: 0;
}
.day-col { flex: 1; position: relative; }
.day-col-header {
  height: 32px;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 600;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-white);
  position: sticky;
  top: 0;
  z-index: 2;
}
.hour-row { height: 60px; border-top: 1px solid var(--color-border); position: relative; }
.half-hour-line { position: absolute; top: 50%; left: 0; right: 0; border-top: 1px dashed #e8ecf0; }
.avail-bg-block { position: absolute; left: 2px; right: 2px; border-radius: 4px; opacity: 0.6; z-index: 0; pointer-events: none; }
.avail-click-zone { position: absolute; left: 2px; right: 2px; z-index: 1; cursor: pointer; border-radius: 4px; }
.avail-click-zone:hover { background: rgba(0,0,0,0.06); }
.appt-block {
  position: absolute;
  left: 4px; right: 4px;
  border-radius: 5px;
  padding: 3px 6px;
  font-size: 0.75rem;
  overflow: hidden;
  cursor: grab;
  z-index: 2;
  border-left-width: 3px;
  border-left-style: solid;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
.appt-block:hover { filter: brightness(0.95); }
.appt-block.dragging { opacity: 0.4; cursor: grabbing; }
.appt-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drop-indicator { position: absolute; left: 4px; right: 4px; height: 2px; background: #3a5276; border-radius: 2px; z-index: 10; pointer-events: none; }
.drag-ghost { position: fixed; pointer-events: none; z-index: 999; border-radius: 5px; padding: 3px 6px; font-size: 0.75rem; opacity: 0.85; box-shadow: 0 4px 12px rgba(0,0,0,0.2); white-space: nowrap; }

/* ── Week / Month view ── */
.agenda-table-wrap { flex: 1; overflow: auto; }
.agenda-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.agenda-table th {
  background: var(--color-white);
  padding: 8px 4px;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 2;
}
.agenda-table td { border: 1px solid var(--color-border); vertical-align: top; padding: 4px; min-height: 80px; background: var(--color-white); }
.agenda-table td.today-cell { background: #f0f5ff; }
.cell-date { font-size: 0.75rem; font-weight: 600; color: var(--color-text-light); margin-bottom: 3px; }
.agenda-avail-chip { font-size: 0.72rem; border-radius: 4px; padding: 2px 5px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; opacity: 0.6; }
.agenda-avail-chip:hover { opacity: 0.85; }
.agenda-appt-chip { font-size: 0.72rem; border-radius: 4px; padding: 2px 5px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; border-left: 3px solid transparent; font-weight: 600; }
.agenda-appt-chip:hover { filter: brightness(0.93); }
.month-counts { font-size: 0.7rem; color: var(--color-text-light); margin-top: 4px; line-height: 1.5; }
.month-counts .booked { color: var(--color-text); font-weight: 600; }
.month-counts .free { color: var(--color-success); }

/* ── Modals ── */
.modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 100; align-items: center; justify-content: center; }
.modal-backdrop.open { display: flex; }
.modal { background: var(--color-white); border-radius: 10px; padding: 24px; width: 380px; max-width: 95vw; box-shadow: 0 8px 32px rgba(0,0,0,0.18); }
.modal h3 { font-size: 1rem; margin-bottom: 16px; }
.modal-footer { margin-top: 20px; display: flex; justify-content: flex-end; gap: 8px; }
.modal-wide { width: 560px !important; max-height: 80vh; display: flex; flex-direction: column; }

/* ── z-index hierarchy ── */
#avail-popup  { z-index: 200; }
#appt-modal   { z-index: 300; }
#confirm-modal { z-index: 400; }
#patient-all-modal { z-index: 350; }

/* ── Availability popup ── */
#avail-popup {
  display: none;
  position: fixed;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 16px;
  width: 240px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.15);
}
#avail-popup h4 { font-size: 0.88rem; margin-bottom: 12px; color: var(--color-text-light); }
#avail-popup .form-group { max-width: none; }
.popup-form-group { margin-top: 8px; }
.popup-footer { margin-top: 14px; display: flex; justify-content: flex-end; gap: 6px; }

/* ── Appointment modal ── */
.appt-modal-inner { width: 420px; }
.specialist-badge { background: var(--color-bg); border-radius: 6px; padding: 8px 12px; margin-bottom: 16px; font-size: 0.85rem; }
.specialist-badge strong { display: block; font-size: 0.95rem; }
.appt-form { display: flex; flex-direction: column; gap: 12px; }
.appt-notes-textarea { resize: vertical; width: 100%; }

/* ── Therapist rows in appointment modal ── */
.therapist-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.therapist-row:last-child { margin-bottom: 0; }
.therapist-autocomplete-wrap { flex: 1; }

/* ── Autocomplete ── */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  display: none;
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-top: none;
  border-radius: 0 0 6px 6px;
  z-index: 300;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.autocomplete-list.open { display: block; }
.autocomplete-item { padding: 8px 12px; cursor: pointer; font-size: 0.875rem; border-bottom: 1px solid var(--color-border); }
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: #f0f4ff; }
.ac-phone { font-size: 0.78rem; color: var(--color-text-light); }

/* ── Overlap warning ── */
.overlap-warning { display: none; color: var(--color-warning); font-size: 0.8rem; margin-top: 6px; }
.overlap-warning.visible { display: block; }

/* ── Custom time picker ── */
.time-picker { display: flex; align-items: center; gap: 4px; }
.time-sep { font-size: 1.1rem; font-weight: 600; color: var(--color-text); line-height: 1; }
.time-part {
  width: 64px;
  padding: 6px 4px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 1rem;
  text-align: center;
  color: var(--color-text);
  background: var(--color-white);
  -moz-appearance: textfield;
}
.time-part:focus { outline: none; border-color: #3a5276; }
.time-part::-webkit-inner-spin-button,
.time-part::-webkit-outer-spin-button { opacity: 1; height: 32px; width: 20px; cursor: pointer; }

/* ── Location badge ── */
.location-badge { font-size: 0.72rem; background: #e8f0fe; color: #3a5276; border-radius: 10px; padding: 1px 7px; margin-left: 6px; }

/* ── Patients ── */
.patients-content { padding: 20px; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; }
.patient-search-input { width: 420px; max-width: 100%; }

.patient-card { background: var(--color-white); border: 1px solid var(--color-border); border-radius: 10px; margin-bottom: 10px; overflow: hidden; max-width: 680px; }
.patient-card-header { display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; transition: background 0.12s; }
.patient-card-header:hover { background: #f4f6fb; }
.patient-card-header .patient-name { font-weight: 600; font-size: 0.95rem; flex: 1; }
.patient-card-header .patient-phone { font-size: 0.82rem; color: var(--color-text-light); }
.patient-card-header .patient-future { font-size: 0.78rem; background: #e8f0fe; color: #3a5276; border-radius: 12px; padding: 2px 8px; }
.patient-card-header .chevron { font-size: 0.75rem; color: var(--color-text-light); transition: transform 0.2s; }
.patient-card-header.open .chevron { transform: rotate(90deg); }
.patient-card-body { display: none; border-top: 1px solid var(--color-border); padding: 10px 16px; }
.patient-card-body.open { display: block; }
.patient-card-footer { padding: 8px 16px 12px; display: none; }
.patient-card-footer.open { display: block; }

.patient-appt-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--color-border); font-size: 0.85rem; }
.patient-appt-row:last-child { border-bottom: none; }
.appt-date { min-width: 160px; font-weight: 500; }
.appt-hours { min-width: 110px; color: var(--color-text-light); }
.appt-spec { flex: 1; display: flex; align-items: center; gap: 6px; }
.spec-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.appt-actions { display: flex; gap: 6px; }

.patient-all-list { flex: 1; overflow-y: auto; margin: 0 -24px; padding: 0 24px; }
.patient-all-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--color-border); font-size: 0.85rem; }
.patient-all-row:last-child { border-bottom: none; }
.patient-all-row.past { background: #f8f8f8; color: var(--color-text-light); border-radius: 4px; padding: 8px 6px; }

/* ── Print window styles (injected into new window via JS) ── */
/* These are referenced by class in openPrintWindow's innerHTML */

/* ── @media print (main window fallback) ── */
@media print {
  body > *:not(#print-area) { display: none !important; }
}

/* ── Misc utility ── */
.empty-msg { padding: 20px; color: #888; font-size: 0.875rem; }
.suspended-label { font-size: 0.75rem; color: var(--color-danger); font-style: italic; margin-left: 6px; }
.rows-wrap { position: relative; }
.today-header { color: #3a5276; }
.drag-over { background: #e8f0fe !important; }
