/* ────────────────────────────────────────────────
   Agenda V2 — Estilos
   Variables CSS centralizadas
   ──────────────────────────────────────────────── */

:root {
  --color-primary:    #0077b6;
  --color-primary-dk: #005f92;
  --color-cyr:        #0077b6;   /* Azul para C&R */
  --color-roma:       #2d6a4f;   /* Verde para ROMA */
  --color-danger:     #dc3545;
  --color-warn:       #e9a800;
  --color-success:    #28a745;
  --color-muted:      #6c757d;
  --color-border:     #dee2e6;
  --color-bg:         #f8f9fa;
  --color-surface:    #ffffff;
  --color-busy:       #ffe0e0;   /* Bloques cruzados de Rodrigo */
  --color-busy-border:#e53e3e;

  --slot-height: 48px;           /* Altura de cada slot de 30 min — sincronizado con agenda.js */
  --sidebar-w:   240px;
  --radius:      8px;
  --shadow:      0 2px 8px rgba(0,0,0,0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  background: var(--color-bg);
  color: #212529;
  height: 100vh;
  overflow: hidden;
}

/* ── Login ─────────────────────────────────────── */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  overflow: auto;
}

.login-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo .logo-icon { font-size: 2.5rem; }
.login-logo h1         { font-size: 1.5rem; font-weight: 700; margin-top: .25rem; }
.login-sub             { color: var(--color-muted); font-size: .875rem; }

/* ── App shell ─────────────────────────────────── */

#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: #1a1d2e;
  color: #fff;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.sidebar-header .logo-icon { font-size: 1.75rem; }
.sidebar-clinic { font-weight: 700; font-size: .95rem; }
.sidebar-user   { font-size: .75rem; color: rgba(255,255,255,.6); margin-top: .125rem; }

.sidebar-nav {
  flex: 1;
  padding: .75rem 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .65rem 1rem;
  color: rgba(255,255,255,.75);
  text-decoration: none;
  cursor: pointer;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-right: .5rem;
  transition: background .15s, color .15s;
}

.nav-item:hover, .nav-item.active {
  background: rgba(255,255,255,.12);
  color: #fff;
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid rgba(255,255,255,.1);
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}

.badge {
  background: rgba(255,255,255,.15);
  color: #fff;
  padding: .2rem .5rem;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 600;
}

.btn-logout {
  margin-left: auto;
  background: none;
  border: 1px solid rgba(255,255,255,.3);
  color: rgba(255,255,255,.7);
  padding: .35rem .75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .8rem;
  transition: background .15s;
}

.btn-logout:hover { background: rgba(255,255,255,.1); }

/* ── Main ──────────────────────────────────────── */

.main-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.page { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.page.active { display: flex; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  gap: .75rem;
  flex-shrink: 0;
}

.page-header h2 { font-size: 1.1rem; font-weight: 700; }

.page-header-actions {
  display: flex;
  align-items: center;
  gap: .75rem;
}

/* ── Agenda grid ───────────────────────────────── */

.agenda-grid {
  display: flex;
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
  padding: 0;
}

/* Columna de horas */
.col-time {
  min-width: 56px;
  width: 56px;
  flex-shrink: 0;
  border-right: 1px solid var(--color-border);
  background: var(--color-surface);
  position: sticky;
  left: 0;
  z-index: 10;
}

/* Columna de unidad */
.col-unit {
  min-width: 200px;
  flex: 1;
  border-right: 1px solid var(--color-border);
  background: var(--color-surface);
  position: relative;
}

.col-header {
  height: 52px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: .5rem .75rem;
  border-bottom: 2px solid var(--color-border);
  background: var(--color-surface);
  position: sticky;
  top: 0;
  z-index: 5;
  font-weight: 600;
  font-size: .8rem;
}

/* Color de encabezado por sede */
.col-unit[data-clinic-id="1"] .col-header { border-bottom-color: var(--color-cyr); }
.col-unit[data-clinic-id="2"] .col-header { border-bottom-color: var(--color-roma); }

.col-clinic {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.col-unit[data-clinic-id="1"] .col-clinic { color: var(--color-cyr); }
.col-unit[data-clinic-id="2"] .col-clinic { color: var(--color-roma); }

.col-unit-name { color: var(--color-muted); font-size: .75rem; }

.time-slot {
  height: var(--slot-height);
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  align-items: center;
  padding: 0 .5rem;
  font-size: .75rem;
  color: var(--color-muted);
  cursor: pointer;
  transition: background .1s;
  position: relative;
}

.col-time .time-slot { cursor: default; }
.col-time .time-slot:hover { background: none; }
.col-unit .time-slot:hover { background: #f0f8ff; }

/* ── Bloques de cita ───────────────────────────── */

.appt-block {
  position: absolute;
  left: 4px;
  right: 4px;
  border-radius: 5px;
  padding: 4px 6px;
  font-size: .72rem;
  overflow: hidden;
  cursor: pointer;
  transition: filter .15s;
  z-index: 2;
  border-left: 3px solid transparent;
}

.appt-block:hover { filter: brightness(.93); }

/* Estados */
.appt-block.status-scheduled  { background: #e3f2fd; border-left-color: var(--color-primary); }
.appt-block.status-confirmed  { background: #e8f5e9; border-left-color: var(--color-success); }
.appt-block.status-in-progress{ background: #fff8e1; border-left-color: var(--color-warn); }
.appt-block.status-completed  { background: #f5f5f5; border-left-color: #bbb; opacity: .75; }
.appt-block.status-cancelled  { background: #fce4ec; border-left-color: var(--color-danger); text-decoration: line-through; opacity: .6; }

/* Bloques externos de Rodrigo (cruzados entre sedes) */
.appt-block.appt-busy-external {
  background: var(--color-busy);
  border-left-color: var(--color-busy-border);
  cursor: default;
  pointer-events: none;
  font-style: italic;
  opacity: .9;
}

.appt-time    { font-weight: 700; color: #333; }
.appt-name    { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt-dentist { color: var(--color-muted); font-size: .68rem; margin-top: 1px; }

/* ── Modal ─────────────────────────────────────── */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
}

.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-close {
  background: none; border: none; font-size: 1.1rem;
  cursor: pointer; color: var(--color-muted); padding: .25rem;
}
.modal-close:hover { color: #333; }

.modal-body { padding: 1.25rem; }

/* ── Formularios ───────────────────────────────── */

.form-group {
  margin-bottom: 1rem;
  position: relative;
}

.form-group label {
  display: block;
  font-weight: 600;
  font-size: .8rem;
  margin-bottom: .3rem;
  color: #444;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: .75rem;
}

input[type="text"], input[type="email"], input[type="password"],
input[type="date"], input[type="time"], input[type="search"],
select, textarea {
  width: 100%;
  padding: .55rem .75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: .875rem;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  color: #212529;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(0,119,182,.12);
}

.field-error {
  display: block;
  color: var(--color-danger);
  font-size: .75rem;
  margin-top: .2rem;
  min-height: 1rem;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  margin-top: 1.25rem;
}

/* ── Buttons ───────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.1rem;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s;
  line-height: 1;
}

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

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

.btn-ghost {
  background: transparent;
  border: 1px solid var(--color-border);
  color: #444;
}
.btn-ghost:hover:not(:disabled) { background: var(--color-bg); }

.btn-full { width: 100%; justify-content: center; }

/* ── Alerts ────────────────────────────────────── */

.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  font-size: .85rem;
  margin-bottom: .75rem;
}

.alert-error   { background: #fce4ec; color: #b71c1c; border: 1px solid #f8bbd0; }
.alert-success { background: #e8f5e9; color: #1b5e20; border: 1px solid #c8e6c9; }

/* ── Suggest list (autocomplete) ───────────────── */

.suggest-list {
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow);
  z-index: 100;
  max-height: 200px;
  overflow-y: auto;
}

.suggest-item {
  padding: .55rem .75rem;
  cursor: pointer;
  font-size: .875rem;
}

.suggest-item:hover { background: var(--color-bg); }
.suggest-empty { color: var(--color-muted); cursor: default; }

/* ── Patients list ─────────────────────────────── */

.patients-list {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: .75rem;
  align-content: start;
}

.patient-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: .9rem 1rem;
  box-shadow: var(--shadow);
}

.patient-name  { font-weight: 700; margin-bottom: .35rem; }
.patient-phone { color: var(--color-muted); font-size: .8rem; }
.patient-email { color: var(--color-muted); font-size: .8rem; }

/* ── Date picker ───────────────────────────────── */

.date-picker {
  padding: .45rem .75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: .875rem;
  background: #fff;
  cursor: pointer;
}

.search-input {
  padding: .45rem .75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: .875rem;
  min-width: 200px;
}

/* ── Toast ─────────────────────────────────────── */

.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.toast {
  padding: .75rem 1.25rem;
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
  font-size: .875rem;
  font-weight: 500;
  transform: translateY(20px);
  opacity: 0;
  transition: transform .25s, opacity .25s;
  max-width: 340px;
}

.toast.toast-show { transform: translateY(0); opacity: 1; }
.toast-success { background: #1b5e20; color: #fff; }
.toast-error   { background: #b71c1c; color: #fff; }
.toast-info    { background: #0d47a1; color: #fff; }

/* ── Spinner ───────────────────────────────────── */

.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}

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

/* ── Utilities ─────────────────────────────────── */

.text-muted { color: var(--color-muted); font-size: .875rem; padding: 1rem; }

/* ── Responsive ────────────────────────────────── */

@media (max-width: 768px) {
  .sidebar { width: 200px; min-width: 200px; }
  .form-row { grid-template-columns: 1fr 1fr; }
  .col-unit { min-width: 160px; }
}

@media (max-width: 540px) {
  .sidebar { display: none; }
  .form-row { grid-template-columns: 1fr; }
}
