/* ============================================================
   ERP elab · assets/app.css
   Tokens derivados del logo (docs/00-diseno-erp-elab.md §2). Menú lateral:
   CSS de Charly con los hex en morado. Ningún color literal fuera de :root y
   del bloque de temas; los semánticos (verde/rojo/ámbar) no cambian por marca.
   ============================================================ */
:root {
  --brand: #A3387F; --brand-dark: #7A2560; --brand-ink: #3B1431; --brand-soft: #F6E6F0;
  --accent: #E8782B; --accent2: #B44D12;
  --star-red: #C9303E; --star-green: #2E9E5B; --star-purple: #7B4DB8;
  --green: #1D9E5F; --red: #D64533; --amber: #D98A12; --blue: #3F74C9;
  --green-soft: rgba(29,158,95,.14); --red-soft: rgba(214,69,51,.14); --amber-soft: rgba(217,138,18,.16); --blue-soft: rgba(63,116,201,.14);
  --bg: #F5F2F6; --card: #FFFFFF; --text: #1C1726; --muted: #6B6475; --border: #E3DCE6; --line-strong: #CDBFD2; --input-bg: #FFFFFF;
  --sidebar-bg: #561C47;
  --sidebar-grad: linear-gradient(180deg, #3B1431 0%, #561C47 45%, #71255E 100%);
  --sidebar-grad-2: linear-gradient(180deg, #4E1A41 0%, #7E2A68 50%, #42163A 100%);
  --sidebar-text: #F5E6F0; --sidebar-muted: #D7AFC9; --sidebar-active-bg: rgba(255,255,255,.16);
  --grad-tape: linear-gradient(90deg, #A3387F 0 62%, #E8782B 62% 100%);
  --grad: linear-gradient(100deg, #3B1431 0%, #7A2560 55%, #A3387F 100%);
  --heat-0:#ECE8EF; --heat-1:#D9B8D0; --heat-2:#B88CC4; --heat-3:#E8C547; --heat-4:#E08B3C; --heat-5:#D1453A;
  --radius: 6px; --radius-sm: 4px; --sidebar-w: 236px; --header-h: 58px;
  --shadow: 0 1px 2px rgba(28,23,38,.06);
  --shadow-lg: 0 12px 32px -8px rgba(28,23,38,.28), 0 0 0 1px var(--border);
  --shadow-key: 0 2px 0 0 rgba(28,23,38,.16);
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --login-bg: radial-gradient(circle at 30% 20%, #561C47, #1E0A19 65%);
  font-size: 14px;
}
[data-theme="noche"] {
  --bg: #120C14; --card: #1C1420; --text: #F1EAF2; --muted: #A596AA; --border: #2E2333; --line-strong: #43354A; --input-bg: #16101A;
  --brand-soft: #2A1A28; --brand-dark: #D77AB8; --brand-ink: #F1EAF2;
  --green-soft: rgba(29,158,95,.22); --red-soft: rgba(214,69,51,.22); --amber-soft: rgba(217,138,18,.22); --blue-soft: rgba(63,116,201,.22);
  --heat-0:#22202A; --heat-1:#3B2E44; --heat-2:#5A3F6E; --heat-3:#9C8420; --heat-4:#B3652A; --heat-5:#C9402F;
  --shadow: 0 1px 2px rgba(0,0,0,.5); --shadow-lg: 0 16px 40px -10px rgba(0,0,0,.7), 0 0 0 1px var(--border); --shadow-key: 0 2px 0 0 rgba(0,0,0,.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: 'Inter', 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; -webkit-font-smoothing: antialiased; font-feature-settings: 'tnum' 1, 'cv05' 1; }
button { font-family: inherit; color: inherit; cursor: pointer; }
a { color: var(--brand-dark); }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.mono { font-family: var(--mono); }
.eyebrow, .nav-section, .field label, .tbl th, .stat-lbl, .role, .cmdk-foot, .tabs-sub .tab { font-family: var(--mono); text-transform: uppercase; letter-spacing: .06em; }
.muted { color: var(--muted); } .small { font-size: .8rem; } .right { text-align: right; } .center { text-align: center; }
.nowrap { white-space: nowrap; } .hidden { display: none !important; }
.ok { color: var(--green); } .err { color: var(--red); } .warn { color: var(--amber); }
.star { width: 26px; height: 26px; flex-shrink: 0; stroke: none; }

/* ── LOGIN ── */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: none; align-items: center; justify-content: center; background: var(--login-bg); padding: 20px; }
.login-wrap.on { display: flex; }
.login-card { background: var(--card); border-radius: 10px; padding: 30px 28px 20px; width: 100%; max-width: 372px; box-shadow: var(--shadow-lg); border-top: 3px solid; border-image: var(--grad-tape) 1; }
.login-logo { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 4px; }
.login-logo .star { width: 38px; height: 38px; }
.login-logo .wordmark { font-size: 2rem; font-weight: 800; letter-spacing: -.03em; color: var(--brand); }
.login-sub { text-align: center; color: var(--muted); font-size: .8rem; margin-bottom: 18px; }
.login-msg { min-height: 1.4em; margin-top: 10px; font-size: .82rem; color: var(--red); text-align: center; }
.login-foot { margin-top: 14px; font-size: .64rem; color: var(--muted); text-align: center; }

/* ── APP LAYOUT ── */
.app { display: none; }
.app.on { display: block; }

/* SIDEBAR (CSS de Charly, hex en morado) */
.sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w); background: var(--sidebar-bg); background-image: var(--sidebar-grad); color: #fff; display: flex; flex-direction: column; z-index: 100; transition: transform .25s cubic-bezier(.4,0,.2,1), width .2s ease; border-right: 1px solid rgba(255,255,255,.07); padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); padding-left: env(safe-area-inset-left, 0px); }
.sidebar::before { content: ''; position: absolute; inset: 0; z-index: 0; pointer-events: none; background-image: var(--sidebar-grad-2); opacity: 0; animation: sbRespira 9s ease-in-out infinite alternate; will-change: opacity; }
.sidebar > * { position: relative; z-index: 1; }
@keyframes sbRespira { from { opacity: 0; } to { opacity: 1; } }
@media (max-width: 900px), (prefers-reduced-motion: reduce) { .sidebar::before { animation: none; opacity: 0; will-change: auto; } }
.sidebar-header { height: var(--header-h); display: flex; align-items: center; padding: 0 18px; border-bottom: 1px solid rgba(255,255,255,.08); gap: 10px; position: relative; flex-shrink: 0; }
.sidebar-header::after { content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--grad-tape); }
.sidebar-header .brand { font-size: 1.25rem; font-weight: 800; letter-spacing: -.02em; color: #fff; }
.sidebar-header .ver { font-size: .66rem; color: var(--sidebar-muted); margin-left: auto; }
.sidebar-user { padding: 18px 20px 16px; border-bottom: 1px solid rgba(255,255,255,.07); display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; }
.sidebar-user .avatar { width: 54px; height: 54px; border-radius: var(--radius); display: flex; align-items: center; justify-content: center; background: var(--grad); color: #fff; font-weight: 800; font-size: 1.1rem; box-shadow: 0 0 0 1px rgba(255,255,255,.18), 0 0 0 4px rgba(163,56,127,.25); }
.sidebar-user .name { font-weight: 600; font-size: .9rem; color: #fff; }
.sidebar-user .role { font-size: .66rem; color: #FFC29E; letter-spacing: .1em; margin-top: 2px; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 0 14px; scrollbar-width: thin; overscroll-behavior: contain; }
.nav-section { padding: 14px 20px 6px; font-size: .6rem; font-weight: 700; color: var(--sidebar-muted); letter-spacing: .14em; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 9px 20px; color: var(--sidebar-text); cursor: pointer; font-size: .865rem; font-weight: 500; position: relative; border-left: 3px solid transparent; transition: color .14s, background .14s; background: none; border-top: 0; border-right: 0; border-bottom: 0; width: 100%; text-align: left; }
.nav-item::before { content: ''; position: absolute; left: -3px; top: 50%; bottom: 50%; width: 3px; background: var(--accent); transition: top .18s ease, bottom .18s ease; }
.nav-item:hover { background: rgba(255,255,255,.09); color: #fff; }
.nav-item:hover::before { top: 6px; bottom: 6px; }
.nav-item.active { background: var(--sidebar-active-bg); color: #fff; font-weight: 600; }
.nav-item.active::before { top: 0; bottom: 0; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; transition: opacity .14s, transform .14s; }
.nav-item:hover svg, .nav-item.active svg { opacity: 1; transform: translateX(1px); }
.nav-item .cnt { margin-left: auto; font-family: var(--mono); font-size: .66rem; background: var(--accent); color: #1C1726; border-radius: 10px; padding: 0 7px; font-weight: 600; }
.nav-item.locked { opacity: .38; cursor: not-allowed; }
.nav-item.locked::after { content: 'PRONTO'; font-family: var(--mono); font-size: .55rem; letter-spacing: .08em; position: absolute; right: 12px; top: 50%; transform: translateY(-50%); border: 1px solid currentColor; border-radius: 2px; padding: 0 3px; }
.sidebar-footer { padding: 12px 20px; border-top: 1px solid rgba(255,255,255,.07); }
.sidebar-footer button { background: none; border: none; color: var(--sidebar-muted); font-size: .82rem; display: flex; align-items: center; gap: 8px; transition: color .15s; padding: 0; }
.sidebar-footer button svg { width: 16px; height: 16px; }
.sidebar-footer button:hover { color: var(--accent); }
.sidebar-footer .sb-link { color: var(--sidebar-muted); font-size: .82rem; display: flex; align-items: center; gap: 8px; text-decoration: none; margin-bottom: 8px; transition: color .15s; }
.sidebar-footer .sb-link svg { width: 16px; height: 16px; } .sidebar-footer .sb-link:hover { color: var(--accent); }
.sidebar-footer #btn-instalar { margin-bottom: 8px; color: #FFC29E; }
body.sb-mini .sidebar-footer .sb-link span, body.sb-mini #btn-instalar span { display: none; }
.sidebar-footer .dbv { font-size: .62rem; color: var(--sidebar-muted); margin-top: 8px; }
.sidebar-footer .dbv.atras { color: #FFC29E; font-weight: 700; }
#sb-collapse { background: none; border: none; color: var(--sidebar-muted); padding: 10px; display: flex; align-items: center; justify-content: center; border-top: 1px solid rgba(255,255,255,.07); transition: color .15s; }
#sb-collapse svg { width: 18px; height: 18px; transition: transform .25s ease; }
#sb-collapse:hover { color: #fff; }
@media (max-width: 1024px) { #sb-collapse { display: none; } }
@media (min-width: 1025px) {
  body.sb-mini { --sidebar-w: 64px; }
  body.sb-mini .sidebar-header .brand, body.sb-mini .sidebar-header .ver, body.sb-mini .nav-section, body.sb-mini .sidebar-user .name, body.sb-mini .sidebar-user .role, body.sb-mini .sidebar-footer button span, body.sb-mini .sidebar-footer .dbv { display: none; }
  body.sb-mini .sidebar-header { justify-content: center; padding: 0 8px; }
  body.sb-mini .sidebar-user { padding: 14px 8px; }
  body.sb-mini .sidebar-user .avatar { width: 38px; height: 38px; font-size: .85rem; }
  body.sb-mini .nav-item { justify-content: center; padding: 12px 0; font-size: 0; gap: 0; }
  body.sb-mini .nav-item svg { width: 19px; height: 19px; }
  body.sb-mini .nav-item .cnt, body.sb-mini .nav-item.locked::after { display: none; }
  body.sb-mini #sb-collapse svg { transform: rotate(180deg); }
  body.sb-mini .sidebar-footer { padding: 12px 8px; display: flex; justify-content: center; }
}
#sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 99; }

/* MAIN */
.main { margin-left: var(--sidebar-w); min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; transition: margin-left .25s ease; min-width: 0; }
.topbar { height: var(--header-h); position: sticky; top: 0; z-index: 50; background: var(--card); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; padding: 0 22px; padding-top: env(safe-area-inset-top, 0px); }
.topbar::after { content: ''; position: absolute; left: 0; right: 0; bottom: -2px; height: 2px; background: var(--grad-tape); }
.topbar h1 { font-size: 1rem; font-weight: 700; color: var(--brand-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
#menu-toggle { display: none; background: none; border: 1px solid var(--border); border-radius: var(--radius-sm); width: 36px; height: 36px; align-items: center; justify-content: center; flex-shrink: 0; }
#menu-toggle svg { width: 20px; height: 20px; }
.topbar .search { margin-left: auto; display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: var(--radius); padding: 0 12px; height: 34px; color: var(--muted); font-size: .82rem; min-width: 260px; background: var(--bg); text-align: left; }
.topbar .search svg { width: 15px; height: 15px; flex-shrink: 0; }
.topbar .search span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .search kbd { font-family: var(--mono); font-size: .66rem; border: 1px solid var(--line-strong); border-radius: 3px; padding: 0 5px; }
.tb-user { background: none; border: 1px solid var(--border); border-radius: var(--radius); padding: 0 10px 0 4px; height: 34px; display: flex; align-items: center; gap: 8px; font-size: .8rem; font-weight: 600; color: var(--text); flex-shrink: 0; }
.tb-user .avatar { width: 26px; height: 26px; border-radius: 4px; background: var(--grad); color: #fff; font-size: .66rem; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.content { padding: 22px; padding-bottom: calc(22px + env(safe-area-inset-bottom, 0px)); flex: 1; }
.page-anim > * { animation: fadeUp .25s ease both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── COMPONENTES ── */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .grow { flex: 1 1 220px; min-width: 0; }
.toolbar .fila-acc { display: flex; gap: 8px; align-items: center; margin-left: auto; flex: none; }
.tabs { display: flex; gap: 6px; margin-bottom: 16px; overflow-x: auto; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
.tab { flex: none; padding: 7px 14px; border: 1px solid var(--border); background: var(--card); color: var(--muted); border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.tab.act { background: var(--brand); color: #fff; border-color: var(--brand); }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; position: relative; box-shadow: var(--shadow); overflow: hidden; min-width: 0; }
.stat-card.click { cursor: pointer; } .stat-card.click:hover { border-color: var(--line-strong); }
.stat-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--c, var(--brand)); }
.stat-lbl { font-size: .62rem; color: var(--muted); font-weight: 600; }
.stat-val { font-size: 1.55rem; font-weight: 800; margin-top: 4px; font-family: var(--mono); color: var(--brand-ink); line-height: 1.2; }
.stat-sub { font-size: .74rem; color: var(--muted); margin-top: 2px; }

.grid2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 14px; }
.grid-eq { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 14px; min-width: 0; }
.card-head { padding: 11px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: .9rem; color: var(--brand-ink); position: relative; flex-wrap: wrap; }
.card-head::before { content: ''; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; background: var(--brand); }
.card-head .right { margin-left: auto; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.card-body { padding: 14px 16px; }
.card-body.flush { padding: 0; }
.empty { padding: 26px 16px; text-align: center; color: var(--muted); font-size: .85rem; }
.empty b { display: block; color: var(--text); margin-bottom: 2px; }

.btn { border: 1px solid var(--line-strong); background: var(--card); color: var(--text); border-radius: var(--radius-sm); padding: 7px 13px; font-size: .8rem; font-weight: 600; box-shadow: var(--shadow-key); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; line-height: 1.3; }
.btn svg { width: 15px; height: 15px; }
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.brand { background: var(--brand); border-color: var(--brand-dark); color: #fff; }
.btn.accent { background: var(--accent); border-color: var(--accent2); color: #1C1726; }
.btn.green { background: var(--green); border-color: #157A48; color: #fff; }
.btn.red { background: var(--red); border-color: #A8362A; color: #fff; }
.btn.ghost { box-shadow: none; background: transparent; }
.btn.sm { padding: 4px 9px; font-size: .74rem; }
.btn.block { width: 100%; justify-content: center; padding: 10px; font-size: .9rem; }
.btn.wa { background: #25D366; border-color: #1AA653; color: #fff; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: .64rem; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea, .inp { font-family: inherit; font-size: .9rem; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--input-bg); color: var(--text); width: 100%; min-width: 0; }
.field input:focus, .field select:focus, .field textarea:focus, .inp:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.field textarea { min-height: 72px; resize: vertical; }
.field .hint { font-size: .72rem; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 8px; font-size: .85rem; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }
fieldset.group { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px 14px; margin-bottom: 14px; }
fieldset.group legend { font-family: var(--mono); font-size: .64rem; text-transform: uppercase; letter-spacing: .08em; color: var(--brand-dark); padding: 0 6px; font-weight: 700; }

.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.tbl { width: 100%; border-collapse: collapse; font-size: .82rem; }
.tbl th { text-align: left; padding: 8px 10px; background: var(--bg); color: var(--muted); font-size: .62rem; font-weight: 600; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--brand-soft); }
.tbl td:first-child { border-left: 3px solid transparent; }
.tbl tr.click:hover td:first-child { border-left-color: var(--accent); }
.tbl .num { text-align: right; font-family: var(--mono); white-space: nowrap; }
.tbl tr.inactivo td { opacity: .55; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 10px; font-size: .68rem; font-weight: 700; white-space: nowrap; }
.b-ok { background: var(--green-soft); color: var(--green); } .b-warn { background: var(--amber-soft); color: #9A5E05; } .b-err { background: var(--red-soft); color: var(--red); }
.b-brand { background: var(--brand-soft); color: var(--brand-dark); } .b-mut { background: var(--bg); color: var(--muted); } .b-blue { background: var(--blue-soft); color: var(--blue); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; background: var(--c, var(--brand)); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 16px; font-size: .8rem; color: var(--muted); }

/* MODAL: cabecera fija, cuerpo con scroll, cierra SOLO con la ✕ */
.modal-overlay { position: fixed; inset: 0; background: rgba(28,23,38,.55); z-index: 200; display: none; align-items: flex-start; justify-content: center; padding: 4vh 16px; padding-bottom: calc(4vh + env(safe-area-inset-bottom, 0px)); overflow-y: auto; }
.modal-overlay.on { display: flex; }
.modal { background: var(--card); color: var(--text); border-radius: 8px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; display: flex; flex-direction: column; max-height: 92vh; max-height: 92dvh; animation: pop .18s ease; border-top: 3px solid; border-image: var(--grad-tape) 1; }
.modal.wide { max-width: 860px; } .modal.xl { max-width: 1100px; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.modal-head h3 { font-size: .95rem; font-weight: 700; color: var(--brand-ink); flex: 1; min-width: 0; }
.modal-head .sub { font-size: .74rem; color: var(--muted); font-weight: 500; }
.modal-x { width: 36px; height: 36px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--card); color: var(--muted); font-size: 1.1rem; line-height: 1; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.modal-x:hover { color: var(--red); border-color: var(--red); }
.modal-body { padding: 16px; overflow-y: auto; }

.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 999; display: flex; flex-direction: column; gap: 8px; padding-bottom: env(safe-area-inset-bottom, 0px); }
.toast { padding: 11px 16px; border-radius: var(--radius); font-size: .85rem; font-weight: 500; color: #fff; box-shadow: var(--shadow-lg); animation: slideup .25s ease; max-width: 340px; }
.toast.ok { background: var(--green); } .toast.err { background: var(--red); } .toast.inf { background: var(--brand-dark); } .toast.warn { background: var(--amber); }
@keyframes slideup { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* Ctrl+K */
.cmdk { position: fixed; inset: 0; z-index: 9999; background: rgba(28,23,38,.5); display: none; align-items: flex-start; justify-content: center; padding: 10vh 16px; }
.cmdk.on { display: flex; }
.cmdk-card { width: 100%; max-width: 580px; background: var(--card); border-radius: 8px; box-shadow: var(--shadow-lg); overflow: hidden; }
.cmdk-card input { width: 100%; border: none; border-bottom: 1px solid var(--border); padding: 14px 16px; font-size: 1rem; font-family: inherit; background: var(--card); color: var(--text); }
.cmdk-card input:focus { outline: none; }
.cmdk-res { max-height: 50vh; overflow-y: auto; }
.cmdk-g { font-family: var(--mono); font-size: .6rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); padding: 8px 16px 2px; }
.cmdk-i { display: flex; align-items: center; gap: 10px; padding: 9px 16px; cursor: pointer; font-size: .88rem; border-left: 3px solid transparent; }
.cmdk-i.sel, .cmdk-i:hover { background: var(--brand-soft); border-left-color: var(--accent); }
.cmdk-i .sub { color: var(--muted); font-size: .76rem; margin-left: auto; font-family: var(--mono); }
.cmdk-foot { padding: 8px 16px; font-size: .62rem; color: var(--muted); border-top: 1px solid var(--border); }

/* Skeleton */
.skel { background: linear-gradient(90deg, var(--border) 25%, var(--bg) 50%, var(--border) 75%); background-size: 200% 100%; animation: skel 1.2s infinite; border-radius: var(--radius-sm); height: 14px; margin: 8px 0; }
@keyframes skel { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* Horario semanal (editor) */
.hor-grid { display: grid; grid-template-columns: 90px 1fr; gap: 6px 10px; align-items: start; font-size: .84rem; }
.hor-dia { font-weight: 600; padding-top: 6px; }
.hor-turnos { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.hor-turno { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.hor-turno input[type=time] { width: 112px; }

/* Lista de citas del día (dashboard) */
.lista-citas { display: flex; flex-direction: column; }
.cita-row { display: grid; grid-template-columns: 56px 1fr auto; gap: 10px; align-items: center; padding: 8px 16px; border-bottom: 1px solid var(--border); font-size: .84rem; }
.cita-row:last-child { border-bottom: 0; }
.cita-row .h { font-family: var(--mono); font-weight: 600; color: var(--brand-ink); }
.cita-row .p { font-weight: 600; } .cita-row .t { font-size: .74rem; color: var(--muted); }
.cita-row .t i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--c); margin-right: 4px; vertical-align: middle; }

/* ── AGENDA ── */
.ag-nav { display: flex; gap: 6px; align-items: center; }
.ag-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); max-height: calc(100dvh - 230px); -webkit-overflow-scrolling: touch; }
.ag-grid { display: grid; position: relative; min-width: max-content; }
.ag-h { position: sticky; top: 0; z-index: 3; background: var(--bg); border-bottom: 1px solid var(--border); border-left: 1px solid var(--border); padding: 6px 8px; font-weight: 700; font-size: .78rem; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ag-h small { display: block; font-weight: 500; color: var(--muted); font-family: var(--mono); font-size: .6rem; text-transform: uppercase; letter-spacing: .04em; }
.ag-h.click { cursor: pointer; } .ag-h.click:hover { color: var(--brand); } .ag-h.hoy { color: var(--brand-dark); box-shadow: inset 0 -3px 0 var(--accent); }
.ag-t { position: sticky; left: 0; z-index: 2; background: var(--bg); font-family: var(--mono); font-size: .66rem; color: var(--muted); text-align: right; padding: 2px 6px 0 0; border-top: 1px solid var(--border); }
.ag-t.hora { border-top-color: var(--line-strong); }
.ag-cell { border-top: 1px solid var(--border); border-left: 1px solid var(--border); }
.ag-cell.hora { border-top-color: var(--line-strong); }
.ag-cell.libre { cursor: pointer; } .ag-cell.libre:hover { background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand); }
.ag-cell.off { background: repeating-linear-gradient(135deg, var(--bg) 0 6px, var(--border) 6px 12px); }
.ag-cell.past:not(.off) { background: rgba(28,23,38,.025); }
.ag-chip { position: relative; z-index: 1; margin: 1px 2px; border-radius: 4px; border-left: 3px solid var(--c); background: color-mix(in srgb, var(--c) 16%, var(--card)); padding: 3px 6px; font-size: .72rem; line-height: 1.25; overflow: hidden; cursor: pointer; box-shadow: var(--shadow); color: var(--text); }
.ag-chip b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ag-chip .t { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.ag-chip .m { font-family: var(--mono); font-size: .6rem; color: var(--muted); }
.ag-chip:hover { filter: brightness(.95); }
.ag-chip.e-confirmada { border-left-style: double; border-left-width: 5px; }
.ag-chip.e-llego { outline: 2px solid var(--blue); outline-offset: -2px; }
.ag-chip.e-atendida { opacity: .7; background: var(--green-soft); }
.ag-chip.e-no_asistio { background: var(--red-soft); opacity: .75; } .ag-chip.e-no_asistio b { text-decoration: line-through; }
.ag-leyenda { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; }
.ag-sw { display: inline-block; width: 12px; height: 12px; border-radius: 2px; vertical-align: middle; margin-right: 4px; border: 1px solid var(--border); }
.ag-mes { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.ag-mes-h { font-family: var(--mono); font-size: .62rem; text-transform: uppercase; color: var(--muted); text-align: center; padding: 4px 0; }
.ag-mes .d { min-height: 76px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px; cursor: pointer; background: var(--card); font-size: .74rem; }
.ag-mes .d:hover { border-color: var(--brand); } .ag-mes .d.otro { opacity: .35; } .ag-mes .d.hoy { outline: 2px solid var(--brand); outline-offset: -2px; } .ag-mes .d.off { background: var(--bg); }
.ag-mes .n { font-family: var(--mono); font-weight: 600; font-size: .8rem; } .ag-mes .cnt { margin-top: 4px; line-height: 1.3; }
.auto-wrap { position: relative; }
.auto-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; background: var(--card); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); max-height: 240px; overflow-y: auto; }
.auto-item { padding: 8px 10px; cursor: pointer; font-size: .85rem; border-bottom: 1px solid var(--border); } .auto-item:last-child { border-bottom: 0; } .auto-item:hover { background: var(--brand-soft); }
.serie-cab { background: var(--brand-soft); border-radius: var(--radius-sm); padding: 8px 12px; font-size: .88rem; }
.serie-tabla tr.conf td { background: var(--red-soft); } .serie-tabla tr.auto td { background: var(--amber-soft); } .serie-tabla tr.omit td { opacity: .45; }
@media (max-width: 768px) { .ag-wrap { max-height: calc(100dvh - 200px); } .ag-mes .d { min-height: 56px; padding: 4px; font-size: .66rem; } }

/* ── EXPEDIENTE ── */
.exp-head { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.exp-avatar { width: 54px; height: 54px; border-radius: var(--radius); background: var(--grad); color: #fff; font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; flex-shrink: 0; }
.exp-nombre { font-size: 1.15rem; font-weight: 800; color: var(--brand-ink); line-height: 1.2; }
.consulta-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; cursor: pointer; background: var(--card); font-size: .88rem; box-shadow: var(--shadow); }
.consulta-card:hover { border-color: var(--brand); }
.consulta-card .fecha { font-family: var(--mono); font-size: .72rem; color: var(--muted); }
.texto-clinico { white-space: pre-wrap; font-size: .9rem; line-height: 1.55; overflow-wrap: anywhere; }
.eva-chart { width: 100%; height: auto; max-height: 240px; display: block; }
.leg { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: .74rem; color: var(--muted); }
.leg i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.eva-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.eva-row input[type=range] { flex: 1 1 120px; accent-color: var(--brand); min-width: 0; }
.eva-val { font-family: var(--mono); font-weight: 700; width: 28px; text-align: center; font-size: 1.05rem; color: var(--brand-dark); }
.arch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.arch-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow); min-width: 0; }
.arch-thumb { height: 130px; background: var(--bg); display: flex; align-items: center; justify-content: center; overflow: hidden; text-decoration: none; }
.arch-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.arch-pdf { font-family: var(--mono); font-weight: 700; color: var(--red); font-size: 1.3rem; border: 2px solid var(--red); border-radius: 6px; padding: 6px 12px; }
.arch-body { padding: 8px 10px; font-size: .8rem; flex: 1; min-width: 0; }
.arch-acc { display: flex; gap: 4px; padding: 6px 8px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.arch-acc .btn { text-decoration: none; }
.drop { border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); cursor: pointer; font-size: .9rem; }
.drop.over { border-color: var(--brand); background: var(--brand-soft); }
details summary { cursor: pointer; }

/* ── POS / CAJA ── */
.pos-grid { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 14px; align-items: start; }
.pos-ticket { position: sticky; top: calc(var(--header-h) + 12px); margin-bottom: 0; }
.pos-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.pos-item { text-align: left; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); font-family: inherit; color: var(--text); cursor: pointer; min-width: 0; }
.pos-item:hover { border-color: var(--brand); background: var(--brand-soft); }
.pos-item:disabled { opacity: .45; cursor: not-allowed; }
.pos-item b { font-size: .88rem; }
.pos-precio { font-family: var(--mono); font-weight: 700; color: var(--brand-dark); margin-top: 2px; }
.pos-pac { display: flex; align-items: center; gap: 8px; background: var(--brand-soft); border-radius: var(--radius-sm); padding: 6px 10px; font-size: .88rem; }
.pos-pac > :first-child { flex: 1; min-width: 0; }
.pos-lineas td { padding: 6px 6px; } .pos-lineas td:first-child { border-left: 0; }
.pos-tot { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; font-size: .9rem; }
.pos-tot > div { display: flex; justify-content: space-between; padding: 2px 0; }
.pos-tot .total { font-size: 1.25rem; font-weight: 800; color: var(--brand-ink); }
.pos-pago { display: grid; grid-template-columns: 1.2fr 1fr 1fr auto; gap: 6px; margin-bottom: 6px; align-items: center; }
.pos-pago .inp { padding: 7px 8px; }
.aviso-turno { display: flex; gap: 10px; align-items: center; background: var(--amber-soft); border: 1px solid var(--amber); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; font-size: .88rem; }
.aviso-turno.suave { background: var(--brand-soft); border-color: var(--border); }
.aviso-turno svg { width: 20px; height: 20px; flex-shrink: 0; color: var(--amber); } .aviso-turno.suave svg { color: var(--brand); }
.aviso-turno span { flex: 1; min-width: 0; }
.tbl-junta th, .tbl-junta td { padding-left: 6px; padding-right: 6px; }
@media (max-width: 1100px) { .pos-grid { grid-template-columns: 1fr; } .pos-ticket { position: static; } }
@media (max-width: 768px) { .pos-pago { grid-template-columns: 1fr 1fr; } .pos-items { grid-template-columns: 1fr 1fr; } }

/* Clave temporal del portal (se enseña UNA vez) */
.clave-grande { font-family: var(--mono); font-size: 2.2rem; font-weight: 700; letter-spacing: .2em; text-align: center; background: var(--brand-soft); color: var(--brand-dark); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
.texto-copia { white-space: pre-wrap; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; font-size: .84rem; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: .86rem; }
.kv dt { color: var(--muted); font-size: .74rem; font-family: var(--mono); text-transform: uppercase; letter-spacing: .05em; padding-top: 2px; }
.kv dd { min-width: 0; overflow-wrap: anywhere; }

/* ── RESPONSIVE ── */
@media (max-width: 1100px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 900px) {
  input, select, textarea { font-size: 16px !important; }
  .form-grid, .form-grid.c3 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 8px; }
}
@media (max-width: 768px) {
  /* translate3d y SIN transition: iOS deja la capa a medio componer con transition en position:fixed */
  .sidebar { transform: translate3d(-100%, 0, 0); transition: none; width: min(280px, 84vw); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translate3d(0, 0, 0); }
  #sidebar-overlay.on { display: block; }
  .main { margin-left: 0; }
  #menu-toggle { display: flex; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar .search { min-width: 0; flex: 1; }
  .topbar .search span, .topbar .search kbd { display: none; }
  .topbar .search { padding: 0 9px; }
  .tb-user span { display: none; }
  .tb-user { padding: 0 4px; }
  .content { padding: 12px 10px; }
  .stats-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .stat-card { padding: 12px; } .stat-val { font-size: 1.25rem; }
  .card-body { padding: 12px; }
  .toolbar .fila-acc { margin-left: 0; width: 100%; }
  .modal-overlay { padding: 2vh 8px; }
  .modal-body { padding: 12px; }
  .cita-row { grid-template-columns: 48px 1fr; } .cita-row > :last-child { grid-column: 2; }
  .toast-container { left: 12px; right: 12px; bottom: 12px; } .toast { max-width: none; }
}
@media (display-mode: standalone) { body { overscroll-behavior-y: none; } }
@media print { .sidebar, .topbar, #sidebar-overlay, .toast-container, .cmdk { display: none !important; } .main { margin-left: 0; } }

/* ── Finanzas: gastos, nómina, IMSS ── */
.fin-in { width: 108px; min-width: 90px; text-align: right; font-family: var(--mono); font-size: .85rem; padding: 5px 7px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--input-bg); color: var(--text); }
.fin-in:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.fin-neg { color: var(--red); } .fin-pos { color: var(--green); }
.fin-periodo { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.fin-periodo .inp { width: auto; }

/* ── Farmacia ── */
.fm-lineas td { vertical-align: middle; }
.fm-lineas select, .fm-lineas input[type=text] { font-family: inherit; font-size: .85rem; padding: 5px 7px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--input-bg); color: var(--text); width: 100%; min-width: 140px; }
.fm-lineas .fin-in { width: 92px; min-width: 80px; }
.fm-lineas tr.servicio td { opacity: .55; }
.fm-stock-bajo { color: var(--red); font-weight: 700; }
.fm-aviso { background: var(--amber-soft); border: 1px solid var(--amber); color: #7A4A00; border-radius: var(--radius); padding: 10px 14px; font-size: .85rem; margin-bottom: 14px; }

/* ── Reportes ── */
.rp-heat { display: grid; grid-template-columns: 52px repeat(7, minmax(44px, 1fr)); gap: 3px; font-size: .78rem; }
.rp-heat .rp-h { font-family: var(--mono); font-size: .66rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; align-self: center; text-align: center; }
.rp-heat .rp-c { border: 1px solid var(--border); border-radius: 4px; min-height: 26px; display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-weight: 600; }
.rp-heat .rp-t { text-align: center; padding-top: 4px; border-top: 2px solid var(--border); font-family: var(--mono); }
.rp-barras text { font-family: var(--mono); }
@media (max-width: 700px) { .rp-heat { grid-template-columns: 38px repeat(7, minmax(0, 1fr)); gap: 2px; font-size: .68rem; } .rp-heat .rp-c { min-height: 22px; } .rp-heat .rp-h { font-size: .58rem; letter-spacing: 0; } }

/* ── Recetas ── */
.rx-items td { vertical-align: top; min-width: 150px; }
.rx-items .rx-in { width: 100%; font-family: inherit; font-size: .83rem; padding: 5px 7px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--input-bg); color: var(--text); }
.rx-items .rx-in:focus { outline: 2px solid var(--brand); outline-offset: -1px; }

/* ── Consentimiento: lectura y firma en pantalla ── */
.consent-texto { max-height: 38vh; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; white-space: pre-wrap; font-size: .92rem; line-height: 1.55; background: var(--bg); }
.firma-canvas { width: 100%; height: 190px; border: 2px dashed var(--line-strong); border-radius: var(--radius); background: #fff; touch-action: none; cursor: crosshair; display: block; }
@media (max-width: 700px) { .consent-texto { max-height: 32vh; font-size: .88rem; } .firma-canvas { height: 160px; } }

/* ── Modo privacidad ── */
.badge svg { width: 12px; height: 12px; vertical-align: -2px; fill: none; stroke: currentColor; stroke-width: 2; }
@media (max-width: 520px) { #ag-priv span, #ag-espera span { display: none; } #ag-priv, #ag-espera { padding-left: 9px; padding-right: 9px; } }
