/* Todos los valores visuales salen de variables que define el tema activo (js/theme.js). */
:root {
  --primary: #2563eb; --secondary: #0ea5e9; --bg: #f1f5f9; --surface: #fff; --menu-bg: #0f172a; --menu-text: #cbd5e1;
  --menu-active: #2563eb; --menu-active-text: #fff; --btn-bg: #2563eb; --btn-text: #fff; --header-bg: #fff; --header-text: #0f172a;
  --text: #0f172a; --muted: #64748b; --border: #e2e8f0; --input-bg: #fff; --success: #16a34a; --warning: #f59e0b; --danger: #dc2626;
  --font: 'Inter', system-ui, sans-serif; --fs: 14px; --title-fs: 22px; --fw: 400; --title-fw: 700; --ls: 0em; --lh: 1.5;
  --radius: 10px; --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 14px rgba(15,23,42,.06); --sp: 1; --menu-w: 250px;
  --primary-soft: color-mix(in srgb, var(--primary) 12%, transparent);
  --hover: color-mix(in srgb, var(--text) 5%, transparent);
  --gap: calc(16px * var(--sp));
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); font-size: var(--fs); font-weight: var(--fw); letter-spacing: var(--ls); line-height: var(--lh);
  color: var(--text); background: var(--bg); background-size: cover; background-attachment: fixed; -webkit-font-smoothing: antialiased;
}
body.dark { color-scheme: dark; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { font-weight: var(--title-fw); margin: 0 0 .5em; line-height: 1.25; }
h1 { font-size: var(--title-fs); }
h2 { font-size: calc(var(--title-fs) * .82); }
h3 { font-size: calc(var(--title-fs) * .7); }
h4 { font-size: calc(var(--fs) * 1.05); }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--gap) 0; }
small, .muted { color: var(--muted); }
.small { font-size: .86em; }
[v-cloak] { display: none; }
svg.ic { width: 1.15em; height: 1.15em; flex: none; vertical-align: -.2em; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
body.icons-filled svg.ic { stroke-width: 2.4; }
body.icons-off .nav svg.ic, body.icons-off .btn svg.ic:not(:only-child) { display: none; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--menu-w); background: var(--menu-bg); color: var(--menu-text); flex: none; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 40; transition: transform .2s;
}
.brand { display: flex; align-items: center; gap: 10px; padding: calc(18px * var(--sp)) 18px; font-weight: 700; font-size: 1.08em; color: var(--menu-text); }
.brand img { max-height: 38px; max-width: 160px; object-fit: contain; }
.brand .logo-mark { width: 36px; height: 36px; border-radius: calc(var(--radius) * .8); background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 800; flex: none; }
.brand small { display: block; font-weight: 400; font-size: .78em; opacity: .7; color: inherit; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px 16px; }
.nav a, .nav button.navlink {
  display: flex; align-items: center; gap: 11px; padding: calc(9px * var(--sp)) 12px; color: var(--menu-text); border-radius: calc(var(--radius) * .8);
  font-weight: 500; text-decoration: none; opacity: .9; background: none; border: 0; font: inherit; cursor: pointer; text-align: left; width: 100%;
}
.nav a:hover, .nav button.navlink:hover { background: color-mix(in srgb, var(--menu-text) 10%, transparent); opacity: 1; }
.nav a.active { background: var(--menu-active); color: var(--menu-active-text); opacity: 1; }
.nav .sep { height: 1px; background: color-mix(in srgb, var(--menu-text) 15%, transparent); margin: 8px 6px; }
.nav .badge-count { margin-left: auto; background: var(--danger); color: #fff; border-radius: 99px; font-size: .72em; padding: 1px 7px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--header-bg); color: var(--header-text); border-bottom: 1px solid var(--border); display: flex; align-items: center;
  gap: 12px; padding: calc(10px * var(--sp)) calc(20px * var(--sp)); position: sticky; top: 0; z-index: 30; min-height: 58px;
}
.topbar .title { font-weight: 600; font-size: 1.05em; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .user { display: flex; align-items: center; gap: 8px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; overflow: hidden; flex: none; font-size: .9em; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.content { padding: calc(22px * var(--sp)); flex: 1; min-width: 0; }
.menu-toggle { display: none; }
.backdrop { display: none; }

/* Menú superior */
body.menu-top .app { flex-direction: column; }
body.menu-top .sidebar { width: 100%; height: auto; position: sticky; flex-direction: row; align-items: center; overflow: visible; }
body.menu-top .nav { flex-direction: row; flex-wrap: wrap; padding: 6px 10px; flex: 1; }
body.menu-top .nav a, body.menu-top .nav button.navlink { width: auto; }
body.menu-top .nav .sep { display: none; }
body.menu-top .topbar { top: auto; position: relative; }

/* ---------- Tarjetas ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: calc(18px * var(--sp)); min-width: 0; }
body.card-elevated .card { box-shadow: var(--shadow); }
body.card-bordered .card, body.card-flat .card { border: 1px solid var(--border); }
body.card-flat .card { box-shadow: none; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h3, .card-head h2 { margin: 0; flex: 1; }
.grid { display: grid; gap: var(--gap); }
.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)); }
.gauto { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.span2 { grid-column: span 2; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.right { margin-left: auto; }
.mt { margin-top: var(--gap); } .mb { margin-bottom: var(--gap); }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: var(--gap); flex-wrap: wrap; }
.page-head h1 { margin: 0; flex: 1; min-width: 200px; }

.kpi { display: flex; flex-direction: column; gap: 4px; position: relative; overflow: hidden; }
.kpi .label { color: var(--muted); font-size: .85em; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 1.9em; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .bar { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent, var(--primary)); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: calc(8px * var(--sp)) 14px; border-radius: calc(var(--radius) * .8);
  border: 1px solid transparent; background: var(--btn-bg); color: var(--btn-text); font: inherit; font-weight: 600; cursor: pointer;
  white-space: nowrap; line-height: 1.3; transition: filter .15s, background .15s; text-decoration: none !important;
}
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
body.btn-outline .btn:not(.ghost):not(.danger):not(.light) { background: transparent; color: var(--btn-bg); border-color: var(--btn-bg); }
body.btn-soft .btn:not(.ghost):not(.danger):not(.light) { background: color-mix(in srgb, var(--btn-bg) 14%, transparent); color: var(--btn-bg); }
.btn.light { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.light:hover { background: var(--hover); filter: none; }
.btn.ghost { background: transparent; color: var(--text); border-color: transparent; }
.btn.ghost:hover { background: var(--hover); filter: none; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger.ghost { background: transparent; color: var(--danger); }
.btn.sm { padding: 4px 9px; font-size: .88em; }
.btn.icon { padding: 7px; }
.btn.sm.icon { padding: 4px; }
.btn-group { display: inline-flex; border: 1px solid var(--border); border-radius: calc(var(--radius) * .8); overflow: hidden; background: var(--surface); }
.btn-group .btn { border-radius: 0; background: transparent; color: var(--text); border: 0; border-right: 1px solid var(--border); }
.btn-group .btn:last-child { border-right: 0; }
.btn-group .btn.on { background: var(--primary); color: #fff; }

/* ---------- Formularios ---------- */
label.f, .f { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.f > span:first-child, .f > .lbl { font-weight: 600; font-size: .88em; color: var(--text); }
.f .req { color: var(--danger); }
.f .help { color: var(--muted); font-size: .82em; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--input-bg); border: 1px solid var(--border); border-radius: calc(var(--radius) * .7);
  padding: calc(8px * var(--sp)) 10px; width: 100%; min-width: 0; outline: none; transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input[type=checkbox], input[type=radio] { width: 17px; height: 17px; accent-color: var(--primary); padding: 0; flex: none; }
input[type=color] { padding: 2px; height: 36px; width: 48px; cursor: pointer; }
textarea { resize: vertical; min-height: 70px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.input-group { display: flex; align-items: stretch; }
.input-group > input { border-radius: calc(var(--radius) * .7) 0 0 calc(var(--radius) * .7); }
.input-group > .addon { display: flex; align-items: center; padding: 0 10px; border: 1px solid var(--border); border-left: 0; border-radius: 0 calc(var(--radius) * .7) calc(var(--radius) * .7) 0; background: var(--hover); color: var(--muted); white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-size: .88em; font-weight: 500; user-select: none; color: var(--text);
}
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; }
.search { position: relative; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 34px; }
.color-field { display: flex; gap: 8px; align-items: center; }
.color-field input[type=text] { font-family: ui-monospace, monospace; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table.t { width: 100%; border-collapse: collapse; }
table.t th, table.t td { padding: calc(9px * var(--sp)) 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.t th { font-size: .78em; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; white-space: nowrap; }
table.t tbody tr:hover { background: var(--hover); }
table.t tr.click { cursor: pointer; }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.t tfoot td { font-weight: 700; border-top: 2px solid var(--border); }
table.t .actions { text-align: right; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: .8em; font-weight: 600; white-space: nowrap; background: var(--hover); }
.swatch { display: inline-block; width: 16px; height: 16px; border-radius: 5px; vertical-align: middle; border: 1px solid rgba(0,0,0,.1); }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty svg.ic { width: 38px; height: 38px; opacity: .45; display: block; margin: 0 auto 10px; }

/* ---------- Pestañas ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: var(--gap); overflow-x: auto; scrollbar-width: thin; }
.tabs button { background: none; border: 0; font: inherit; padding: 10px 14px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.tabs button.on { color: var(--primary); border-bottom-color: var(--primary); }
.tabs button .count { background: var(--hover); border-radius: 99px; padding: 0 7px; font-size: .8em; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 4vh 16px; overflow-y: auto; backdrop-filter: blur(2px); }
.modal { background: var(--surface); color: var(--text); border-radius: calc(var(--radius) * 1.3); width: 100%; max-width: 620px; box-shadow: 0 25px 60px rgba(0,0,0,.3); display: flex; flex-direction: column; max-height: none; }
.modal.lg { max-width: 860px; } .modal.xl { max-width: 1100px; } .modal.sm { max-width: 440px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; flex: 1; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }

/* ---------- Avisos ---------- */
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 40px); }
.toast { background: #0f172a; color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.25); display: flex; gap: 10px; align-items: center; animation: tin .2s ease-out; max-width: 420px; }
.toast.error { background: var(--danger); } .toast.success { background: var(--success); } .toast.warning { background: #b45309; }
@keyframes tin { from { transform: translateY(10px); opacity: 0; } }
.alert { padding: 10px 14px; border-radius: calc(var(--radius) * .8); display: flex; gap: 10px; align-items: flex-start; font-size: .92em; }
.alert.info { background: color-mix(in srgb, var(--secondary) 13%, transparent); }
.alert.warning { background: color-mix(in srgb, var(--warning) 18%, transparent); }
.alert.danger, .alert.error { background: color-mix(in srgb, var(--danger) 13%, transparent); color: var(--danger); }
.alert.success { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.login-side { background: var(--primary) center/cover no-repeat; position: relative; display: flex; align-items: flex-end; padding: 40px; color: #fff; }
.login-side::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 30%, rgba(0,0,0,.55)); }
.login-side > * { position: relative; z-index: 1; }
.login-form { display: flex; align-items: center; justify-content: center; padding: 30px 16px; }
.login-form .card { width: 100%; max-width: 400px; }

/* ---------- Agenda ---------- */
.agenda-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.agenda-bar .date-label { font-weight: 700; font-size: 1.1em; min-width: 180px; }
.cal { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); overflow: auto; position: relative; max-height: calc(100vh - 190px); }
.cal-head { display: flex; position: sticky; top: 0; z-index: 6; background: var(--surface); border-bottom: 1px solid var(--border); min-width: max-content; }
.cal-head .gutter { width: 58px; flex: none; position: sticky; left: 0; background: var(--surface); z-index: 2; }
.cal-head .colh { flex: 1 0 var(--colw, 140px); padding: 8px 6px; text-align: center; border-left: 1px solid var(--border); font-weight: 600; font-size: .9em; min-width: var(--colw, 140px); }
.cal-head .colh small { display: block; font-weight: 500; }
.cal-head .colh.today { color: var(--primary); }
.cal-head .colh .hol { display: block; font-size: .78em; color: var(--danger); font-weight: 600; }
.cal-body { display: flex; position: relative; min-width: max-content; }
.cal-gutter { width: 58px; flex: none; position: sticky; left: 0; background: var(--surface); z-index: 5; border-right: 1px solid var(--border); }
.cal-gutter .hl { position: absolute; right: 6px; font-size: .75em; color: var(--muted); transform: translateY(-50%); font-variant-numeric: tabular-nums; }
.cal-col { flex: 1 0 var(--colw, 140px); min-width: var(--colw, 140px); position: relative; border-left: 1px solid var(--border); cursor: cell; }
.cal-col .line { position: absolute; left: 0; right: 0; border-top: 1px solid var(--border); pointer-events: none; }
.cal-col .line.half { border-top-style: dashed; opacity: .6; }
.cal-col .off { position: absolute; left: 0; right: 0; background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--muted) 9%, transparent) 0 6px, color-mix(in srgb, var(--muted) 15%, transparent) 6px 12px); pointer-events: none; }
.cal-col .blk { position: absolute; left: 2px; right: 2px; border-radius: 6px; background: repeating-linear-gradient(45deg, color-mix(in srgb, var(--danger) 10%, var(--surface)) 0 8px, color-mix(in srgb, var(--danger) 18%, var(--surface)) 8px 16px); border: 1px dashed color-mix(in srgb, var(--danger) 55%, transparent); font-size: .75em; padding: 2px 6px; color: var(--danger); font-weight: 600; overflow: hidden; z-index: 1; cursor: pointer; }
.cal-col .now { position: absolute; left: 0; right: 0; border-top: 2px solid var(--danger); z-index: 4; pointer-events: none; }
.cal-col .now::before { content: ''; position: absolute; left: -5px; top: -6px; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }
.cal-col .ghost { position: absolute; left: 2px; right: 2px; border: 2px dashed var(--primary); border-radius: 6px; background: var(--primary-soft); z-index: 3; pointer-events: none; font-size: .75em; padding: 1px 6px; color: var(--primary); font-weight: 700; }
.ev {
  position: absolute; border-radius: 6px; padding: 2px 6px; overflow: hidden; z-index: 2; cursor: pointer; font-size: .8em; line-height: 1.25;
  background: color-mix(in srgb, var(--c) 16%, var(--surface)); border-left: 4px solid var(--c); color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,.08); user-select: none; touch-action: none; min-height: 6px;
}
.ev:hover { z-index: 5; box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.ev.dragging { opacity: .85; z-index: 10; box-shadow: 0 10px 25px rgba(0,0,0,.25); }
.ev.freed { opacity: .5; background: repeating-linear-gradient(135deg, var(--surface) 0 6px, color-mix(in srgb, var(--c) 10%, var(--surface)) 6px 12px); text-decoration: line-through; }
.ev .t { font-weight: 700; font-variant-numeric: tabular-nums; }
.ev .p { font-weight: 600; }
.ev .st { display: inline-block; padding: 0 5px; border-radius: 4px; font-size: .85em; color: #fff; font-weight: 600; }
.ev.tiny { padding: 0 5px; font-size: .72em; white-space: nowrap; display: flex; gap: 5px; align-items: center; }
.ev .rs { position: absolute; left: 0; right: 0; bottom: 0; height: 7px; cursor: ns-resize; }
.ev.pending-dur { outline: 2px dashed var(--warning); }
.month { display: grid; grid-template-columns: repeat(var(--cols, 7), minmax(0, 1fr)); border-top: 1px solid var(--border); border-left: 1px solid var(--border); }
.month .mh { padding: 8px; font-weight: 700; font-size: .8em; text-transform: uppercase; color: var(--muted); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--surface); }
.month .md { min-height: 116px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 4px; background: var(--surface); cursor: pointer; min-width: 0; }
.month .md.other { opacity: .5; }
.month .md.closed { background: repeating-linear-gradient(135deg, var(--surface) 0 6px, color-mix(in srgb, var(--muted) 8%, var(--surface)) 6px 12px); }
.month .md .dn { font-weight: 700; font-size: .85em; padding: 2px 4px; display: flex; justify-content: space-between; gap: 4px; }
.month .md.today .dn b { background: var(--primary); color: #fff; border-radius: 99px; padding: 0 7px; }
.month .mev { font-size: .75em; padding: 1px 5px; border-radius: 4px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 3px solid var(--c); background: color-mix(in srgb, var(--c) 14%, var(--surface)); }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: .82em; color: var(--muted); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* Duración libre */
.dur-quick { display: flex; flex-wrap: wrap; gap: 6px; }
.dur-quick .chip { min-width: 58px; justify-content: center; }
.slot-ok { color: var(--success); font-weight: 600; }
.free-chip { font-size: .8em; padding: 3px 9px; }

/* ---------- Ficha paciente ---------- */
.p-head { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.p-head .avatar { width: 64px; height: 64px; font-size: 1.4em; }
.stat-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.stat-pill { background: var(--hover); border-radius: calc(var(--radius) * .8); padding: 6px 12px; text-align: center; min-width: 88px; }
.stat-pill b { display: block; font-size: 1.25em; }
.stat-pill small { font-size: .75em; }
.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ''; position: absolute; left: 7px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.tl-item { position: relative; margin-bottom: 16px; }
.tl-item::before { content: ''; position: absolute; left: -20px; top: 18px; width: 12px; height: 12px; border-radius: 50%; background: var(--primary); border: 2px solid var(--surface); }
.kv { display: grid; grid-template-columns: minmax(130px, 32%) 1fr; gap: 6px 14px; }
.kv > div:nth-child(odd) { color: var(--muted); font-weight: 600; font-size: .9em; }
.kv > div { min-width: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.progress { height: 9px; background: var(--hover); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); border-radius: 99px; }
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.file-card { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); display: flex; flex-direction: column; }
.file-card .thumb { height: 120px; background: var(--hover); display: grid; place-items: center; overflow: hidden; }
.file-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-card .thumb svg.ic { width: 42px; height: 42px; color: var(--muted); }
.file-card .meta { padding: 8px 10px; font-size: .85em; }
.drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--muted); cursor: pointer; }
.drop.over { border-color: var(--primary); background: var(--primary-soft); }
.scale { display: flex; gap: 4px; flex-wrap: wrap; }
.scale button { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-weight: 700; font: inherit; }
.scale button.on { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Barras simples ---------- */
.hbar { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: 8px 10px; align-items: center; font-size: .9em; }
.hbar .track { height: 10px; background: var(--hover); border-radius: 99px; overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 99px; background: var(--primary); }
.vbars { display: flex; align-items: flex-end; gap: 8px; height: 150px; padding-top: 10px; }
.vbars .vb { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
.vbars .stack { width: 100%; max-width: 38px; display: flex; flex-direction: column-reverse; border-radius: 6px 6px 0 0; overflow: hidden; }
.vbars .vb small { font-size: .72em; white-space: nowrap; }
.list-item { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.time-pill { font-variant-numeric: tabular-nums; font-weight: 700; background: var(--hover); border-radius: 6px; padding: 3px 7px; font-size: .86em; white-space: nowrap; }

/* ---------- Configuración ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--gap); }
.settings-card { display: flex; gap: 14px; align-items: flex-start; cursor: pointer; transition: transform .12s; color: var(--text); text-decoration: none !important; }
.settings-card:hover { transform: translateY(-2px); }
.settings-card .ico { width: 42px; height: 42px; border-radius: calc(var(--radius) * .8); background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; flex: none; }
.settings-card .ico svg.ic { width: 22px; height: 22px; }
.settings-card p { margin: 3px 0 0; color: var(--muted); font-size: .88em; }
.sortable-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: calc(var(--radius) * .8); background: var(--surface); margin-bottom: 6px; }
.sortable-item.drag-over { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.handle { cursor: grab; color: var(--muted); }
.perm-group { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.perm-group h4 { margin-bottom: 8px; }
.theme-card { border: 2px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; background: var(--surface); }
.theme-card.on { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.theme-card .prev { height: 74px; display: flex; }
.theme-card .prev .m { width: 28%; }
.theme-card .prev .b { flex: 1; padding: 8px; display: flex; flex-direction: column; gap: 5px; }
.theme-card .prev .b i { display: block; height: 9px; border-radius: 4px; }
.preview-box { border: 1px dashed var(--border); border-radius: var(--radius); padding: 16px; }
.img-field { display: flex; gap: 10px; align-items: center; }
.img-field .ph { width: 80px; height: 56px; border-radius: 8px; border: 1px solid var(--border); background: var(--hover) center/contain no-repeat; flex: none; }
code.var { background: var(--hover); padding: 1px 6px; border-radius: 5px; font-size: .86em; cursor: pointer; }

/* ---------- Impresión ---------- */
@media print {
  .sidebar, .topbar, .no-print, .btn { display: none !important; }
  .content { padding: 0; }
  .card { box-shadow: none !important; border: 0 !important; }
  body { background: #fff !important; color: #000; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-105%); visibility: hidden; transition: transform .2s, visibility .2s; }
  body.menu-open .sidebar { transform: none; visibility: visible; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  body.menu-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; }
  .menu-toggle { display: inline-flex; }
  body.menu-top .sidebar { position: fixed; width: var(--menu-w); height: 100vh; flex-direction: column; align-items: stretch; overflow-y: auto; }
  body.menu-top .nav { flex-direction: column; flex-wrap: nowrap; }
  body.menu-top .nav a, body.menu-top .nav button.navlink { width: 100%; }
  .g2, .g3 { grid-template-columns: minmax(0, 1fr); }
  .span2 { grid-column: auto; }
  .login { grid-template-columns: 1fr; }
  .login-side { min-height: 180px; padding: 24px; }
}
@media (max-width: 640px) {
  .content { padding: 12px; }
  .topbar { padding: 8px 12px; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .kpi .value { font-size: 1.45em; }
  .modal-bg { padding: 0; }
  .modal { border-radius: 0; min-height: 100vh; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv > div:nth-child(even) { margin-bottom: 8px; }
  .hide-sm { display: none !important; }
  .cal { max-height: calc(100vh - 230px); }
  .month .md { min-height: 70px; }
  .month .mev { font-size: .65em; }
  .topbar .user .name { display: none; }
  .agenda-bar .date-label { min-width: 0; font-size: 1em; flex-basis: 100%; order: -1; }
  .page-head h1 { min-width: 0; }
}

/* Carga del logo del consultorio */
.logo-drop { width: 200px; height: 120px; border: 2px dashed var(--border); border-radius: var(--radius); display: grid; place-items: center; background: var(--hover); overflow: hidden; flex: none; padding: 8px; }
.logo-drop.over { border-color: var(--primary); background: var(--primary-soft); }
.logo-drop img { max-width: 100%; max-height: 100%; object-fit: contain; }

.brand.brand-logo { flex-direction: column; align-items: flex-start; gap: 6px; }
.brand.brand-logo img { max-height: 56px; max-width: 100%; }
.brand.brand-logo small { opacity: .75; font-weight: 500; }
body.menu-top .brand.brand-logo { flex-direction: row; align-items: center; }
body.menu-top .brand.brand-logo img { max-height: 40px; max-width: 180px; }

/* ---------- Celular ---------- */
.bottom-nav { display: none; }
@media (max-width: 900px) {
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; background: var(--surface); border-top: 1px solid var(--border);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); box-shadow: 0 -4px 16px rgba(0,0,0,.06);
  }
  .bottom-nav a, .bottom-nav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; font: inherit; font-size: .68em; font-weight: 600;
    color: var(--muted); background: none; border: 0; text-decoration: none !important; cursor: pointer; border-radius: 10px; position: relative; }
  .bottom-nav a.active { color: var(--primary); }
  .bottom-nav svg.ic { width: 22px; height: 22px; }
  .bottom-nav .plus { color: #fff; }
  .bottom-nav .plus span.circle { width: 44px; height: 44px; margin-top: -18px; border-radius: 50%; background: var(--primary); display: grid; place-items: center; box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 45%, transparent); }
  .bottom-nav .plus span.lbl { color: var(--muted); }
  .bottom-nav .badge-count { position: absolute; top: 2px; right: 22%; background: var(--danger); color: #fff; border-radius: 99px; font-size: .9em; padding: 0 5px; }
  .content { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .toasts { bottom: calc(80px + env(safe-area-inset-bottom)); }
  .topbar .new-turno { display: none; }
}
@media (max-width: 640px) {
  /* Evita el zoom automático de iPhone al tocar un campo */
  input, select, textarea { font-size: 16px; }
  .btn { padding: 9px 13px; }
  .card { padding: 14px; }
  .kpi { padding: 10px 12px; gap: 2px; }
  .kpi .label { font-size: .72em; }
  .kpi .value { font-size: 1.3em; }
  .page-head { margin-bottom: 12px; }
  .page-head h1 { font-size: 1.35em; }
  /* Ventanas a pantalla completa con encabezado y botones siempre visibles */
  .modal { display: flex; flex-direction: column; }
  .modal-head { position: sticky; top: 0; background: var(--surface); z-index: 2; }
  .modal-foot { position: sticky; bottom: 0; background: var(--surface); z-index: 2; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1 1 auto; }
  .modal-body { flex: 1; }
  .btn.ghost.wrap, .btn.wrap { white-space: normal; text-align: left; }
  /* Tablas como tarjetas */
  table.t.cards thead { display: none; }
  table.t.cards, table.t.cards tbody, table.t.cards tfoot { display: block; }
  table.t.cards tr { display: block; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; padding: 8px 12px; background: var(--surface); }
  table.t.cards td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 4px 0; text-align: right; }
  table.t.cards td::before { content: attr(data-label); color: var(--muted); font-size: .82em; font-weight: 600; text-align: left; flex: none; max-width: 45%; }
  table.t.cards td:first-child { font-weight: 700; font-size: 1.05em; }
  table.t.cards td:empty, table.t.cards td.empty-cell { display: none; }
  table.t.cards td.actions { justify-content: flex-end; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 6px; }
  table.t.cards td.actions::before { content: none; }
  table.t.cards tr:has(td.empty) { border: 0; }
  table.t.cards td.empty { display: block; text-align: center; }
  table.t.cards td.empty::before { content: none; }
  table.t.cards tfoot tr { background: var(--hover); }
  .table-wrap { overflow: visible; }
  .agenda-filters.collapsed { display: none; }
  .tabs button { padding: 10px 10px; }
}

/* Evolución del paciente */
.evo-grid-wrap { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: var(--gap); }
.evo-plot { position: relative; margin-top: 8px; }
.evo-plot svg { width: 100%; height: auto; display: block; overflow: visible; }
.evo-grid { stroke: var(--border); stroke-width: 1; }
.evo-axis { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.evo-line { fill: none; stroke: var(--primary); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.evo-dot { fill: var(--primary); stroke: var(--surface); stroke-width: 2; }
.evo-dot.on { r: 6.5; }
.evo-last { fill: var(--text); font-size: 12px; font-weight: 700; font-family: var(--font); }
.evo-tip { position: absolute; transform: translate(-50%, calc(-100% - 12px)); background: var(--text); color: var(--surface); padding: 6px 10px; border-radius: 8px; font-size: .8em; pointer-events: none; white-space: nowrap; z-index: 5; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
@media print { .evo-card { break-inside: avoid; } .tabs, .p-head .row, .alert { display: none !important; } }

/* Consentimiento y firma */
.consent-text { max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; background: var(--hover); font-size: .95em; line-height: 1.6; }
.sig-pad { position: relative; background: #fff; border: 2px dashed var(--border); border-radius: var(--radius); height: 194px; touch-action: none; overflow: hidden; }
.sig-pad canvas { display: block; touch-action: none; cursor: crosshair; position: relative; z-index: 1; }
.sig-hint { position: absolute; inset: 0; display: grid; place-items: center; color: #9ca3af; font-size: .9em; pointer-events: none; }
.sig-line { position: absolute; left: 24px; right: 24px; bottom: 38px; border-top: 1px solid #d1d5db; pointer-events: none; }
