/* RALVEN UI — sistema de diseño compartido.
 * Base de todas las pantallas: tipografía, tokens, controles y componentes.
 * Los colores de marca vienen de brand/ralven.css (fuente única de verdad).
 */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("vendor/inter/inter-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("vendor/inter/inter-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  /* Neutros */
  --ui-bg: #F5F7FB;
  --ui-surface: #FFFFFF;
  --ui-surface-muted: #F8FAFC;
  --ui-border: #E2E8F0;
  --ui-border-strong: #CBD5E1;
  --ui-text: #0F1F33;
  --ui-text-muted: #5B6B7F;
  --ui-text-subtle: #8494A7;

  /* Marca y estados */
  --ui-primary: var(--ralven-navy);
  --ui-primary-hover: #123E78;
  --ui-accent: var(--ralven-blue);
  --ui-accent-soft: #EAF3FF;
  --ui-teal: var(--ralven-teal);
  --ui-teal-soft: #E6F9F6;
  --ui-success: #0E9F6E;
  --ui-success-soft: #E7F7EF;
  --ui-warning: #B45309;
  --ui-warning-soft: #FFF6E5;
  --ui-danger: #C53030;
  --ui-danger-soft: #FDECEC;

  /* Forma */
  --ui-radius-sm: 8px;
  --ui-radius: 10px;
  --ui-radius-lg: 16px;
  --ui-shadow-sm: 0 1px 2px rgba(15, 31, 51, .06);
  --ui-shadow: 0 1px 2px rgba(15, 31, 51, .04), 0 6px 24px rgba(15, 31, 51, .06);
  --ui-shadow-pop: 0 12px 40px rgba(15, 31, 51, .16);
  --ui-ring: 0 0 0 3px rgba(30, 136, 255, .28);

  /* Ritmo */
  --ui-control-h: 44px;
  --ui-gap: 16px;
  --ui-page-w: 760px;
}

/* ===== Base ===== */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body.ui {
  margin: 0;
  min-height: 100vh;
  background: var(--ui-bg);
  color: var(--ui-text);
  font: 400 15px/1.55 var(--ralven-font-family);
  font-feature-settings: "cv11", "ss01";
}

body.ui :is(h1, h2, h3, h4) {
  color: var(--ui-text);
  font-weight: 650;
  letter-spacing: -0.015em;
  line-height: 1.25;
}

body.ui a { color: var(--ui-accent); text-underline-offset: 2px; }

[hidden] { display: none !important; }

/* Foco de teclado siempre visible con outline (también en alto contraste). */
:is(button, input, select, textarea, a[href], [tabindex]):focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: 2px;
}

/* ===== Barra superior ===== */

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--ui-border);
}

.app-header-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  max-width: 1120px;
  height: 64px;
  margin: 0 auto;
  padding: 0 20px;
}

.app-logo { display: flex; align-items: center; }
.app-logo img { display: block; height: 26px; width: auto; }

.app-nav {
  display: flex;
  gap: 4px;
  margin-right: auto;
}

.app-nav a {
  padding: 8px 12px;
  border-radius: var(--ui-radius-sm);
  color: var(--ui-text-muted);
  font-weight: 550;
  font-size: 14px;
  text-decoration: none;
}

.app-nav a:hover { color: var(--ui-text); background: var(--ui-surface-muted); }
.app-nav a[aria-current="page"] { color: var(--ui-primary); background: var(--ui-accent-soft); }

.app-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

.app-user form { margin: 0; }

.avatar {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ralven-blue), var(--ralven-teal));
  color: #fff;
  font-weight: 700;
  font-size: 13px;
}

.app-user-nombre { color: var(--ui-text); font-weight: 550; }

@media (max-width: 640px) {
  .app-header-inner { gap: 12px; padding: 0 14px; }
  .app-logo img { height: 22px; }
  .app-user-nombre, .app-user .avatar { display: none; }
  .app-user .btn-ghost { padding: 6px 8px; }
  .app-nav a { padding: 8px; font-size: 13px; white-space: nowrap; }
}

/* ===== Contenedores ===== */

.app-main {
  max-width: var(--ui-page-w);
  margin: 0 auto;
  padding: 28px 20px 64px;
}

.app-main.ancho { max-width: 1040px; }

.page-head { margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 26px; }
.page-head p { margin: 6px 0 0; color: var(--ui-text-muted); }

.card {
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-lg);
  box-shadow: var(--ui-shadow);
  padding: 24px;
}

.card + .card { margin-top: 16px; }

.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 4px;
  font-size: 18px;
}

.card-subtitle { margin: 0 0 18px; color: var(--ui-text-muted); font-size: 14px; }

@media (max-width: 640px) {
  .app-main { padding: 18px 12px 48px; }
  .card { padding: 18px; border-radius: 14px; }
}

/* ===== Campos ===== */

.field { display: flex; flex-direction: column; gap: 6px; }
.field + .field { margin-top: 14px; }

.ui label, .label {
  color: var(--ui-text);
  font-size: 14px;
  font-weight: 600;
}

.hint { color: var(--ui-text-muted); font-size: 13px; }

.ui :is(input:not([type="checkbox"], [type="radio"], [type="hidden"]), select, textarea) {
  width: 100%;
  min-height: var(--ui-control-h);
  padding: 10px 12px;
  border: 1px solid var(--ui-border-strong);
  border-radius: var(--ui-radius);
  background: var(--ui-surface);
  color: var(--ui-text);
  font: inherit;
  font-size: 15px;
  transition: border-color .15s, box-shadow .15s;
}

.ui textarea { min-height: 88px; line-height: 1.5; resize: vertical; }

.ui :is(input, select, textarea)::placeholder { color: var(--ui-text-subtle); }

.ui :is(input, select, textarea):hover { border-color: #AAB7C8; }

.ui :is(input, select, textarea):focus {
  border-color: var(--ui-accent);
  box-shadow: var(--ui-ring);
}

.ui select {
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%235B6B7F' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.ui :is(input, select, textarea)[aria-invalid="true"] {
  border-color: var(--ui-danger);
}

.ui input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--ui-primary);
}

/* ===== Botones ===== */

.ui button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--ui-control-h);
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--ui-radius);
  background: var(--ui-primary);
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, box-shadow .15s, transform .05s;
}

.ui button:hover, .btn:hover { background: var(--ui-primary-hover); }
body.ui a.btn { color: #fff; }
body.ui a.btn:is(.btn-secondary, .btn-ghost) { color: var(--ui-text); }
.ui button:active, .btn:active { transform: translateY(1px); }
.ui button:disabled { opacity: .55; cursor: not-allowed; }

.ui .btn-secondary, .btn-secondary {
  background: var(--ui-surface);
  border-color: var(--ui-border-strong);
  color: var(--ui-text);
}

.ui .btn-secondary:hover, .btn-secondary:hover {
  background: var(--ui-surface-muted);
  border-color: #AAB7C8;
}

.ui .btn-ghost, .btn-ghost {
  background: transparent;
  color: var(--ui-text-muted);
}

.ui .btn-ghost:hover, .btn-ghost:hover { background: var(--ui-surface-muted); color: var(--ui-text); }

.ui .btn-sm, .btn-sm { min-height: 34px; padding: 6px 12px; font-size: 14px; }
.ui .btn-block, .btn-block { width: 100%; }

/* ===== Insignias, alertas, listas de datos ===== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}

.badge-neutral { background: #EEF2F7; color: #475569; }
.badge-info { background: var(--ui-accent-soft); color: #0B5CC4; }
.badge-success { background: var(--ui-success-soft); color: #08744F; }
.badge-warning { background: var(--ui-warning-soft); color: var(--ui-warning); }
.badge-teal { background: var(--ui-teal-soft); color: #037A6B; }

.alert {
  padding: 12px 14px;
  border-radius: var(--ui-radius);
  border: 1px solid;
  font-size: 14px;
}

.alert-error { background: var(--ui-danger-soft); border-color: #F5C2C2; color: #8A1F1F; }
.alert-info { background: var(--ui-accent-soft); border-color: #C7DFFF; color: #0B4A9E; }
.alert-success { background: var(--ui-success-soft); border-color: #BDE8D3; color: #08613F; }

.dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 18px;
  margin: 0;
  font-size: 14px;
}

.dl dt { color: var(--ui-text-muted); }
.dl dd { margin: 0; color: var(--ui-text); font-weight: 550; }

.divider { height: 1px; margin: 20px 0; border: 0; background: var(--ui-border); }

/* Aviso discreto de funciones simuladas (firma, identidad institucional). */
.mock-note {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ui-text-subtle);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: uppercase;
}

/* ===== Navegación con sidebar (médico con cuenta) ===== */

.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  width: 248px;
  padding: 20px 14px;
  background: var(--ui-surface);
  border-right: 1px solid var(--ui-border);
}

.app-sidebar-logo { display: block; padding: 4px 10px 24px; }
.app-sidebar-logo img { display: block; height: 26px; width: auto; }

.app-sidebar-nav { display: grid; gap: 2px; }

body.ui .app-sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--ui-radius);
  color: var(--ui-text-muted);
  font-size: 14px;
  font-weight: 550;
  text-decoration: none;
}

body.ui .app-sidebar-nav a:hover { background: var(--ui-surface-muted); color: var(--ui-text); }
body.ui .app-sidebar-nav a[aria-current="page"] { background: var(--ui-accent-soft); color: var(--ui-primary); }

body.ui .app-sidebar-nav a.app-sidebar-destacado {
  margin: 4px 0 10px;
  background: var(--ui-primary);
  color: #fff;
}

body.ui .app-sidebar-nav a.app-sidebar-destacado:hover { background: var(--ui-primary-hover); color: #fff; }
.app-sidebar-nav a.app-sidebar-destacado[aria-current="page"] { box-shadow: 0 0 0 3px rgba(30, 136, 255, .25); }

.app-sidebar-usuario {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding: 12px 8px 0;
  border-top: 1px solid var(--ui-border);
}

.app-sidebar-usuario form { margin: 0 0 0 auto; }
.app-sidebar-usuario-datos { min-width: 0; font-size: 13px; line-height: 1.3; }
.app-sidebar-usuario-datos strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-sidebar-usuario-datos span { color: var(--ui-text-muted); }

.app-topbar, .app-tabbar { display: none; }

body.con-sidebar { padding-left: 248px; }
body.con-sidebar .app-main.ancho { max-width: 1040px; }

@media (max-width: 860px) {
  body.con-sidebar { padding-left: 0; padding-bottom: 72px; }
  .app-sidebar { display: none; }

  .app-topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 14px;
    background: rgba(255, 255, 255, .94);
    backdrop-filter: saturate(1.4) blur(8px);
    border-bottom: 1px solid var(--ui-border);
  }

  .app-topbar img { display: block; height: 22px; width: auto; }
  .app-topbar form { margin: 0; }

  .app-tabbar {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 60;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, .97);
    border-top: 1px solid var(--ui-border);
  }

  body.ui .app-tabbar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-height: 48px;
    padding: 4px;
    border-radius: var(--ui-radius);
    color: var(--ui-text-subtle);
    font-size: 11px;
    font-weight: 600;
    text-decoration: none;
  }

  body.ui .app-tabbar a[aria-current="page"] { color: var(--ui-primary); }
  .app-tabbar a[aria-current="page"] svg { stroke: var(--ui-accent); }
}

body.ui a.app-sidebar-usuario-datos { color: inherit; text-decoration: none; border-radius: 8px; padding: 2px 4px; }
body.ui a.app-sidebar-usuario-datos:hover span, body.ui a.app-sidebar-usuario-datos[aria-current="page"] span { color: var(--ui-accent); }
.app-topbar-acciones { display: flex; align-items: center; gap: 4px; }
.app-topbar-acciones form { margin: 0; }

/* ===== Diálogo propio (avisos y confirmaciones) ===== */
.dialogo-app {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(92vw, 460px); margin: 0; padding: 0; border: 0;
  border-radius: var(--ui-radius-lg, 16px); box-shadow: var(--ui-shadow-pop, 0 20px 50px rgba(15,31,51,.25));
  background: var(--ui-surface, #fff); color: var(--ui-text, #0F1F33);
}
.dialogo-app::backdrop { background: rgba(15, 31, 51, .5); backdrop-filter: blur(2px); }
.dialogo-app-contenido { padding: 24px; border-top: 4px solid var(--ralven-blue, #1E6FD9); border-radius: inherit; }
.dialogo-app[data-tipo="error"] .dialogo-app-contenido { border-top-color: var(--ui-danger, #C62828); }
.dialogo-app h2 { margin: 0 0 8px; font-size: 19px; }
.dialogo-app p { margin: 0; color: var(--ui-text-muted, #5B6B7F); white-space: pre-line; line-height: 1.5; }
.dialogo-app-acciones { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.dialogo-app-acciones button { min-height: 44px; min-width: 120px; }
.dialogo-app-acciones .btn-secundario {
  background: var(--ui-surface, #fff); border: 1px solid var(--ui-border-strong, #CBD5E1); color: var(--ui-text, #0F1F33);
}
.dialogo-app-acciones .btn-peligro { background: var(--ui-danger, #C62828); border-color: var(--ui-danger, #C62828); }
.dialogo-app-acciones button:focus-visible { outline: 3px solid var(--ralven-blue, #1E6FD9); outline-offset: 2px; }
@media (max-width: 480px) { .dialogo-app-acciones { flex-direction: column-reverse; } .dialogo-app-acciones button { width: 100%; } }
