:root {
  --orange: #d9622b;
  --orange-dark: #b94f1f;
  --gray-900: #1f2430;
  --gray-700: #4a5163;
  --gray-400: #98a0b3;
  --gray-200: #e3e6ec;
  --gray-100: #f4f5f8;
  --white: #ffffff;
  --danger: #c0392b;
  --good: #3f7d5c;
  --good-wash: #e4f1ea;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--gray-100);
  color: var(--gray-900);
}

.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}
.brand img { height: 28px; width: auto; display: block; }
.brand span { color: var(--orange); font-style: italic; }

.topbar nav {
  display: flex;
  align-items: center;
}
.topbar nav a {
  margin-left: 24px;
  text-decoration: none;
  color: var(--gray-700);
  font-weight: 600;
  font-size: 14px;
}
.topbar nav a:hover { color: var(--orange); }

.user-chip {
  margin-left: 24px;
  font-size: 13px;
  color: var(--gray-400);
  background: var(--gray-100);
  padding: 5px 12px;
  border-radius: 20px;
}

.auth-body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-100);
  font-family: "Segoe UI", Arial, sans-serif;
}
.auth-box {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 32px;
  width: 360px;
  max-width: 90vw;
  box-shadow: 0 6px 24px rgba(0,0,0,0.06);
}
.auth-box h2 { text-align: center; margin-top: 4px; }
.auth-box label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-700);
  margin: 14px 0 4px;
}
.auth-box input, .auth-box select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: 14px;
}
.brand.center { display: flex; justify-content: center; margin-bottom: 4px; }
.brand.center img { height: 48px; width: auto; }
.btn-primary.full { width: 100%; margin-top: 20px; padding: 11px; }

.pasos { line-height: 1.9; padding-left: 20px; }
.pasos code, .card code {
  background: var(--gray-100);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 13px;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.footer {
  text-align: center;
  color: var(--gray-400);
  font-size: 12px;
  padding: 20px;
}

.flash {
  background: #fff3cd;
  border: 1px solid #ffe08a;
  color: #7a5c00;
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 24px;
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
}

.layout-paciente {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  align-items: start;
}
@media (max-width: 900px) {
  .layout-paciente { grid-template-columns: 1fr; }
}

.historial-col .card { position: sticky; top: 20px; max-height: calc(100vh - 40px); overflow-y: auto; }
.historial-lista { display: flex; flex-direction: column; gap: 10px; }
.historial-item {
  border: 1px solid var(--gray-200);
  border-left: 4px solid var(--orange);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fdf6f1;
}
.historial-item.estado-disponible { border-left-color: var(--gray-400); background: var(--gray-100); }
.historial-item.estado-atendido,
.historial-item.estado-atencion_sin_cita { border-left-color: var(--good); background: var(--good-wash); }
.historial-item.estado-no_asistio,
.historial-item.estado-no_responde { border-left-color: var(--danger); background: #fceceb; }
.historial-item.estado-cancelado { border-left-color: var(--gray-400); background: var(--gray-100); opacity: 0.8; }
.historial-item.estado-reprogramado { border-left-color: var(--orange); background: #fdf1e6; }

.historial-fecha { font-size: 11px; font-weight: 700; color: var(--gray-400); text-transform: uppercase; }
.historial-doctor { font-size: 13.5px; font-weight: 600; margin-top: 2px; }
.historial-detalle { font-size: 12px; color: var(--gray-700); margin-top: 2px; }
.historial-notas { font-size: 12px; color: var(--gray-400); font-style: italic; margin-top: 4px; }
.historial-item .tag { margin-top: 6px; margin-right: 4px; display: inline-block; }

.sidebar {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px;
  height: fit-content;
}
.sidebar h3 { margin-top: 0; font-size: 13px; text-transform: uppercase; color: var(--gray-400); }

.cat-list { list-style: none; margin: 0; padding: 0; }
.cat-list a {
  display: flex;
  justify-content: space-between;
  text-decoration: none;
  color: var(--gray-700);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 2px;
}
.cat-list a:hover { background: var(--gray-100); }
.cat-list a.active { background: var(--orange); color: var(--white); }
.badge {
  background: var(--gray-200);
  color: var(--gray-700);
  border-radius: 20px;
  padding: 1px 8px;
  font-size: 12px;
}
.cat-list a.active .badge { background: rgba(255,255,255,0.3); color: var(--white); }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.search { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filtro-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--gray-700);
  white-space: nowrap;
  background: var(--gray-100);
  padding: 9px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.filtro-check input { width: auto; margin: 0; }
.search input {
  padding: 9px 12px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  min-width: 260px;
  font-size: 14px;
}
.search button {
  padding: 9px 16px;
  border: 1px solid var(--gray-200);
  background: var(--white);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

.btn-primary, .btn-secondary, .btn-danger {
  border: none;
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--orange); color: var(--white); }
.btn-primary:hover { background: var(--orange-dark); }
.btn-secondary { background: var(--gray-200); color: var(--gray-900); }
.btn-danger { background: #fceceb; color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: var(--white); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.tabla {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
}
.tabla th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--gray-400);
  padding: 12px 14px;
  border-bottom: 1px solid var(--gray-200);
}
.tabla td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--gray-100);
  font-size: 14px;
}
.tabla tbody tr[onclick] { cursor: pointer; }
.tabla tbody tr[onclick]:hover { background: var(--gray-100); }
.fila-tratamiento.seleccionada { background: #fceceb; outline: 2px solid var(--danger); }
.tabla .nombre { font-weight: 600; }
.tabla .empty { text-align: center; color: var(--gray-400); padding: 40px; }
.tabla .acciones { display: flex; gap: 8px; }

.tag {
  background: #fdece2;
  color: var(--orange-dark);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.card h3 { margin-top: 0; }
.card h4 { margin-bottom: 8px; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.grid-2 .span-2 { grid-column: 1 / -1; }
.grid-2 label, .card label, .modal-box label {
  display: block;
  font-size: 12px;
  color: var(--gray-700);
  margin-bottom: 4px;
  font-weight: 600;
}
.grid-2 input, .grid-2 select, .grid-2 textarea,
.modal-box input, .modal-box select, .modal-box textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}

.upload-form {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 10px;
}
.upload-form select { padding: 9px; border-radius: 6px; border: 1px solid var(--gray-200); }

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

.tratamientos-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 40px;
  flex-wrap: wrap;
  gap: 10px;
}

.producto-card {
  position: relative;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  text-align: left;
}
.producto-img {
  width: 100%;
  height: 90px;
  background: var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}
.producto-img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.producto-img-vacia { color: var(--gray-400); font-size: 13px; }
.producto-info { padding: 14px 16px; }
.producto-info h4 { margin: 0 0 4px; font-size: 15px; }
.producto-info p { margin: 0 0 4px; font-size: 13px; color: var(--gray-700); }
.producto-precio { font-weight: 700; color: var(--orange-dark); font-size: 14px !important; }
.producto-editar-btn { margin-top: 8px; }

.producto-item.seleccionada { outline: 2px solid var(--danger); }
#productos-grid.modo-eliminar .producto-item { cursor: pointer; }
#productos-grid.modo-eliminar .producto-item:hover { outline: 2px solid var(--gray-400); }
#productos-grid.modo-eliminar .producto-editar-btn { display: none; }

.producto-add {
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 220px;
  background: var(--gray-100);
  border: 2px dashed var(--gray-200);
  color: var(--gray-700);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
.producto-add:hover { border-color: var(--orange); color: var(--orange); }
.producto-add-icono { font-size: 30px; line-height: 1; color: var(--orange); }

.presupuesto-item-row {
  display: grid;
  grid-template-columns: 1fr 70px 110px 32px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.presupuesto-item-row input {
  padding: 8px 10px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: 13px;
}

.back-link { text-decoration: none; color: var(--gray-700); font-size: 14px; }

.ficha-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin: 10px 0 20px;
}
.ficha-meta { color: var(--gray-400); font-size: 13px; }

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.plantilla-botones { display: flex; flex-direction: column; gap: 8px; }
.btn-plantilla {
  display: block;
  text-align: center;
  text-decoration: none;
  padding: 12px 16px;
}
.plantilla-idioma {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 -2px;
  color: var(--gray-400);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.plantilla-idioma::before,
.plantilla-idioma::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--gray-200);
}
.plantilla-botones > .plantilla-idioma:first-child { margin-top: 0; }

.plantillas-acciones { display: flex; gap: 8px; flex-wrap: wrap; }

.plantillas-grid.modo-eliminar .plantilla-item,
#plantillas-grid.modo-eliminar .plantilla-item {
  cursor: pointer;
  background: var(--white);
  color: var(--gray-900);
  border: 2px solid var(--gray-200);
}
#plantillas-grid.modo-eliminar .plantilla-item:hover { border-color: var(--danger); }
#plantillas-grid.modo-eliminar .plantilla-item.seleccionada {
  background: #fceceb;
  border-color: var(--danger);
  color: var(--danger);
  font-weight: 700;
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal.open { display: flex; }
.modal-box {
  background: var(--white);
  border-radius: var(--radius);
  padding: 24px;
  width: 420px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
}
.modal-box h3 { margin-top: 0; }
.modal-box label { margin-top: 10px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

/* ---------- Agenda ---------- */
.agenda-fecha-titulo { color: var(--orange); font-weight: 700; font-size: 16px; margin-top: 2px; }
.agenda-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.agenda-fecha-form input[type="date"] {
  padding: 8px 10px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: 13px;
}

.agenda-tabla-wrap {
  overflow-x: auto;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: var(--white);
}

.agenda-tabla-horario {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  table-layout: fixed;
}
.agenda-tabla-horario th {
  position: sticky;
  top: 0;
  background: var(--gray-100);
  padding: 10px 12px;
  font-size: 13px;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
  z-index: 1;
}
.agenda-tabla-horario .col-hora {
  width: 64px;
  font-size: 11px;
  color: var(--gray-400);
  text-align: right;
  padding-right: 8px;
  vertical-align: top;
  white-space: nowrap;
  border-right: 1px solid var(--gray-200);
}
.agenda-tabla-horario tr.franja-en-punto .col-hora { padding-top: 2px; }
.agenda-tabla-horario td { border-bottom: 1px solid var(--gray-100); }
.agenda-tabla-horario tr.franja-en-punto td { border-bottom: 1px solid var(--gray-200); }
.agenda-tabla-horario tr td.col-hora { border-bottom: none; }

.celda-libre {
  height: 26px;
  cursor: pointer;
}
.celda-libre:hover { background: var(--gray-100); }

.celda-cita-wrap {
  vertical-align: top;
  padding: 3px 5px;
  cursor: pointer;
}

.celda-cita {
  padding: 6px 8px;
  border-left: 4px solid var(--orange);
  background: #fdf6f1;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  height: 100%;
  box-sizing: border-box;
}
.celda-cita-wrap:hover .celda-cita { filter: brightness(0.98); }
.celda-cita.estado-disponible { border-left-color: var(--gray-400); background: var(--gray-100); }
.celda-cita.estado-atendido { border-left-color: var(--good); background: var(--good-wash); }
.celda-cita.estado-atencion_sin_cita { border-left-color: var(--good); background: var(--good-wash); }
.celda-cita.estado-no_asistio { border-left-color: var(--danger); background: #fceceb; opacity: 0.85; }
.celda-cita.estado-cancelado { border-left-color: var(--gray-400); background: var(--gray-100); opacity: 0.7; }
.celda-cita.estado-reprogramado { border-left-color: var(--orange); background: #fdf1e6; opacity: 0.85; }
.celda-cita.estado-no_responde { border-left-color: var(--danger); background: #fceceb; opacity: 0.85; }

.mini-calendario-panel {
  display: none;
  gap: 24px;
  flex-wrap: wrap;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px;
  margin: 10px 0 16px;
}
.mini-calendario-panel.open { display: flex; }
.mini-calendario-tabla { border-collapse: collapse; }
.mini-calendario-tabla th { font-size: 11px; color: var(--gray-400); padding: 4px 8px; font-weight: 600; }
.mini-calendario-tabla td { text-align: center; padding: 2px; }
.mini-calendario-tabla td a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: 34px; height: 38px; border-radius: 6px; text-decoration: none; color: var(--gray-700);
  padding-top: 3px;
}
.mini-calendario-tabla td a:hover { background: var(--gray-100); }
.mini-dia-fuera a { color: var(--gray-400); opacity: 0.5; }
.mini-dia-hoy a { font-weight: 700; color: var(--orange); }
.mini-dia-sel a { background: var(--orange); color: var(--white) !important; }
.mini-dia-num { font-size: 12.5px; }
.mini-dia-puntos { display: flex; gap: 2px; }
.mini-dia-punto { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.mini-dia-punto.ausente { background: var(--gray-400) !important; opacity: 0.4; }
.mini-calendario-checks { min-width: 200px; }

.cita-hora { font-size: 11px; font-weight: 700; color: var(--gray-400); text-transform: uppercase; }
.cita-paciente { font-size: 13.5px; font-weight: 600; margin-top: 2px; }
.cita-detalle { font-size: 12px; color: var(--gray-700); margin-top: 2px; }
.cita-disponible { font-size: 13px; color: var(--gray-400); font-style: italic; margin-top: 2px; }

.celda-cita.celda-almuerzo {
  border-left-color: #e6b800;
  background: #fff9db;
  text-align: center;
}
.cita-almuerzo {
  font-size: 14px;
  font-weight: 700;
  color: #8a6d00;
  text-align: center;
  padding: 6px 0;
}

.tag-nuevo { background: var(--orange); color: var(--white); margin-left: 4px; }
.tag-pendiente { background: var(--gray-200); color: var(--gray-700); margin-left: 4px; }
.tag-confirmado { background: #fff3cd; color: #8a6d00; margin-left: 4px; }
.tag-ok { background: var(--good-wash); color: var(--good); margin-top: 4px; display: inline-block; }
.tag-bad { background: #fceceb; color: var(--danger); margin-top: 4px; display: inline-block; }
.tag-estado-atendido { background: var(--good-wash); color: var(--good); margin-top: 4px; display: inline-block; }
.tag-estado-atencion_sin_cita { background: var(--good-wash); color: var(--good); margin-top: 4px; display: inline-block; }
.tag-estado-no_asistio { background: #fceceb; color: var(--danger); margin-top: 4px; display: inline-block; }
.tag-estado-cancelado { background: var(--gray-200); color: var(--gray-700); margin-top: 4px; display: inline-block; }
.tag-estado-reprogramado { background: #fdf1e6; color: var(--orange-dark); margin-top: 4px; display: inline-block; }
.tag-estado-no_responde { background: #fceceb; color: var(--danger); margin-top: 4px; display: inline-block; }

.reporte-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.reporte-tile {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.reporte-tile-label { font-size: 12px; color: var(--gray-400); text-transform: uppercase; letter-spacing: 0.04em; }
.reporte-tile-valor { font-size: 26px; font-weight: 700; margin-top: 6px; }
.reporte-tile.destacado { background: var(--orange); border-color: var(--orange); }
.reporte-tile.destacado .reporte-tile-label { color: rgba(255,255,255,0.85); }
.reporte-tile.destacado .reporte-tile-valor { color: var(--white); }
.reporte-tile.alerta .reporte-tile-valor { color: var(--danger); }

.fila-efectivo-ok { background: var(--good-wash); }

/* Barras horizontales (reportes) */
.barra-fila { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.barra-label { width: 130px; font-size: 13px; color: var(--gray-700); flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barra-track { flex: 1; height: 14px; background: var(--gray-100); border-radius: 7px; overflow: hidden; }
.barra-fill { height: 100%; background: var(--orange); border-radius: 7px; }
.barra-valor { width: 90px; text-align: right; font-size: 13px; font-weight: 600; flex-shrink: 0; }

/* Histórico mensual (barras verticales) */
.historico-chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; }
.historico-barra { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.historico-barra-valor { font-size: 10px; color: var(--gray-400); margin-bottom: 4px; white-space: nowrap; }
.historico-barra-rect { width: 100%; background: var(--orange); border-radius: 4px 4px 0 0; min-height: 2px; }
.historico-barra-mes { font-size: 11px; color: var(--gray-700); margin-top: 6px; }

/* Metas mensuales (anillos) */
.metas-wrap { display: flex; gap: 32px; flex-wrap: wrap; align-items: center; }
.meta-ring {
  width: 110px; height: 110px; border-radius: 50%;
  background: conic-gradient(var(--orange) calc(var(--pct, 0) * 1%), var(--gray-200) 0);
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.meta-ring::before {
  content: ""; position: absolute; width: 80px; height: 80px; border-radius: 50%; background: var(--white);
}
.meta-ring-valor { position: relative; font-size: 20px; font-weight: 700; }
.meta-box { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.meta-box-label { font-size: 13px; font-weight: 600; color: var(--gray-700); }
.meta-box-detalle { font-size: 12px; color: var(--gray-400); }

.reporte-tablas {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.sugerencias {
  position: relative;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  margin-top: -1px;
  max-height: 160px;
  overflow-y: auto;
  background: var(--white);
}
.sugerencias:empty { border: none; }
.sugerencia { padding: 8px 10px; font-size: 13px; cursor: pointer; }
.sugerencia:hover { background: var(--gray-100); }

.productos-cita-lista { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.producto-cita-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--gray-100);
  border-radius: 6px;
  padding: 6px 8px;
}
.producto-cita-nombre { flex: 1; font-size: 13px; }
.producto-cita-cant {
  width: 50px; padding: 5px 6px; border: 1px solid var(--gray-200); border-radius: 6px; font-size: 12px;
}
.producto-cita-precio {
  width: 80px; padding: 5px 6px; border: 1px solid var(--gray-200); border-radius: 6px; font-size: 12px;
}

.cita-productos { margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px; }
.cita-productos .tag { background: var(--gray-200); color: var(--gray-700); font-size: 11px; padding: 2px 8px; }

/* ---------- Celular ---------- */
@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: center;
    padding: 12px 16px;
  }
  .topbar nav {
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px 14px;
    margin-top: 10px;
  }
  .topbar nav a { margin-left: 0; }
  .user-chip { margin-left: 0; }

  .container { padding: 16px 14px 40px; }

  .ficha-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .agenda-nav { justify-content: center; }

  .toolbar { justify-content: center; text-align: center; }
  .search { justify-content: center; }

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