:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}
a { color: var(--primary-dark); }
h1, h2, h3 { margin: 0 0 .5rem; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}
.brand { font-size: 1.3rem; font-weight: 700; color: var(--primary-dark); }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; margin-top: .2rem; }

/* ---------- App shell ---------- */
.app { display: none; grid-template-columns: 230px 1fr; min-height: 100vh; }
.app.active { display: grid; }
.sidebar {
  background: #0f172a;
  color: #cbd5e1;
  padding: 1rem .75rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
}
.sidebar .logo { color: #fff; font-weight: 700; padding: .5rem .6rem 1rem; font-size: 1.05rem; }
.sidebar button {
  background: none; border: none; color: #cbd5e1; text-align: left;
  padding: .55rem .6rem; border-radius: 8px; cursor: pointer; font-size: .9rem; width: 100%;
}
.sidebar button:hover { background: #1e293b; color: #fff; }
.sidebar button.active { background: var(--primary); color: #fff; }
.sidebar .nav-group { color: #64748b; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: .7rem .6rem .2rem; }
.sidebar .spacer { flex: 1; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 1rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: .6rem 1.25rem;
}
.topbar .who { text-align: right; font-size: .82rem; color: var(--muted); }
.notif-bell { position: relative; background: none; border: none; font-size: 1.25rem; cursor: pointer; padding: .2rem .4rem; }
.notif-count { position: absolute; top: -2px; right: -4px; background: var(--danger); color: #fff; border-radius: 999px; font-size: .65rem; font-weight: 700; padding: 0 .3rem; min-width: 1rem; text-align: center; }
.conv-list-item { display: flex; gap: .5rem; align-items: center; padding: .6rem .5rem; border-bottom: 1px solid var(--border); cursor: pointer; }
.conv-list-item:hover { background: #f8fafc; }
.msg-bubble { max-width: 75%; padding: .5rem .7rem; border-radius: 10px; margin: .3rem 0; }
.msg-bubble.mine { background: var(--primary); color: #fff; margin-left: auto; }
.msg-bubble.theirs { background: #f1f5f9; }
.msg-thread { max-height: 45vh; overflow-y: auto; display: flex; flex-direction: column; padding: .5rem 0; }
.topbar select { max-width: 260px; }
.content { padding: 1.5rem; overflow: auto; }

/* ---------- Components ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1.25rem;
}
.row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-end; }
label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .25rem; }
input, select, textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid var(--border);
  border-radius: 8px; font-size: .9rem; font-family: inherit; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.field { flex: 1; min-width: 160px; }

button.btn {
  background: var(--primary); color: #fff; border: none; padding: .55rem 1rem;
  border-radius: 8px; cursor: pointer; font-size: .9rem; font-weight: 600;
}
button.btn:hover { background: var(--primary-dark); }
button.btn.secondary { background: #e2e8f0; color: var(--text); }
button.btn.ghost { background: none; color: var(--primary-dark); padding: .3rem .5rem; }
button.btn:disabled { opacity: .5; cursor: not-allowed; }

table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .02em; }
tbody tr:hover { background: #f8fafc; }

.badge {
  display: inline-block; padding: .12rem .5rem; border-radius: 999px;
  font-size: .74rem; font-weight: 600; background: #e2e8f0; color: #475569;
}
.badge.ok { background: #dcfce7; color: #166534; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.pending { background: #e0e7ff; color: #3730a3; }
.badge.danger { background: #fee2e2; color: #991b1b; }

.msg { padding: .6rem .8rem; border-radius: 8px; margin: .5rem 0; font-size: .88rem; }
.msg.error { background: #fee2e2; color: #991b1b; }
.msg.ok { background: #dcfce7; color: #166534; }

.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 2rem; }
.section-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.section-head h2 { margin: 0; }
.section-head .btn { margin-left: auto; }
.pills { display: flex; flex-wrap: wrap; gap: .4rem; }
.pill-check { display: flex; align-items: center; gap: .35rem; font-size: .82rem; color: var(--text); background: #f1f5f9; padding: .3rem .55rem; border-radius: 8px; }
.pill-check input { width: auto; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: none; place-items: center; padding: 1rem; z-index: 50; }
.modal-backdrop.active { display: grid; }
.modal { background: var(--surface); border-radius: 14px; padding: 1.5rem; width: 100%; max-width: 540px; max-height: 90vh; overflow: auto; }
.modal h3 { margin-bottom: 1rem; }
.modal-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1.2rem; }

/* ---------- Modo embebido (pestaña Compras del HIS) ----------
   La SPA se presenta como MÓDULO: sin barra lateral ni selector de
   organización — la navegación la ponen las subpestañas del HIS. La cesta y
   la campana se conservan (operativa de compra). El acento adopta el verde
   azulado del HIS para integrarse visualmente. El modo autónomo no cambia. */
body.embed { --primary: #4c8391; --primary-dark: #3d6a76; }
body.embed .app { grid-template-columns: 1fr; }
body.embed .sidebar { display: none; }
body.embed .topbar > div:first-child { display: none; } /* selector de organización */
body.embed .topbar .who { display: none; }
body.embed .topbar { padding: .4rem 1rem; }
body.embed .content { padding: 1rem 1.25rem; }

/* ---------- Banda de modo demostración (iteración 3.0) ----------
   La inyecta el SERVIDOR en el HTML que sirve (src/demo.js), no está en el
   fichero index.html: así no existe ninguna copia sin banda.

   No es descartable A PROPÓSITO: no hay botón de cerrar, y como está fija arriba
   se ve en TODAS las vistas, también en la de acceso y también embebida en el
   HIS. Contraste alto (ámbar sobre casi negro, ~11:1) para que se lea en un
   proyector de sala de reuniones, que es donde se van a ver estas pantallas. */
.demo-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: .1rem 1rem;
  padding: .45rem 1rem;
  background: #111827;
  color: #fbbf24;
  border-bottom: 3px solid #f59e0b;
  font-size: .82rem;
  letter-spacing: .04em;
  text-align: center;
  /* Ni se selecciona ni se tapa: no hay forma de "quitarla" sin editar el
     servidor, que es exactamente lo que se pretende. */
  pointer-events: none;
}
.demo-banner strong { text-transform: uppercase; font-weight: 700; }
.demo-banner span { color: #e5e7eb; font-size: .76rem; letter-spacing: normal; }

/* Todo el contenido baja para dejarle sitio a la banda. */
body[data-demo-mode] { padding-top: 2.6rem; }
body[data-demo-mode] .app { min-height: calc(100vh - 2.6rem); }
body[data-demo-mode] .login-wrap { min-height: calc(100vh - 2.6rem); }
