/* Esteticdeux - Estilos principales (paleta Esthetic Deux, diseño suave) */
:root {
  --sidebar-width: 260px;
  --header-height: 56px;
  --color-primary: #0d9488;
  --color-primary-dark: #0f766e;
  --color-bg: #f1f5f9;
  --color-sidebar: #0f766e;
  --color-card: #fff;
  --shadow: 0 1px 3px rgba(0,0,0,.06);
  --shadow-soft: 0 4px 14px rgba(0,0,0,.06);
  --radius: 12px;
  --radius-sm: 10px;
  --border: 1px solid rgba(0,0,0,.06);
  --input-border: 1px solid #e2e8f0;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--color-bg);
  color: #475569;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, #0f766e 0%, #0d5c55 100%);
  color: #e2e8f0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-soft);
}
.sidebar-brand {
  padding: 1.35rem 1.5rem;
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: .02em;
}
.sidebar-brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.sidebar-brand-row .sidebar-brand {
  border-bottom: none;
  flex: 1;
}
.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.75rem;
  line-height: 1;
  padding: .5rem 1rem;
  cursor: pointer;
  opacity: .85;
}
.sidebar-close:hover { opacity: 1; }
.sidebar-overlay {
  display: none;
}
.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 42px;
  height: 42px;
  padding: 10px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}
.nav-toggle-bar {
  display: block;
  height: 2px;
  width: 100%;
  background: #0f766e;
  border-radius: 2px;
}
.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: .75rem;
  min-width: 0;
}
.header-brand {
  display: none;
  font-weight: 700;
  color: #0f766e;
  font-size: 1.05rem;
}
.header-user {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 42vw;
}
.sidebar-nav { flex: 1; padding: .75rem 0; overflow-y: auto; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .7rem 1.5rem;
  margin: 0 .5rem;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.8);
  text-decoration: none;
  transition: background .2s, color .2s;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.1); color: #fff; }
.sidebar-nav a.active { background: rgba(255,255,255,.2); color: #fff; }
.sidebar-nav .icon { width: 1.25rem; height: 1.25rem; opacity: .9; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.header {
  height: var(--header-height);
  background: var(--color-card);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  border-bottom: var(--border);
}
.content { flex: 1; padding: 1.75rem; }

/* Colores del logo Esthetic Deux - teal/verde menta */
:root {
  --esthetic-teal: #0d9488;
  --esthetic-teal-light: #14b8a6;
  --esthetic-teal-dark: #0f766e;
  --esthetic-input-bg: #fef9c3;
  --esthetic-text-dark: #1f2937;
  --esthetic-gray-line: #9ca3af;
}

/* Página de login - Esthetic Deux */
.login-page .login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e5e7eb;
}
.login-page .login-box {
  position: relative;
  background: #fff;
  padding: 2.5rem;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,.08);
  width: 100%;
  max-width: 400px;
  overflow: hidden;
}
.login-deco {
  position: absolute;
  top: -60px;
  right: -60px;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(13, 148, 136, .25) 0%, rgba(255,255,255,0) 70%);
  pointer-events: none;
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.75rem;
}
.login-logo-figure {
  width: 48px;
  height: 96px;
  color: var(--esthetic-teal);
  flex-shrink: 0;
}
.login-logo-figure svg {
  width: 100%;
  height: 100%;
  display: block;
}
.login-logo-divider {
  width: 1px;
  height: 56px;
  background: var(--esthetic-gray-line);
  flex-shrink: 0;
}
.login-logo-text {
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.login-logo-brand {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--esthetic-text-dark);
  letter-spacing: .02em;
}
.login-logo-tagline {
  font-size: .875rem;
  color: var(--esthetic-teal);
  font-weight: 500;
}
.login-page .form-group { margin-bottom: 1.25rem; }
.login-page .form-group label { display: block; margin-bottom: .4rem; font-weight: 500; color: var(--esthetic-text-dark); }
.login-page .form-group input {
  width: 100%;
  padding: .65rem .85rem;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 1rem;
  background: var(--esthetic-input-bg);
}
.login-page .form-group input:focus {
  outline: none;
  border-color: var(--esthetic-teal);
  box-shadow: 0 0 0 2px rgba(13, 148, 136, .2);
}
.login-page .btn-login {
  width: 100%;
  padding: .75rem 1.25rem;
  font-size: .95rem;
  font-weight: 600;
  letter-spacing: .04em;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: var(--esthetic-teal);
  color: #fff;
  transition: background .2s, transform .05s;
}
.login-page .btn-login:hover { background: var(--esthetic-teal-dark); }
.login-page .btn-login:active { transform: scale(0.98); }
.login-page .alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.login-page .alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }

/* Botones y formularios generales (resto de la app) - diseño suave */
.form-group { margin-bottom: 1.35rem; }
.form-group label { display: block; margin-bottom: .45rem; font-weight: 500; color: #475569; font-size: .9375rem; }
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: .65rem .85rem;
  border: var(--input-border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  background: #fff;
  transition: border-color .2s, box-shadow .2s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, .12);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: .65rem 1.35rem;
  font-size: .9375rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .2s, transform .05s, box-shadow .2s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); box-shadow: 0 4px 12px rgba(13, 148, 136, .35); }
.alert { padding: .85rem 1.1rem; border-radius: var(--radius-sm); margin-bottom: 1.25rem; font-size: .9375rem; }
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }

/* Cards y tablas - más suaves */
.page-title { margin: 0 0 1.5rem; font-size: 1.5rem; font-weight: 600; color: #334155; letter-spacing: -.02em; }
.card {
  background: var(--color-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 1.75rem;
  margin-bottom: 1.5rem;
  border: var(--border);
}
.table-wrap {
  overflow: auto;
  border-radius: var(--radius-sm);
  max-height: 55vh;
}
.table-wrap table { width: 100%; border-collapse: collapse; }
.table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--color-card);
  box-shadow: 0 1px 0 0 #f1f5f9;
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: .75rem 1rem; text-align: left; border-bottom: 1px solid #f1f5f9; }
th { font-weight: 600; color: #64748b; font-size: .8125rem; text-transform: uppercase; letter-spacing: .04em; }
tbody tr { transition: background .15s; }
tbody tr:hover td { background: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }
.btn-sm { padding: .4rem .75rem; font-size: .875rem; border-radius: 8px; }
.btn-secondary { background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; }
.btn-secondary:hover { background: #e2e8f0; color: #334155; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* FullCalendar - integrado en calendario.php */
.calendar-wrapper { margin-top: 1rem; }
.calendar-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; flex-wrap: wrap; gap: .5rem; }
/* Overrides FullCalendar para paleta Esthetic Deux */
.fc { --fc-border-color: #e2e8f0; --fc-button-bg-color: var(--color-primary); --fc-button-border-color: var(--color-primary); --fc-button-hover-bg-color: var(--color-primary-dark); --fc-button-hover-border-color: var(--color-primary-dark); --fc-event-bg-color: #0d9488; --fc-event-border-color: #0f766e; }
.fc .fc-toolbar-title { font-size: 1.35rem; font-weight: 600; color: #334155; }
.fc .fc-button { border-radius: var(--radius-sm); font-weight: 500; padding: .5rem 1rem; }
.fc .fc-daygrid-day-number { color: #64748b; font-size: .875rem; padding: .35rem; }
.fc .fc-col-header-cell-cushion { padding: .5rem; color: #64748b; font-size: .75rem; font-weight: 600; text-transform: uppercase; }
.fc .fc-scrollgrid { border-radius: var(--radius-sm); overflow: hidden; }
.fc-theme-standard td, .fc-theme-standard th { border-color: #f1f5f9; }
.fc .fc-daygrid-event { border-radius: 6px; padding: 2px 6px; }
.fc .fc-event-title { font-size: .8125rem; }

/* Formulario Nuevo Paciente */
.card-form-paciente .card-title-paciente {
  margin: 0 0 1rem;
  padding: .75rem 1rem;
  background: var(--esthetic-teal, #0d9488);
  color: #fff;
  border-radius: var(--radius);
  font-size: 1.1rem;
}
.form-row { display: flex; gap: 1rem; }
.form-row .form-group { flex: 1; }
.req { color: #dc2626; }
.radio-group { display: flex; gap: 1.5rem; margin-top: .25rem; }
.radio-label { display: inline-flex; align-items: center; gap: .5rem; font-weight: normal; cursor: pointer; }
.historia-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
}
.historia-actions input { flex: 1; min-width: 120px; }
.validar-msg { display: block; margin-top: .35rem; font-size: .875rem; }
.validar-msg.ok { color: #059669; }
.validar-msg.error { color: #dc2626; }
.form-actions { margin-top: 1.25rem; display: flex; gap: .5rem; }

/* Ingreso de tratamiento - buscador paciente */
.ingreso-tratamiento-buscador .form-group { margin-bottom: 0; }
.buscador-wrap { position: relative; max-width: 420px; }
.buscador-resultados {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  margin-top: 2px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-soft);
  max-height: 280px;
  overflow-y: auto;
  z-index: 10;
  display: none;
}
.buscador-resultados.open { display: block; }
.buscador-item {
  padding: .6rem .85rem;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  font-size: .9375rem;
}
.buscador-item:last-child { border-bottom: none; }
.buscador-item:hover { background: #f1f5f9; }
.buscador-item-empty { color: #64748b; cursor: default; }

.form-grid-ingreso {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem 1.25rem;
}
.form-grid-ingreso .form-group-full { grid-column: 1 / -1; }
.tabla-ingreso-tratamiento { font-size: .875rem; }
.tabla-ingreso-tratamiento th, .tabla-ingreso-tratamiento td { padding: .5rem .6rem; }

/* Modal día vencimiento cuotas */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-box {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0,0,0,.2);
  padding: 1.75rem;
  max-width: 380px;
  width: 100%;
}
.modal-actions { margin-top: 1.25rem; display: flex; gap: .5rem; }
.btn-cerrar-modal {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: #64748b;
  cursor: pointer;
  padding: 0 .25rem;
}
.btn-cerrar-modal:hover { color: #0f766e; }
.modal-movimientos .table-wrap { max-height: 60vh; overflow: auto; }
.modal-movimientos .table-wrap thead th { background: #fff; }
.pago-deuda-info { color: var(--color-primary-dark); font-size: .9375rem; }

/* Pagos - buscador y total deuda */
.pagos-buscador-cliente .buscador-wrap { max-width: 420px; }
.pagos-total-deuda { margin: .5rem 0 1rem; padding: .5rem 0; font-size: 1.1rem; color: var(--color-primary-dark); }
.pagos-total-deuda strong { color: #0f766e; }
.pagos-tratamiento-deshabilitado .pagos-tratamiento-fijo {
  display: block;
  padding: .65rem .85rem;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  color: #64748b;
  pointer-events: none;
}
.pagos-tratamiento-deshabilitado .pagos-tratamiento-fijo strong { color: #475569; }

/* Cuotas del tratamiento (Pagos) */
.tabla-cuotas .form-editar-cuota { margin: 0; }
.tabla-cuotas input[name="monto_pagado"] { text-align: right; }
.estado-cuota {
  display: inline-block;
  padding: .2rem .5rem;
  border-radius: 6px;
  font-size: .8125rem;
  font-weight: 500;
}
.estado-cuota.estado-pagada { background: #dcfce7; color: #166534; }
.estado-cuota.estado-parcial { background: #fffbeb; color: #b45309; }
.estado-cuota.estado-pendiente { background: #f1f5f9; color: #64748b; }

/* Informe mensual */
.informe-mensual-card { max-width: 100%; }
.informe-mensual-header { margin-bottom: 1rem; padding-bottom: 1rem; border-bottom: 1px solid #e2e8f0; }
.informe-totales { display: flex; gap: 2rem; margin: 0.5rem 0 0; font-size: 1.1rem; }
.informe-totales strong { color: var(--color-primary-dark); }
.informe-filtros { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.informe-filtros label { margin-right: 0.25rem; }
.informe-export-search { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem; }
.informe-search input[type="text"] { width: 200px; }
.tabla-informe th { white-space: nowrap; }
.tabla-informe td:nth-child(6), .tabla-informe td:nth-child(7) { text-align: right; }

/* Utilidades */
.mb-0 { margin-bottom: 0; }
.mt-1 { margin-top: .5rem; }
.text-muted { color: #64748b; font-size: .875rem; }

.toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1rem;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 768px) {
  .form-grid-2 { grid-template-columns: 1fr; }
}
.buscador-input,
#buscador-clientes {
  width: 100%;
  max-width: 320px;
  min-width: 0 !important;
  padding: .5rem .85rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: .9rem;
  outline: none;
}

/* ========== Responsive: tablet y móvil ========== */
@media (max-width: 992px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1200;
    width: min(86vw, 300px);
    max-width: 300px;
    transform: translateX(-105%);
    transition: transform .25s ease;
    box-shadow: none;
  }
  .app.sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: 8px 0 28px rgba(0,0,0,.22);
  }
  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: rgba(15, 23, 42, .45);
    border: 0;
    padding: 0;
    margin: 0;
    cursor: pointer;
  }
  .sidebar-overlay[hidden] { display: none !important; }
  .sidebar-close { display: block; }
  .nav-toggle { display: inline-flex; }
  .header-brand { display: inline-block; }
  .header {
    padding: 0 .85rem;
    gap: .5rem;
    position: sticky;
    top: 0;
    z-index: 50;
  }
  .content { padding: 1rem; }
  .page-title { font-size: 1.25rem; margin-bottom: 1rem; }
  .card { padding: 1.15rem; margin-bottom: 1rem; }
  body.nav-locked { overflow: hidden; }
  .sidebar-nav a {
    padding: .8rem 1.15rem;
    min-height: 44px;
  }
}

@media (max-width: 768px) {
  .header-role { display: none; }
  .header-user { max-width: 28vw; font-size: .8rem; }
  .form-row { flex-direction: column; gap: 0; }
  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .form-actions .btn { width: 100%; }
  .historia-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .historia-actions .btn { width: 100%; }
  .radio-group { flex-wrap: wrap; gap: .85rem 1.25rem; }
  .table-wrap {
    max-height: none;
    margin: 0 -.25rem;
    -webkit-overflow-scrolling: touch;
  }
  .table-wrap table {
    min-width: 640px;
  }
  th, td { padding: .65rem .7rem; }
  .actions { gap: .4rem; }
  .btn { min-height: 42px; }
  .btn-sm { min-height: 36px; }
  .buscador-wrap { max-width: none; }
  .buscador-input,
  #buscador-clientes { max-width: none; }
  .informe-totales {
    flex-direction: column;
    gap: .35rem;
    font-size: 1rem;
  }
  .informe-export-search,
  .informe-filtros {
    flex-direction: column;
    align-items: stretch;
  }
  .informe-search input[type="text"] { width: 100%; }
  .login-page .login-wrap { padding: 1rem; align-items: flex-start; padding-top: 2.5rem; }
  .login-page .login-box { padding: 1.5rem 1.15rem; max-width: 100%; }
  .login-logo { gap: .75rem; margin-bottom: 1.25rem; }
  .login-logo-figure { width: 40px; height: 80px; }
  .login-logo-brand { font-size: 1.25rem; }
  .fc .fc-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: .5rem;
  }
  .fc .fc-toolbar-title { font-size: 1.1rem; }
  .fc .fc-button { padding: .45rem .7rem; }
  .modal-box { padding: 1.25rem; max-width: 100%; }
  .form-grid-ingreso {
    grid-template-columns: 1fr 1fr;
  }
  /* Grids inline frecuentes */
  .card form[style*="max-width"] { max-width: 100% !important; }
}

@media (max-width: 480px) {
  .content { padding: .75rem; }
  .card { padding: .9rem; border-radius: 10px; }
  .page-title { font-size: 1.15rem; }
  .header-brand { font-size: .95rem; }
  .header-user { display: none; }
  .form-grid-ingreso { grid-template-columns: 1fr; }
  .card-form-paciente .card-title-paciente {
    font-size: 1rem;
    padding: .65rem .85rem;
  }
  .login-logo-divider { display: none; }
}

/* Safe area (notch / home indicator) */
@supports (padding: env(safe-area-inset-bottom)) {
  .sidebar {
    padding-bottom: env(safe-area-inset-bottom);
  }
  .header {
    padding-left: max(.85rem, env(safe-area-inset-left));
    padding-right: max(.85rem, env(safe-area-inset-right));
  }
  @media (max-width: 992px) {
    .content {
      padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
  }
}
