/* CONWIA MED: barra lateral azul marino, fondo claro, acento naranja. Sin build ni CDN. */
:root {
  --navy: #0f2a4a;
  --navy-2: #173a63;
  --orange: #fc7903;
  --orange-dark: #692d00;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #5b6676;
  --border: #d9dee6;
  --danger: #a4161a;
  --ok: #1b6e3a;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.5; }
a { color: var(--navy-2); }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }
.skip-link { position: absolute; left: -999px; }
.skip-link:focus { left: 16px; top: 16px; background: #fff; padding: 8px; z-index: 10; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.shell { display: flex; min-height: 100vh; }
.sidebar { width: 240px; background: var(--navy); color: #fff; padding: 24px 16px; flex-shrink: 0; }
.sidebar ul { list-style: none; padding: 0; margin: 24px 0 0; }
.sidebar a { display: block; color: #fff; text-decoration: none; padding: 10px 12px; border-radius: 8px; min-height: 24px; }
.sidebar a:hover { background: var(--navy-2); }
.brand { display: flex; align-items: center; line-height: 1; }
.brand img { display: block; width: 100%; max-width: 240px; height: auto; }
.brand-dark { justify-content: center; margin-bottom: 24px; }
.content { flex: 1; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
main { padding: 24px; }
.inline { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
.user { color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.badge { display: inline-block; background: #fdeedf; color: var(--orange-dark); border-radius: 999px; padding: 2px 10px; font-size: .85rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.member-table th, .member-table td { overflow-wrap: anywhere; }

label { display: block; font-weight: 600; margin: 12px 0 4px; }
input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font: inherit; min-height: 44px; }
.form-card { max-width: 760px; }
.table-wrap { overflow-x: auto; }
.preserve-lines { white-space: pre-wrap; overflow-wrap: anywhere; }
.errorlist { color: var(--danger); }
input[type="checkbox"] { width: auto; min-height: 24px; }
.btn { display: inline-block; padding: 10px 18px; border-radius: 8px; border: 1px solid var(--border); background: #fff; color: var(--text); font: inherit; cursor: pointer; text-decoration: none; min-height: 44px; }
.btn-primary { background: var(--orange); border-color: var(--orange); color: #1c1006; font-weight: 600; margin-top: 16px; }
.btn-primary:hover { background: var(--orange-dark); color: #fff; }
.btn-link { border: 0; background: none; color: var(--navy-2); text-decoration: underline; min-height: 24px; padding: 4px; }
.field-error { color: var(--danger); margin: 4px 0; }
.messages { list-style: none; padding: 0; }
.msg { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; border: 1px solid var(--border); background: #fff; }
.msg-error, .msg-warning { border-color: #e9b4b4; background: #fdf1f1; color: var(--danger); }
.msg-success { border-color: #b4dcc2; background: #effaf3; color: var(--ok); }

.auth { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; background: radial-gradient(ellipse at top, #fff0e2, transparent 65%), var(--bg); }
.auth-card { width: 100%; max-width: 440px; background: var(--card); border-radius: var(--radius); border: 1px solid var(--border); border-top: 3px solid var(--orange); box-shadow: 0 12px 40px #692d000d; padding: 32px; }
.qr { display: block; margin: 16px auto; background: #fff; }
.secret { word-break: break-all; }
.codes { columns: 2; font-size: 1.1rem; }

@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; padding: 12px 16px; }
  .sidebar ul { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
  main { padding: 16px; }
}

.agenda-days { align-items: start; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 270px), 1fr)); gap: 12px; }
.agenda-appointment { border-top: 1px solid var(--border); padding: 10px 0; overflow-wrap: anywhere; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }

.queue-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 12px; }
.ticket-number { font-size: clamp(2.5rem, 7vw, 5rem); font-weight: 800; }
.queue-screen { margin: 0; background: var(--navy); color: white; }
.queue-screen header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 20px; padding: 24px; }
.queue-screen main { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 350px), 1fr)); gap: 24px; }
.queue-screen .card { color: var(--text); margin-bottom: 16px; }

.clinical-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(250px, 1fr); gap: 24px; align-items: start; }
.clinical-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.document-workspace, .document-settings { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.pdf-preview { width: 100%; height: 650px; border: 1px solid var(--border); background: #fff; }
.document-pdf { min-width: 0; }
.billing-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.billing-line { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 16px; padding: 16px; }
.table-scroll { max-width: 100%; overflow-x: auto; }
.table-scroll table { min-width: 640px; width: 100%; border-collapse: collapse; }
.table-scroll th, .table-scroll td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
@media (max-width: 900px) { .billing-grid { grid-template-columns: minmax(0, 1fr); } }
.pdf-mobile-hint { display: none; }
@media (max-width: 600px) { .document-pdf .pdf-preview { display: none; } .pdf-mobile-hint { display: block; } }
.document-full { height: 750px; }
.document-review { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 20px; align-items: start; }
@media (max-width: 950px) { .document-review { grid-template-columns: minmax(0, 1fr); } }
.logo-preview { width: 150px; max-height: 150px; object-fit: contain; }
.document-filters { display: flex; flex-wrap: wrap; gap: 16px; align-items: end; }
.document-filters p { flex: 1; min-width: 140px; }
.document-editor { min-height: 420px; resize: vertical; line-height: 1.5; }
.document-settings > section { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.document-settings > section h2 { grid-column: 1 / -1; }
@media (max-width: 600px) { .document-settings > section { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 950px) { .document-workspace, .document-settings { grid-template-columns: minmax(0, 1fr); } }
.clinical-note-form textarea { resize: vertical; }
.clinical-note-form details { border-block: 1px solid var(--border); padding: 16px 0; }
summary { cursor: pointer; font-weight: 600; }
.clinical-print { max-width: 900px; margin: auto; padding: 24px; background: #fff; color: #111; }
.clinical-print header img { width: 180px; }
.clinical-print code { overflow-wrap: anywhere; }
@media (max-width: 900px) { .clinical-layout { grid-template-columns: minmax(0, 1fr); } }
@media print { .no-print { display: none; } .clinical-print { padding: 0; font-size: 11pt; } .clinical-print h2 { break-after: avoid; } }

/* B8: QR vectorial, zona de silencio y módulos enteros en pantallas pequeñas. */
.qr { width: 294px; height: auto; max-width: 100%; image-rendering: pixelated; }
.secret { overflow-wrap: anywhere; }
.auth-card .helptext { display: block; font-size: .875rem; color: var(--muted); }
@media (max-width: 420px) { .auth-card { padding: 24px; } .qr { width: 245px; } }
@media (max-width: 350px) { .auth-card { padding: 18px; } .qr { width: 196px; } }

/* UX B8: contexto persistente y navegación compacta; sin librerías externas. */
[hidden] { display: none !important; }
.skip-link:focus { position: fixed; z-index: 100; }
html { scroll-padding-top: var(--focus-clearance, 120px); }
:focus-visible { outline-color: var(--orange-dark); }
.sidebar :focus-visible { outline-color: var(--orange); }
.topbar { position: sticky; top: 0; z-index: 40; padding: 10px 20px; gap: 8px 16px; }
.topbar .btn-primary { margin-top: 0; }
.topbar .context { min-width: 0; overflow-wrap: anywhere; }
.patient-context-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; width: 100%; }
.patient-context-row:not(:has(*)) { display: none; }
.patient-context { display: flex; flex-wrap: wrap; gap: 2px 8px; min-width: 0; align-items: baseline; }
.patient-context strong, .user { overflow-wrap: anywhere; }
.patient-context > span, .patient-context small { color: var(--muted); font-size: .875rem; }
.mobile-navigation, .nav-close { display: none; }
.mobile-navigation :focus-visible { outline-color: var(--orange); }
.sidebar a, .sidebar summary { min-width: 24px; min-height: 44px; }
.sidebar summary { padding: 10px 12px; }
main a { display: inline-block; min-height: 24px; min-width: 24px; }
summary { min-height: 44px; padding: 10px 4px; }
fieldset { border: 0; padding: 12px 0; margin: 0; min-width: 0; }
legend { font-size: 1.1rem; font-weight: 700; padding: 8px 0; }
input, textarea, select { border-color: #7a8696; max-width: 100%; }
input[type="checkbox"] { min-width: 24px; min-height: 24px; }
button, a, summary { touch-action: manipulation; }
h1 { font-size: clamp(1.4rem, 2.5vw, 1.85rem); }
h1, h2, h3, p, li, dd { overflow-wrap: anywhere; }
.clinical-header { margin-bottom: 12px; }
.clinical-header h1 { margin-block: 8px; }
.breadcrumbs { margin-block: 0 8px; font-size: .9rem; }
.clinical-summary { position: sticky; top: var(--header-height, 100px); z-index: 30; border: 1px solid var(--border); border-left: 4px solid var(--orange); background: white; border-radius: 8px; padding: 0 12px; margin-bottom: 16px; max-height: 35vh; overflow-y: auto; }
.clinical-summary summary { color: var(--orange-dark); }
.summary-brief { display: grid; gap: 3px; color: var(--text); font-size: .8rem; font-weight: 400; padding-top: 6px; }
.summary-groups { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.summary-groups h2 { font-size: 1rem; margin: 4px 0; }
.summary-groups ul { padding-left: 18px; margin-top: 4px; }
.summary-groups li { margin-bottom: 8px; }
.summary-state { margin-block: 4px; font-weight: 600; }
.summary-help, .helptext { color: var(--muted); font-size: .875rem; }
.save-status { padding: 8px 12px; border-left: 3px solid var(--orange-dark); background: #fff5ec; font-weight: 600; margin-bottom: 12px; }
.save-conflict { border: 2px solid var(--orange-dark); padding: 12px; background: #fff5ec; margin-bottom: 12px; }
.consultation-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.followup section { border-top: 1px solid var(--border); }
.followup h3 { font-size: 1rem; }
@media (max-width: 1023px) {
  .shell { flex-direction: column; }
  .topbar { padding: 8px 12px; gap: 4px 8px; }
  .mobile-navigation { display: flex; align-items: center; gap: 8px; width: 100%; justify-content: space-between; background: var(--navy); border-radius: 6px; padding: 2px 6px; }
  .mobile-navigation img { max-width: 132px; height: 34px; }
  .js .sidebar { position: fixed; top: var(--header-height, 160px); left: 0; right: 0; width: 100%; z-index: 50; max-height: calc(100dvh - var(--header-height, 160px)); overflow-y: auto; padding: 12px; }
  .js .sidebar ul { display: block; margin-top: 4px; }
  .js .sidebar .brand { display: none; }
  .nav-close { display: inline-block; }
  .topbar .context { font-size: .875rem; flex: 1 1 60%; }
  .context .badge { display: none; }
  .topbar .inline { font-size: .875rem; flex-wrap: wrap; }
  main { padding: 16px 12px; }
}
@media (max-width: 767px) {
  .patient-context-row { gap: 4px; }
  .patient-context { flex: 1 1 100%; font-size: .9rem; }
  .patient-context small { display: none; }
  .clinical-summary { max-height: 40vh; }
  .summary-groups { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .clinical-summary summary { font-size: .875rem; }
  .clinical-layout { gap: 12px; }
  .card { padding: 14px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .document-workspace .pdf-preview { display: none; }
  .member-table, .member-table tbody { display: block; width: 100%; }
  .member-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .member-table tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(60px, auto); gap: 10px 16px; padding: 16px 12px; border-bottom: 1px solid var(--border); }
  .member-table td { display: block; padding: 0; border: 0; min-width: 0; }
  .member-table td:nth-child(2) { max-width: 9em; overflow-wrap: normal; }
  .member-table td:nth-child(3) { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px 16px; }
}
@media (max-height: 500px) and (max-width: 1023px) {
  .mobile-navigation img { height: 24px; }
  .topbar { padding-block: 2px; }
  .topbar .context, .topbar .inline { font-size: .8rem; }
  .clinical-summary { position: static; }
}
