:root {
  color-scheme: light;
  --bg: #eef3f7;
  --surface: #ffffff;
  --surface-soft: #f6f9fb;
  --line: #d8e3ea;
  --line-strong: #b7c9d5;
  --text: #172f42;
  --muted: #63798a;
  --brand: #1b6f9f;
  --brand-dark: #0d4c73;
  --brand-deep: #092f4d;
  --brand-soft: #e6f2f8;
  --cyan: #56afd6;
  --warning: #d99021;
  --warning-soft: #fff4df;
  --success: #23845e;
  --success-soft: #e6f5ee;
  --danger: #b94343;
  --danger-soft: #fae8e8;
  --violet: #6758b8;
  --violet-soft: #eeeafd;
  --shadow-sm: 0 6px 18px rgba(17, 54, 76, 0.08);
  --shadow-md: 0 16px 42px rgba(17, 54, 76, 0.15);
  --radius: 8px;
  --conversation-panel-width: 340px;
}


* { box-sizing: border-box; }
html { min-width: 320px; }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}
button, input, textarea { font: inherit; }
button, a.soft-link {
  min-height: 34px;
  border: 0;
  border-radius: var(--radius);
  padding: 0 12px;
  color: #fff;
  background: var(--brand);
  box-shadow: 0 8px 18px rgba(27, 111, 159, 0.18);
  cursor: pointer;
  text-decoration: none;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease, border-color 150ms ease;
}
button:hover, a.soft-link:hover { transform: translateY(-1px); box-shadow: 0 11px 22px rgba(27, 111, 159, 0.24); }
button:disabled { opacity: 0.42; cursor: not-allowed; transform: none; box-shadow: none; }
.hidden { display: none !important; }
body.is-loading .app-header::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--cyan), transparent);
  animation: loadingBar 1.1s linear infinite;
}
@keyframes loadingBar { from { transform: translateX(-70%); } to { transform: translateX(70%); } }

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 11px;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
input:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(27, 111, 159, 0.12); }
textarea { resize: vertical; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 650; }
.error { min-height: 18px; margin: 0; color: var(--danger); }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #082b45 0%, #0d4c73 55%, #56afd6 100%);
}
.login-panel {
  width: min(440px, 100%);
  display: grid;
  gap: 15px;
  padding: 30px;
  border: 1px solid rgba(255,255,255,0.72);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.98);
  box-shadow: 0 28px 80px rgba(0, 26, 44, 0.32);
}
.login-brand { display: grid; justify-items: center; gap: 10px; text-align: center; }
.brand-mark {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  color: #fff;
  background: linear-gradient(145deg, var(--brand), var(--brand-deep));
  font-size: 20px;
  font-weight: 850;
}
.brand-mark.small { width: 44px; height: 44px; font-size: 12px; background: #ffffff1f; border: 1px solid #ffffff2e; }
.login-brand span { color: var(--brand-deep); font-size: 12px; font-weight: 850; text-transform: uppercase; }
.login-panel h1 { margin: 2px 0 0; text-align: center; font-size: 26px; line-height: 1.15; }
.login-panel p { margin: -6px 0 4px; color: var(--muted); text-align: center; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-expanded-width) minmax(0, 1fr);
  background: var(--bg);
}
.app-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
  padding: 14px;
  color: #dcecf5;
  background: linear-gradient(180deg, #082d49 0%, #0a3858 55%, #0d4c73 100%);
  box-shadow: inset -1px 0 0 rgba(255,255,255,0.08);
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 6px 4px 14px; border-bottom: 1px solid rgba(255,255,255,0.12); }
.sidebar-brand strong, .sidebar-brand span, .operator-chip strong, .operator-chip small { display: block; }
.sidebar-brand strong { color: #fff; font-size: 14px; }
.sidebar-brand span, .operator-chip small { margin-top: 2px; color: #a9c5d6; font-size: 12px; }
.module-nav { min-height: 0; overflow: auto; display: grid; align-content: start; gap: 6px; padding-right: 2px; }
.module-link {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid transparent;
  padding: 0 10px;
  color: #dcecf5;
  background: transparent;
  box-shadow: none;
  text-align: left;
  font-weight: 750;
}
.module-link:hover { color: #fff; background: rgba(255,255,255,0.1); box-shadow: none; }
.module-link.active { color: #fff; background: rgba(86, 175, 214, 0.22); border-color: rgba(255,255,255,0.18); }
.nav-icon {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: #fff;
  background: rgba(255,255,255,0.14);
  font-size: 10px;
  font-weight: 850;
}
.sidebar-footer { display: grid; gap: 10px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,0.12); }
.operator-chip { display: flex; align-items: center; gap: 10px; min-width: 0; }
.operator-avatar { width: 34px; height: 34px; display: grid; place-items: center; border-radius: var(--radius); color: #fff; background: rgba(255,255,255,0.14); font-size: 11px; font-weight: 850; }
.sidebar-logout { color: #082d49; background: #fff; box-shadow: none; }

.workspace { min-width: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100vh; overflow: hidden; }
.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 20px;
  color: #fff;
  background: linear-gradient(90deg, var(--brand-dark), var(--brand));
  box-shadow: var(--shadow-sm);
}
.header-kicker { display: block; margin-bottom: 3px; color: #cdeaf7; font-size: 11px; font-weight: 850; text-transform: uppercase; }
.app-header h1 { margin: 0; font-size: 23px; line-height: 1.12; }
.app-header p { margin: 4px 0 0; color: #dcecf5; }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.soft-button, .soft-link {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--brand-deep);
  background: var(--brand-soft);
  border: 1px solid var(--line);
  box-shadow: none;
  font-size: 13px;
  font-weight: 750;
}
.app-header .soft-button { color: #fff; background: rgba(255,255,255,0.14); border-color: rgba(255,255,255,0.22); }
.soft-button.warn { color: #6a4300; background: var(--warning-soft); }
.soft-button.danger { color: var(--danger); background: var(--danger-soft); }
.action-button.primary { background: var(--brand); }
.action-button.success { background: var(--success); }
.action-button.neutral { color: var(--brand-deep); background: var(--brand-soft); box-shadow: none; }

.dashboard-strip {
  display: none;
  grid-template-columns: repeat(6, minmax(136px, 1fr));
  gap: 10px;
  padding: 14px 18px;
  background: #e8f0f5;
  border-bottom: 1px solid var(--line);
}
.metric-card {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.metric-card.pending { border-left-color: var(--warning); }
.metric-card.active { border-left-color: var(--brand); }
.metric-card.closed { border-left-color: var(--success); }
.metric-card.review { border-left-color: var(--danger); }
.metric-card.incomplete { border-left-color: var(--violet); }
.metric-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 7px; color: var(--brand-deep); background: var(--brand-soft); font-size: 11px; font-weight: 850; }
.metric-card.pending .metric-icon { color: #6a4300; background: var(--warning-soft); }
.metric-card.closed .metric-icon { color: var(--success); background: var(--success-soft); }
.metric-card.review .metric-icon { color: var(--danger); background: var(--danger-soft); }
.metric-card.incomplete .metric-icon { color: var(--violet); background: var(--violet-soft); }
.metric-card small, .metric-card em { display: block; color: var(--muted); font-size: 11px; font-style: normal; }
.metric-card strong { display: block; margin: 1px 0; font-size: 23px; line-height: 1; }

.module-view { min-height: 0; overflow: auto; display: none; padding: 18px; }
.module-view.active { display: block; }
#moduleOperativo.active { overflow: hidden; padding: 0; }
.ops-layout { height: 100%; min-height: 0; display: grid; grid-template-columns: minmax(280px, var(--conversation-panel-width)) 6px minmax(520px, 1fr); gap: 0; overflow: hidden; }
.conversation-panel { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr); border-right: 1px solid var(--line); background: var(--surface); }
.conversation-resizer { min-width: 6px; cursor: col-resize; background: linear-gradient(90deg, transparent, var(--line), transparent); }
.conversation-resizer:hover, body.is-resizing-conversation-panel .conversation-resizer { background: var(--brand-soft); }
body.is-resizing-conversation-panel { cursor: col-resize; user-select: none; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; padding: 14px; border-bottom: 1px solid var(--line); }
.panel-heading strong { display: block; margin-top: 2px; font-size: 17px; }
.section-title { display: block; color: var(--brand); font-size: 11px; font-weight: 850; text-transform: uppercase; }
.search-filter-bar { display: grid; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--surface-soft); }
.filters { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 2px; }
.filters button { min-height: 30px; flex: 0 0 auto; color: var(--brand-deep); background: #fff; border: 1px solid var(--line); box-shadow: none; font-size: 12px; }
.filters button.active { color: #fff; background: var(--brand); border-color: var(--brand); }
.conversation-list { min-height: 0; overflow: auto; padding: 10px; }
.conversation-item {
  width: 100%;
  display: grid;
  gap: 7px;
  margin-bottom: 9px;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 4px solid #8096a6;
  border-radius: var(--radius);
  color: var(--text);
  text-align: left;
  background: var(--surface);
  box-shadow: 0 3px 12px rgba(17, 54, 76, 0.05);
}
.conversation-item:hover, .conversation-item.active { border-color: rgba(27,111,159,0.38); border-left-color: var(--brand); background: var(--brand-soft); }
.conversation-item.PENDIENTE_OPERADOR { border-left-color: var(--warning); }
.conversation-item.EN_ATENCION { border-left-color: var(--brand); }
.conversation-item.CERRADO { border-left-color: var(--success); }
.item-head, .item-foot { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.conversation-item strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta, .conversation-item small { color: var(--muted); font-size: 12px; }
.doc-dot { display: inline-flex; border-radius: 99px; padding: 2px 6px; font-size: 10px; font-style: normal; font-weight: 850; }
.doc-dot.manual { color: #7b2600; background: #ffe2c6; }
.doc-dot.warning { color: #5f3a00; background: #ffedc4; }

.status-badge, .doc-status {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 99px;
  padding: 4px 8px;
  color: #fff;
  background: #75899a;
  font-size: 11px;
  font-weight: 850;
  white-space: nowrap;
}
.status-badge.PENDIENTE_OPERADOR { color: #5a3800; background: #f2c66a; }
.status-badge.EN_ATENCION { background: var(--brand); }
.status-badge.CERRADO { background: var(--success); }
.status-badge.BOT { background: #667b89; }
.doc-status.valid { color: var(--success); background: var(--success-soft); }
.doc-status.invalid { color: var(--danger); background: var(--danger-soft); }
.doc-status.warning { color: #6a4300; background: var(--warning-soft); }
.doc-status.manual { color: #873f00; background: #ffe5cf; }
.doc-status.received { color: var(--brand-deep); background: var(--brand-soft); }

.detail { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; background: var(--bg); }
.detail-header { min-width: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 16px 18px; border-bottom: 1px solid var(--line); background: var(--surface); }
.detail-header > div:first-child { min-width: 0; }
.detail-kicker { display: block; margin-bottom: 4px; color: var(--brand); font-size: 11px; font-weight: 850; text-transform: uppercase; }
.detail-header h2 { margin: 0; font-size: 22px; line-height: 1.15; }
.detail-header p { margin: 5px 0 0; color: var(--muted); }
.actions { min-width: 0; display: flex; flex-wrap: wrap; gap: 7px; justify-content: flex-end; }
.actions button { white-space: nowrap; }
.detail-scroll { min-height: 0; overflow: auto; padding: 14px 18px 18px; }
.patient-data, .submitted-data, .files-list, .quick-replies { display: grid; gap: 10px; margin-bottom: 14px; }
.patient-card-grid, .data-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 9px; }
.source-badge { display: inline-flex; margin-left: 6px; border-radius: 99px; padding: 1px 6px; color: var(--brand); background: var(--brand-soft); font-size: 10px; font-style: normal; font-weight: 850; vertical-align: middle; }
.source-badge.warn { color: #6a4300; background: var(--warning-soft); }
.source-badge.manual { color: var(--success); background: var(--success-soft); }
.operator-audit { display: grid; grid-template-columns: repeat(2, minmax(180px, 1fr)); gap: 9px; margin-bottom: 9px; }
.operator-audit div { border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: var(--radius); padding: 10px 11px; background: var(--surface); box-shadow: 0 3px 12px rgba(17,54,76,0.05); }
.operator-audit span, .operator-audit small { display: block; color: var(--muted); font-size: 11px; font-weight: 750; }
.operator-audit strong { display: block; margin: 4px 0 2px; font-size: 13px; }
.info-card, .field, .module-card, .module-stat {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 3px 12px rgba(17,54,76,0.05);
}
.info-card, .field { padding: 10px 11px; }
.info-card span, .field span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 11px; font-weight: 750; }
.info-card strong { display: block; overflow-wrap: anywhere; font-size: 13px; }
.field { overflow-wrap: anywhere; }
.document-grid { display: grid; grid-template-columns: repeat(2, minmax(280px, 1fr)); gap: 10px; }
.document-card { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 12px; padding: 10px; border: 1px solid var(--line); border-left: 4px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.document-card.valid { border-left-color: var(--success); }
.document-card.invalid { border-left-color: var(--danger); }
.document-card.warning { border-left-color: var(--warning); }
.document-card.manual { border-left-color: #db7b2b; }
.document-thumb { width: 88px; height: 88px; overflow: hidden; display: grid; place-items: center; padding: 0; border: 1px solid var(--line); color: var(--brand); background: var(--brand-soft); box-shadow: none; }
.document-thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.doc-icon { display: grid; place-items: center; width: 100%; height: 100%; color: var(--brand); font-size: 13px; font-weight: 850; text-decoration: none; }
.document-body { min-width: 0; display: grid; gap: 6px; }
.document-head { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.document-head strong, .document-body small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.document-body small, .document-body p { color: var(--muted); font-size: 12px; }
.document-body p { margin: 0; }
.document-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.internal-note { margin-top: 2px; }
.internal-note input { min-height: 30px; padding: 7px 9px; font-size: 12px; }
.quick-reply-grid { display: flex; flex-wrap: wrap; gap: 7px; }
.quick-reply-grid.static span { display: inline-flex; align-items: center; min-height: 30px; border: 1px solid var(--line); border-radius: var(--radius); padding: 0 10px; background: var(--surface-soft); color: var(--muted); font-size: 12px; }
.messages { min-height: 280px; overflow: auto; display: flex; flex-direction: column; gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(180deg, #ffffff 0%, #eff7fb 100%); }
.message { max-width: min(720px, 78%); padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px 8px 8px 3px; background: var(--surface); box-shadow: var(--shadow-sm); }
.message.out { align-self: flex-end; border-color: #b9ddec; border-radius: 8px 8px 3px 8px; background: #e7f5fb; }
.message.system { align-self: center; max-width: 90%; color: var(--muted); background: var(--surface-soft); box-shadow: none; }
.message small { display: block; margin-top: 6px; color: var(--muted); font-size: 11px; }
.composer-notice { padding: 14px; border-top: 1px solid var(--line); color: var(--muted); background: var(--surface); font-weight: 750; }
.composer { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: end; gap: 9px; padding: 12px 14px; border-top: 1px solid var(--line); background: var(--surface); }
.compose-main { min-width: 0; }
.composer textarea { min-height: 44px; max-height: 150px; }
.attachment-label { min-height: 17px; margin-top: 4px; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.attach-button { min-height: 34px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: var(--radius); padding: 0 12px; color: var(--brand-deep); background: var(--brand-soft); cursor: pointer; font-size: 13px; font-weight: 750; }
.attach-button input { display: none; }

.module-card { padding: 16px; margin-bottom: 14px; }
.module-card-header { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.module-card h2 { margin: 4px 0 0; font-size: 19px; }
.module-card p { color: var(--muted); }
.module-grid { display: grid; grid-template-columns: repeat(3, minmax(180px, 1fr)); gap: 12px; margin-bottom: 14px; }
.module-grid.two { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
.module-stat { padding: 14px; border-left: 4px solid var(--brand); }
.module-stat span { display: block; color: var(--muted); font-size: 12px; }
.module-stat strong { display: block; margin-top: 5px; font-size: 25px; }
.inline-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; color: var(--muted); }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 13px; }
th { color: var(--brand-deep); background: var(--surface-soft); font-size: 11px; text-transform: uppercase; }
td strong, td small { display: block; }
td small { margin-top: 3px; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
.table-note { min-width: 180px; min-height: 30px; padding: 7px 9px; }

.modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: clamp(10px, 2vw, 24px); background: rgba(8,26,40,0.58); backdrop-filter: blur(7px); }
.modal-panel { width: min(1080px, 100%); max-height: 92vh; display: grid; grid-template-rows: auto minmax(0, 1fr); overflow: hidden; border: 1px solid rgba(255,255,255,0.7); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-md); }
.modal-panel header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 15px; border-bottom: 1px solid var(--line); }
.preview-panel { width: min(1180px, calc(100vw - 24px)); height: min(860px, calc(100vh - 24px)); }
.preview-body { min-width: 0; min-height: 0; overflow: hidden; display: grid; place-items: center; padding: clamp(8px, 1.5vw, 14px); background: #102b40; }
.preview-body img { display: block; max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; background: #fff; }
.preview-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.preview-fallback { max-width: min(420px, 100%); display: grid; gap: 10px; justify-items: center; padding: 20px; border: 1px solid rgba(255,255,255,0.24); border-radius: var(--radius); color: #fff; text-align: center; background: rgba(255,255,255,0.08); }
.preview-fallback span { color: #dcecf5; font-size: 13px; }
.download-link { color: #fff; font-weight: 850; }
.admin-panel { width: min(940px, 100%); height: auto; }
.password-panel { width: min(460px, 100%); height: auto; }
.password-form { display: grid; gap: 12px; padding: 18px; }
.admin-body { min-height: 0; overflow: auto; display: grid; grid-template-columns: minmax(270px, 330px) minmax(0, 1fr); gap: 16px; padding: 16px; background: var(--surface-soft); }
.user-form, .users-list { display: grid; align-content: start; gap: 10px; }
.user-form, .user-row { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.user-form { padding: 14px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; color: var(--text); }
.checkbox-label input { width: auto; }
.user-row { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px; }
.user-actions { flex: 0 0 auto; display: flex; align-items: center; gap: 7px; }
.notification-toast, .app-toast { position: fixed; z-index: 40; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-md); }
.notification-toast { right: 18px; bottom: 18px; width: min(410px, calc(100vw - 32px)); display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px; border: 1px solid rgba(27,111,159,0.22); border-left: 5px solid var(--brand); }
.notification-toast strong, .notification-toast span { display: block; }
.notification-toast span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.app-toast { right: 18px; top: 78px; padding: 11px 13px; border: 1px solid var(--line); border-left: 5px solid var(--success); color: var(--text); }
.empty-state { padding: 14px; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface-soft); }

@media (max-width: 1360px) {
  .dashboard-strip { grid-template-columns: repeat(3, minmax(136px, 1fr)); }
  .patient-card-grid, .data-grid { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
  .document-grid { grid-template-columns: 1fr; }
}
@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 220px minmax(0, 1fr); }
  .ops-layout { grid-template-columns: 1fr; overflow: auto; }
  .conversation-panel { max-height: 430px; border-right: 0; border-bottom: 1px solid var(--line); }
  #moduleOperativo.active { overflow: auto; }
  .workspace { height: auto; min-height: 100vh; overflow: visible; }
  .detail { min-height: 720px; }
}
@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-sidebar { position: relative; height: auto; grid-template-rows: auto auto auto; }
  .module-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace { height: auto; }
  .app-header { position: relative; flex-direction: column; align-items: flex-start; }
  .dashboard-strip { grid-template-columns: repeat(2, minmax(136px, 1fr)); }
  .patient-card-grid, .data-grid, .module-grid, .module-grid.two { grid-template-columns: 1fr; }
  .detail-header { flex-direction: column; }
  .actions { justify-content: flex-start; }
  .composer { grid-template-columns: 1fr; }
  .admin-body { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .dashboard-strip { grid-template-columns: 1fr; padding: 12px; }
  .module-view { padding: 12px; }
  .module-nav { grid-template-columns: 1fr; }
  .document-card { grid-template-columns: 1fr; }
  .document-thumb { width: 100%; height: 150px; }
  .message { max-width: 92%; }
  .notification-toast { align-items: stretch; flex-direction: column; }
  .user-row, .user-actions { align-items: flex-start; flex-direction: column; }
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(130px, 1fr));
  gap: 7px;
  min-width: min(520px, 100%);
}
.permission-grid.compact {
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  min-width: 0;
}
.permission-check {
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 8px;
  color: var(--text);
  background: var(--surface-soft);
  font-size: 12px;
  font-weight: 750;
}
.permission-check input {
  width: auto;
  margin: 0;
}
.permission-row {
  align-items: flex-start;
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(260px, 1.4fr) auto;
}
.user-main { min-width: 0; }

@media (max-width: 820px) {
  .permission-row { grid-template-columns: 1fr; }
  .permission-grid, .permission-grid.compact { grid-template-columns: 1fr; }
}

/* Responsive app shell: expanded, collapsed, and mobile drawer states. */
:root {
  --sidebar-expanded-width: 320px;
  --sidebar-collapsed-width: 72px;
  --active-sidebar-width: var(--sidebar-expanded-width);
}
html, body { width: 100%; max-width: 100%; overflow-x: hidden; }
.app-shell {
  width: 100%;
  max-width: 100vw;
  grid-template-columns: var(--sidebar-expanded-width) minmax(0, 1fr);
  overflow-x: hidden;
}
.app-shell.sidebar-expanded { --active-sidebar-width: var(--sidebar-expanded-width); grid-template-columns: var(--sidebar-expanded-width) minmax(0, 1fr); }
.app-shell.sidebar-collapsed { --active-sidebar-width: var(--sidebar-collapsed-width); grid-template-columns: var(--sidebar-collapsed-width) minmax(0, 1fr); }
.app-sidebar { width: 100%; min-width: 0; transition: width 180ms ease, padding 180ms ease, transform 180ms ease; }
.sidebar-toggle {
  min-width: 36px;
  width: 36px;
  min-height: 36px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,0.22);
  color: #fff;
  background: rgba(255,255,255,0.14);
  box-shadow: none;
  font-weight: 850;
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.22); box-shadow: none; }
.mobile-toggle { display: none; flex: 0 0 auto; }
.sidebar-overlay { display: none; }
.header-copy { min-width: 0; }
.app-header { min-width: 0; }
.workspace { width: calc(100vw - var(--active-sidebar-width)); max-width: calc(100vw - var(--active-sidebar-width)); }
.app-header > .header-copy { flex: 1 1 auto; }
.header-actions { flex: 0 1 auto; }

.app-shell.sidebar-collapsed .app-sidebar { padding: 12px 8px; }
.app-shell.sidebar-collapsed .sidebar-brand {
  justify-content: center;
  padding: 4px 0 12px;
}
.app-shell.sidebar-collapsed .sidebar-brand > div:not(.brand-mark) { display: none; }
.app-shell.sidebar-collapsed .desktop-toggle { position: absolute; top: 58px; left: 18px; width: 34px; min-width: 34px; min-height: 30px; }
.app-shell.sidebar-collapsed .module-nav { padding-top: 34px; }
.app-shell.sidebar-collapsed .module-link {
  justify-content: center;
  gap: 0;
  padding: 0;
  font-size: 0;
}
.app-shell.sidebar-collapsed .nav-icon {
  width: 38px;
  height: 38px;
  font-size: 11px;
}
.app-shell.sidebar-collapsed .sidebar-footer { align-items: center; }
.app-shell.sidebar-collapsed .operator-chip { justify-content: center; }
.app-shell.sidebar-collapsed .operator-chip > div { display: none; }
.app-shell.sidebar-collapsed .sidebar-logout {
  min-width: 42px;
  width: 42px;
  padding: 0;
  overflow: hidden;
  font-size: 0;
}
.app-shell.sidebar-collapsed .sidebar-logout::before {
  content: "Salir";
  font-size: 10px;
  font-weight: 850;
}

.dashboard-strip { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.metric-card { min-width: 0; }
.workspace, .module-view, .detail, .detail-scroll, .table-wrap { min-width: 0; }
.table-wrap { max-width: 100%; overflow-x: auto; }
.module-card { max-width: 100%; overflow: hidden; }
.ops-layout { max-width: 100%; }
.conversation-panel, .detail { min-width: 0; }
.app-shell.sidebar-collapsed .ops-layout { grid-template-columns: minmax(280px, var(--conversation-panel-width)) 6px minmax(620px, 1fr); }

@media (max-width: 1365px) and (min-width: 769px) {
  .app-shell { grid-template-columns: var(--sidebar-collapsed-width) minmax(0, 1fr); }
  .app-shell.sidebar-expanded { grid-template-columns: var(--sidebar-expanded-width) minmax(0, 1fr); }
  .app-shell.sidebar-collapsed { grid-template-columns: var(--sidebar-collapsed-width) minmax(0, 1fr); }
  .dashboard-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 1080px) and (min-width: 769px) {
  .ops-layout { grid-template-columns: 1fr; overflow: auto; }
  .app-shell.sidebar-collapsed .ops-layout { grid-template-columns: 1fr; }
  .conversation-resizer { display: none; }
  .conversation-panel { max-height: 430px; border-right: 0; border-bottom: 1px solid var(--line); }
  #moduleOperativo.active { overflow: auto; }
  .workspace { height: auto; min-height: 100vh; overflow: visible; }
  .detail { min-height: 720px; }
}

@media (max-width: 768px) {
  body.sidebar-drawer-open { overflow: hidden; }
  .app-shell,
  .app-shell.sidebar-expanded,
  .app-shell.sidebar-collapsed {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    min-height: 100vh;
  }
  .app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 25;
    width: min(82vw, var(--sidebar-expanded-width));
    height: 100vh;
    transform: translateX(-100%);
    grid-template-rows: auto minmax(0, 1fr) auto;
    padding: 14px;
  }
  .app-shell.sidebar-mobile-open .app-sidebar { transform: translateX(0); }
  .app-shell.sidebar-mobile-open .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(5, 24, 38, 0.48);
  }
  .desktop-toggle { display: none; }
  .mobile-toggle { display: inline-grid; }
  .workspace { width: 100%; max-width: 100%; min-height: 100vh; height: auto; overflow: visible; }
  .app-header {
    position: sticky;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
  }
  .header-copy { flex: 1 1 calc(100% - 48px); }
  .app-header h1 { font-size: clamp(18px, 5vw, 22px); }
  .app-header p { font-size: 12px; }
  .header-actions { width: 100%; justify-content: flex-start; }
  .module-view { padding: 12px; }
  #moduleOperativo.active { overflow: visible; }
  .ops-layout { grid-template-columns: 1fr; overflow: visible; }
  .conversation-resizer { display: none; }
  .conversation-panel { max-height: 460px; border-right: 0; border-bottom: 1px solid var(--line); }
  .detail { min-height: 0; }
  .detail-header { flex-direction: column; padding: 14px; }
  .detail-scroll { padding: 12px; }
  .patient-card-grid, .data-grid, .module-grid, .module-grid.two { grid-template-columns: 1fr; }
  .document-grid { grid-template-columns: 1fr; }
  .composer { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .app-sidebar { width: min(88vw, var(--sidebar-expanded-width)); }
  .filters { max-width: calc(100vw - 48px); }
  .document-card { grid-template-columns: 1fr; }
  .document-thumb { width: 100%; height: 150px; }
  .message { max-width: 92%; }
}

@media (max-width: 768px) {
  .module-nav { grid-template-columns: 1fr; }
}
.validation-checks, .association-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.validation-checks span {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 0 8px;
  color: var(--success);
  background: var(--success-soft);
  font-size: 11px;
  font-weight: 850;
}
.association-actions span {
  flex: 1 1 180px;
  color: var(--muted);
  font-size: 12px;
}
.duplicate-warning {
  color: var(--warning) !important;
  font-weight: 750;
}
.ocr-input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 9px;
  color: var(--text);
  background: var(--panel);
  font: inherit;
  font-size: 13px;
}
.ocr-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}
.ocr-actions.inline {
  margin-top: -4px;
}
