:root {
  --bg: #f4f6f9; --surface: #fff; --ink: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --brand: #0f766e; --brand-d: #115e59; --brand-l: #ccfbf1; --blue: #2563eb; --red: #dc2626; --amber: #d97706;
  --green: #16a34a; --side: #0b1f2a; --radius: 10px; --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 14px rgba(15,23,42,.05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5; }
a { color: var(--brand); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; letter-spacing: -.01em; } h2 { font-size: 1.1rem; margin: 0 0 .75rem; } h3 { font-size: .95rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; } .muted { color: var(--muted); } .small { font-size: .85rem; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }

/* ---- layout */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.side { background: var(--side); color: #cbd5e1; padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: .6rem; align-items: center; color: #fff; font-weight: 700; font-size: 1.05rem; padding: .25rem .5rem 1rem; }
.brand .logo { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, #14b8a6, #0f766e); display: grid; place-items: center; font-size: 18px; }
.clinic-switch { background: rgba(255,255,255,.07); border-radius: 8px; padding: .55rem .7rem; margin-bottom: 1rem; font-size: .85rem; }
.clinic-switch strong { color: #fff; display: block; } .clinic-switch select { width: 100%; margin-top: .4rem; background: #12303f; color: #e2e8f0; border: 1px solid #1e4254; }
.nav-group { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #64748b; margin: 1rem .6rem .3rem; }
.nav a { display: flex; align-items: center; gap: .6rem; padding: .5rem .65rem; border-radius: 7px; color: #cbd5e1; font-size: .92rem; }
.nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; gap: .75rem; align-items: center; padding: .7rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar form.search { flex: 1; max-width: 460px; } .topbar .spacer { flex: 1; }
.menu-btn { display: none; }
.content { padding: 1.5rem; max-width: 1280px; width: 100%; margin: 0 auto; }
.page-head { display: flex; gap: 1rem; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---- components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card.flush { padding: 0; overflow: hidden; } .card-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.card.flush .card-head { padding: 1rem 1.25rem 0; }
.grid { display: grid; gap: 1rem; } .g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.15rem; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; } .stat .value { font-size: 1.75rem; font-weight: 700; letter-spacing: -.02em; } .stat .hint { color: var(--muted); font-size: .8rem; }
.btn, button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: .5rem .9rem; display: inline-flex; align-items: center; gap: .4rem; font-weight: 500; line-height: 1.2; }
.btn:hover, button:hover { background: #f1f5f9; text-decoration: none; }
.btn.primary, button.primary { background: var(--brand); border-color: var(--brand); color: #fff; } .btn.primary:hover, button.primary:hover { background: var(--brand-d); }
.btn.danger, button.danger { color: var(--red); border-color: #fecaca; } .btn.danger:hover, button.danger:hover { background: #fef2f2; }
.btn.sm, button.sm { padding: .3rem .6rem; font-size: .82rem; } .btn.link { border: 0; background: none; color: var(--brand); padding: 0; }
form.inline { display: inline; }
label { display: block; font-size: .82rem; font-weight: 600; color: #334155; margin-bottom: .25rem; }
input, select, textarea { font: inherit; width: 100%; padding: .5rem .65rem; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus, button:focus-visible, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
input[type=checkbox], input[type=radio] { width: auto; margin-right: .4rem; } textarea { min-height: 84px; resize: vertical; }
.field { margin-bottom: .85rem; } .field .help { font-size: .78rem; color: var(--muted); margin-top: .2rem; }
.form-grid { display: grid; gap: .25rem 1rem; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.span-all { grid-column: 1 / -1; }
.check { display: flex; align-items: center; font-weight: 500; font-size: .92rem; margin-bottom: .4rem; } .check input { margin-right: .5rem; }
table { width: 100%; border-collapse: collapse; } th, td { text-align: left; padding: .6rem .85rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: #f8fafc; font-weight: 600; }
tr:last-child td { border-bottom: 0; } tbody tr:hover td { background: #fafcff; } td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.badge { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .74rem; font-weight: 600; background: #e2e8f0; color: #334155; white-space: nowrap; }
.badge.programada { background: #dbeafe; color: #1d4ed8; } .badge.confirmada { background: #dcfce7; color: #15803d; } .badge.en_curso { background: #fef3c7; color: #b45309; }
.badge.completada { background: #e2e8f0; color: #334155; } .badge.cancelada, .badge.anulada, .badge.rechazada, .badge.fallido { background: #fee2e2; color: #b91c1c; }
.badge.no_asistio { background: #ffedd5; color: #c2410c; } .badge.pagada, .badge.vigente, .badge.firmada, .badge.enviado, .badge.aceptada { background: #dcfce7; color: #15803d; }
.badge.emitida, .badge.borrador, .badge.pendiente, .badge.generada { background: #fef3c7; color: #b45309; }
.badge.grave { background: #fee2e2; color: #b91c1c; } .badge.moderada { background: #ffedd5; color: #c2410c; } .badge.leve { background: #fef9c3; color: #a16207; }
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: .6rem; border: 1px solid; font-size: .92rem; }
.flash.success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; } .flash.error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.flash.info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; } .flash.secret { background: #fffbeb; border-color: #fde68a; color: #92400e; font-family: ui-monospace, monospace; word-break: break-all; }
.alert { padding: .8rem 1rem; border-radius: 8px; background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; margin-bottom: 1rem; }
.alert.danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: .35rem .75rem; font-size: .92rem; } .kv dt { color: var(--muted); } .kv dd { margin: 0; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .55rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; } .tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs a.active { color: var(--brand); border-color: var(--brand); }
.pager { display: flex; gap: .5rem; justify-content: center; align-items: center; padding: .9rem; }
.list { list-style: none; margin: 0; padding: 0; } .list li { padding: .65rem 0; border-bottom: 1px solid var(--line); display: flex; gap: .75rem; justify-content: space-between; align-items: center; } .list li:last-child { border-bottom: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; } .perm-group { margin-bottom: 1rem; } .perm-group h3 { color: var(--brand); }
.suggest { position: relative; } .suggest ul { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); list-style: none; margin: 2px 0 0; padding: .25rem; max-height: 260px; overflow-y: auto; }
.suggest li { padding: .45rem .6rem; border-radius: 6px; cursor: pointer; font-size: .9rem; } .suggest li:hover, .suggest li.on { background: var(--brand-l); }
.slots { display: flex; flex-wrap: wrap; gap: .4rem; } .slot { padding: .35rem .7rem; border: 1px solid #cbd5e1; border-radius: 7px; background: #fff; cursor: pointer; font-size: .88rem; } .slot:hover { border-color: var(--brand); } .slot.sel { background: var(--brand); border-color: var(--brand); color: #fff; }
.rx-row { border: 1px solid var(--line); border-radius: 8px; padding: .8rem; margin-bottom: .75rem; background: #fcfdfe; position: relative; }

/* ---- calendario */
.cal { display: grid; grid-template-columns: 52px repeat(var(--cols), minmax(0, 1fr)); background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.cal-head { padding: .55rem .4rem; text-align: center; border-bottom: 1px solid var(--line); border-left: 1px solid var(--line); background: #f8fafc; font-size: .85rem; } .cal-head.today { background: var(--brand-l); color: var(--brand-d); font-weight: 700; }
.cal-gutter { position: relative; } .cal-gutter span { position: absolute; right: 6px; font-size: .72rem; color: var(--muted); transform: translateY(-50%); }
.cal-col { position: relative; border-left: 1px solid var(--line); background-image: linear-gradient(var(--line) 1px, transparent 1px); background-size: 100% var(--hpx); } .cal-col.off { background-color: #fef2f2; }
.cal-off { position: absolute; top: 4px; left: 4px; right: 4px; font-size: .75rem; color: #b91c1c; font-weight: 600; z-index: 1; }
.ev { position: absolute; left: 3px; right: 3px; border-radius: 6px; padding: 2px 6px; font-size: .74rem; line-height: 1.25; color: #fff; overflow: hidden; border-left: 4px solid rgba(0,0,0,.25); box-shadow: 0 1px 2px rgba(0,0,0,.2); } .ev:hover { text-decoration: none; filter: brightness(1.08); z-index: 5; }
.ev.done { opacity: .55; } .now-line { position: absolute; left: 0; right: 0; height: 2px; background: #ef4444; z-index: 4; }

/* ---- gráficos */
.chart svg { width: 100%; height: auto; display: block; } .chart text { font-size: 10px; fill: #64748b; } .chart .val { font-size: 10px; fill: #0f172a; font-weight: 600; } .chart rect.bar { fill: var(--brand); } .chart rect.bar:hover { fill: var(--brand-d); }

/* ---- auth / landing */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: radial-gradient(1200px 500px at 10% -10%, #ccfbf1, transparent), var(--bg); }
.auth-card { width: 100%; max-width: 440px; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 2rem; } .auth-card.wide { max-width: 560px; }
.auth-card .brand { color: var(--ink); padding: 0 0 1rem; }
.hero { padding: 4rem 1.5rem; text-align: center; max-width: 900px; margin: 0 auto; } .hero h1 { font-size: 2.4rem; } .hero p.lead { font-size: 1.15rem; color: var(--muted); margin: 1rem auto 1.5rem; max-width: 640px; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; max-width: 1100px; margin: 0 auto; padding: 0 1.5rem 3rem; } .features .card h3 { color: var(--brand); }

/* ---- impresión (recetas y facturas) */
.paper { background: #fff; max-width: 820px; margin: 0 auto; padding: 2rem 2.25rem; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.paper header { display: flex; justify-content: space-between; border-bottom: 2px solid var(--brand); padding-bottom: .75rem; margin-bottom: 1rem; }
.rx-item { padding: .6rem 0; border-bottom: 1px dashed #cbd5e1; } .rx-item:last-child { border: 0; } .watermark { color: #dc2626; font-weight: 800; font-size: 1.4rem; letter-spacing: .1em; }
@media print { .side, .topbar, .no-print, .flash { display: none !important; } .app { display: block; } .content { padding: 0; max-width: none; } .paper { border: 0; box-shadow: none; padding: 0; } body { background: #fff; } }

/* ---- responsive */
@media (max-width: 1000px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-main, .g3 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; } .side { position: fixed; z-index: 40; width: 270px; left: -280px; transition: left .2s; box-shadow: 4px 0 20px rgba(0,0,0,.3); }
  body.nav-open .side { left: 0; } body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 30; }
  body.nav-open .side { z-index: 40; } .menu-btn { display: inline-flex; } .content { padding: 1rem; } .topbar { padding: .6rem 1rem; }
  .g2, .g4 { grid-template-columns: minmax(0, 1fr); } .kv { grid-template-columns: minmax(0, 1fr); } .kv dt { margin-top: .4rem; } .hero h1 { font-size: 1.8rem; }
  .cal { --cols: 7; font-size: .8rem; overflow-x: auto; } .cal-wrap { overflow-x: auto; } .cal-wrap .cal { min-width: 720px; }
}

.back-home { display: inline-block; margin-bottom: .75rem; font-size: .9rem; color: var(--muted); } .back-home:hover { color: var(--brand); }
