:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --line: #e3e8ee;
  --line-2: #eef2f6;
  --text: #0f1b2d;
  --muted: #627084;
  --faint: #94a0b2;
  --brand: #0d9488;
  --brand-2: #0f766e;
  --brand-soft: #e6f6f4;
  --blue: #2563eb;
  --blue-soft: #e8efff;
  --red: #dc2626;
  --red-soft: #fdeceb;
  --amber: #d97706;
  --amber-soft: #fdf3e2;
  --green: #16a34a;
  --green-soft: #e7f6ec;
  --violet: #7c3aed;
  --wa: #25d366;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 27, 45, .05), 0 2px 8px rgba(15, 27, 45, .04);
  --shadow-lg: 0 20px 60px rgba(15, 27, 45, .22);
  --side: 232px;
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }
.span-all { grid-column: 1 / -1; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side { background: #0f1f2e; color: #c9d4e0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 18px 14px; color: #fff; }
.brand img { width: 34px; height: 34px; border-radius: 9px; object-fit: contain; background: #fff; }
.brand b { display: block; font-size: 15px; line-height: 1.15; }
.brand small { color: #7f93a8; font-size: 11.5px; }
.nav { padding: 6px 10px; flex: 1; overflow: auto; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: 8px; color: #c9d4e0; font-weight: 500; margin-bottom: 2px; }
.nav a:hover { background: rgba(255, 255, 255, .06); text-decoration: none; color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.nav .badge { margin-left: auto; background: #f59e0b; color: #1f1300; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; }
.nav-sep { height: 1px; background: rgba(255, 255, 255, .08); margin: 10px 8px; }
.side-foot { padding: 12px 14px; border-top: 1px solid rgba(255, 255, 255, .08); display: flex; align-items: center; gap: 10px; }
.side-foot .who { flex: 1; min-width: 0; }
.side-foot .who b { display: block; color: #fff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-foot .who small { color: #7f93a8; font-size: 11.5px; }
.side-foot button { background: none; border: 0; color: #7f93a8; cursor: pointer; padding: 6px; border-radius: 6px; }
.side-foot button:hover { color: #fff; background: rgba(255, 255, 255, .07); }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 26px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .search { position: relative; width: 340px; max-width: 45vw; }
.topbar .search input { width: 100%; padding-left: 34px; background: var(--panel-2); }
.topbar .search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; color: var(--faint); z-index: 2; pointer-events: none; }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); max-height: 420px; overflow: auto; z-index: 30; }
.search-results a { display: block; padding: 9px 12px; color: var(--text); border-bottom: 1px solid var(--line-2); }
.search-results a:hover, .search-results a.sel { background: var(--brand-soft); text-decoration: none; }
.license-banner { background: var(--amber-soft); color: #7a4a00; padding: 8px 26px; font-size: 13px; border-bottom: 1px solid #f4dfb6; }
.license-banner.danger { background: var(--red-soft); color: #8c1d18; border-color: #f6c9c5; }
.content { padding: 22px 26px 40px; max-width: 1500px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 2px 0 0; color: var(--muted); }

/* ---------- componentes ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px 18px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 13px 18px; border-bottom: 1px solid var(--line-2); }
.card-head h3 { flex: 1; }
.card-body { padding: 14px 18px; }
.empty { padding: 28px 18px; text-align: center; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 550; white-space: nowrap; line-height: 1.2; text-decoration: none !important; color: var(--text); }
.btn:hover { background: var(--panel-2); border-color: #cfd7e1; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-soft); border-color: #f2b8b3; }
.btn.danger-fill { background: var(--red); color: #fff; border-color: var(--red); }
.btn.wa { background: var(--wa); border-color: var(--wa); color: #fff; }
.btn.wa:hover { background: #1eb956; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--line-2); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.xs { padding: 3px 7px; font-size: 12px; border-radius: 6px; }
.btn.icon { padding: 6px; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 8px 8px 0; }
.btn-group .btn.on { background: var(--brand-soft); border-color: #9fd8d1; color: var(--brand-2); z-index: 1; }

input[type=text], input[type=password], input[type=search], input[type=email], input[type=tel], input[type=date], input[type=time], input[type=number], input[type=datetime-local], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #d5dce5; border-radius: 8px; background: #fff; outline: none; min-height: 36px;
}
textarea { min-height: 80px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(13, 148, 136, .14); }
label.field { display: block; }
label.field > span { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
label.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
input[type=color] { width: 44px; height: 36px; padding: 2px; border: 1px solid #d5dce5; border-radius: 8px; background: #fff; }

.tag { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--line-2); color: var(--muted); white-space: nowrap; }
.tag.brand { background: var(--brand-soft); color: var(--brand-2); }
.tag.blue { background: var(--blue-soft); color: #1d4ed8; }
.tag.red { background: var(--red-soft); color: #b91c1c; }
.tag.amber { background: var(--amber-soft); color: #92400e; }
.tag.green { background: var(--green-soft); color: #15803d; }
.tag.violet { background: #f1eafe; color: #6d28d9; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.alert-box { display: flex; gap: 10px; padding: 10px 13px; border-radius: 9px; background: var(--red-soft); color: #8c1d18; border: 1px solid #f6c9c5; align-items: flex-start; }
.alert-box svg { width: 18px; flex: none; margin-top: 1px; }
.info-box { padding: 10px 13px; border-radius: 9px; background: var(--blue-soft); color: #1e3a8a; border: 1px solid #c9d8fb; }

table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; padding: 9px 12px; border-bottom: 1px solid var(--line); background: var(--panel-2); white-space: nowrap; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #f6fbfa; }
.tbl tfoot td { font-weight: 650; background: var(--panel-2); border-top: 1px solid var(--line); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.tabs a { padding: 10px 14px; color: var(--muted); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--brand-2); border-bottom-color: var(--brand); }
.tabs a .count { background: var(--line-2); color: var(--muted); font-size: 11px; border-radius: 99px; padding: 1px 6px; margin-left: 4px; }

.stat { padding: 16px 18px; }
.stat .lbl { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.stat .val { font-size: 24px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; }
.stat .sub { color: var(--faint); font-size: 12px; margin-top: 2px; }

.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 12px; flex: none; }
.avatar.lg { width: 54px; height: 54px; font-size: 19px; }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 27, 45, .45); display: grid; place-items: center; z-index: 100; padding: 20px; animation: fade .12s ease-out; }
.modal { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow-lg); width: 560px; max-width: 100%; max-height: calc(100vh - 40px); display: flex; flex-direction: column; animation: pop .14s ease-out; }
.modal.lg { width: 820px; }
.modal.xl { width: 1080px; }
.modal-head { display: flex; align-items: center; padding: 15px 20px; border-bottom: 1px solid var(--line-2); gap: 10px; }
.modal-head h2 { flex: 1; }
.modal-body { padding: 18px 20px; overflow: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 13px 20px; border-top: 1px solid var(--line-2); background: var(--panel-2); border-radius: 0 0 14px 14px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }

#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #0f1f2e; color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); max-width: 380px; animation: pop .15s ease-out; }
.toast.error { background: #a61b1b; }
.toast.ok { background: #0f766e; }

/* ---------- login / instalación ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 30px 16px; background: linear-gradient(135deg, #0f1f2e 0%, #134e4a 100%); }
.auth-card { width: 420px; max-width: 100%; background: #fff; border-radius: 16px; box-shadow: var(--shadow-lg); padding: 30px; }
.auth-card.wide { width: 620px; }
.auth-logo { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.auth-logo img { width: 46px; height: 46px; border-radius: 12px; object-fit: contain; }
.auth-logo b { font-size: 19px; display: block; }
.steps { display: flex; gap: 6px; margin-bottom: 18px; }
.steps i { flex: 1; height: 4px; border-radius: 4px; background: var(--line); }
.steps i.on { background: var(--brand); }

/* ---------- agenda ---------- */
.agenda-wrap { overflow: auto; max-height: calc(100vh - 190px); border-radius: var(--radius); }
.agenda { display: grid; position: relative; min-width: 100%; }
.agenda .colhead { position: sticky; top: 0; z-index: 6; background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 8px; text-align: center; font-weight: 650; font-size: 13px; }
.agenda .colhead small { display: block; font-weight: 500; color: var(--muted); font-size: 11.5px; }
.agenda .colhead.today { color: var(--brand-2); }
.agenda .corner { position: sticky; left: 0; top: 0; z-index: 8; background: var(--panel); border-bottom: 1px solid var(--line); }
.agenda .hours { position: sticky; left: 0; z-index: 5; background: var(--panel); border-right: 1px solid var(--line); }
.agenda .hour { font-size: 11px; color: var(--faint); text-align: right; padding: 0 8px; transform: translateY(-7px); }
.agenda .col { position: relative; border-right: 1px solid var(--line-2); }
.agenda .slot { border-bottom: 1px solid #f3f5f8; cursor: pointer; }
.agenda .slot.h { border-bottom-color: #e7ebf0; }
.agenda .slot:hover { background: var(--brand-soft); }
.agenda .slot.off { background: repeating-linear-gradient(-45deg, #fafbfc, #fafbfc 6px, #f3f5f8 6px, #f3f5f8 12px); }
.appt { position: absolute; left: 3px; right: 3px; border-radius: 7px; padding: 4px 7px; font-size: 12px; overflow: hidden; cursor: pointer; border-left: 4px solid; background: #fff; box-shadow: 0 1px 3px rgba(15, 27, 45, .12); line-height: 1.3; z-index: 2; }
.appt:hover { z-index: 4; box-shadow: 0 4px 14px rgba(15, 27, 45, .2); }
.appt b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12.5px; }
.appt .meta { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt .icons { position: absolute; top: 3px; right: 5px; display: flex; gap: 3px; }
.appt .icons span { font-size: 11px; }
.appt.st-cancelada { opacity: .45; text-decoration: line-through; }
.appt.st-no_acudio { opacity: .6; background: #fff5f5; }
.appt.st-atendida { background: #f3faf6; }
.appt.st-en_sala { background: #fffbeb; }
.appt.block { background: repeating-linear-gradient(-45deg, #f1f5f9, #f1f5f9 6px, #e7ecf2 6px, #e7ecf2 12px); border-left-color: #94a3b8 !important; }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--red); z-index: 3; pointer-events: none; }
.now-line::before { content: ""; position: absolute; left: -4px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--red); }
.st-badge { font-size: 11.5px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }

/* ---------- odontograma ---------- */
.odo-layout { display: grid; grid-template-columns: 1fr 300px; gap: 16px; align-items: start; }
.odo-tools { position: sticky; top: 80px; }
.odo-svg { width: 100%; height: auto; user-select: none; }
.odo-svg .tooth { cursor: pointer; }
.odo-svg .surf { fill: #fff; stroke: #8796a8; stroke-width: 1; transition: fill .1s; }
.odo-svg .surf:hover { fill: #d9f2ef; }
.odo-svg .tooth.sel .frame { stroke: var(--brand); stroke-width: 2.5; }
.odo-svg .frame { fill: none; stroke: transparent; }
.odo-svg .num { font-size: 12px; fill: #475569; font-weight: 600; text-anchor: middle; }
.odo-svg .tooth:hover .num { fill: var(--brand-2); }
.tool-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tool { display: flex; align-items: center; gap: 7px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; background: #fff; font-size: 12.5px; font-weight: 550; text-align: left; }
.tool:hover { border-color: #b9c4d2; }
.tool.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-2); box-shadow: inset 0 0 0 1px var(--brand); }
.tool svg { width: 20px; height: 20px; flex: none; }
.status-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.status-pick button { padding: 7px 4px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 12.5px; font-weight: 600; }
.status-pick button.on[data-st=existente] { background: var(--blue-soft); border-color: var(--blue); color: #1d4ed8; }
.status-pick button.on[data-st=pendiente] { background: var(--red-soft); border-color: var(--red); color: #b91c1c; }
.status-pick button.on[data-st=realizado] { background: var(--green-soft); border-color: var(--green); color: #15803d; }

/* ---------- firma ---------- */
.sign-pad { border: 2px dashed #b9c4d2; border-radius: 10px; background: #fff; touch-action: none; width: 100%; height: 200px; cursor: crosshair; display: block; }
.consent-text { white-space: pre-wrap; background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 14px; max-height: 300px; overflow: auto; line-height: 1.55; }

/* ---------- documentos ---------- */
.docs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.doc { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; cursor: pointer; display: flex; flex-direction: column; }
.doc:hover { box-shadow: var(--shadow); border-color: #c5d0dc; }
.doc .thumb { height: 120px; background: #0f1f2e center/cover no-repeat; display: grid; place-items: center; color: #94a3b8; font-weight: 700; font-size: 20px; }
.doc .thumb.file { background: var(--panel-2); color: var(--muted); }
.doc .info { padding: 8px 10px; font-size: 12px; }
.doc .info b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12.5px; }
.dropzone { border: 2px dashed #c5d0dc; border-radius: 12px; padding: 22px; text-align: center; color: var(--muted); background: var(--panel-2); cursor: pointer; }
.dropzone.over { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-2); }
.viewer { background: #0b1520; display: grid; place-items: center; min-height: 60vh; border-radius: 8px; }
.viewer img { max-width: 100%; max-height: 75vh; }
.viewer iframe { width: 100%; height: 75vh; border: 0; background: #fff; }

/* ---------- gráficos ---------- */
.bars { display: flex; align-items: flex-end; gap: 8px; height: 180px; padding-top: 10px; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; min-width: 0; }
.bars .b i { display: block; width: 100%; max-width: 46px; background: var(--brand); border-radius: 5px 5px 0 0; min-height: 2px; }
.bars .b i:hover { background: var(--brand-2); }
.bars .b small { font-size: 11px; color: var(--muted); white-space: nowrap; }
.bars .b em { font-style: normal; font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.hbar { display: grid; grid-template-columns: 160px 1fr 90px; gap: 10px; align-items: center; margin-bottom: 9px; font-size: 13px; }
.hbar .track { height: 10px; background: var(--line-2); border-radius: 6px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; background: var(--brand); border-radius: 6px; }

.patient-head { display: flex; gap: 16px; align-items: center; padding: 18px; }
.patient-head .facts { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-top: 5px; }
.balance { display: flex; gap: 22px; }
.balance div { text-align: right; }
.balance small { display: block; color: var(--muted); font-size: 11.5px; font-weight: 600; }
.balance b { font-size: 17px; }

.timeline { position: relative; padding-left: 20px; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.timeline .ev { position: relative; padding-bottom: 16px; }
.timeline .ev::before { content: ""; position: absolute; left: -19px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--brand); }
.note-text { white-space: pre-wrap; line-height: 1.5; margin-top: 4px; }

.list-row { display: flex; gap: 12px; align-items: center; padding: 11px 16px; border-bottom: 1px solid var(--line-2); }
.list-row:last-child { border-bottom: 0; }

@media (max-width: 1100px) {
  .odo-layout { grid-template-columns: 1fr; }
  .odo-tools { position: static; }
  .grid4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  :root { --side: 64px; }
  .brand div, .nav a span, .side-foot .who, .nav .badge { display: none; }
  .nav a { justify-content: center; }
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .span2, .span3 { grid-column: auto; }
}

@media print {
  .side, .topbar, #toasts, .no-print { display: none !important; }
  .layout { display: block; }
  body { background: #fff; }
}
