/*
 * external-clinical-portals-ui@1.1.0
 * Portal de financiadores: una capa propia sobre la identidad HRE compartida.
 */

:root {
  --color-bg: #f4f8fb;
  --color-panel: #ffffff;
  --color-border: #d8e6f1;
  --color-text: #0b2440;
  --color-text-muted: #52697f;
  --color-primary: #043b6b;
  --color-primary-soft: #0b568f;
  --color-accent: #9c2c2c;
  --color-success: #007a35;
  --color-warning: #9a5a05;
  --portal-ink: #0b2440;
  --portal-navy: #002b55;
  --portal-blue: #043b6b;
  --portal-sky: #dceef9;
  --portal-mist: #f4f8fb;
  --portal-green: #007a35;
  --portal-red: #9c2c2c;
  --portal-amber: #9a5a05;
  --shadow-sm: 0 1px 2px rgba(11, 36, 64, 0.06);
  --shadow-md: 0 22px 60px rgba(0, 43, 85, 0.18);
  --radius: 4px;
}

html {
  color-scheme: light;
}

body {
  min-width: 320px;
  background:
    linear-gradient(90deg, rgba(4, 59, 107, 0.035) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--portal-mist);
  color: var(--portal-ink);
  font-family: var(--font-ui, "Alegreya Sans", sans-serif);
}

button,
input {
  font: inherit;
}

button:focus-visible,
input:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid #68b9e8;
  outline-offset: 3px;
}

.muted {
  color: var(--color-text-muted);
}

/* Acceso */

.login-shell {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  background:
    radial-gradient(circle at 15% 18%, rgba(117, 170, 219, 0.22), transparent 34rem),
    linear-gradient(135deg, #002b55 0%, #043b6b 58%, #0a4b7f 100%);
}

.login-shell::before,
.login-shell::after {
  position: absolute;
  z-index: -1;
  content: "";
  pointer-events: none;
}

.login-shell::before {
  inset: 0;
  opacity: 0.18;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.16) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(90deg, #000, transparent 72%);
}

.login-shell::after {
  width: min(46vw, 620px);
  aspect-ratio: 1;
  right: -11vw;
  bottom: -19vw;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  box-shadow:
    0 0 0 54px rgba(255, 255, 255, 0.025),
    0 0 0 108px rgba(255, 255, 255, 0.025);
}

.login-card {
  width: min(470px, 100%);
  gap: 18px;
  padding: 42px 44px 38px;
  border: 1px solid rgba(216, 230, 241, 0.86);
  border-top: 5px solid #75aadb;
  border-radius: 3px;
  box-shadow: var(--shadow-md);
}

.login-card::before {
  content: "ACCESO INSTITUCIONAL EXTERNO";
  color: var(--portal-blue);
  font-family: var(--font-mono, "IBM Plex Mono", monospace);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-align: center;
}

.login-card img {
  width: min(220px, 72%);
  height: 58px;
}

.login-card h1,
.topbar h1,
.account-intro h2 {
  font-family: var(--font-institucional, "Ibarra Real Nova", serif);
  font-weight: 600;
  letter-spacing: -0.025em;
}

.login-card h1 {
  font-size: clamp(1.8rem, 5vw, 2.25rem);
}

.login-card > .muted {
  max-width: 36ch;
  margin: 0 auto 6px;
  font-family: var(--font-lectura, "Alegreya", serif);
  font-size: 1.05rem;
  line-height: 1.45;
  text-align: center;
}

.login-card label {
  gap: 7px;
}

.login-card label span {
  color: var(--portal-ink);
  font-size: 0.88rem;
  font-weight: 700;
}

.login-card input,
.ui-planilla-filter {
  min-height: 46px;
  border-color: #b9ccdc;
  border-radius: 3px;
  background: #fff;
  color: var(--portal-ink);
}

.login-card input:hover,
.ui-planilla-filter:hover {
  border-color: #7b9bb6;
}

.login-card input:focus,
.ui-planilla-filter:focus {
  border-color: var(--portal-blue);
  box-shadow: 0 0 0 3px rgba(4, 59, 107, 0.12);
}

.login-card button.primary {
  min-height: 48px;
  margin-top: 4px;
  border-radius: 3px;
  background: var(--portal-blue);
  letter-spacing: 0.01em;
}

.login-card button.primary:hover {
  background: var(--portal-navy);
}

.login-error {
  border-left: 4px solid var(--portal-red);
  border-radius: 2px;
}

/* Navegación y cabecera */

.app-shell {
  grid-template-columns: 272px minmax(0, 1fr);
  min-width: 0;
  max-width: 100%;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px 18px 22px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0)),
    var(--portal-navy);
  box-shadow: 1px 0 0 rgba(255, 255, 255, 0.06);
  min-width: 0;
}

.brand-block {
  gap: 6px;
  padding: 0 8px 22px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.brand-block img {
  width: 190px;
  height: 52px;
  margin-bottom: 12px;
  padding: 7px 10px;
  border-radius: 2px;
}

.brand-block span,
.eyebrow,
.section-kicker,
.account-intro__label {
  font-family: var(--font-mono, "IBM Plex Mono", monospace);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.brand-block strong {
  font-size: 1.28rem;
}

.nav-list {
  gap: 6px;
  min-width: 0;
}

.nav-item {
  position: relative;
  min-height: 46px;
  padding: 11px 14px 11px 20px;
  border: 1px solid transparent;
  border-radius: 2px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.98rem;
}

.nav-item::before {
  position: absolute;
  top: 12px;
  bottom: 12px;
  left: 0;
  width: 3px;
  background: transparent;
  content: "";
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.07);
}

.nav-item.active {
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.11);
}

.nav-item.active::before {
  background: #75aadb;
}

.sidebar-link {
  min-height: 42px;
  padding: 8px 10px;
  border-radius: 2px;
}

.sidebar-link::before {
  margin-right: 8px;
  content: "↻";
}

.main {
  min-width: 0;
  max-height: none;
  padding: 30px clamp(22px, 4vw, 58px) 64px;
  overflow: visible;
}

.topbar {
  position: relative;
  align-items: center;
  padding-bottom: 20px;
  border-bottom-color: #c9dce9;
}

.topbar::after {
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 84px;
  height: 3px;
  background: var(--portal-blue);
  content: "";
}

.topbar .eyebrow {
  margin-bottom: 7px;
  color: var(--portal-blue);
}

.topbar h1 {
  color: var(--portal-navy);
  font-size: clamp(1.75rem, 3vw, 2.35rem);
}

.topbar-actions {
  gap: 10px;
}

.user-chip {
  display: grid;
  gap: 1px;
  min-width: 172px;
  padding: 8px 12px;
  border-color: #c9dce9;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.78);
  line-height: 1.15;
}

.user-chip span {
  color: var(--portal-ink);
  font-weight: 700;
}

.user-chip strong {
  color: var(--color-text-muted);
  font-size: 0.72rem;
  font-weight: 500;
}

button.ghost {
  min-height: 40px;
  border-color: #b9ccdc;
  border-radius: 2px;
  background: #fff;
  color: var(--portal-blue);
  font-weight: 700;
}

button.ghost:hover {
  border-color: var(--portal-blue);
  background: #eef7fc;
}

.tab-section {
  min-width: 0;
  gap: 24px;
}

.panel {
  min-width: 0;
  padding: clamp(18px, 3vw, 34px);
  border-color: #c9dce9;
  border-radius: 2px;
  box-shadow: 0 12px 32px rgba(0, 43, 85, 0.06);
}

/* Resumen de cuenta: elemento distintivo de la superficie financiador */

.account-intro {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
}

.account-intro__label,
.section-kicker {
  display: block;
  margin-bottom: 6px;
  color: var(--portal-blue);
}

.account-intro h2 {
  margin: 0;
  color: var(--portal-navy);
  font-size: clamp(1.45rem, 2.4vw, 2rem);
}

.account-intro p {
  max-width: 48ch;
  margin: 0;
  color: var(--color-text-muted);
  font-family: var(--font-lectura, "Alegreya", serif);
  font-size: 1rem;
  line-height: 1.4;
  text-align: right;
}

.account-intro p span {
  margin-right: 4px;
  color: var(--portal-green);
}

.account-ledger {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 34px;
  border: 1px solid var(--portal-blue);
  border-top-width: 4px;
  background: #fafdff;
}

.account-ledger__item {
  position: relative;
  display: grid;
  gap: 4px;
  min-height: 126px;
  padding: 22px 24px;
  border-right: 1px solid #c9dce9;
}

.account-ledger__item:last-child {
  border-right: 0;
}

.account-ledger__item > span {
  color: var(--color-text-muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.account-ledger__item strong,
.money-value {
  color: var(--portal-navy);
  font-family: var(--font-mono, "IBM Plex Mono", monospace);
  font-variant-numeric: tabular-nums;
}

.account-ledger__item strong {
  font-size: clamp(1.35rem, 2.15vw, 1.85rem);
  line-height: 1.1;
  white-space: nowrap;
}

.account-ledger__item small {
  align-self: end;
  color: var(--color-text-muted);
}

.account-ledger__item--attention {
  background: #fffaf5;
}

.account-ledger__item--attention::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: #d68a2c;
  content: "";
}

.account-ledger__item--attention strong {
  color: #773f00;
}

.portal-section + .portal-section {
  margin-top: 38px;
  padding-top: 34px;
  border-top: 1px solid #c9dce9;
}

.portal-section,
.portal-table,
.portal-table .ui-planilla-scroll {
  min-width: 0;
}

.portal-section__heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 15px;
}

.portal-section__heading h3 {
  margin: 0;
  color: var(--portal-navy);
  font-family: var(--font-institucional, "Ibarra Real Nova", serif);
  font-size: 1.35rem;
}

.portal-section__heading p {
  max-width: 52ch;
  margin: 0;
  color: var(--color-text-muted);
  line-height: 1.35;
  text-align: right;
}

/* Tablas */

.portal-table {
  border-color: #c9dce9;
  border-radius: 2px;
}

.portal-table .ui-planilla-toolbar,
.portal-table .ui-planilla-footer {
  background: #f5f9fc;
}

.portal-table .ui-planilla-toolbar {
  padding: 13px 14px;
}

.portal-table .ui-planilla-filter {
  width: min(100%, 560px);
}

.portal-table .ui-planilla-table thead th {
  padding: 11px 13px;
  background: #eaf3f8;
  color: var(--portal-navy);
  font-size: 0.75rem;
  letter-spacing: 0.045em;
  text-transform: uppercase;
}

.portal-table .ui-planilla-table td {
  padding: 12px 13px;
  color: #233b52;
}

.portal-table .ui-planilla-table tbody tr:hover {
  background: #f5faff;
}

.portal-table .ui-planilla-footer {
  font-family: var(--font-mono, "IBM Plex Mono", monospace);
  font-size: 0.72rem;
}

.table-action {
  min-width: 104px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1;
}

.status-badge--success {
  color: #006c30;
  background: #ecf8f0;
}

.status-badge--warning {
  color: #7a4500;
  background: #fff6e8;
}

.status-badge--danger {
  color: #8c2525;
  background: #fff0f0;
}

.status-badge--neutral {
  color: #405c75;
  background: #edf3f7;
}

/* Estados */

.portal-state {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  min-height: 110px;
  padding: 22px;
  border: 1px solid #c9dce9;
  border-left: 4px solid var(--portal-blue);
  background: #f7fbfe;
}

.portal-state__mark {
  width: 15px;
  height: 15px;
  margin-top: 4px;
  border: 2px solid #a8c7db;
  border-top-color: var(--portal-blue);
  border-radius: 50%;
  animation: portal-spin 0.8s linear infinite;
}

.portal-state strong {
  color: var(--portal-navy);
}

.portal-state p {
  margin: 3px 0 0;
  color: var(--color-text-muted);
}

.portal-state--error {
  border-left-color: var(--portal-red);
  background: #fff8f8;
}

.portal-state--error .portal-state__mark {
  border-color: var(--portal-red);
  border-radius: 2px;
  animation: none;
}

@keyframes portal-spin {
  to { transform: rotate(360deg); }
}

/* Modal clínico */

.ui-modal-backdrop {
  padding: clamp(12px, 3vw, 32px);
  background: rgba(0, 32, 61, 0.72);
  backdrop-filter: blur(3px);
}

.ui-modal {
  width: min(880px, 100%);
  max-height: min(88vh, 920px);
  border: 1px solid #aac5d9;
  border-radius: 2px;
  box-shadow: 0 28px 80px rgba(0, 23, 46, 0.35);
}

.ui-modal-header {
  border-bottom: 3px solid var(--portal-blue);
  background: #f5f9fc;
}

.ui-modal-header h3 {
  color: var(--portal-navy);
  font-family: var(--font-institucional, "Ibarra Real Nova", serif);
  font-size: 1.35rem;
}

.ui-modal-close {
  color: var(--portal-blue);
}

.ui-modal-body {
  padding: clamp(18px, 3vw, 30px);
}

.clinical-readonly-note {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  padding: 12px 14px;
  border-left: 4px solid var(--portal-green);
  background: #eef8f2;
}

.clinical-readonly-note strong {
  color: #005a29;
}

.clinical-readonly-note span {
  color: #395849;
  font-size: 0.88rem;
  text-align: right;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 20px;
}

.detail-grid--summary {
  padding: 16px 18px;
  border: 1px solid #c9dce9;
  background: #f7fbfe;
}

.detail-field {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.detail-field > span {
  color: var(--color-text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.035em;
  text-transform: uppercase;
}

.detail-field > strong {
  color: var(--portal-ink);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.clinical-section {
  margin-top: 24px;
}

.clinical-section h4 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 10px;
  padding-bottom: 7px;
  border-bottom: 1px solid #c9dce9;
  color: var(--portal-navy);
  font-family: var(--font-institucional, "Ibarra Real Nova", serif);
  font-size: 1.08rem;
}

.clinical-section h4 span {
  min-width: 26px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #eaf3f8;
  font-family: var(--font-mono, "IBM Plex Mono", monospace);
  font-size: 0.7rem;
  text-align: center;
}

.clinical-list {
  display: grid;
  gap: 8px;
}

.clinical-entry {
  display: grid;
  gap: 7px;
  padding: 11px 14px;
  border-left: 3px solid #8eb9d4;
  background: #f7fbfe;
}

.clinical-entry--image {
  border-left-color: var(--portal-blue);
}

.clinical-entry__meta {
  color: var(--color-text-muted);
  font-size: 0.86rem;
}

.clinical-link {
  color: var(--portal-blue);
  font-weight: 700;
  text-underline-offset: 3px;
}

.clinical-report {
  margin-top: 4px;
}

.clinical-report summary {
  color: var(--portal-blue);
  cursor: pointer;
  font-weight: 700;
}

.clinical-report > div {
  margin-top: 8px;
  white-space: pre-wrap;
}

.clinical-empty {
  margin: 0;
  padding: 12px 14px;
  border-left: 3px solid #c9dce9;
  background: #f7f9fb;
  color: var(--color-text-muted);
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    width: auto;
    height: auto;
    padding: 14px 18px;
    gap: 12px;
    max-width: 100vw;
  }

  .brand-block {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    column-gap: 14px;
    padding: 0 0 12px;
  }

  .brand-block img {
    grid-row: 1 / 3;
    width: 144px;
    height: 44px;
    margin: 0;
  }

  .nav-list {
    flex-direction: row;
    width: 100%;
    overflow-x: auto;
    scrollbar-width: thin;
  }

  .nav-item {
    flex: 0 0 auto;
  }

  .sidebar-footer {
    display: none;
  }

  .main {
    padding-top: 24px;
  }
}

@media (max-width: 680px) {
  .login-shell {
    align-items: stretch;
    padding: 0;
    background: var(--portal-navy);
  }

  .login-card {
    align-self: end;
    width: 100%;
    min-height: 78vh;
    justify-content: center;
    padding: 34px 24px;
    border-width: 5px 0 0;
  }

  .brand-block {
    grid-template-columns: 1fr;
  }

  .brand-block img {
    grid-row: auto;
  }

  .brand-block span,
  .brand-block strong {
    display: none;
  }

  .nav-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    overflow: visible;
  }

  .nav-item {
    min-width: 0;
    min-height: 54px;
    padding: 8px 6px;
    font-size: 0.8rem;
    line-height: 1.12;
    text-align: center;
  }

  .nav-item::before {
    inset: auto 10px 0;
    width: auto;
    height: 3px;
  }

  .main {
    padding: 20px 14px 48px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .user-chip {
    display: none;
  }

  .account-intro,
  .portal-section__heading,
  .clinical-readonly-note {
    align-items: flex-start;
    flex-direction: column;
  }

  .account-intro p,
  .portal-section__heading p,
  .clinical-readonly-note span {
    text-align: left;
  }

  .account-ledger {
    grid-template-columns: 1fr;
  }

  .account-ledger__item {
    min-height: 105px;
    border-right: 0;
    border-bottom: 1px solid #c9dce9;
  }

  .account-ledger__item:last-child {
    border-bottom: 0;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .portal-table .ui-planilla-scroll {
    overflow-x: auto;
  }

  .portal-table .ui-planilla-table {
    min-width: 620px;
  }

  .portal-table--patients .ui-planilla-table {
    min-width: 520px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
