:root {
  --blue: #1f8a8c;
  --blue-strong: #156e74;
  --cyan: #18b8b1;
  --green: #2a9d3d;
  --amber: #f3b23f;
  --accent: #ff6b5e;
  --brand-grad: linear-gradient(135deg, #18b8b1 0%, #1f8a8c 55%, #166b8f 100%);
  --ink: #1c2b39;
  --muted: #6b7785;
  --line: #e3e8ee;
  --surface: #ffffff;
  --page: #eef2f6;
  --soft-blue: #e6f6f6;
  --soft-green: #eaf7ec;
  --soft-amber: #fff5dc;
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--page); }
body { margin: 0; min-height: 100%; color: var(--ink); background: var(--page); font-size: 14px; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.top-shell { height: 64px; display: grid; grid-template-columns: auto minmax(240px, 480px) 1fr; align-items: center; gap: 18px; padding: 0 26px; background: #fff; color: var(--ink); border-bottom: 1px solid var(--line); box-shadow: 0 2px 10px rgba(28,43,57,.04); position: sticky; top: 0; z-index: 20; }
.brand { display: inline-flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand-logo { height: 34px; width: auto; display: block; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; color: #fff; background: var(--brand-grad); font-size: 13px; font-weight: 700; }
.global-search { height: 42px; display: flex; align-items: center; gap: 9px; border-radius: 999px; background: var(--page); border: 1px solid var(--line); padding: 0 16px; color: var(--muted); transition: border-color .15s, box-shadow .15s; }
.global-search:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(31,138,140,.14); background: #fff; }
.global-search input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); }
.global-search input::placeholder { color: #94a1ad; }
.search-glyph { font-size: 18px; line-height: 1; color: var(--blue); }
.top-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; min-width: 0; }
.quiet-button, .clinic-button { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); color: #44515d; background: #fff; font-weight: 600; white-space: nowrap; border-radius: 999px; padding: 8px 14px; }
.quiet-button:hover, .clinic-button:hover { background: var(--page); }
.clinic-button { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--brand-grad); color: #fff; font-weight: 700; }
.role-pill { padding: 5px 11px; border-radius: 999px; background: var(--soft-blue); color: var(--blue-strong); font-weight: 600; white-space: nowrap; }

.module-nav { height: 60px; display: flex; align-items: center; gap: 6px; padding: 0 22px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 64px; z-index: 19; overflow-x: auto; }
.module-nav a { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; color: #50616f; border-radius: 999px; white-space: nowrap; font-weight: 600; transition: background .15s, color .15s; }
.module-nav a.active { color: #fff; background: var(--brand-grad); box-shadow: 0 6px 16px rgba(24,184,177,.32); font-weight: 700; }
.module-nav a:hover:not(.active) { background: var(--page); color: var(--ink); }
.module-nav a.active .nav-icon { background: rgba(255,255,255,.22); border-color: rgba(255,255,255,.4); color: #fff; }

.page-shell { padding: 24px clamp(14px, 2.4vw, 40px); }
.workspace { width: min(100%, 1600px); margin: 0 auto; animation: enter .28s ease-out; }
.single-panel { width: min(100%, 1440px); }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 10px 30px rgba(28,43,57,.06); min-width: 0; overflow: hidden; }
.agenda-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); align-items: start; }
.day-sidebar { background: #fff; border: 1px solid var(--line); border-right: 0; padding: 14px; min-height: 710px; border-radius: 18px 0 0 18px; }
.date-card { text-align: center; padding: 8px 0 12px; }
.weekday, .month { display: block; font-size: 18px; }
.day-row { display: grid; grid-template-columns: 36px 1fr 36px; align-items: center; gap: 6px; }
.day-row button { border: 0; background: transparent; color: #183b58; font-size: 48px; line-height: 1; }
.day-row strong { font-size: 48px; line-height: 1; }
.soft-alert { margin: 0 -12px 10px; padding: 10px; text-align: center; color: #a66f18; background: var(--soft-amber); border-top: 1px solid #f4dfad; border-bottom: 1px solid #f4dfad; }
.select-label { display: block; margin: 8px 0 5px; color: var(--muted); }
.control, input, select { min-height: 38px; border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 7px 12px; color: var(--ink); }
.filter-stack { display: grid; gap: 9px; padding-top: 12px; color: var(--blue); }
.filter-stack label { display: flex; gap: 8px; line-height: 1.35; }

.tabs-bar { min-height: 56px; display: flex; align-items: center; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fbfcfd; position: relative; overflow-x: auto; }
.tab-title, .tab, .tabs-bar a.tab { display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 15px; border: 0; border-radius: 999px; background: transparent; color: #536272; white-space: nowrap; font-weight: 600; }
.tab-title { font-size: 16px; font-weight: 700; color: var(--ink); }
.tab-title span { padding: 4px 9px; border-radius: 999px; color: #fff; background: var(--accent); font-size: 12px; font-weight: 700; }
.tab:hover, .tabs-bar a.tab:hover { background: #eef2f6; }
.tab.active, .tabs-bar a.active { background: var(--soft-blue); color: var(--blue-strong); box-shadow: inset 0 0 0 1px rgba(31,138,140,.3); }
.tab-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; padding: 5px 8px; }
.tab-actions button, .filter-row button, .content-header button, .patient-filter button { min-height: 32px; border: 1px solid #bbc5cf; border-radius: 5px; background: #fff; padding: 0 12px; }
.primary { color: #fff; border-color: transparent !important; background: var(--brand-grad) !important; font-weight: 700; box-shadow: 0 6px 16px rgba(24,184,177,.28); }
.primary:hover { filter: brightness(1.04); }
.success { color: #fff; border-color: #75bd80 !important; background: #82c98b !important; font-weight: 700; }

.inline-search { display: flex; align-items: center; gap: 8px; padding: 14px 10px 10px; }
.inline-search input { width: 100%; }
.agenda-table { padding-bottom: 18px; }
.agenda-head, .appointment-row { display: grid; grid-template-columns: 74px minmax(260px, 1.7fr) minmax(150px, 1fr) minmax(150px, .95fr) minmax(132px, .7fr); align-items: center; column-gap: 12px; padding: 0 10px; }
.agenda-head { height: 32px; font-weight: 700; color: #0c1825; }
.appointment-row { min-height: 78px; border-top: 1px solid var(--line); position: relative; transition: background .12s; }
.appointment-row:hover { background: var(--soft-blue); }
.time-chip { width: 54px; min-height: 62px; display: grid; place-items: center; border-radius: 12px; color: #fff; background: var(--brand-grad); font-weight: 700; box-shadow: 0 5px 14px rgba(24,184,177,.28); }
.time-chip b { line-height: .8; }
.patient-cell { display: grid; gap: 3px; position: relative; }
.patient-cell small { color: #425264; }
.link-button, .state-link { border: 0; background: transparent; color: var(--blue-strong); padding: 0; text-align: left; font-weight: 700; }
.state-link { font-weight: 500; }
.status-pill { display: inline-flex; justify-content: center; min-width: 130px; padding: 7px 12px; border-radius: 999px; color: #fff; background: var(--green); font-weight: 700; }
.floating-menu { display: none; position: absolute; z-index: 30; min-width: 230px; background: #fff; border: 1px solid #aeb8c2; border-radius: 6px; box-shadow: 0 10px 28px rgba(21,32,43,.16); padding: 8px 0; }
.floating-menu.open { display: grid; animation: pop .15s ease-out; }
.floating-menu.right { right: 24px; }
.floating-menu button { border: 0; background: #fff; text-align: left; padding: 9px 16px; color: #2d3b48; }
.floating-menu button:hover { background: #f0f7fc; }
@keyframes pop { from { opacity: 0; transform: scale(.98) translateY(-4px); } to { opacity: 1; transform: scale(1) translateY(0); } }

.content-header { display: flex; justify-content: space-between; gap: 16px; align-items: start; padding: 24px 20px 12px; }
h1 { margin: 0 0 6px; font-size: clamp(22px, 2.2vw, 30px); line-height: 1.05; font-weight: 500; color: #35485a; }
h2 { margin: 0 0 10px; font-size: 16px; }
p { margin: 0; color: #566575; line-height: 1.5; }
.info-band { margin: 10px 12px; padding: 13px 16px; border: 1px solid #acd7ed; border-radius: 5px; color: #16658f; background: #dff3fb; }
.patient-filter, .filter-row { display: flex; gap: 10px; align-items: center; padding: 12px 18px; flex-wrap: wrap; }
.patient-filter input:first-of-type { flex: 1 1 280px; }
.wide-table { overflow: auto; padding: 10px 18px 18px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th { background: var(--blue-strong); color: #fff; text-align: left; padding: 12px 10px; font-size: 13px; }
td { border-bottom: 1px solid #e1e5e9; padding: 12px 10px; color: #46515c; }
.patients-table th { background: var(--blue); }
.dots { width: 30px; height: 30px; border: 0; border-radius: 5px; background: transparent; font-size: 22px; }
.check { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; border: 2px solid #b6c0c9; color: #fff; font-size: 12px; font-weight: 700; }
.check.on { border-color: #49ad5a; background: #49ad5a; }
.progress { width: 90px; height: 14px; background: #e7edf2; border-radius: 3px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--blue); }

.stat-row { display: grid; grid-template-columns: repeat(4, minmax(130px, 1fr)); gap: 12px; padding: 14px 20px; }
.stat-row div, .finance-grid article, .admin-grid article, .report-board article, .kanban article { border: 1px solid #dbe1e7; border-radius: 8px; background: #fff; padding: 14px; }
.stat-row span, .finance-grid span { display: block; color: #52606d; }
.stat-row strong, .finance-grid strong { display: block; margin-top: 6px; color: var(--blue); font-size: 28px; line-height: 1; }
.stat-row small { display: block; margin-top: 8px; color: var(--muted); }
.stat-row .green strong { color: var(--green); }
.stat-row .cyan strong { color: var(--cyan); }
.stat-row .amber strong { color: var(--amber); }

.analysis-intro { max-width: 720px; margin: 36px auto 18px; text-align: center; }
.analysis-grid { display: grid; grid-template-columns: 220px 1fr; gap: 36px; align-items: end; padding: 26px 60px; }
.funnel { height: 240px; display: grid; place-items: center; color: #fff; font-size: 22px; font-weight: 700; background: var(--brand-grad); clip-path: polygon(8% 0, 92% 0, 68% 100%, 32% 100%); }
.line-chart, .bar-chart { height: 260px; display: flex; align-items: end; gap: 11px; padding: 20px; border: 1px solid #d7dde3; background: repeating-linear-gradient(to top, #fff, #fff 39px, #edf1f5 40px); }
.line-chart span, .bar-chart span { flex: 1; min-width: 18px; border-radius: 5px 5px 0 0; background: linear-gradient(180deg, #2fc0b8, #1f8a8c); position: relative; }
.bar-chart span { background: linear-gradient(#60bc73, #289b44); }
.bar-chart b { position: absolute; left: 50%; bottom: -24px; transform: translateX(-50%); color: #566575; font-size: 11px; white-space: nowrap; }
.metric-strip { display: flex; justify-content: center; gap: 4px; padding: 16px 20px 34px; }
.metric-strip strong { min-width: 130px; text-align: center; color: #fff; padding: 14px; background: var(--blue); border-radius: 10px; }
.metric-strip strong:nth-child(2) { background: #55b75b; }
.metric-strip strong:nth-child(3) { background: #f2ae41; }
.metric-strip b { font-size: 26px; }
.finance-grid, .admin-grid, .report-board, .kanban { display: grid; gap: 14px; padding: 14px 20px; }
.finance-grid { grid-template-columns: repeat(3, 1fr); }
.admin-grid { grid-template-columns: repeat(3, 1fr); }
.report-board { grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); }
.kanban { grid-template-columns: repeat(3, 1fr); align-items: start; }
.task { display: grid; gap: 5px; padding: 12px; border: 1px solid #dce2e8; border-radius: 7px; background: #f9fbfc; margin-top: 10px; }
.task span { color: #607080; }

@media (min-width: 1500px) {
  .workspace { width: min(100%, 1880px); }
  .single-panel { width: min(100%, 1680px); }
  .agenda-head, .appointment-row { grid-template-columns: 80px minmax(360px, 1.8fr) minmax(210px, 1fr) minmax(190px, .9fr) minmax(150px, .7fr); }
}

@media (max-width: 900px) {
  .top-shell { grid-template-columns: 1fr auto; height: auto; padding: 10px 12px; gap: 10px; }
  .global-search { grid-column: 1 / -1; order: 3; }
  .top-actions { gap: 8px; }
  .quiet-button, .clinic-button { display: none; }
  .module-nav { top: 94px; padding: 0 8px; }
  .page-shell { padding: 12px 8px; }
  .agenda-layout { grid-template-columns: 1fr; }
  .day-sidebar { min-height: auto; border-right: 1px solid #d6dce3; }
  .filter-stack { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .agenda-panel { border-top: 0; }
  .agenda-head { display: none; }
  .appointment-row { grid-template-columns: 62px 1fr; gap: 10px; padding: 12px; align-items: start; }
  .appointment-row > div:nth-child(n+3) { grid-column: 2; }
  .status-pill { min-width: 0; }
  .content-header { flex-direction: column; }
  .stat-row, .finance-grid, .admin-grid, .report-board, .kanban, .analysis-grid { grid-template-columns: 1fr; padding-left: 12px; padding-right: 12px; }
  .funnel { max-width: 260px; margin: 0 auto; }
  .metric-strip { flex-direction: column; }
}

@media (max-width: 560px) {
  body { font-size: 13px; }
  .brand { font-size: 18px; }
  .role-pill { display: none; }
  .tabs-bar { align-items: center; }
  .tab-title, .tab, .tabs-bar a.tab { padding: 0 10px; }
  .tab-actions { position: sticky; right: 0; background: linear-gradient(90deg, rgba(255,255,255,.8), #fff 22px); }
  .filter-stack { grid-template-columns: 1fr; }
  .patient-filter input, .patient-filter select, .filter-row input, .filter-row select { flex: 1 1 100%; width: 100%; }
  .line-chart, .bar-chart { overflow-x: auto; }
}

/* Dental22 refinements */
.panel, .day-sidebar, .login-card { border-radius: 8px; }
.agenda-layout { gap: 12px; }
.day-sidebar { border-right: 1px solid #d6dce3; }
.top-shell { box-shadow: 0 3px 14px rgba(5, 57, 100, .18); }
.module-nav { box-shadow: 0 2px 12px rgba(30, 41, 54, .06); }
.control, input, select, .tab-actions button, .filter-row button, .content-header button, .patient-filter button, .task button { border-radius: 8px; }
.time-chip, .status-pill, .tab-title span, .role-pill { border-radius: 8px; }
.floating-menu { position: fixed; border-radius: 8px; z-index: 100; padding: 7px; }
.floating-menu button { display: flex; align-items: center; gap: 9px; border-radius: 7px; min-height: 38px; }
.link-button, .state-link, .status-pill, .quiet-button, .clinic-button, .module-nav a, .task button { display: inline-flex; align-items: center; gap: 7px; }
.logout-form { margin: 0; }
.logout-form button { min-height: 30px; border: 1px solid rgba(255,255,255,.45); border-radius: 8px; color: #fff; background: rgba(255,255,255,.12); padding: 0 10px; }

.nav-icon, .btn-icon, .menu-icon, .title-icon { display: inline-grid; place-items: center; flex: 0 0 auto; width: 18px; height: 18px; border-radius: 5px; background: #e8f5fc; border: 1px solid #b7dff3; color: var(--blue); position: relative; }
.btn-icon { width: 16px; height: 16px; border-radius: 4px; }
.menu-icon { width: 20px; height: 20px; }
.title-icon { width: 28px; height: 28px; border-radius: 8px; vertical-align: middle; margin-right: 8px; }
.nav-icon::before, .btn-icon::before, .menu-icon::before, .title-icon::before { content: ""; width: 9px; height: 9px; border: 2px solid currentColor; border-radius: 2px; }
.icon-patient::before { border-radius: 50% 50% 3px 3px; width: 8px; height: 8px; box-shadow: 0 6px 0 -2px currentColor; }
.icon-agenda::before, .icon-date::before { width: 10px; height: 9px; border-radius: 2px; box-shadow: inset 0 3px 0 currentColor; }
.icon-cash::before, .icon-wallet::before { width: 11px; height: 8px; border-radius: 2px; box-shadow: inset 4px 0 0 rgba(8,121,201,.25); }
.icon-report::before { width: 3px; height: 11px; border-width: 0; background: currentColor; box-shadow: 5px -3px 0 currentColor, 10px -7px 0 currentColor; }
.icon-crm::before, .icon-chat::before { width: 11px; height: 8px; border-radius: 5px; box-shadow: 4px 6px 0 -5px currentColor; }
.icon-admin::before { border-radius: 50%; width: 10px; height: 10px; box-shadow: 0 0 0 3px rgba(8,121,201,.15); }
.icon-check::before { width: 9px; height: 5px; border-width: 0 0 2px 2px; transform: rotate(-45deg); border-radius: 0; }
.icon-alert::before { width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 12px solid currentColor; border-top: 0; border-radius: 1px; }
.icon-clock::before { border-radius: 50%; }
.icon-clock::after { content: ""; position: absolute; width: 5px; height: 2px; background: currentColor; transform: translate(2px, 0); }
.icon-plus::before { width: 10px; height: 2px; border: 0; background: currentColor; box-shadow: 0 0 0 currentColor; }
.icon-plus::after { content: ""; position: absolute; width: 2px; height: 10px; background: currentColor; }
.icon-print::before { width: 11px; height: 8px; border-radius: 2px; box-shadow: 0 -5px 0 -2px currentColor; }
.icon-search::before { border-radius: 50%; width: 8px; height: 8px; }
.icon-search::after { content: ""; position: absolute; width: 6px; height: 2px; background: currentColor; transform: translate(5px, 5px) rotate(45deg); }
.icon-mail::before { width: 11px; height: 8px; transform: skewY(-8deg); }
.icon-cancel::before { width: 11px; height: 2px; border: 0; background: currentColor; transform: rotate(45deg); }
.icon-cancel::after { content: ""; position: absolute; width: 11px; height: 2px; background: currentColor; transform: rotate(-45deg); }
.icon-note::before, .icon-plan::before { width: 10px; height: 12px; box-shadow: inset 0 4px 0 rgba(8,121,201,.25); }
.icon-history::before { border-radius: 50%; border-left-color: transparent; }
.icon-status::before { border-radius: 50%; width: 9px; height: 9px; background: currentColor; box-shadow: 0 0 0 3px rgba(8,121,201,.14); }
.icon-login::before { width: 10px; height: 8px; border-left: 0; border-radius: 0 2px 2px 0; }
.icon-news::before { width: 11px; height: 8px; border-radius: 2px; transform: skewX(-10deg); }
.icon-clinic::before { width: 12px; height: 10px; border-radius: 2px; box-shadow: inset 0 -4px 0 rgba(8,121,201,.22); }

.screen-intro { display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, 320px); gap: 14px; padding: 18px 18px 8px; align-items: start; }
.screen-intro h1 { display: flex; align-items: center; }
.intro-tip, .side-help, .filter-explain { border: 1px solid #c9e2f1; background: #f1f9fd; border-radius: 8px; padding: 12px; color: #36566d; }
.intro-tip, .side-help, .filter-explain { display: grid; gap: 5px; }
.intro-tip strong, .side-help strong, .filter-explain strong { color: #0d6092; }
.intro-tip span, .side-help span, .filter-explain span { line-height: 1.45; }
.side-help { margin-bottom: 10px; }
.filter-explain { margin: 12px 0 2px; }
.week-board, .global-board, .reschedule-board, .crm-status-grid, .settings-grid, .practice-list { display: grid; gap: 12px; padding: 12px 18px; }
.week-board { grid-template-columns: repeat(5, minmax(120px, 1fr)); }
.week-board article, .global-board article, .reschedule-board article, .crm-status-grid article, .settings-section, .practice-list { border: 1px solid #d9e1e8; border-radius: 8px; background: #fff; padding: 14px; }
.week-board article { display: grid; gap: 8px; }
.week-board button, .task button { border: 1px solid #c5d4df; border-radius: 8px; background: #f7fbfd; color: #176792; min-height: 32px; }
.global-board { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.global-board article { display: grid; gap: 7px; }
.global-board article span { border-radius: 6px; background: #edf7ee; padding: 7px 9px; color: #2f6640; }
.reschedule-board { grid-template-columns: 1fr 1fr; }

.settings-section { margin: 14px 20px; }
.section-title { padding: 4px 0 12px; }
.section-title.compact { padding: 16px 20px 0; }
.settings-grid { grid-template-columns: repeat(3, minmax(180px, 1fr)); padding: 0; }
.settings-grid label { display: grid; gap: 6px; color: #506172; }
.practice-list { margin-top: 12px; background: #fffaf0; border-color: #f0d69b; }
.practice-list span { display: flex; align-items: center; gap: 8px; color: #594717; }
.crm-status-grid { grid-template-columns: repeat(3, 1fr); }
.crm-status-grid article { display: grid; gap: 6px; }
.crm-status-grid strong { color: var(--blue); }
.crm-status-grid small { color: var(--muted); }
.task button { justify-content: center; margin-top: 6px; }

.login-body { min-height: 100vh; background: linear-gradient(135deg, #18b8b1 0%, #1f8a8c 46%, #eef2f6 46%); }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(100%, 430px); background: #fff; border: 1px solid #d7e1ea; box-shadow: 0 24px 80px rgba(22,45,68,.22); padding: 28px; }
.login-brand { display: flex; justify-content: center; margin-bottom: 14px; }
.login-brand img { height: 60px; width: auto; max-width: 100%; }
.login-form { display: grid; gap: 8px; margin-top: 18px; }
.login-form button { min-height: 42px; border-radius: 8px; margin-top: 8px; }
.login-error { margin-top: 14px; border: 1px solid #efb9b9; background: #fff1f1; color: #9e2d2d; border-radius: 8px; padding: 10px 12px; }

@media (max-width: 900px) {
  .screen-intro, .global-board, .reschedule-board, .crm-status-grid, .settings-grid { grid-template-columns: 1fr; }
  .week-board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .week-board { grid-template-columns: 1fr; }
  .logout-form button { padding: 0 8px; }
}

/* ===== Dental22 v3: filtros, modales, recarga, CRM chat ===== */

/* Filtro multiple de estados */
.filter-multi { display: grid; gap: 8px; padding: 10px; margin-top: 4px; border: 1px solid #d4dde6; border-radius: 10px; background: #fbfdff; }
.filter-multi .fm-all { display: flex; align-items: center; gap: 8px; padding-bottom: 6px; border-bottom: 1px dashed #d4dde6; color: #2b4a63; }
.filter-multi .fm-options { display: grid; gap: 7px; max-height: 220px; overflow: auto; }
.filter-multi .fm-options label { display: flex; align-items: center; gap: 8px; color: #3a4a5a; line-height: 1.3; }
.filter-multi input[type=checkbox] { min-height: 0; width: 16px; height: 16px; accent-color: var(--blue); }
.fm-apply { justify-content: center; margin-top: 2px; }
.fm-count { color: var(--muted); }

/* Tarjeta de recarga automatica */
.reload-card { display: flex; gap: 10px; align-items: flex-start; margin-top: 14px; padding: 12px; border: 1px solid #cfe6d6; border-radius: 10px; background: #f3fbf5; cursor: pointer; }
.reload-card input { margin-top: 2px; width: 18px; height: 18px; accent-color: var(--green); }
.reload-card strong { display: block; color: #1f7a39; }
.reload-card small { display: block; margin-top: 3px; color: #4f6a59; line-height: 1.4; }

/* Boton soft-alert ahora clickeable */
button.soft-alert { width: calc(100% + 24px); border: none; border-top: 1px solid #f4dfad; border-bottom: 1px solid #f4dfad; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 600; }
button.soft-alert:hover { background: #ffeec8; }

/* Split button (Dar cita) */
.split-btn { position: relative; display: inline-flex; }
.split-btn .split-arrow { padding: 0 8px; border-left: 1px solid rgba(255,255,255,.4) !important; border-radius: 0 8px 8px 0 !important; }
.split-btn > .primary:first-child { border-radius: 8px 0 0 8px !important; }
.tab-actions .icon-only { padding: 0 10px; }

/* ===== Modales ===== */
body.modal-open { overflow: hidden; }
.modal-backdrop { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 18px; background: rgba(15,28,40,.55); animation: fade .15s ease-out; }
.modal-backdrop[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal { width: min(100%, 460px); max-height: 92vh; overflow: auto; background: #fff; border-radius: 14px; box-shadow: 0 30px 80px rgba(10,25,40,.4); animation: pop .16s ease-out; }
.modal-lg { width: min(100%, 880px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 6px; }
.modal-head h2 { margin: 0; font-size: 19px; color: #2c3e50; }
.modal-x { border: 0; background: transparent; font-size: 18px; color: #7c8a98; width: 32px; height: 32px; border-radius: 8px; }
.modal-x:hover { background: #eef2f6; }
.modal-help { padding: 0 20px 12px; color: #5a6a78; line-height: 1.5; }
.modal-info { margin: 0 20px 16px; padding: 14px 16px; border-radius: 10px; background: #eef6fb; color: #2c5d7c; }
.modal > input[type=date] { margin: 0 20px; width: calc(100% - 40px); }
.modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px 18px; color: var(--muted); }
.modal-foot > div { display: flex; gap: 10px; margin-left: auto; }
.modal-foot button { min-height: 38px; border: 1px solid #c2ccd6; border-radius: 9px; background: #fff; padding: 0 16px; }

/* Anulaciones */
.anul-list { display: grid; gap: 10px; padding: 0 20px 8px; }
.anul-row { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid #e6dcc4; border-radius: 10px; background: #fffaf0; }
.anul-row .anul-time { font-weight: 700; color: #a66f18; min-width: 46px; }
.anul-row strong { display: block; color: #3a4a5a; }
.anul-row small { color: var(--muted); }
.anul-row .primary { margin-left: auto; min-height: 34px; padding: 0 14px; border-radius: 9px; }

/* Dar cita - calendario semanal */
.dc-grid { display: grid; grid-template-columns: 230px 1fr; gap: 16px; padding: 0 20px 8px; }
.dc-filters { display: grid; gap: 12px; align-content: start; }
.dc-filters label { display: grid; gap: 5px; color: #51616f; font-size: 13px; }
.dc-check { display: flex !important; align-items: center; gap: 8px; }
.dc-week { border: 1px solid #dde3e9; border-radius: 12px; overflow: hidden; }
.dc-week-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; background: #f3f7fa; border-bottom: 1px solid #e1e7ed; }
.dc-week-head button { border: 0; background: transparent; color: var(--blue); font-weight: 600; }
.dc-week-head strong { text-transform: capitalize; color: #36485a; }
.dc-days { display: flex; flex-wrap: wrap; align-content: start; gap: 0; max-height: 380px; overflow: auto; }
.dc-day { flex: 1 1 200px; min-width: 180px; border-right: 1px solid #eef1f4; padding: 10px 12px; display: block; }
.dc-day:last-child { border-right: 0; }
.dc-day.today { background: #f0f9ff; }
.dc-day-name { display: block; font-size: 12px; font-weight: 700; color: #5e6e7c; text-transform: capitalize; padding-bottom: 6px; margin-bottom: 8px; border-bottom: 1px solid #eef1f4; }
.dc-day.today .dc-day-name { color: var(--blue); }
.dc-slot-wrap { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 6px; }
.dc-slot { border: 1px solid #cfe0ec; border-radius: 7px; background: #fff; color: #1f6b97; padding: 6px 0; font-size: 12px; cursor: pointer; }
.dc-slot:hover { background: #e9f5fd; }
.dc-slot.picked { background: var(--blue); color: #fff; border-color: var(--blue-strong); }
/* Buscador de paciente en el modal */
.dc-search { position: relative; }
.dc-search-results { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 2px); background: #fff; border: 1px solid #d5e0e8; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); overflow: hidden; max-height: 240px; overflow-y: auto; }
.dc-sr-item { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid #eef3f7; background: #fff; padding: 8px 12px; cursor: pointer; }
.dc-sr-item:hover { background: #f1f9fd; }
.dc-sr-item strong { display: block; color: #0d3b52; font-size: 13px; }
.dc-sr-item small { color: #748896; font-size: 11px; }
.dc-sr-empty { padding: 10px 12px; color: #748896; font-size: 12px; }
.dc-hint { display: block; font-size: 11px; color: #8496a3; margin-top: 3px; font-weight: 400; }
.dc-hint.ok { color: #1e8b52; font-weight: 600; }

/* ===== CRM estilo WhatsApp ===== */
.crm-wide { width: min(100%, 1320px); }
@media (min-width: 1500px) { .crm-wide { width: min(100%, 1500px); } }
.crm-summary { display: flex; flex-wrap: wrap; gap: 10px; padding: 8px 20px 16px; }
.sum-chip { display: grid; gap: 2px; padding: 10px 14px; min-width: 120px; border: 1px solid #dde4ea; border-radius: 12px; background: #fff; }
.sum-chip .sum-num { font-size: 24px; font-weight: 800; color: #3a4a5a; line-height: 1; }
.sum-chip span:last-child { color: #6a7785; font-size: 12px; }
.sum-chip.tone-blue { border-color: #b9ddf3; background: #f1f9fd; } .sum-chip.tone-blue .sum-num { color: var(--blue); }
.sum-chip.tone-cyan { border-color: #b6e8e4; background: #effbfa; } .sum-chip.tone-cyan .sum-num { color: var(--cyan); }
.sum-chip.tone-green { border-color: #bfe5c6; background: #f1faf3; } .sum-chip.tone-green .sum-num { color: var(--green); }
.sum-chip.tone-amber { border-color: #f1dca5; background: #fff9ec; } .sum-chip.tone-amber .sum-num { color: #c98a1d; }

.crm-app { display: grid; grid-template-columns: 340px 1fr; gap: 0; margin: 0 16px 18px; height: clamp(460px, calc(100vh - 250px), 820px); border: 1px solid #d7dde3; border-radius: 14px; overflow: hidden; background: #fff; }
.crm-list { display: flex; flex-direction: column; border-right: 1px solid #e2e7ec; background: #f7f9fb; min-width: 0; min-height: 0; }
.crm-list-head { display: flex; align-items: center; gap: 8px; padding: 12px; border-bottom: 1px solid #e6ebef; }
.crm-list-head input { width: 100%; }
.crm-list-hint { padding: 8px 12px; font-size: 11.5px; color: #7a8794; background: #eef3f7; }
.crm-items { overflow-y: auto; flex: 1; }
.crm-item { display: flex; gap: 10px; width: 100%; text-align: left; padding: 11px 12px; border: 0; border-bottom: 1px solid #eef2f5; background: transparent; align-items: flex-start; position: relative; }
.crm-item:hover { background: #eef4f9; }
.crm-item.active { background: #e3f1fb; box-shadow: inset 3px 0 0 var(--blue); }
.crm-ava { flex: 0 0 auto; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; background: var(--brand-grad); text-transform: uppercase; font-size: 14px; }
.crm-ava.lg { width: 46px; height: 46px; }
.crm-item-body { display: grid; gap: 3px; min-width: 0; flex: 1; }
.crm-item-top { display: flex; justify-content: space-between; gap: 8px; }
.crm-item-top strong { color: #2b3a48; font-size: 14px; }
.crm-item-top small { color: #93a0ac; font-size: 11px; white-space: nowrap; }
.crm-item-preview { color: #6a7884; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crm-item-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.ia-badge { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 20px; color: #fff; }
.ia-gpt { background: #10a37f; } .ia-gemini { background: #6f5bd1; }
.mini-tag { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 20px; }
.tag-green { background: #e2f6e7; color: #1f7a39; } .tag-amber { background: #fdeccc; color: #a86a12; } .tag-blue { background: #e0eefb; color: #1668a8; }
.tag-pay { background: #fde68a; color: #92560a; }
.pay-warning { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: #fff4cc; border-bottom: 1px solid #f0d98a; color: #7a5b18; font-size: 13px; }
.pay-warning .pay-ico { font-size: 18px; }
.pay-warning .pay-btn { margin-left: auto; border: 1px solid #d9a93a; border-radius: 8px; min-height: 32px; padding: 0 12px; background: #f3b23f; color: #3a2c08; font-weight: 700; white-space: nowrap; }

/* Administracion: estado de conexiones e instrucciones */
.conn-status { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 4px 0 16px; }
.conn-card { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid #dbe1e7; border-radius: 10px; background: #fff; }
.conn-card .conn-dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; }
.conn-card.on { border-color: #bfe5c6; background: #f4fbf5; } .conn-card.on .conn-dot { background: #2a9d3d; box-shadow: 0 0 0 3px rgba(42,157,61,.18); }
.conn-card.off { border-color: #f0cfa0; background: #fffaf0; } .conn-card.off .conn-dot { background: #e08b2f; box-shadow: 0 0 0 3px rgba(224,139,47,.18); }
.conn-card strong { display: block; color: #2c3e50; } .conn-card small { color: #6b7785; }
.howto-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 6px 0 16px; }
.howto { border: 1px solid #d9e1e8; border-radius: 12px; padding: 16px; background: #fff; }
.howto.local { background: #f3f9fd; border-color: #cfe0ec; }
.howto.prod { background: #fbf6ff; border-color: #e0d0f0; }
.howto h3 { display: flex; align-items: center; gap: 9px; margin: 0 0 8px; font-size: 16px; color: #2c3e50; }
.badge-num { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--blue); color: #fff; font-size: 13px; }
.howto ol, .howto ul { margin: 8px 0; padding-left: 20px; color: #44515d; line-height: 1.6; }
.prod-list { list-style: none; padding-left: 0; }
.prod-list li { padding: 8px 0; border-bottom: 1px dashed #e3dcef; }
.howto code { background: #eef2f6; padding: 2px 6px; border-radius: 5px; font-size: 12.5px; word-break: break-all; }
.howto-tip { margin-top: 8px; font-size: 12.5px; color: #5a6a78; }
.settings-grid .span-3 { grid-column: 1 / -1; }
.settings-grid input[readonly] { background: #f6f8fa; color: #44515d; }
@media (max-width: 900px) { .conn-status, .howto-grid { grid-template-columns: 1fr; } }

/* Administracion: pestañas y formulario */
.admin-tabs { display: flex; gap: 6px; padding: 8px 20px 0; border-bottom: 1px solid #e1e6eb; flex-wrap: wrap; }
.admin-tab-btn { border: 1px solid transparent; border-bottom: 0; background: transparent; padding: 10px 16px; border-radius: 10px 10px 0 0; color: #5a6a78; font-weight: 600; }
.admin-tab-btn.active { background: #fff; border-color: #e1e6eb; color: var(--blue); box-shadow: 0 -2px 0 var(--blue) inset; }
.admin-tab { padding: 8px 20px 18px; }
.admin-tab[hidden] { display: none; }
.save-ok { margin: 10px 0; padding: 12px 16px; border-radius: 10px; background: #eaf7ec; border: 1px solid #bfe5c6; color: #1f7a39; font-weight: 600; }
.big-text { width: 100%; min-height: 90px; border: 1px solid #c8d0d8; border-radius: 10px; padding: 10px 12px; font: inherit; color: var(--ink); resize: vertical; line-height: 1.5; }
.full-label { display: grid; gap: 6px; margin: 12px 0; color: #506172; }
.full-label > span { font-size: 13px; }
.chk-field { display: flex !important; align-items: center; gap: 9px; }
.chk-field input { width: 18px; height: 18px; accent-color: var(--blue); }
.form-actions { display: flex; justify-content: flex-end; padding: 16px 0 4px; }
.form-actions .primary { min-height: 42px; padding: 0 22px; border-radius: 10px; }

/* CRM: filtros de la lista */
.crm-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px; border-bottom: 1px solid #e6ebef; }
.crm-filter { border: 1px solid #cdd7e0; background: #fff; color: #51616f; border-radius: 16px; padding: 4px 11px; font-size: 12px; font-weight: 600; }
.crm-filter:hover { background: #eef4f9; }
.crm-filter.on { background: var(--blue); border-color: var(--blue-strong); color: #fff; }

/* Fix #9: cadena flex para que el chat largo no rompa el diseño (mensajes scrollean, composer fijo) */
.crm-chat { min-height: 0; }
.crm-thread { min-height: 0; }
.crm-messages { min-height: 0; }
.crm-thread-head, .crm-state-strip, .pay-warning, .crm-composer { flex-shrink: 0; }
.crm-unread { position: absolute; right: 12px; top: 32px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 10px; background: #25d366; color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }

.crm-chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; background: #e9edf0; }
.crm-empty { margin: auto; text-align: center; color: #7a8794; padding: 30px; }
.crm-empty .big-glyph { display: inline-grid; place-items: center; width: 70px; height: 70px; border-radius: 50%; background: #d7e6ef; margin-bottom: 12px; }
.crm-empty .big-glyph::before { content: ""; width: 30px; height: 22px; border: 3px solid #8fb6cf; border-radius: 8px; }
.crm-empty h2 { color: #4a5a68; }
.crm-thread { display: flex; flex-direction: column; flex: 1; height: 100%; min-height: 0; }
.crm-thread[hidden] { display: none; }
.crm-thread-head { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: #fff; border-bottom: 1px solid #e2e7ec; flex-wrap: wrap; }
.crm-head-info { min-width: 0; }
.crm-head-info strong { display: block; color: #2b3a48; }
.crm-head-info small { color: #8e9ba7; }
.crm-head-meta { display: flex; align-items: center; gap: 14px; margin-left: auto; flex-wrap: wrap; }
.meta-field { display: grid; gap: 3px; font-size: 11px; color: #7a8794; }
.meta-field select { min-height: 32px; }
.ia-switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.ia-switch input { display: none; }
.switch-track { width: 42px; height: 24px; border-radius: 20px; background: #c2ccd4; position: relative; transition: background .2s; }
.switch-dot { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.ia-switch input:checked + .switch-track { background: #25d366; }
.ia-switch input:checked + .switch-track .switch-dot { left: 21px; }
.switch-text { font-size: 12px; font-weight: 600; color: #4a5a68; }

.crm-state-strip { display: flex; flex-wrap: wrap; gap: 14px; padding: 8px 16px; background: #f5f8fa; border-bottom: 1px solid #e6ebef; font-size: 12.5px; color: #51616f; }
.state-item { display: inline-flex; align-items: center; gap: 6px; }
.state-item strong { color: #2b3a48; }
.state-item .dot { width: 9px; height: 9px; border-radius: 50%; }
.crm-status-field select { min-height: 30px; border: 1px solid #ccd8e1; border-radius: 5px; background: #fff; color: #243341; font-weight: 700; }
.d-blue { background: var(--blue); } .d-cyan { background: var(--cyan); } .d-green { background: var(--green); } .d-gray { background: #9aa6b1; }

.crm-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; background-color: #e9edf0; background-image: radial-gradient(rgba(255,255,255,.5) 1px, transparent 0); background-size: 18px 18px; }
.bubble-row { display: flex; }
.bubble-row.in { justify-content: flex-start; }
.bubble-row.out { justify-content: flex-end; }
.bubble { max-width: 76%; padding: 8px 11px 6px; border-radius: 12px; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.08); position: relative; }
.bubble-row.out .bubble { background: #dcf8c6; }
.bubble.ai { background: #e7e0fb; }
.bubble-row.out .bubble.ai { background: #d9eefb; }
.bubble-author { display: block; font-size: 11px; font-weight: 700; color: #5b46a8; margin-bottom: 2px; }
.bubble.ai .bubble-author { color: #5b46a8; }
.bubble-text { display: block; color: #2c3a47; line-height: 1.4; white-space: pre-wrap; }
.bubble-media { margin: 6px 0 2px; }
.bubble-media img { max-width: 220px; max-height: 280px; border-radius: 10px; display: block; border: 1px solid rgba(0,0,0,.1); }
.bubble-media .media-doc { display: inline-block; padding: 8px 12px; border-radius: 10px; background: #eef2f6; color: #1f6b97; font-weight: 600; text-decoration: none; }
.bubble-time { display: block; text-align: right; font-size: 10px; color: #90a0ab; margin-top: 2px; }

.crm-composer { background: #f0f3f5; border-top: 1px solid #e2e7ec; padding: 10px 12px; }
.ia-note { display: flex; gap: 10px; align-items: center; padding: 10px 12px; margin-bottom: 8px; border-radius: 10px; background: #fff6e6; border: 1px solid #f0dba8; color: #7a5b18; font-size: 12.5px; }
.ia-note[hidden] { display: none; }
.empty-filter { padding: 24px 18px; text-align: center; color: var(--muted); }
.empty-filter[hidden] { display: none; }
.composer-input { display: flex; gap: 8px; align-items: center; }
.composer-input input { flex: 1; min-height: 42px; border-radius: 22px; padding: 0 16px; }
.composer-ai { display: inline-flex; align-items: center; gap: 6px; border: 1px solid #c9d6e0; border-radius: 22px; background: #fff; color: #1f6b97; min-height: 42px; padding: 0 14px; white-space: nowrap; font-size: 12.5px; }
.composer-send { min-height: 42px; border-radius: 22px; padding: 0 18px; }
.composer-input.locked { opacity: .5; pointer-events: none; }

/* Sandbox de prueba IA */
.crm-sandbox { margin: 0 16px 14px; border: 1px solid #cfe0ec; border-radius: 12px; background: #f3f9fd; overflow: hidden; }
.crm-sandbox summary { cursor: pointer; padding: 12px 16px; font-weight: 700; color: #14628f; display: flex; align-items: center; gap: 8px; list-style: none; }
.crm-sandbox summary::-webkit-details-marker { display: none; }
.crm-sandbox[open] summary { border-bottom: 1px solid #d8e6f0; }
.sandbox-body { padding: 14px 16px; }
.sandbox-help { color: #4a6678; line-height: 1.5; margin-bottom: 12px; }
.sandbox-messages { display: flex; flex-direction: column; gap: 8px; min-height: 60px; max-height: 320px; overflow-y: auto; padding: 8px; background: #fff; border: 1px solid #e0e8ef; border-radius: 10px; }
.sb-row { display: flex; }
.sb-row.user { justify-content: flex-end; }
.sb-row.ai { justify-content: flex-start; }
.sb-bubble { max-width: 78%; padding: 8px 12px; border-radius: 12px; line-height: 1.4; white-space: pre-wrap; }
.sb-row.user .sb-bubble { background: #dcf8c6; color: #243; }
.sb-row.ai .sb-bubble { background: #eef2f6; color: #2c3a47; }
.sandbox-input { display: flex; gap: 8px; margin-top: 10px; }
.sandbox-input input { flex: 1; min-height: 42px; border-radius: 22px; padding: 0 16px; }
.sandbox-input button { min-height: 42px; border-radius: 22px; padding: 0 16px; border: 1px solid #c2ccd6; background: #fff; }
.sandbox-status { margin-top: 8px; min-height: 18px; font-size: 13px; color: #1f7a39; }

/* CRM en vivo */
.crm-list-empty { padding: 20px 16px; color: #7a8794; font-size: 13px; line-height: 1.5; }
.crm-list-empty a, .sandbox-help a, .crm-thread a { color: var(--blue); }
.crm-back { display: none; border: 0; background: transparent; font-size: 24px; line-height: 1; color: var(--blue); width: 32px; }
.content-header a.primary { display: inline-flex; align-items: center; gap: 7px; min-height: 38px; padding: 0 16px; border-radius: 8px; text-decoration: none; }
@media (max-width: 920px) { .crm-back { display: inline-flex; } }

/* Pagina de chat publica (estilo WhatsApp/Messenger) */
.pubchat-body { margin: 0; min-height: 100vh; background: #e9edf0; }
.pubchat { display: flex; flex-direction: column; width: min(100%, 480px); height: 100vh; margin: 0 auto; background: #e9edf0; box-shadow: 0 0 40px rgba(0,0,0,.12); }
.pubchat-head { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--blue); color: #fff; }
.pubchat-head img { height: 30px; background: #fff; border-radius: 8px; padding: 3px 8px; }
.pubchat-head strong { display: block; }
.pubchat-head small { opacity: .9; font-size: 12px; }
.pubchat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; background-image: radial-gradient(rgba(255,255,255,.5) 1px, transparent 0); background-size: 18px 18px; }
.pc-row { display: flex; }
.pc-row.out { justify-content: flex-end; }
.pc-row.in { justify-content: flex-start; }
.pc-bubble { max-width: 80%; padding: 9px 13px; border-radius: 14px; line-height: 1.4; white-space: pre-wrap; box-shadow: 0 1px 1px rgba(0,0,0,.08); }
.pc-row.out .pc-bubble { background: #dcf8c6; color: #243; border-bottom-right-radius: 4px; }
.pc-row.in .pc-bubble { background: #fff; color: #2c3a47; border-bottom-left-radius: 4px; }
.pubchat-input { display: flex; gap: 8px; padding: 10px; background: #f0f3f5; }
.pubchat-input input { flex: 1; min-height: 46px; border-radius: 24px; padding: 0 18px; border: 1px solid #d4dde6; }
.pubchat-input button { width: 46px; height: 46px; border-radius: 50%; font-size: 18px; }

@media (max-width: 920px) {
  .crm-app { grid-template-columns: 1fr; height: 76vh; }
  .crm-app .crm-chat { display: none; }
  .crm-app.show-chat .crm-list { display: none; }
  .crm-app.show-chat .crm-chat { display: flex; }
  .dc-grid { grid-template-columns: 1fr; }
  .dc-days { grid-auto-flow: row; grid-template-columns: repeat(3, 1fr); }
  .crm-head-meta { width: 100%; }
}

/* ===== Agenda v4: barra horizontal de controles (sin sidebar) ===== */
.agenda-page { width: min(100%, 1320px); }
@media (min-width: 1500px) { .agenda-page { width: min(100%, 1480px); } }

.agenda-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 18px; border-bottom: 1px solid var(--line); background: #fbfcfd; }
.date-nav { display: flex; align-items: center; gap: 6px; }
.dn-arrow { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: #fff; color: var(--blue-strong); font-size: 22px; line-height: 1; text-decoration: none; transition: background .12s, transform .12s; }
.dn-arrow:hover { background: var(--soft-blue); transform: scale(1.05); }
.dn-current { min-width: 150px; text-align: center; line-height: 1.15; }
.dn-current strong { display: block; font-size: 17px; color: var(--ink); text-transform: capitalize; }
.dn-current span { font-size: 12px; color: var(--muted); text-transform: capitalize; }
.dn-today { margin-left: 4px; padding: 7px 13px; border-radius: 999px; background: var(--soft-blue); color: var(--blue-strong); font-weight: 700; font-size: 13px; text-decoration: none; }
.dn-today:hover { background: #d3eeee; }

.tb-field { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--muted); }
.tb-field select { min-width: 190px; }

.state-filter { position: relative; }
.state-filter > summary { display: inline-flex; align-items: center; gap: 8px; list-style: none; cursor: pointer; min-height: 38px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: #44515d; font-weight: 600; }
.state-filter > summary::-webkit-details-marker { display: none; }
.state-filter[open] > summary { background: var(--soft-blue); color: var(--blue-strong); border-color: rgba(31,138,140,.3); }
.state-filter .sf-help { color: var(--muted); margin-bottom: 8px; line-height: 1.4; }
.state-filter-panel { position: absolute; z-index: 60; top: calc(100% + 8px); left: 0; width: 300px; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 16px 40px rgba(20,32,43,.18); padding: 14px; display: grid; gap: 9px; }
.state-filter-panel .fm-all { display: flex; align-items: center; gap: 8px; padding-bottom: 7px; border-bottom: 1px dashed var(--line); color: var(--ink); }
.state-filter-panel .fm-options { display: grid; gap: 8px; max-height: 240px; overflow: auto; }
.state-filter-panel .fm-options label { display: flex; align-items: center; gap: 8px; color: #3a4a5a; }
.state-filter-panel input[type=checkbox] { width: 16px; height: 16px; min-height: 0; accent-color: var(--blue); }
.state-filter-panel .fm-apply { justify-content: center; margin-top: 2px; min-height: 38px; }

.alert-chip { display: inline-flex; align-items: center; gap: 7px; min-height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid #f0d98a; background: var(--soft-amber); color: #a66f18; font-weight: 600; }
.alert-chip:hover { background: #ffeec8; }

.reload-toggle { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; padding: 7px 12px; border-radius: 999px; border: 1px solid #cfe6d6; background: #f3fbf5; color: #1f7a39; font-weight: 600; cursor: pointer; }
.reload-toggle input { width: 16px; height: 16px; min-height: 0; accent-color: var(--green); }

.empty-day { padding: 40px 20px; text-align: center; color: var(--muted); line-height: 1.5; }

@media (max-width: 760px) {
  .agenda-toolbar { gap: 8px; }
  .reload-toggle { margin-left: 0; }
  .tb-field select { min-width: 150px; }
  .state-filter-panel { width: min(86vw, 300px); }
}

/* ===== Agenda v5: calendario por profesional + lista + filtros ===== */
.cal-topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 18px 20px 8px; flex-wrap: wrap; }
.cal-topbar h1 { margin: 0; }
.cal-topbar p { color: var(--muted); text-transform: capitalize; }
.cal-actions { display: flex; align-items: center; gap: 8px; }
.cal-actions > button { min-height: 40px; border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 0 12px; }

.cal-toolbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 8px 20px 14px; border-bottom: 1px solid var(--line); }
.period-pills { display: inline-flex; gap: 4px; background: var(--page); padding: 4px; border-radius: 999px; }
.period-pills .pill { padding: 8px 15px; border-radius: 999px; color: #55616d; font-weight: 600; font-size: 13px; text-decoration: none; }
.period-pills .pill.on { background: var(--brand-grad); color: #fff; box-shadow: 0 4px 12px rgba(24,184,177,.3); }
.period-pills .pill:hover:not(.on) { background: #fff; }
.range-form { display: inline-flex; align-items: center; gap: 8px; }
.range-form .control { min-height: 38px; }
.range-form span { color: var(--muted); }
.view-toggle { margin-left: auto; display: inline-flex; gap: 4px; background: var(--page); padding: 4px; border-radius: 10px; }
.view-toggle .vt { display: grid; place-items: center; width: 40px; height: 34px; border-radius: 8px; }
.view-toggle .vt.on { background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.1); }
.view-toggle .vt.on .btn-icon { color: var(--blue); border-color: var(--blue); }

/* Calendario tipo Google Calendar */
.cal { overflow-x: auto; padding: 0 10px 16px; }
.cal-head-row { display: flex; position: sticky; top: 0; background: #fff; z-index: 3; border-bottom: 2px solid var(--line); }
.cal-corner { width: 58px; flex: 0 0 58px; }
.cal-head { flex: 1 1 0; min-width: 150px; padding: 10px 12px; text-align: center; border-left: 1px solid var(--line); }
.cal-head strong { display: block; color: var(--ink); font-size: 14px; }
.cal-head span { color: var(--muted); font-size: 12px; }
.cal-body-row { display: flex; position: relative; }
.cal-times { width: 58px; flex: 0 0 58px; position: relative; }
.cal-time { position: absolute; right: 8px; transform: translateY(-8px); font-size: 11px; color: var(--muted); }
.cal-col-body { flex: 1 1 0; min-width: 150px; position: relative; border-left: 1px solid var(--line); background-image: linear-gradient(to bottom, var(--line) 1px, transparent 1px); background-repeat: repeat-y; }
.cal-appt { position: absolute; left: 4px; right: 4px; border-radius: 8px; padding: 4px 8px; overflow: hidden; background: #eaf4ff; border-left: 4px solid var(--blue); box-shadow: 0 1px 3px rgba(0,0,0,.08); cursor: default; }
.cal-appt .ca-time { font-size: 10px; font-weight: 700; color: #55616d; }
.cal-appt .ca-name { display: block; font-weight: 700; font-size: 12px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-appt .ca-state { display: block; font-size: 10px; color: #6b7785; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* colores por estado */
.st-blue { background: #eaf4ff; border-left-color: #3b82c4; }
.st-green { background: #e9f8ee; border-left-color: #2a9d3d; }
.st-amber { background: #fff6e0; border-left-color: #f3b23f; }
.st-orange { background: #ffefe3; border-left-color: #ff7a45; }
.st-red { background: #fdeaea; border-left-color: #e0574f; }
.st-gray { background: #eef1f4; border-left-color: #9aa6b1; }

/* Lista */
.list-view { padding: 8px 18px 20px; }
.list-day-head { display: flex; justify-content: space-between; align-items: baseline; margin: 16px 0 8px; padding-bottom: 6px; border-bottom: 2px solid var(--line); font-weight: 800; color: var(--ink); text-transform: capitalize; }
.list-day-head span { font-size: 12px; font-weight: 600; color: var(--muted); }
.list-appt { display: grid; grid-template-columns: 108px minmax(180px, 1.6fr) minmax(130px, 1fr) minmax(140px, 1fr) minmax(120px, .8fr); align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); border-left: 4px solid var(--blue); background: #fff; margin-bottom: 8px; }
.list-appt.st-green { border-left-color: #2a9d3d; } .list-appt.st-amber { border-left-color: #f3b23f; }
.list-appt.st-orange { border-left-color: #ff7a45; } .list-appt.st-red { border-left-color: #e0574f; } .list-appt.st-gray { border-left-color: #9aa6b1; }
.la-time { font-weight: 700; color: #40505c; display: inline-flex; gap: 4px; align-items: center; }
.la-time b { color: #b9c3cc; font-weight: 400; }
.la-patient { display: grid; gap: 2px; }
.la-patient small { color: var(--muted); }
.la-pro { color: #40505c; }
.la-state { display: inline-flex; align-items: center; gap: 7px; color: #40505c; font-size: 13px; }
.la-state .dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; opacity: .6; }

@media (max-width: 760px) {
  .cal-toolbar { gap: 8px; }
  .view-toggle { margin-left: 0; }
  .list-appt { grid-template-columns: 1fr; gap: 4px; }
  .cal-head, .cal-col-body { min-width: 128px; }
}

/* Patients and admin actions */
.button-like { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 34px; border: 1px solid #bbc5cf; border-radius: 8px; background: #fff; padding: 0 12px; color: var(--ink); text-decoration: none; }
.button-like:hover { background: #f4f8fb; }
.floating-menu a, .floating-menu form button { display: flex; align-items: center; gap: 9px; min-height: 38px; width: 100%; border: 0; border-radius: 7px; background: #fff; color: #2d3b48; text-align: left; padding: 9px 16px; text-decoration: none; }
.floating-menu a:hover, .floating-menu form button:hover { background: #f0f7fc; }
.floating-menu form { margin: 0; }
.patient-create-form { margin: 12px 20px; }
.detail-panel { margin: 12px 20px; border: 1px solid #d9e1e8; border-radius: 8px; background: #fbfdff; padding: 14px; }
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(160px, 1fr)); gap: 10px; }
.detail-grid span { display: grid; gap: 4px; border: 1px solid #e0e7ee; border-radius: 8px; background: #fff; padding: 10px; }
.detail-grid b { color: #607080; font-size: 12px; }
.compact-table { padding: 12px 0 0; }
.inline-admin-form { display: grid; grid-template-columns: minmax(220px, 1fr) auto; gap: 12px; align-items: end; margin: 12px 20px; }
.inline-admin-form label { display: grid; gap: 6px; color: #506172; }
.chk-field { display: flex !important; align-items: center; gap: 8px !important; min-height: 38px; }
.conn-status { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; padding: 12px 20px; }
.conn-card { display: flex; gap: 10px; align-items: center; border: 1px solid #dbe1e7; border-radius: 8px; background: #fff; padding: 12px; }
.conn-card small { display: block; color: var(--muted); }
.conn-dot { width: 11px; height: 11px; border-radius: 50%; background: #aab4be; }
.conn-card.on .conn-dot { background: var(--green); }
.conn-card.off .conn-dot { background: #d59a22; }
@media (max-width: 900px) { .detail-grid, .inline-admin-form, .conn-status { grid-template-columns: 1fr; } }

/* Administration and account controls */
.section-title.padded { padding: 18px 20px 8px; }
.settings-grid .span-2 { grid-column: span 2; }
.day-checks { display: flex; flex-wrap: wrap; gap: 10px; padding: 0 0 12px; }
.day-checks label, .switch-row, .inline-form { display: inline-flex; align-items: center; gap: 8px; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch-row span { width: 42px; height: 24px; border-radius: 999px; background: #ccd5dd; position: relative; transition: background .15s; }
.switch-row span::after { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; left: 3px; top: 3px; background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,.18); transition: transform .15s; }
.switch-row input:checked + span { background: var(--green); }
.switch-row input:checked + span::after { transform: translateX(18px); }
.inline-toggle { margin: 0; }
.inline-form select { min-width: 140px; }
.inline-form button { min-height: 34px; border: 1px solid #c7d1db; border-radius: 8px; background: #fff; padding: 0 10px; }
.narrow-form { max-width: 760px; }
.compact-table table { min-width: 520px; }
.save-ok { margin-left: 20px; margin-right: 20px; }
.settings-grid select[multiple] { min-height: 138px; padding: 8px; }

@media (max-width: 900px) {
  .settings-grid .span-2 { grid-column: 1; }
}

/* ===== Admin: Sedes y Boxes ===== */
.res-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; padding: 0 20px; }
.chip-check { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0 8px; }
.chip-check.compact { max-width: 320px; gap: 5px; padding: 0; }
.chk-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font-size: 13px; color: #44515d; cursor: pointer; }
.chip-check.compact .chk-chip { padding: 4px 8px; font-size: 12px; }
.chk-chip input { width: 15px; height: 15px; accent-color: var(--blue); }
.chk-chip:hover { background: var(--page); }
.movement-edit { display: grid; grid-template-columns: repeat(5, minmax(92px, 1fr)) auto; gap: 6px; align-items: end; min-width: 560px; }
.movement-edit label { display: grid; gap: 2px; margin: 0; }
.movement-edit label span { font-size: 10px; text-transform: uppercase; letter-spacing: .02em; color: #6d7c88; font-weight: 700; }
.movement-edit input, .movement-edit select { min-height: 32px; width: 100%; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.mini-btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 5px 10px; font-size: 12px; font-weight: 600; color: #44515d; }
.mini-btn:hover { background: var(--page); }
.mini-btn.danger { color: #b3453d; border-color: #f0c7c3; }
@media (max-width: 900px) { .res-grid { grid-template-columns: 1fr; } }

/* ===== Agendamiento inteligente ===== */
.smart-book { padding: 8px 20px 24px; display: grid; grid-template-columns: 400px 1fr; gap: 18px 32px; align-items: start; }
.sb-left { display: flex; flex-direction: column; }
.sb-results { align-self: start; }
.smart-book .sb-confirm { grid-column: 1 / -1; }
@media (max-width: 900px) { .smart-book { grid-template-columns: 1fr; } }
.sb-step { display: flex; gap: 14px; padding: 14px 0; border-bottom: 1px dashed var(--line); }
.sb-num { flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-grad); color: #fff; font-weight: 800; }
.sb-body { flex: 1; }
.sb-body > label { display: block; font-weight: 700; color: var(--ink); margin-bottom: 8px; }
.sb-when { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.sb-when .pill { padding: 8px 15px; border-radius: 999px; border: 1px solid var(--line); background: #fff; font-weight: 600; color: #55616d; }
.sb-when .pill.on { background: var(--brand-grad); color: #fff; border-color: transparent; }
.sb-actions { padding: 16px 0; }
.sb-actions .primary { min-height: 44px; padding: 0 22px; }
.sb-results { min-height: 40px; }
.sb-hint { color: var(--muted); padding: 10px 0; }
.slot-day { margin-bottom: 14px; }
.slot-day h4 { margin: 6px 0; color: var(--ink); text-transform: capitalize; font-size: 14px; }
.slot-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.slot-chip { display: inline-grid; gap: 1px; padding: 8px 14px; border-radius: 12px; border: 1px solid var(--line); background: #fff; text-align: center; min-width: 96px; }
.slot-chip b { color: var(--blue-strong); font-size: 15px; }
.slot-chip span { color: var(--muted); font-size: 11px; white-space: nowrap; }
.slot-chip:hover { background: var(--soft-blue); border-color: var(--blue); }
.slot-chip.on { background: var(--brand-grad); border-color: transparent; }
.slot-chip.on b, .slot-chip.on span { color: #fff; }
.sb-confirm { margin-top: 16px; padding-top: 16px; border-top: 2px solid var(--line); }
.sb-chosen { padding: 12px 14px; border-radius: 12px; background: var(--soft-green); color: #1f7a39; margin-bottom: 14px; }

/* ===== Ficha clinica / presupuestos / pagos ===== */
.ficha-summary{display:flex;gap:12px;flex-wrap:wrap;align-items:center;padding:12px 20px}
.ficha-kpi{background:#f4f8fb;border:1px solid #e2ecf3;border-radius:12px;padding:8px 16px;display:flex;flex-direction:column;min-width:120px}
.ficha-kpi span{font-size:.72rem;color:#6b7c8a;text-transform:uppercase;letter-spacing:.04em}
.ficha-kpi strong{font-size:1.15rem;color:#0d3b52}
.ficha-alert{background:#fff3f0;border:1px solid #ffd3c9;color:#c0392b;border-radius:10px;padding:8px 14px;font-weight:600}
.tabs-row{display:flex;gap:6px;border-bottom:1px solid #e2ecf3;margin-top:6px}
.tabs-row .tab{padding:10px 16px;border-radius:10px 10px 0 0;color:#57707f;text-decoration:none;font-weight:600}
.tabs-row .tab.on{background:#0879c9;color:#fff}
.ficha-grid{display:grid;grid-template-columns:1fr 1fr;gap:16px;padding:16px 20px}
@media(max-width:900px){.ficha-grid{grid-template-columns:1fr}}
.ficha-card{background:#fff;border:1px solid #e2ecf3;border-radius:14px;padding:16px}
.ficha-card h3{margin:0 0 12px;color:#0d3b52}
.ficha-card label{display:block;margin-bottom:10px}
.ficha-card label span{display:block;font-size:.8rem;color:#57707f;margin-bottom:3px}
.ficha-timeline{padding-bottom:20px}
.tl-entry{display:grid;grid-template-columns:130px 1fr;gap:14px;padding:12px 20px;border-top:1px solid #eef3f7}
.tl-date{color:#57707f;font-size:.82rem}
.tl-body p{margin:2px 0}
.budget-picks{display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:8px;margin-bottom:12px}
.budget-picks .pick{display:flex;align-items:center;gap:8px;background:#f7fafc;border:1px solid #e2ecf3;border-radius:10px;padding:8px 12px;margin:0}
.budget-picks .pick em{margin-left:auto;color:#0879c9;font-style:normal;font-weight:600}
.budget-card{background:#fff;border:1px solid #e2ecf3;border-radius:14px;padding:14px;margin-bottom:12px}
.budget-head{display:flex;align-items:center;gap:12px;margin-bottom:8px}
.budget-head .budget-date{color:#8496a3;font-size:.82rem}
.budget-head .budget-total{margin-left:auto;font-size:1.1rem;color:#0d3b52}
.mini-table{width:100%;border-collapse:collapse}
.mini-table td{padding:4px 8px;border-top:1px solid #eef3f7;font-size:.9rem}
.badge{font-size:.72rem;padding:3px 10px;border-radius:999px;font-weight:700}
.badge-draft{background:#eef3f7;color:#57707f}
.badge-approved{background:#e6f7ee;color:#1e8b52}
.badge-rejected{background:#fdecea;color:#c0392b}
.badge-closed{background:#e7f0fb;color:#0879c9}
.budget-actions{display:flex;gap:8px;margin-top:8px}
.mini-btn{border:0;border-radius:8px;padding:6px 14px;cursor:pointer;font-weight:600}
.mini-btn.ok{background:#1e8b52;color:#fff}
.mini-btn.danger{background:#c0392b;color:#fff}
.state-select{border:1px solid #d5e0e8;border-radius:8px;padding:5px 8px;background:#fff;font-size:.82rem;color:#0d3b52;max-width:180px}
.list-appt.state-saved{outline:2px solid #1e8b52;transition:outline .2s}

/* Aviso de conflicto de cita en el modal Dar cita */
.dc-conflict { color: #c0392b; font-weight: 700; }
#dcContinue:disabled { opacity: .5; cursor: not-allowed; }

/* ===== Tablero / Reportes ===== */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; padding: 16px 20px; }
.kpi { border-radius: 16px; padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; color: #fff; box-shadow: 0 6px 18px rgba(28,43,57,.10); }
.kpi span { font-size: .78rem; opacity: .92; text-transform: uppercase; letter-spacing: .03em; }
.kpi strong { font-size: 1.9rem; line-height: 1.05; }
.kpi small { font-size: .78rem; opacity: .9; }
.kpi-green { background: linear-gradient(135deg,#159a5b,#0f7f4a); }
.kpi-blue { background: linear-gradient(135deg,#1479c9,#0b5fa3); }
.kpi-amber { background: linear-gradient(135deg,#e8912b,#cf7615); }
.kpi-teal { background: linear-gradient(135deg,#12a3a3,#0c7f82); }
.kpi-violet { background: linear-gradient(135deg,#7a5cd0,#5b3fb0); }
.kpi-slate { background: linear-gradient(135deg,#5a6b7c,#42505e); }
.report-board { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; padding: 8px 20px 24px; }
@media (max-width: 900px) { .report-board { grid-template-columns: 1fr; } }
.rb-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; }
.rb-card h2 { margin: 0 0 14px; font-size: 1.05rem; color: #0d3b52; }
.income-chart { display: flex; align-items: flex-end; gap: 10px; min-height: 160px; }
.ic-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; justify-content: flex-end; }
.ic-bar { width: 70%; max-width: 46px; border-radius: 8px 8px 0 0; background: linear-gradient(180deg,#1e9bd7,#0b5fa3); }
.ic-day { color: #6b7c8a; text-transform: capitalize; font-size: 11px; }
.ic-val { color: #0d3b52; font-size: 10px; font-weight: 600; }
.state-list { list-style: none; margin: 0; padding: 0; }
.state-list li { display: flex; align-items: center; gap: 8px; padding: 9px 4px; border-bottom: 1px solid #eef3f7; color: #40515f; }
.state-list li b { margin-left: auto; color: #0d3b52; font-size: 1.05rem; }
.state-list .dot { width: 8px; height: 8px; border-radius: 50%; background: #1479c9; }

/* ===== Odontograma ===== */
.odo-wrap { padding: 16px 20px 28px; }
.odo-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 18px; }
.odo-conditions { display: flex; flex-wrap: wrap; gap: 6px; }
.odo-cond { border: 1px solid #d5e0e8; background: #fff; border-radius: 999px; padding: 5px 12px; font-size: 12px; font-weight: 600; cursor: pointer; color: #40515f; }
.odo-cond.on { outline: 2px solid #0879c9; }
.odo-cond.c-caries { border-color: #e0b400; } .odo-cond.c-obturado { border-color: #1479c9; }
.odo-cond.c-corona { border-color: #8a63d2; } .odo-cond.c-endodoncia { border-color: #e8912b; }
.odo-cond.c-implante { border-color: #12a3a3; } .odo-cond.c-ausente { border-color: #c0392b; }
.odo-cond.c-fractura { border-color: #d35400; }
.odo-active { margin-left: auto; color: #57707f; font-size: 13px; }
.odo-arch { display: flex; justify-content: center; gap: 22px; margin: 6px 0; }
.odo-quad { display: flex; gap: 4px; }
.odo-arch:nth-child(3) .odo-quad, .odo-arch:last-child .odo-quad { align-items: flex-start; }
.tooth { width: 40px; display: flex; flex-direction: column; align-items: center; gap: 3px; border: 0; background: transparent; cursor: pointer; padding: 2px; }
.tooth .tooth-face { width: 30px; height: 34px; border: 1.5px solid #b9c6d0; border-radius: 6px 6px 8px 8px; background: #fff; display: block; }
.tooth small { font-size: 10px; color: #7a8794; }
.tooth:hover .tooth-face { border-color: #0879c9; box-shadow: 0 0 0 2px rgba(8,121,201,.15); }
.tooth.t-caries .tooth-face { background: #ffe58a; border-color: #e0b400; }
.tooth.t-obturado .tooth-face { background: #bcd9f5; border-color: #1479c9; }
.tooth.t-corona .tooth-face { background: #e5d8fb; border-color: #8a63d2; }
.tooth.t-endodoncia .tooth-face { background: #ffd9ad; border-color: #e8912b; }
.tooth.t-implante .tooth-face { background: #b7ecec; border-color: #12a3a3; }
.tooth.t-ausente .tooth-face { background: repeating-linear-gradient(45deg,#f3d6d2,#f3d6d2 4px,#fff 4px,#fff 8px); border-color: #c0392b; }
.tooth.t-fractura .tooth-face { background: linear-gradient(135deg,#fff 45%,#f0a97f 45%,#f0a97f 55%,#fff 55%); border-color: #d35400; }
.span-2 { grid-column: span 2; }

/* ===== Recetas + logo ===== */
.rx-table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.rx-table th { text-align: left; font-size: 11px; text-transform: uppercase; color: #748896; padding: 6px 6px; border-bottom: 1px solid var(--line); }
.rx-table td { padding: 4px 4px; }
.rx-table .control { padding: 6px 8px; font-size: 13px; }
.rx-table .rx-del { padding: 4px 10px; }
.logo-preview { display: flex; align-items: center; justify-content: center; min-height: 120px; border: 1px dashed #cdd8e0; border-radius: 12px; background: #f7fafc; margin-bottom: 12px; padding: 10px; }
.logo-preview img { max-height: 120px; max-width: 100%; object-fit: contain; }
.logo-empty { color: #94a3af; font-size: 13px; }

/* Cabecera profesional de la ficha */
.patient-hero { display: flex; align-items: center; gap: 16px; }
.patient-avatar { flex: 0 0 auto; width: 56px; height: 56px; border-radius: 50%; background: var(--brand-grad, linear-gradient(135deg,#0879c9,#12a3a3)); color: #fff; display: grid; place-items: center; font-size: 20px; font-weight: 800; }
.patient-hero h1 { margin: 0; font-size: 1.5rem; }
.patient-hero p { margin: 2px 0 0; color: var(--muted, #6b7c8a); font-size: .9rem; }

/* ===== Adjuntos de la ficha ===== */
.attach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.attach-card { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; display: flex; flex-direction: column; }
.attach-thumb { height: 140px; display: flex; align-items: center; justify-content: center; background: #f4f8fb; overflow: hidden; text-decoration: none; }
.attach-thumb img { width: 100%; height: 100%; object-fit: cover; }
.attach-file { font-size: 22px; font-weight: 800; color: #0879c9; letter-spacing: .05em; }
.attach-meta { padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.attach-meta strong { color: #0d3b52; font-size: 13px; }
.attach-meta small { color: #748896; font-size: 11px; }
.attach-meta form { margin-top: 6px; }

/* ============================================================
   PULIDO VISUAL Y UX (capa final)
   ============================================================ */

/* Tablas de datos — usadas en Ficha, Cajas, Recaudación, Inventario, Reportes */
.data-table { border-collapse: separate; border-spacing: 0; font-size: 13.5px; background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.data-table thead th { text-align: left; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); background: #f6f9fb; padding: 11px 14px; border-bottom: 1px solid var(--line); font-weight: 700; }
.data-table tbody td { padding: 11px 14px; border-bottom: 1px solid #eef2f6; color: #33424f; vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr { transition: background .12s; }
.data-table tbody tr:hover td { background: #f4fafb; }
.data-table th.num, .data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Foco accesible y agradable en campos */
.control:focus, input:focus, select:focus, textarea:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(24,184,177,.18); }
.control::placeholder { color: #9aa7b2; }
textarea.control { min-height: unset; line-height: 1.5; resize: vertical; }

/* Botones — transiciones y feedback consistente */
.primary, .button-like, .quiet-button, .clinic-button, .mini-btn, .module-nav a, .pill, .tab { transition: transform .08s ease, box-shadow .15s ease, background .15s ease, color .15s ease; }
.primary:hover { filter: brightness(1.05); box-shadow: 0 8px 20px rgba(24,184,177,.34); }
.primary:active, .button-like:active, .quiet-button:active { transform: translateY(1px); }
.button-like:hover { border-color: #b6d9d9; box-shadow: 0 3px 10px rgba(28,43,57,.08); }
button:disabled, .primary:disabled { opacity: .55; cursor: not-allowed; transform: none; }

/* Tarjetas — leve elevación al pasar el mouse */
.kpi { transition: transform .12s ease, box-shadow .15s ease; }
.kpi[href]:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(28,43,57,.16); }
.rb-card, .ficha-card, .budget-card, .attach-card, .panel { transition: box-shadow .15s ease; }
.attach-card:hover { box-shadow: 0 8px 22px rgba(28,43,57,.12); }

/* Pestañas de la ficha — más claras y con hover */
.tabs-row .tab { transition: background .15s, color .15s; }
.tabs-row .tab:not(.on):hover { background: #eef4f7; color: var(--ink); }

/* Nav superior: permitir 2 filas si no cabe (mejor que scroll oculto) */
.module-nav { flex-wrap: wrap; height: auto; min-height: 60px; padding-top: 8px; padding-bottom: 8px; row-gap: 6px; }

/* Estado vacío reutilizable */
.empty-state { text-align: center; color: var(--muted); padding: 34px 20px; }
.empty-state .es-emoji { font-size: 30px; display: block; margin-bottom: 8px; opacity: .8; }

/* Encabezado de página un poco más aireado */
.content-header h1 { letter-spacing: -.01em; }
.content-header p { color: var(--muted); }

/* Badges: base uniforme por si falta */
.badge { display: inline-block; line-height: 1.5; }

/* Chips de hora del agendador y slots — cursor claro */
.slot-chip, .dc-slot, .state-select, .pill, .tab { cursor: pointer; }

/* Scrollbars discretas en zonas con overflow */
.dc-days::-webkit-scrollbar, .crm-thread::-webkit-scrollbar, .module-nav::-webkit-scrollbar { height: 8px; width: 8px; }
.dc-days::-webkit-scrollbar-thumb, .crm-thread::-webkit-scrollbar-thumb { background: #cfdae1; border-radius: 8px; }

/* ============ PULIDO — capa 2 ============ */

/* Tablas "clásicas" (Pacientes, Administración): encabezado más suave + hover + zebra */
.wide-table { border: 1px solid var(--line); border-radius: 14px; overflow: auto; margin: 6px 20px 18px; padding: 0; }
.wide-table table { min-width: 720px; }
.wide-table th { background: #f6f9fb; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-size: 11px; font-weight: 700; padding: 11px 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; }
.wide-table td { padding: 11px 14px; border-bottom: 1px solid #eef2f6; }
.wide-table tbody tr { transition: background .12s; }
.wide-table tbody tr:hover td { background: #f4fafb; }
.wide-table tbody tr:last-child td { border-bottom: 0; }
.patients-table th { background: #f6f9fb; }

/* Tarjetas de resumen antiguas: coherencia con los KPI nuevos */
.stat-row div, .finance-grid article { border-radius: 14px; transition: transform .12s, box-shadow .15s; }
.stat-row div:hover, .finance-grid article:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(28,43,57,.12); }

/* Login: más marca y aire */
.login-body { min-height: 100vh; background: radial-gradient(1200px 600px at 15% -10%, rgba(24,184,177,.35), transparent 60%), linear-gradient(135deg, #18b8b1 0%, #1f8a8c 40%, #eef2f6 40%); }
.login-card { border-radius: 20px; box-shadow: 0 30px 90px rgba(22,45,68,.28); padding: 34px 32px; }
.login-brand { text-align: center; margin-bottom: 6px; }
.login-brand img { height: 66px; }
.login-sub { text-align: center; color: var(--muted); margin: 0 0 18px; font-size: 13.5px; }
.login-form label { display: block; margin-bottom: 12px; }
.login-form .primary { width: 100%; justify-content: center; min-height: 46px; border-radius: 12px; font-size: 15px; margin-top: 4px; }

/* Encabezados de sección/paneles: título con acento sutil */
.content-header h1 { display: flex; align-items: center; gap: 10px; }

/* Filtros redondeados coherentes */
.filter-row .control, .range-form .control, .sede-filter .control { border-radius: 10px; }

/* Modales: un poco más de aire y sombra */
.modal { border-radius: 16px; }
.modal-head h2 { letter-spacing: -.01em; }

/* Panel general: sombra más suave y moderna */
.panel { box-shadow: 0 8px 28px rgba(28,43,57,.07); }

/* Scroll global sutil */
body::-webkit-scrollbar { width: 12px; }
body::-webkit-scrollbar-thumb { background: #cdd8e1; border-radius: 12px; border: 3px solid var(--page); }

/* ============ PULIDO — capa 3 (correcciones) ============ */

/* Logo del login sin deformar (respeta proporción) */
.login-brand img { height: auto !important; width: auto !important; max-height: 62px; max-width: 86%; object-fit: contain; }

/* Agenda: tarjetas de cita legibles (no cortar el nombre, más aire) */
.cal-appt { min-height: 46px; left: 5px; right: 5px; padding: 5px 9px; border-radius: 9px; display: flex; flex-direction: column; gap: 1px; }
.cal-appt .ca-time { font-size: 10px; font-weight: 700; color: #52606d; line-height: 1.1; }
.cal-appt .ca-name { font-size: 12px; font-weight: 700; color: var(--ink); line-height: 1.15; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cal-appt .ca-state { font-size: 10px; }
.cal-appt:hover { box-shadow: 0 4px 12px rgba(28,43,57,.16); z-index: 3; }

/* Receta: cabecera de tabla clara (anula el th teal global) + notas cómodas */
.rx-table th { background: #f6f9fb !important; color: #596b78 !important; border-bottom: 1px solid var(--line); }
.rx-table td { border-bottom: 0; padding: 6px 6px; }
.rx-table { min-width: 0; }
.rx-notes { min-height: 90px; }

/* ============ Atención rápida (cockpit) ============ */
.atn-quick { display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 20px 4px; }
.atn-quick a { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 14px; font-weight: 600; color: #40515f; font-size: 13px; transition: background .12s, box-shadow .12s; }
.atn-quick a:hover { background: var(--soft-blue); box-shadow: 0 3px 10px rgba(28,43,57,.08); }
.atn-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; padding: 12px 20px; align-items: start; }
@media (max-width: 900px) { .atn-grid { grid-template-columns: 1fr; } }
.atn-side { display: flex; flex-direction: column; gap: 16px; }
.atn-main textarea.control { min-height: 96px; }
.atn-start { color: var(--cyan); margin-right: 2px; }
.atn-start:hover { color: var(--blue-strong); }

/* ============ Agenda: buscador + detalle de cita ============ */
.agenda-search { position: relative; display: flex; align-items: center; min-width: 240px; flex: 1; max-width: 340px; }
.agenda-search .as-glyph { position: absolute; left: 12px; color: #90a0ac; font-size: 15px; }
.agenda-search input { width: 100%; min-height: 38px; border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px 7px 32px; background: #fff; }
.cal-appt.js-cita { text-align: left; border: 0; border-left: 4px solid var(--blue); width: calc(100% - 10px); font: inherit; }
.cal-appt.js-cita:hover { filter: brightness(.99); }
.cita-detail { padding: 14px 20px 4px; }
.cita-when-line strong { font-size: 22px; color: var(--ink); }
.cita-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.cita-actions .primary, .cita-actions .button-like { min-height: 40px; text-decoration: none; }
.button-like.danger-btn { border-color: #f1c3bd; color: #c0392b; }
.button-like.danger-btn:hover { background: #fdecea; }

/* ============ Correcciones de modales e íconos ============ */

/* Íconos dentro de botones primarios: blancos y sin cajita celeste (se veían mal sobre el teal) */
.primary .btn-icon, .primary .nav-icon, .primary .menu-icon,
.content-header a.primary .btn-icon, .cita-actions .primary .btn-icon,
.form-actions .primary .btn-icon {
  background: transparent !important;
  border-color: transparent !important;
  color: #fff !important;
}

/* Modal Reprogramar: más ancho y grilla que no desborda (adiós scroll horizontal) */
#modalReprogramar .modal { width: min(100%, 540px); }
#modalReprogramar .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; padding: 4px 20px; }
#modalReprogramar .settings-grid label { min-width: 0; }
#modalReprogramar .settings-grid .span-2,
#modalReprogramar .settings-grid .span-3 { grid-column: 1 / -1; }
#modalReprogramar .modal-help { padding: 0 20px; }
.modal { overflow-x: hidden; }

/* Modal de detalle de cita: acciones cómodas y parejas */
.cita-actions { gap: 8px; }
.cita-actions .primary, .cita-actions .button-like { padding: 0 14px; }
.cita-when-line { margin: 2px 0 4px; }

/* ============ Panel de datos de conexión (webhook) ============ */
.conn-help { margin: 6px 20px 14px; padding: 16px 18px; border: 1px solid #cfe3ef; border-radius: 14px; background: linear-gradient(180deg,#f2f9fd,#ffffff); }
.conn-help h3 { margin: 0 0 4px; color: #0d3b52; display: flex; align-items: center; gap: 8px; }
.conn-field { margin-top: 10px; }
.conn-field label { display: block; font-size: 12px; font-weight: 700; color: #57707f; margin-bottom: 4px; }
.cf-row { display: flex; gap: 8px; align-items: center; }
.cf-row input { flex: 1; min-width: 0; min-height: 38px; border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 7px 12px; color: #33424f; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; }
.cf-row .button-like { white-space: nowrap; }

/* ============ Filtro de estado en la agenda ============ */
.agenda-filter { position: relative; }
.stF-panel { position: absolute; z-index: 40; top: calc(100% + 6px); right: 0; min-width: 250px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 30px rgba(28,43,57,.16); padding: 8px; max-height: 360px; overflow: auto; }
.stF-head { display: flex; gap: 8px; padding: 4px 6px 8px; border-bottom: 1px solid #eef2f6; }
.stF-link { border: 0; background: #eef4f7; color: #40515f; border-radius: 999px; padding: 5px 12px; font-weight: 600; font-size: 12px; }
.stF-quick { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 6px; border-bottom: 1px solid #eef2f6; }
.stF-chip { border: 1px solid #cfe0ec; background: #fff; color: #1f6b97; border-radius: 999px; padding: 5px 12px; font-size: 12px; font-weight: 600; }
.stF-chip:hover { background: var(--soft-blue); }
.stF-item { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.stF-item:hover { background: #f4fafb; }
.stF-item span { font-size: 13px; color: #33424f; }
#stFilterCount { color: var(--cyan); font-weight: 700; }

/* ============ Ausencia rápida del profesional ============ */
.cal-head { position: relative; }
.cal-head.is-absent { background: #fdecea; }
.absent-badge { display: inline-block; margin-top: 2px; background: #c0392b; color: #fff; font-size: 10px; font-weight: 800; padding: 2px 8px; border-radius: 999px; letter-spacing: .04em; }
.js-absent { display: block; margin: 6px auto 8px; border: 1px solid #e2c3bd; background: #fff; color: #c0392b; border-radius: 999px; padding: 3px 12px; font-size: 11px; font-weight: 700; }
.js-absent:hover { background: #fdecea; }
.js-absent.on { border-color: #bfe3cd; color: #1e8b52; }
.js-absent.on:hover { background: #eaf7ee; }

/* ============ Fix layout de formularios de la ficha ============ */
.ficha-grid { align-items: start; }
.ficha-card label { display: block; margin-bottom: 12px; }
.ficha-card label > span { display: block; font-size: .8rem; color: #57707f; margin-bottom: 4px; }
/* Todos los controles ocupan el ancho de su celda/tarjeta */
.ficha-card .control,
.ficha-card label > input,
.ficha-card label > select,
.ficha-card label > textarea { width: 100%; }
.ficha-card textarea.control { min-height: 96px; line-height: 1.5; resize: vertical; }
.ficha-card .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.ficha-card .settings-grid label { margin-bottom: 0; }
/* Antecedentes: textarea grande y cómoda */
#antecedentesCard textarea, .ficha-card textarea[name*="MedicalNotes"] { min-height: 120px; }
/* Receta: notas grandes */
.rx-notes { min-height: 100px !important; }
/* Evita que las tarjetas queden con espacio muerto */
.ficha-card { display: flex; flex-direction: column; }
.ficha-card .form-actions { margin-top: auto; }

/* Presupuesto variable */
.bg-total-line { text-align: right; font-size: 1.05rem; color: #0d3b52; margin: 8px 0; }
.bg-total-line strong { color: #0879c9; }
#bgTable td { padding: 6px 8px; vertical-align: middle; }
#bgTable .control { padding: 6px 8px; }

/* ============ Editor de texto enriquecido ============ */
.rich-editor { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; margin-bottom: 12px; }
.re-toolbar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 6px 8px; background: #f6f9fb; border-bottom: 1px solid var(--line); }
.re-toolbar button { border: 1px solid #d5e0e8; background: #fff; border-radius: 6px; min-width: 30px; height: 30px; padding: 0 8px; font-size: 13px; color: #40515f; }
.re-toolbar button:hover { background: var(--soft-blue); }
.re-sep { width: 1px; height: 20px; background: #d5e0e8; margin: 0 4px; }
.re-area { min-height: 180px; padding: 12px 14px; line-height: 1.6; font-size: 14px; color: #2c3e50; outline: none; }
.re-area:empty::before { content: attr(data-placeholder); color: #9aa7b2; }
.re-area h3 { margin: 10px 0 4px; font-size: 15px; }
.re-area ul, .re-area ol { margin: 6px 0 6px 22px; }
.re-area p { margin: 6px 0; }

/* ============ Acciones rápidas por paciente ============ */
.row-actions { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
.row-actions .button-like { min-height: 30px; padding: 0 10px; font-size: 12px; }
.qa-menu a, .qa-menu button { white-space: nowrap; }

/* ============================================================
   RESPONSIVE MÓVIL (full adaptable)
   ============================================================ */
@media (max-width: 820px) {
  .page-shell { padding: 12px 8px; }
  .workspace, .single-panel { width: 100%; }
  .content-header { flex-direction: column; align-items: stretch; gap: 10px; padding: 16px 14px 10px; }
  .content-header h1 { font-size: 1.35rem; }

  /* Cualquier grilla multi-columna -> una sola columna */
  .ficha-grid, .report-board, .settings-grid, .atn-grid, .kpi-grid,
  .detail-grid, .conn-status, .howto-grid, .form-grid, .res-grid,
  .ficha-card .settings-grid { grid-template-columns: 1fr !important; }
  .settings-grid .span-2, .settings-grid .span-3 { grid-column: 1 / -1 !important; }

  /* Tablas: scroll horizontal en vez de romper el layout */
  .data-table, .mini-table, .rx-table, #bgTable { display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .panel { overflow-x: hidden; }

  /* Modales casi a pantalla completa */
  .modal, .modal-lg, #modalReprogramar .modal { width: calc(100vw - 20px); max-height: 88vh; }
  .modal-backdrop { padding: 10px; }
  .dc-grid { grid-template-columns: 1fr; }

  /* Agenda: cuadrícula por profesional con scroll horizontal */
  .cal-body-row, .cal-head-row { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .cal-head, .cal-col-body { min-width: 150px; }
  .cal-toolbar { flex-wrap: wrap; gap: 8px; }
  .agenda-search { max-width: 100%; order: 3; width: 100%; }

  /* Pestañas de la ficha: scroll horizontal */
  .tabs-row { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
  .tabs-row .tab { white-space: nowrap; }

  /* Nav superior: scroll horizontal cómodo */
  .module-nav { flex-wrap: nowrap; overflow-x: auto; }
  .module-nav a { flex: 0 0 auto; }

  /* KPIs y tarjetas más compactas */
  .kpi strong { font-size: 1.5rem; }
  .ficha-summary { padding: 10px 14px; }

  /* Acciones que se salían */
  .cita-actions, .budget-actions, .form-actions { flex-wrap: wrap; }
  .row-actions { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .top-shell { padding: 8px 10px; }
  .brand-logo { height: 30px; }
  .avatar, .role-pill { display: none; }
  .content-header h1 { font-size: 1.2rem; }
  .kpi strong { font-size: 1.35rem; }
  .re-toolbar { gap: 3px; }
  .re-toolbar button { min-width: 26px; height: 26px; padding: 0 5px; font-size: 12px; }
}

/* ============================================================
   MOBILE v2 — repaso completo (header, tablas, agenda, filtros)
   Esta capa va al final: gana ante reglas mobile anteriores.
   ============================================================ */
@media (max-width: 860px) {
  html, body { overflow-x: hidden; }

  /* ---- Header sin superposiciones ---- */
  .top-shell { display: flex; flex-wrap: wrap; align-items: center; height: auto; padding: 8px 12px; gap: 8px 10px; }
  .brand { order: 0; }
  .brand-logo { height: 30px; }
  .top-actions { order: 1; margin-left: auto; gap: 8px; align-items: center; }
  .global-search { order: 2; flex: 1 1 100%; height: 40px; }
  .top-actions .quiet-button, .top-actions .clinic-button, .role-pill { display: none !important; }
  .logout-form button { padding: 8px 12px; }
  .module-nav { position: sticky; top: auto; }

  /* ---- Tablas: scroll horizontal limpio (no se cortan) ---- */
  .panel, .rb-card, .ficha-card, .detail-panel { overflow: visible; }
  .data-table, .rx-table, .mini-table, #bgTable, .wide-table > table {
    display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap;
  }
  .data-table th, .data-table td, .wide-table th, .wide-table td { padding: 9px 10px; font-size: 12.5px; }
  .wide-table { border: 0; }

  /* ---- Grillas a una columna ---- */
  .ficha-grid, .report-board, .settings-grid, .atn-grid, .kpi-grid,
  .detail-grid, .conn-status, .form-grid, .ficha-card .settings-grid { grid-template-columns: 1fr !important; }
  .settings-grid .span-2, .settings-grid .span-3 { grid-column: 1 / -1 !important; }

  /* ---- Agenda: toolbar sin desbordar ---- */
  .cal-toolbar { flex-wrap: wrap; gap: 8px; align-items: stretch; }
  .period-pills { flex-wrap: wrap; gap: 6px; }
  .agenda-search { flex: 1 1 100%; max-width: none; order: 6; }
  .agenda-filter { order: 5; }
  .date-nav { order: 4; }
  .view-toggle { order: 3; }

  /* Filtro de estado como hoja inferior (no se sale de pantalla) */
  .stF-panel { position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: auto; min-width: 0;
    max-height: 68vh; border-radius: 16px 16px 0 0; box-shadow: 0 -10px 30px rgba(0,0,0,.2); z-index: 80; }

  /* ---- Calendario: head + body scrollean juntos y alineados ---- */
  .cal { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .cal-head-row, .cal-body-row { width: max-content; min-width: 100%; }
  .cal-corner, .cal-times { flex: 0 0 46px; width: 46px; min-width: 46px; }
  .cal-head, .cal-col-body { flex: 0 0 168px; width: 168px; min-width: 168px; }
  .cal-appt { left: 4px; right: 4px; }
  .cal-appt .ca-name { font-size: 12px; }
  .js-absent { font-size: 10px; padding: 2px 8px; }

  /* Lista de citas: apila cómodo */
  .list-appt { grid-template-columns: 1fr !important; gap: 6px; padding: 12px; }
  .list-appt .la-state, .list-appt .la-sit { justify-self: start; }
  .state-select { max-width: 100%; }

  /* ---- Modales full-width ---- */
  .modal, .modal-lg, #modalReprogramar .modal { width: calc(100vw - 20px); max-height: 90vh; overflow: auto; }
  .modal-backdrop { padding: 10px; align-items: flex-start; }
  .dc-grid { grid-template-columns: 1fr; }
  .cita-actions { flex-direction: column; }
  .cita-actions .primary, .cita-actions .button-like { width: 100%; }

  /* ---- Pestañas de la ficha deslizables ---- */
  .tabs-row { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
  .tabs-row .tab { white-space: nowrap; }

  .kpi strong { font-size: 1.5rem; }
}

@media (max-width: 480px) {
  .avatar { width: 30px; height: 30px; }
  .content-header h1 { font-size: 1.2rem; }
  .cal-head, .cal-col-body { flex-basis: 150px; width: 150px; min-width: 150px; }
}

/* ============ Matriz de permisos ============ */
.perm-matrix table { min-width: 620px; }
.perm-matrix th, .perm-matrix td { text-align: center; }
.perm-matrix .pm-permcol { text-align: left; position: sticky; left: 0; background: #fff; z-index: 1; min-width: 200px; }
.perm-matrix thead th { background: #f6f9fb; }
.perm-matrix .pm-module td { background: #eef4f7; font-weight: 800; color: #0d3b52; text-transform: uppercase; font-size: 11px; letter-spacing: .05em; text-align: left; position: sticky; left: 0; }
.perm-matrix .pm-cell { padding: 6px; }
.perm-matrix .switch-row { justify-content: center; }

/* ============ Plan de tratamiento por fases ============ */
.plan-card { background:#fff; border:1px solid var(--line); border-radius:14px; padding:14px 16px; margin-bottom:14px; }
.plan-head { display:flex; align-items:center; gap:12px; flex-wrap:wrap; margin-bottom:8px; }
.plan-head strong { color:#0d3b52; }
.plan-total { color:#0879c9; font-weight:700; }
.plan-progress { display:flex; align-items:center; gap:10px; margin:4px 0 6px; }
.pp-bar { flex:1; height:10px; background:#e7edf2; border-radius:999px; overflow:hidden; }
.pp-bar span { display:block; height:100%; background:linear-gradient(90deg,#12a3a3,#0b5fa3); border-radius:999px; transition:width .3s; }
.plan-progress small { color:#57707f; white-space:nowrap; }
.phase-done td { opacity:.7; }
.phase-actions { display:flex; gap:6px; flex-wrap:wrap; }
.plan-addfase { display:flex; gap:8px; flex-wrap:wrap; align-items:center; margin-top:10px; padding-top:10px; border-top:1px dashed var(--line); }
.plan-addfase .control { padding:7px 10px; }

/* Plan: dinero + chip de plan activo */
.plan-money { display:flex; flex-wrap:wrap; gap:16px; margin:2px 0 6px; font-size:13.5px; color:#57707f; }
.plan-money strong { color:#0d3b52; }
.plan-money .pm-due strong { color:#c0392b; }
.ficha-kpi.kpi-plan { text-decoration:none; background:#eef7ff; border-color:#cfe3ef; min-width:180px; }
.ficha-kpi.kpi-plan strong { color:#0879c9; font-size:1rem; }
.ficha-kpi.kpi-plan small { color:#57707f; font-size:.72rem; }

/* Cobro por folio */
.cobro-info { font-size: 13px; color: #40515f; }
.cobro-info.ok b { color: #c0392b; }
.cobro-info.err { color: #c0392b; }

/* Nota por voz */
.voice-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.voice-bar .rec-on { background: #fde8e8; color: #c0392b; border-color: #f5b7b1; animation: recPulse 1.2s infinite; }
@keyframes recPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(192, 57, 43, .25); } 50% { box-shadow: 0 0 0 6px rgba(192, 57, 43, .08); } }

/* Notas del plan en la ficha */
.plan-notes { font-size: 13px; color: #46586a; margin: 6px 0; display: flex; flex-direction: column; gap: 2px; }
.plan-notes .pn-k { color: #8496a3; font-weight: 600; }
