/* =========================================================
   Panel de administración de citas
   Densidad mayor que el sitio público (escala 8–32px)
   ========================================================= */
body { background: var(--bg); }
.center { text-align: center; }

/* ---------- Login ---------- */
.login { display: grid; grid-template-columns: 1fr 1fr; min-height: 100dvh; }
.login-brand { position: relative; overflow: hidden; display: grid; place-items: center; padding: var(--s-12); color: #fff;
  background: radial-gradient(ellipse at 20% 0%, rgba(255, 255, 255, .12), transparent 60%), linear-gradient(150deg, var(--primary-800), var(--primary)); }
.login-brand::after { content: ''; position: absolute; right: -80px; bottom: -80px; width: 320px; height: 320px; opacity: .14; transform: rotate(10deg);
  background: linear-gradient(var(--accent), var(--accent)) center / 96px 100% no-repeat, linear-gradient(var(--accent), var(--accent)) center / 100% 96px no-repeat; }
.login-brand-inner { position: relative; z-index: 1; max-width: 420px; }
.login-logo { display: inline-block; padding: var(--s-4); background: #fff; border-radius: var(--r-lg); margin-bottom: var(--s-8); box-shadow: var(--shadow-lg); }
.login-logo img { width: 140px; }
.login-brand h1 { color: #fff; font-size: 34px; letter-spacing: -.02em; }
.login-brand p { color: #C7D2FE; font-size: 17px; }
.login-brand ul { list-style: none; padding: 0; margin: var(--s-8) 0 0; display: flex; flex-direction: column; gap: var(--s-3); }
.login-brand li { display: flex; gap: var(--s-3); align-items: center; color: #E0E7FF; }
.login-form-wrap { display: grid; place-items: center; padding: var(--s-8) var(--s-4); background: var(--surface); }
.login-form { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: var(--s-5); }
.login-form h2 { font-size: 28px; margin: 0; }
.login-form > .muted { margin: -12px 0 0; }
.pass-wrap { position: relative; }
.pass-wrap .input { padding-right: 48px; }
.pass-wrap .btn { position: absolute; right: 4px; top: 4px; }
.back-site { display: inline-flex; align-items: center; gap: 6px; justify-content: center; font-size: 14px; font-weight: 600; text-decoration: none; }
@media (max-width: 860px) { .login { grid-template-columns: 1fr; } .login-brand { padding: var(--s-8) var(--s-4); } .login-brand ul, .login-brand p { display: none; } .login-logo { margin-bottom: var(--s-4); } .login-brand h1 { font-size: 24px; margin: 0; } }

/* ---------- Shell ---------- */
.app { display: grid; grid-template-columns: 252px 1fr; min-height: 100dvh; }
.sidebar { position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--border); padding: var(--s-4) var(--s-3); z-index: var(--z-drawer); }
.sb-brand { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-3) var(--s-5); }
.sb-brand img { width: 44px; mix-blend-mode: multiply; }
.sb-brand strong { display: block; font-family: var(--font-head); font-weight: 800; color: var(--primary); font-size: 17px; line-height: 1.1; }
.sb-brand small { font-size: 12px; color: var(--text-muted); }
.sb-nav { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.sb-nav a, .sb-link { display: flex; align-items: center; gap: var(--s-3); min-height: 44px; padding: 0 var(--s-3); border-radius: var(--r-sm); color: var(--text-muted); font-weight: 500; font-size: 15px; text-decoration: none; transition: background-color var(--dur-fast), color var(--dur-fast); }
.sb-nav a:hover, .sb-link:hover { background: var(--surface-2); color: var(--text); }
.sb-nav a[aria-current="page"] { background: var(--primary-50); color: var(--primary); font-weight: 600; }
.sb-nav a[aria-current="page"] .icon { color: var(--primary); }
.sb-nav .count { margin-left: auto; min-width: 22px; padding: 0 7px; border-radius: var(--r-full); background: var(--warning-50); color: var(--warning); font-size: 12px; font-weight: 700; text-align: center; line-height: 22px; }
.sb-foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--s-2); padding-top: var(--s-4); border-top: 1px solid var(--border); }
.sb-user { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-2) 0 var(--s-3); }
.sb-user > div { flex: 1; min-width: 0; line-height: 1.25; }
.sb-user strong { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user small { font-size: 12px; color: var(--text-muted); }
.sb-scrim { display: none; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: var(--z-sticky); display: flex; align-items: center; gap: var(--s-4); min-height: 72px; padding: var(--s-3) var(--s-8); background: rgba(246, 248, 252, .92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.tb-title { min-width: 0; flex: 1; }
.tb-title h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
.tb-title p { margin: 0; font-size: 13px; }
.tb-title p::first-letter { text-transform: uppercase; }
.tb-search { margin-left: auto; width: min(340px, 34vw); }
.sb-toggle { display: none; }
.search-pop { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-lg); max-height: 360px; overflow: auto; padding: 6px; }
.search-pop button { display: flex; width: 100%; align-items: center; gap: var(--s-3); padding: 8px 10px; border: 0; background: none; border-radius: var(--r-sm); text-align: left; }
.search-pop button:hover, .search-pop button[aria-selected="true"] { background: var(--primary-50); }
.search-pop small { display: block; color: var(--text-muted); font-size: 12px; }
.search-pop .avatar { width: 32px; height: 32px; font-size: 12px; }
.search-pop .empty-s { padding: 12px; color: var(--text-muted); font-size: 14px; }

.view { padding: var(--s-8); flex: 1; }
.view:focus { outline: none; }

@media (max-width: 1024px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: 280px; transform: translateX(-100%); transition: transform var(--dur) var(--ease-out); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .sb-scrim.open { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: calc(var(--z-drawer) - 1); }
  .sb-toggle { display: inline-flex; }
  .topbar { padding: var(--s-3) var(--s-4); gap: var(--s-2); }
  .view { padding: var(--s-5) var(--s-4); }
}
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; }
  .tb-search { order: 5; width: 100%; }
  #new-cita span { display: none; }
  #new-cita { min-width: 44px; padding: 0; }
}

/* ---------- Componentes del panel ---------- */
.grid { display: grid; gap: var(--s-5); }
.kpis { grid-template-columns: repeat(4, 1fr); }
.dash-2 { grid-template-columns: 1.6fr 1fr; align-items: start; }
@media (max-width: 1200px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 960px) { .dash-2 { grid-template-columns: 1fr; } }
@media (max-width: 480px) { .kpis { grid-template-columns: 1fr 1fr; gap: var(--s-3); } }

.kpi { padding: var(--s-5); display: flex; flex-direction: column; gap: var(--s-2); }
.kpi-top { display: flex; justify-content: space-between; align-items: center; color: var(--text-muted); font-size: 14px; font-weight: 500; }
.kpi-ico { display: grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r-sm); background: var(--chip-bg); color: var(--chip-fg); }
.kpi-val { font-family: var(--font-head); font-size: 32px; font-weight: 800; line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--text-muted); font-size: 13px; }
@media (max-width: 480px) { .kpi { padding: var(--s-4); } .kpi-val { font-size: 26px; } }

.box { padding: 0; overflow: hidden; }
.box-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--border); }
.box-head h2 { font-size: 17px; margin: 0; display: flex; align-items: center; gap: var(--s-2); }
.box-head h2 .icon { color: var(--primary); }
.box-body { padding: var(--s-5); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.appt-row { display: grid; grid-template-columns: 72px 1fr auto; align-items: center; gap: var(--s-4); width: 100%; padding: var(--s-3) var(--s-5); background: none; border: 0; text-align: left; transition: background-color var(--dur-fast); }
.appt-row:hover { background: var(--surface-2); }
.appt-time { font-family: var(--font-head); font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.appt-time small { display: block; font-family: var(--font-body); font-weight: 400; font-size: 12px; color: var(--text-muted); }
.appt-who { min-width: 0; }
.appt-who strong { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt-who span { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.appt-row.is-now { background: var(--violet-50); }
@media (max-width: 560px) { .appt-row { grid-template-columns: 60px 1fr; } .appt-row .chip { grid-column: 2; justify-self: start; } }

.req-item { display: flex; gap: var(--s-3); padding: var(--s-4) var(--s-5); align-items: flex-start; }
.req-item .grow { flex: 1; min-width: 0; }
.req-item strong { display: block; font-size: 15px; }
.req-item p { margin: 2px 0 var(--s-3); font-size: 13px; color: var(--text-muted); }
.req-actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }

.meter { display: grid; grid-template-columns: minmax(0, 1fr) 120px 48px; align-items: center; gap: var(--s-3); padding: var(--s-2) 0; font-size: 14px; }
.meter-name { display: flex; gap: var(--s-2); align-items: center; min-width: 0; }
.meter-name span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meter-bar { height: 8px; border-radius: var(--r-full); background: var(--surface-2); overflow: hidden; }
.meter-bar i { display: block; height: 100%; border-radius: inherit; background: var(--primary); }
.meter-val { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s-2); padding: var(--s-10) var(--s-4); color: var(--text-muted); }
.empty-state .icon { width: 36px; height: 36px; color: var(--text-subtle); }
.empty-state strong { color: var(--text); font-family: var(--font-head); font-size: 17px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s-3); margin-bottom: var(--s-5); }
.toolbar .field { min-width: 150px; }
.toolbar .field.grow { flex: 1; min-width: 220px; }
.toolbar .spacer { flex: 1; }
.toolbar label { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.date-nav { display: flex; align-items: center; gap: var(--s-2); }
.date-nav h2 { font-size: 18px; margin: 0 var(--s-2); }
.date-nav h2::first-letter { text-transform: uppercase; }
@media (max-width: 560px) { .date-nav h2 { font-size: 15px; } }

/* ---------- Tabla ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { position: sticky; top: 0; padding: 12px 16px; text-align: left; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted); background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th button { background: none; border: 0; padding: 0; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; display: inline-flex; gap: 4px; align-items: center; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { cursor: pointer; transition: background-color var(--dur-fast); }
.table tbody tr:hover { background: var(--primary-50); }
.table tbody tr:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.cell-main { font-weight: 600; }
.cell-sub { display: block; font-size: 13px; color: var(--text-muted); }
.pager { display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-5); font-size: 14px; color: var(--text-muted); border-top: 1px solid var(--border); }
@media (max-width: 760px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--border); }
  .table td { padding: 4px 0; border: 0; display: flex; justify-content: space-between; gap: var(--s-3); text-align: right; }
  .table td::before { content: attr(data-label); font-size: 12px; font-weight: 600; color: var(--text-muted); text-align: left; }
  .table td[data-label=""]::before { display: none; }
}

/* ---------- Agenda (vista día) ---------- */
.agenda { --ppm: 2.2px; display: flex; align-items: flex-start; overflow: auto; max-height: calc(100dvh - 230px); border-radius: var(--r-lg); border: 1px solid var(--border); background: var(--surface); }
.ag-times { position: sticky; left: 0; z-index: 3; flex: none; width: 64px; background: var(--surface); border-right: 1px solid var(--border); }
.ag-col { flex: 1 0 200px; border-right: 1px solid var(--border); min-width: 200px; }
.ag-col:last-child { border-right: 0; }
.ag-head { position: sticky; top: 0; z-index: 2; height: 64px; display: flex; align-items: center; gap: var(--s-2); padding: 0 var(--s-3); background: var(--surface); border-bottom: 1px solid var(--border); }
.ag-times .ag-head { z-index: 4; }
.ag-head .avatar { width: 32px; height: 32px; font-size: 12px; }
.ag-head strong { display: block; font-size: 13px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ag-head small { font-size: 12px; color: var(--text-muted); }
.ag-head > div { min-width: 0; }
.ag-body { position: relative; background-image: repeating-linear-gradient(to bottom, var(--border) 0 1px, transparent 1px calc(var(--ppm) * 60)); }
.ag-off { position: absolute; left: 0; right: 0; background: repeating-linear-gradient(135deg, var(--surface-2) 0 6px, #fff 6px 12px); }
.ag-hour { position: absolute; right: 8px; transform: translateY(-50%); font-size: 12px; color: var(--text-subtle); font-variant-numeric: tabular-nums; background: var(--surface); padding: 0 2px; }
.ag-free { position: absolute; left: 4px; right: 4px; display: flex; align-items: center; justify-content: center; gap: 4px; border: 1px dashed transparent; border-radius: 6px; background: none; color: transparent; font-size: 12px; font-weight: 600; transition: all var(--dur-fast); }
.ag-free:hover, .ag-free:focus-visible { border-color: var(--primary); color: var(--primary); background: var(--primary-50); }
.ag-free .icon { width: 14px; height: 14px; }
@media (hover: none) { .ag-free { color: var(--text-subtle); border-color: var(--border); } }
.ag-appt { position: absolute; left: 4px; right: 4px; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-start; padding: 4px 8px 4px 10px; border: 0; border-radius: 6px; text-align: left; font-size: 12px; line-height: 1.3;
  background: var(--chip-bg); color: var(--text); box-shadow: inset 3px 0 0 var(--chip-fg), 0 0 0 1px rgba(15, 23, 42, .06); transition: box-shadow var(--dur-fast), transform var(--dur-fast); }
.ag-appt:hover { box-shadow: inset 3px 0 0 var(--chip-fg), var(--shadow-md); z-index: 1; }
.ag-appt strong { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ag-appt span { color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 4px; }
.ag-appt span .icon { width: 12px; height: 12px; color: var(--chip-fg); }
.ag-appt.tone-neutral { opacity: .7; }
.ag-appt.tone-neutral strong { text-decoration: line-through; }
.ag-now { position: absolute; left: 0; right: 0; height: 2px; background: var(--accent); z-index: 1; pointer-events: none; }
.ag-now::before { content: ''; position: absolute; left: -4px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.legend { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-3); }

/* ---------- Médicos ---------- */
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--s-4); }
.doc-card { padding: var(--s-5); display: flex; flex-direction: column; gap: var(--s-4); }
.doc-card.off { opacity: .6; }
.doc-top { display: flex; gap: var(--s-3); align-items: center; }
.doc-top .avatar { width: 48px; height: 48px; }
.doc-top h3 { font-size: 16px; margin: 0; }
.doc-top p { margin: 0; font-size: 13px; color: var(--text-muted); }
.days-row { display: flex; gap: 4px; }
.days-row span { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 6px; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--text-subtle); }
.days-row span.on { background: var(--primary-50); color: var(--primary); }
.doc-meta { display: flex; gap: var(--s-4); flex-wrap: wrap; font-size: 14px; color: var(--text-muted); }
.doc-meta span { display: flex; gap: 6px; align-items: center; }
.doc-meta .icon { width: 16px; height: 16px; }
.doc-actions { display: flex; gap: var(--s-2); margin-top: auto; }
.day-checks { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.day-checks label { position: relative; }
.day-checks input { position: absolute; opacity: 0; }
.day-checks span { display: grid; place-items: center; min-width: 52px; height: 40px; padding: 0 var(--s-2); border-radius: var(--r-sm); border: 1.5px solid var(--border-strong); font-size: 14px; font-weight: 600; cursor: pointer; }
.day-checks input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }
.day-checks input:focus-visible + span { box-shadow: var(--ring); }

/* ---------- Switch ---------- */
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: var(--s-4); padding: var(--s-4) 0; border-bottom: 1px solid var(--border); }
.switch-row:last-child { border-bottom: 0; }
.switch-row strong { display: block; font-size: 15px; }
.switch-row p { margin: 0; font-size: 13px; color: var(--text-muted); }
.switch { position: relative; flex: none; width: 48px; height: 28px; }
.switch input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: var(--r-full); background: var(--border-strong); transition: background-color var(--dur-fast); }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform var(--dur) var(--ease-out); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { box-shadow: var(--ring); }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-5); align-items: start; }
@media (max-width: 960px) { .settings-grid { grid-template-columns: 1fr; } }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- Drawer de cita ---------- */
.d-section { padding: var(--s-5) 0; border-bottom: 1px solid var(--border); }
.d-section:first-child { padding-top: 0; }
.d-section:last-child { border-bottom: 0; }
.d-section h3 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: var(--s-3); }
.d-patient { display: flex; gap: var(--s-3); align-items: center; }
.d-patient .avatar { width: 48px; height: 48px; font-size: 16px; }
.d-patient strong { display: block; font-size: 17px; font-family: var(--font-head); }
.d-patient small { color: var(--text-muted); }
.d-contact { display: flex; gap: var(--s-2); margin-top: var(--s-3); flex-wrap: wrap; }
.dl { display: grid; grid-template-columns: 120px 1fr; gap: var(--s-2) var(--s-4); margin: 0; font-size: 14px; }
.dl dt { color: var(--text-muted); }
.dl dd { margin: 0; font-weight: 500; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 var(--s-5); position: relative; }
.timeline::before { content: ''; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline li { position: relative; padding-bottom: var(--s-3); font-size: 14px; }
.timeline li::before { content: ''; position: absolute; left: calc(-1 * var(--s-5) + 1px); top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--chip-fg, var(--primary)); }
.timeline small { display: block; color: var(--text-muted); font-size: 12px; }
.drawer .modal-foot { flex-wrap: wrap; justify-content: flex-start; }
.drawer .modal-foot .btn-primary { margin-left: auto; order: 9; }
.slot-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; max-height: 200px; overflow: auto; padding: 2px; }
.slot-pick button { min-height: 40px; border: 1.5px solid var(--border); border-radius: var(--r-sm); background: var(--surface); font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.slot-pick button:hover { border-color: var(--primary); color: var(--primary); }
.slot-pick button[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }
.pat-results { border: 1px solid var(--border); border-radius: var(--r-sm); max-height: 180px; overflow: auto; }
.pat-results button { display: flex; justify-content: space-between; width: 100%; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--border); background: none; text-align: left; font-size: 14px; }
.pat-results button:last-child { border-bottom: 0; }
.pat-results button:hover { background: var(--primary-50); }
.pat-chosen { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3); border: 1.5px solid var(--primary); background: var(--primary-50); border-radius: var(--r-sm); }
.pat-chosen > div { flex: 1; }
.pat-chosen small { display: block; color: var(--text-muted); }
.note-box { display: flex; gap: var(--s-2); align-items: flex-start; padding: var(--s-3) var(--s-4); background: var(--surface-2); border-radius: var(--r-sm); font-size: 14px; }
