:root,
[data-theme="verde"] {
  --ink: #1a2e2a;
  --ink-soft: #3d5a52;
  --muted: #6b857c;
  --line: rgba(26, 46, 42, 0.12);
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #f4faf7;
  --accent: #1f7a65;
  --accent-deep: #145a4b;
  --accent-mid: #2a9d7c;
  --accent-soft: #d4efe6;
  --warn: #b45309;
  --danger: #b42318;
  --ok: var(--accent);
  --online: #22c55e;
  --radius: 14px;
  --shadow: 0 18px 40px rgba(20, 50, 42, 0.08);
  --shadow-accent: 0 8px 20px rgba(31, 122, 101, 0.35);
  --shadow-accent-sm: 0 6px 16px rgba(31, 122, 101, 0.3);
  --shadow-accent-btn: 0 6px 16px rgba(31, 122, 101, 0.28);
  --glow-1: #c8e8dc;
  --glow-2: #a8d4c8;
  --bg-1: #e8f5f0;
  --bg-2: #dceee8;
  --bg-3: #cfe6df;
  --font: "Manrope", system-ui, sans-serif;
  --display: "Sora", system-ui, sans-serif;
  --theme-color: #1f7a65;
}

[data-theme="rosado"] {
  --ink: #2e1a22;
  --ink-soft: #5a3d48;
  --muted: #85706b;
  --line: rgba(46, 26, 34, 0.12);
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #faf4f6;
  --accent: #b85a7a;
  --accent-deep: #8f3d5a;
  --accent-mid: #d4789a;
  --accent-soft: #f5d6e0;
  --warn: #b45309;
  --danger: #b42318;
  --ok: var(--accent);
  --online: #22c55e;
  --shadow: 0 18px 40px rgba(50, 20, 32, 0.08);
  --shadow-accent: 0 8px 20px rgba(184, 90, 122, 0.35);
  --shadow-accent-sm: 0 6px 16px rgba(184, 90, 122, 0.3);
  --shadow-accent-btn: 0 6px 16px rgba(184, 90, 122, 0.28);
  --glow-1: #e8c8d4;
  --glow-2: #d4a8bc;
  --bg-1: #f5e8ee;
  --bg-2: #eedce4;
  --bg-3: #e6cfd8;
  --theme-color: #b85a7a;
}

[data-theme="amarillo"] {
  --ink: #2e2a1a;
  --ink-soft: #5a523d;
  --muted: #857c6b;
  --line: rgba(46, 42, 26, 0.12);
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #faf8f4;
  --accent: #b8860b;
  --accent-deep: #8a6508;
  --accent-mid: #d4a017;
  --accent-soft: #f5e6c8;
  --warn: #b45309;
  --danger: #b42318;
  --ok: var(--accent);
  --online: #22c55e;
  --shadow: 0 18px 40px rgba(50, 42, 20, 0.08);
  --shadow-accent: 0 8px 20px rgba(184, 134, 11, 0.35);
  --shadow-accent-sm: 0 6px 16px rgba(184, 134, 11, 0.3);
  --shadow-accent-btn: 0 6px 16px rgba(184, 134, 11, 0.28);
  --glow-1: #e8dcc8;
  --glow-2: #d4c4a8;
  --bg-1: #f5f0e8;
  --bg-2: #eee8dc;
  --bg-3: #e6dfcf;
  --theme-color: #b8860b;
}

[data-theme="celeste"] {
  --ink: #1a242e;
  --ink-soft: #3d4d5a;
  --muted: #6b7a85;
  --line: rgba(26, 36, 46, 0.12);
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #f4f8fa;
  --accent: #1f6f8a;
  --accent-deep: #145066;
  --accent-mid: #2a9db8;
  --accent-soft: #d4eaf0;
  --warn: #b45309;
  --danger: #b42318;
  --ok: var(--accent);
  --online: #22c55e;
  --shadow: 0 18px 40px rgba(20, 40, 50, 0.08);
  --shadow-accent: 0 8px 20px rgba(31, 111, 138, 0.35);
  --shadow-accent-sm: 0 6px 16px rgba(31, 111, 138, 0.3);
  --shadow-accent-btn: 0 6px 16px rgba(31, 111, 138, 0.28);
  --glow-1: #c8dce8;
  --glow-2: #a8c8d4;
  --bg-1: #e8f2f5;
  --bg-2: #dce8ee;
  --bg-3: #cfdfe6;
  --theme-color: #1f6f8a;
}

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

html {
  font-size: 16px;
}

body {
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 60% at 10% 0%, var(--glow-1) 0%, transparent 55%),
    radial-gradient(ellipse 70% 50% at 100% 20%, var(--glow-2) 0%, transparent 50%),
    linear-gradient(165deg, var(--bg-1) 0%, var(--bg-2) 40%, var(--bg-3) 100%);
  background-attachment: fixed;
  transition: color 0.25s ease, background 0.35s ease;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* Sidebar */
.sidebar {
  padding: 2rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.35);
  backdrop-filter: blur(12px);
  animation: fadeSlide 0.5s ease both;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background:
    linear-gradient(135deg, var(--accent) 0%, var(--accent-mid) 100%);
  box-shadow: var(--shadow-accent);
  position: relative;
  flex-shrink: 0;
}

.brand-mark.hidden {
  display: none;
}

.brand-logo {
  width: auto;
  height: 52px;
  max-width: 150px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 8px;
  background: #fff;
  padding: 4px 6px;
}

.brand-logo.hidden {
  display: none;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 11px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  border-top-color: transparent;
}

.brand-name {
  font-family: var(--display);
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.brand-sub {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-btn {
  text-align: left;
  background: transparent;
  border: none;
  padding: 0.7rem 1rem;
  border-radius: 10px;
  cursor: pointer;
  color: var(--ink-soft);
  font-weight: 500;
  transition: background 0.2s, color 0.2s, transform 0.15s;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
}

.nav-icon {
  display: none;
  font-size: 1.1rem;
  line-height: 1;
  opacity: 0.85;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.5);
  color: var(--ink);
}

.nav-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-accent-sm);
}

.sidebar-foot {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.4;
}

.env-badge {
  margin-top: 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #92400e;
  background: #fef3c7;
  border: 1px solid rgba(146, 64, 14, 0.2);
  border-radius: 8px;
  padding: 0.4rem 0.55rem;
  text-align: center;
}

/* Sesión / usuario logueado */
.session {
  margin-top: auto;
  padding: 0.85rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(20, 50, 42, 0.06);
}

.session-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.75rem;
}

.session-avatar {
  position: relative;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent-deep);
  background: linear-gradient(145deg, var(--accent-deep), var(--accent-mid));
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.03em;
  line-height: 1;
}

.session-online {
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--online);
  border: 2px solid #fff;
}

.session-info {
  flex: 1;
  min-width: 0;
}

.session-name {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.25;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-role {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.session-out {
  display: block;
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s, color 0.15s;
}

.session-out:hover {
  background: rgba(180, 35, 24, 0.06);
  border-color: rgba(180, 35, 24, 0.25);
  color: var(--danger);
}

.topbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.75rem;
}

.topbar-session {
  font-size: 0.8rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
  padding: 0.4rem 0.85rem;
  border-radius: 10px;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.greeting {
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--accent-deep);
  margin-bottom: 0.35rem;
  animation: rise 0.45s ease both;
}

/* Main */
.main {
  padding: 1.25rem 2.25rem 3rem;
  animation: fadeIn 0.45s ease both;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent); }
  50% { box-shadow: 0 0 0 6px transparent; }
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: rise 0.4s ease both;
}

.view-header {
  margin-bottom: 1.75rem;
}

.view-header.row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.view-header h1 {
  font-family: var(--display);
  font-size: clamp(1.75rem, 3vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
}

.lede {
  color: var(--muted);
  font-weight: 300;
  font-size: 1.05rem;
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.stat {
  padding: 1.35rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
  transition: transform 0.2s;
}

.stat:hover {
  transform: translateY(-2px);
}

.stat-value {
  display: block;
  font-family: var(--display);
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--accent-deep);
  line-height: 1;
  margin-bottom: 0.4rem;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 500;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.35rem 1.5rem;
  backdrop-filter: blur(8px);
}

.panel h2 {
  font-family: var(--display);
  font-size: 1.2rem;
  font-weight: 500;
  margin-bottom: 1rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.15rem;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.95rem;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
}

.btn:active {
  transform: scale(0.97);
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-accent-btn);
}

.btn.primary:hover {
  background: var(--accent-deep);
}

.btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink-soft);
}

.btn.ghost:hover {
  background: rgba(255, 255, 255, 0.6);
}

.btn.danger {
  background: transparent;
  color: var(--danger);
  border-color: rgba(180, 35, 24, 0.25);
}

.btn.danger:hover {
  background: rgba(180, 35, 24, 0.08);
}

.btn.icon {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 1.4rem;
  line-height: 1;
  background: transparent;
  border: none;
  color: var(--muted);
  border-radius: 8px;
}

.btn.icon:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--ink);
}

.btn.sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}

/* Toolbar */
.toolbar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.toolbar input[type="search"],
.toolbar input[type="date"],
.toolbar select {
  flex: 1;
  min-width: 180px;
  padding: 0.7rem 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.toolbar input:focus,
.toolbar select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}

/* Fichas grid */
.fichas-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.ficha-card {
  text-align: left;
  width: 100%;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  backdrop-filter: blur(8px);
}

.ficha-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}

.ficha-card h3 {
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.ficha-meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.ficha-diag {
  font-size: 0.9rem;
  color: var(--ink-soft);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ficha-tag {
  display: inline-block;
  margin-top: 0.85rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent-deep);
  background: var(--accent-soft);
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
}

/* Lists */
.list {
  list-style: none;
}

.list li.empty,
.empty-msg {
  padding: 1.5rem 0;
  color: var(--muted);
  font-weight: 300;
  text-align: center;
}

.cita-item {
  display: grid;
  grid-template-columns: 90px 1fr auto;
  gap: 1rem;
  align-items: center;
  padding: 1rem 0;
  border-bottom: 1px solid var(--line);
  animation: rise 0.35s ease both;
}

.cita-item:last-child {
  border-bottom: none;
}

.citas-list .cita-item {
  padding: 1.1rem 1.15rem;
  margin-bottom: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  border-bottom: 1px solid var(--line);
}

.cita-hora {
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--accent-deep);
}

.cita-fecha-mini {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  font-family: var(--font);
  font-weight: 400;
  margin-top: 0.15rem;
}

.cita-info strong {
  display: block;
  font-weight: 560;
  margin-bottom: 0.15rem;
}

.cita-info span {
  font-size: 0.85rem;
  color: var(--muted);
}

.cita-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  letter-spacing: 0.02em;
}

.badge.Programada { background: #e8f0fe; color: #1a56a8; }
.badge.Confirmada { background: var(--accent-soft); color: var(--accent-deep); }
.badge.Atendida { background: #e8e8e8; color: #555; }
.badge.Cancelada { background: #fde8e8; color: var(--danger); }
.badge.Pendiente { background: #fff4e5; color: #b45309; }
.badge.Reservada { background: #e8f0fe; color: #1a56a8; }
.badge.Ocupada { background: var(--accent-soft); color: var(--accent-deep); }
.badge.Finalizada { background: #e8e8e8; color: #555; }

.salas-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.sala-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sala-card.sala-libre {
  border-color: rgba(31, 122, 101, 0.28);
}

.sala-card.sala-ocupada {
  border-color: rgba(180, 83, 9, 0.28);
}

.sala-card-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
}

.sala-card-head h3 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.05rem;
}

.sala-card-head p {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.sala-status {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent-deep);
  white-space: nowrap;
}

.sala-ocupada .sala-status {
  color: var(--warn);
}

.sala-slots {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  flex: 1;
}

.sala-slot {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.4rem;
  align-items: center;
  font-size: 0.86rem;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line);
}

.sala-slot.libre {
  display: block;
  color: var(--muted);
  font-style: italic;
}

.salas-registro {
  margin-top: 0.5rem;
}

.salas-registro h2 {
  margin: 0 0 0.85rem;
  font-size: 1.05rem;
}

/* Modal */
.modal {
  border: none;
  border-radius: 18px;
  padding: 0;
  max-width: 520px;
  width: calc(100% - 2rem);
  max-height: calc(100dvh - 2rem);
  height: fit-content;
  margin: auto;
  position: fixed;
  inset: 0;
  box-shadow: 0 24px 60px rgba(20, 50, 42, 0.2);
  background: var(--surface-solid);
}

.modal::backdrop {
  background: rgba(20, 40, 35, 0.45);
  backdrop-filter: blur(4px);
}

.modal[open] {
  animation: modalIn 0.25s ease;
}

.modal form,
.modal-inner {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 2rem);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.35rem 0.5rem;
}

.modal-header h2 {
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 500;
}

.modal-body {
  padding: 0.75rem 1.35rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-height: 60vh;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1.35rem 1.25rem;
  flex-wrap: wrap;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-soft);
}

label input,
label select,
label textarea {
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  outline: none;
  font-weight: 400;
  color: var(--ink);
  transition: border-color 0.2s, box-shadow 0.2s;
}

label input:focus,
label select:focus,
label textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}

label textarea {
  resize: vertical;
  min-height: 72px;
}

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

.detalle-grid {
  display: grid;
  gap: 0.85rem;
}

.detalle-block dt {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.detalle-block dd {
  font-size: 0.95rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

/* Vista paciente / historial (página completa) */
.btn-back {
  margin-bottom: 0.65rem;
}

.historial-badge-inline {
  display: inline-block;
  font-size: 0.72rem !important;
  font-weight: 600 !important;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #92400e !important;
  background: #fef3c7;
  border: 1px solid rgba(146, 64, 14, 0.2);
  border-radius: 6px;
  padding: 0.25rem 0.55rem;
  margin-bottom: 0.55rem !important;
  animation: none !important;
}

.paciente-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(300px, 1.15fr);
  gap: 1.25rem;
  align-items: start;
}

.paciente-resumen h3,
.historial-panel h3 {
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 500;
  margin-bottom: 0.85rem;
}

.paciente-col-historial .historial-panel {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.historial-timeline {
  max-height: none;
}

@media (max-width: 900px) {
  .paciente-layout {
    grid-template-columns: 1fr;
  }
}

/* Historial paciente ↔ profesional */
.historial-badge {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #92400e;
  background: #fef3c7;
  border: 1px solid rgba(146, 64, 14, 0.2);
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
}

.historial-panel {
  margin-top: 1.25rem;
  padding-top: 1.15rem;
  border-top: 1px solid var(--line);
}

.historial-panel.panel {
  margin-top: 0;
  padding: 1.35rem 1.5rem;
  border-top: none;
}

.historial-head {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  margin-bottom: 0.85rem;
}

.historial-head-hint {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.35;
}

.form-hint {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}

.inicio-cta {
  margin-top: 1.25rem;
}

.inicio-cta .lede {
  margin-bottom: 1rem;
}

.historial-resumen {
  margin-bottom: 1rem;
}

.historial-sub {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.65rem;
}

.historial-timeline {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0;
  position: relative;
  padding-left: 0.25rem;
}

.historial-item {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 0.75rem;
  position: relative;
  padding-bottom: 1rem;
}

.historial-item:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 14px;
  bottom: 0;
  width: 2px;
  background: color-mix(in srgb, var(--accent) 25%, var(--line));
}

.historial-dot {
  width: 12px;
  height: 12px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  z-index: 1;
}

.historial-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.2rem;
}

.historial-top strong {
  font-size: 0.92rem;
  font-weight: 600;
}

.historial-meta {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}

.historial-empty {
  font-size: 0.9rem;
  color: var(--muted);
  padding: 0.5rem 0 0.25rem;
  list-style: none;
}

@keyframes fadeSlide {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

/* —— Notebook / tablet landscape —— */
@media (max-width: 1100px) {
  .app {
    grid-template-columns: 220px 1fr;
    max-width: none;
  }

  .main {
    padding: 1.25rem 1.5rem 2.5rem;
  }

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

/* —— Móvil y tablet portrait —— */
@media (max-width: 860px) {
  body {
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    min-height: 100dvh;
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 40;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    padding-top: calc(0.75rem + env(safe-area-inset-top, 0px));
    border-right: none;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(14px);
  }

  .brand-sub,
  .sidebar-foot,
  .session-out,
  .session-role {
    display: none;
  }

  .env-badge:not(.hidden) {
    display: block;
    width: 100%;
    margin: 0.35rem 0 0;
    order: 20;
  }

  .session {
    margin-top: 0;
    padding: 0.35rem 0.5rem;
    max-width: none;
    width: auto;
    box-shadow: none;
    background: transparent;
    border: none;
  }

  .session-row {
    gap: 0.5rem;
  }

  .session-name {
    max-width: 110px;
    font-size: 0.8rem;
  }

  .nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    flex-direction: row;
    justify-content: space-around;
    gap: 0;
    width: 100%;
    padding: 0.4rem 0.35rem calc(0.4rem + env(safe-area-inset-bottom, 0px));
    background: rgba(255, 255, 255, 0.96);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(14px);
    box-shadow: 0 -8px 24px rgba(20, 50, 42, 0.06);
    overflow: visible;
  }

  .nav-btn {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 0.2rem;
    padding: 0.45rem 0.25rem;
    min-height: 52px;
    font-size: 0.68rem;
    font-weight: 600;
    text-align: center;
    border-radius: 10px;
    color: var(--muted);
  }

  .nav-btn.active {
    background: var(--accent-soft);
    color: var(--accent-deep);
    box-shadow: none;
  }

  .nav-icon {
    display: block;
    font-size: 1.15rem;
  }

  .nav-label {
    line-height: 1.1;
  }

  .main {
    padding: 1rem 1rem 1.5rem;
  }

  .topbar {
    margin-bottom: 0.5rem;
  }

  .topbar-session {
    font-size: 0.7rem;
    max-width: 100%;
    white-space: normal;
    line-height: 1.3;
  }

  .view-header {
    margin-bottom: 1.15rem;
  }

  .view-header h1 {
    font-size: 1.55rem;
  }

  .view-header.row {
    flex-direction: column;
    align-items: stretch;
  }

  .view-header.row .btn,
  .view-header.row .header-actions {
    width: 100%;
  }

  .header-actions .btn {
    flex: 1;
  }

  .stats {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.55rem;
  }

  .stat {
    padding: 0.9rem 0.65rem;
  }

  .stat-value {
    font-size: 1.45rem;
  }

  .stat-label {
    font-size: 0.7rem;
  }

  .toolbar {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 0.5rem;
    margin-bottom: 0.85rem;
  }

  .toolbar input[type="search"],
  .toolbar input[type="date"],
  .toolbar select {
    flex: 1;
    min-width: 0;
    width: auto;
    font-size: 16px; /* evita zoom en iOS */
    padding: 0.55rem 0.7rem;
    min-height: 42px;
    height: 42px;
    border-radius: 10px;
    background: #fff;
    background-color: var(--surface-solid);
    color: var(--ink);
    border: 1px solid var(--line);
    box-shadow: none;
    -webkit-appearance: none;
    appearance: none;
    color-scheme: light;
  }

  .toolbar input[type="date"]::-webkit-calendar-picker-indicator {
    opacity: 0.55;
  }

  .toolbar .btn {
    flex: 0 0 auto;
    width: auto;
    min-height: 42px;
    height: 42px;
    padding: 0 0.75rem;
    font-size: 0.85rem;
    white-space: nowrap;
    background: var(--surface-solid);
    border: 1px solid var(--line);
  }

  label input,
  label select,
  label textarea {
    font-size: 16px;
    width: 100%;
  }

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

  .cita-item,
  .citas-list .cita-item {
    grid-template-columns: 1fr;
    gap: 0.55rem;
    padding: 0.85rem 0.9rem;
  }

  .cita-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .cita-actions .btn {
    flex: 1;
    min-height: 40px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .perfil-layout {
    grid-template-columns: 1fr;
  }

  .perfil-form .btn,
  .perfil-upload-btn,
  .perfil-actions .btn {
    width: 100%;
  }

  .modal {
    width: calc(100% - 1rem);
    max-width: none;
    max-height: calc(100dvh - 1.5rem);
    margin: auto;
    inset: 0;
    border-radius: 16px;
  }

  .modal-body {
    max-height: min(55dvh, 420px);
  }

  .modal-footer {
    flex-direction: column-reverse;
  }

  .modal-footer .btn {
    width: 100%;
    min-height: 44px;
  }

  .auth-screen {
    padding: 1rem;
    padding-top: calc(1rem + env(safe-area-inset-top, 0px));
    align-items: flex-start;
  }

  .auth-card {
    margin-top: 1.5rem;
    padding: 1.35rem 1.15rem 1.25rem;
  }

  .btn {
    min-height: 44px;
  }
}

/* —— Teléfonos estrechos —— */
@media (max-width: 420px) {
  .stats {
    grid-template-columns: 1fr;
  }

  .session-info {
    display: none;
  }

  .brand-name {
    font-size: 1.2rem;
  }
}

.hidden {
  display: none !important;
}

/* Auth screen */
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  animation: fadeIn 0.4s ease both;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.75rem 1.5rem 1.5rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  margin-bottom: 1.25rem;
  padding: 0.3rem;
  background: rgba(26, 46, 42, 0.05);
  border-radius: 10px;
}

.auth-tab {
  border: none;
  background: transparent;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  color: var(--muted);
}

.auth-tab.active {
  background: #fff;
  color: var(--accent-deep);
  box-shadow: 0 2px 8px rgba(20, 50, 42, 0.08);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.auth-submit {
  width: 100%;
  margin-top: 0.35rem;
}

.auth-form input:disabled,
.auth-form .auth-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.auth-title {
  font-family: Sora, sans-serif;
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0 0 0.35rem;
  color: var(--accent-deep);
}

.auth-lede {
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.45;
  margin: 0 0 0.85rem;
}

.password-rules {
  list-style: none;
  margin: -0.35rem 0 0;
  padding: 0.35rem 0.65rem 0.45rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  background: rgba(26, 46, 42, 0.04);
  border-radius: 8px;
}

.password-rules li {
  font-size: 0.78rem;
  color: var(--muted);
  padding-left: 1.15rem;
  position: relative;
}

.password-rules li::before {
  content: "○";
  position: absolute;
  left: 0;
  font-size: 0.7rem;
}

.password-rules li.ok {
  color: var(--accent-deep);
}

.password-rules li.ok::before {
  content: "✓";
}

.auth-error {
  color: var(--danger);
  font-size: 0.85rem;
  background: rgba(180, 35, 24, 0.08);
  border: 1px solid rgba(180, 35, 24, 0.2);
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
}

.auth-ok {
  color: var(--accent-deep);
  font-size: 0.85rem;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
}

.optional {
  font-weight: 400;
  color: var(--muted);
}

.session-foto {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  z-index: 1;
}

.session-foto:not(.hidden) {
  display: block;
}

.session-avatar #session-iniciales {
  position: relative;
  z-index: 0;
}

.session-online {
  z-index: 2;
}

.perfil-foto:not(.hidden) {
  display: block;
}

.perfil-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 1.5rem;
  align-items: start;
}

.perfil-photo-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.perfil-preview {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--accent-deep), var(--accent-mid));
  color: #fff;
  font-weight: 600;
  font-size: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: var(--shadow-accent);
}

.perfil-foto {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.perfil-upload-btn {
  cursor: pointer;
  width: 100%;
}

.perfil-photo-hint {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}

.perfil-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.perfil-form .btn {
  margin-top: 0;
}

.perfil-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.35rem;
}

.perfil-actions .btn {
  align-self: auto;
}

.theme-picker {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 1rem 1rem;
  margin: 0.25rem 0 0;
  background: rgba(255, 255, 255, 0.35);
}

.theme-picker legend {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  padding: 0 0.25rem;
}

.theme-picker-hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.theme-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.55rem;
}

.theme-option {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  padding: 0.55rem 0.35rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}

.theme-option:hover {
  transform: translateY(-1px);
}

.theme-option:has(input:checked) {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.theme-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.theme-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.65), 0 4px 10px rgba(0, 0, 0, 0.12);
  background: linear-gradient(145deg, var(--swatch-deep), var(--swatch-mid));
}

.theme-swatch-verde {
  --swatch-deep: #145a4b;
  --swatch-mid: #2a9d7c;
}

.theme-swatch-rosado {
  --swatch-deep: #8f3d5a;
  --swatch-mid: #d4789a;
}

.theme-swatch-amarillo {
  --swatch-deep: #8a6508;
  --swatch-mid: #d4a017;
}

.theme-swatch-celeste {
  --swatch-deep: #145066;
  --swatch-mid: #2a9db8;
}

.theme-option-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-soft);
}

@media (max-width: 860px) {
  .theme-options {
    grid-template-columns: repeat(2, 1fr);
  }

  .perfil-layout {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .perfil-photo-panel {
    width: 100%;
  }

  .perfil-form.panel {
    width: 100%;
  }

  .perfil-form .form-row {
    grid-template-columns: 1fr;
  }

  .perfil-actions {
    flex-direction: column;
  }

  .perfil-form .btn,
  .perfil-upload-btn,
  .perfil-actions .btn {
    width: 100%;
  }
}
