/* PM Portal de accesos.
   Base de estilo de Connect (superficies frías con tinte lavanda, tarjetas
   suaves, botón marino) con paleta propia: marino #1C2B5A y acento índigo
   pervinca #5B6BE8. Tono claro fijo, ni blanco puro ni crema. Ancho completo.
   Tipografía: Instrument Sans (OFL), servida en local. */
@font-face {
  font-family: "Instrument Sans";
  src: url("/fonts/instrument-sans.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
:root {
  color-scheme: light;
  --bg: #eef1f7;
  --panel: #f7f9fc;
  --raised: #fbfcfe;
  --sunken: #f1f4f9;
  --ink: #1a2340;
  --ink-2: #414b68;
  --muted: #6b7591;
  --line: #dde3ee;
  --line-soft: #e8ecf4;
  --navy: #1c2b5a;
  --navy-2: #2a3c75;
  --accent: #5b6be8;
  --accent-ink: #ffffff;
  --accent-soft: #e9ecfc;
  --ok: #1f8a65;
  --wait: #b07a1a;
  --fail: #c2462b;
  --r-lg: 16px;
  --r: 10px;
  --shadow: 0 1px 2px rgb(28 43 90 / 5%), 0 8px 24px rgb(28 43 90 / 6%);
  --font: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); font-feature-settings: "tnum" 1; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; line-height: 1.2; }
p, dl, dd { margin: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.defs { position: absolute; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Recuadro de marca (como el de Connect, con la sigla PM) */
.tile { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(160deg, var(--navy-2), var(--navy)); color: #fff; font: 700 15px/1 var(--font); letter-spacing: -0.02em; box-shadow: 0 6px 16px rgb(28 43 90 / 22%); flex: none; }
.tile-lg { width: 64px; height: 64px; border-radius: 16px; font-size: 21px; }

/* Controles */
button { font: 600 14px var(--font); border-radius: var(--r); padding: 10px 18px; cursor: pointer; border: 1px solid transparent; }
button.primary { background: var(--navy); color: var(--accent-ink); }
button.primary:hover { background: var(--navy-2); }
button.secondary { background: var(--raised); color: var(--navy); border-color: var(--line); }
button.secondary:hover { background: var(--accent-soft); border-color: var(--accent); }
button.ghost { background: transparent; color: var(--ink-2); padding: 6px 8px; font-weight: 500; }
button.ghost:hover { color: var(--accent); }
button.wide { width: 100%; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 16px; }
input { display: block; width: 100%; margin-top: 6px; padding: 11px 13px; font: 15px var(--font); color: var(--ink); background: var(--raised); border: 1px solid var(--line); border-radius: var(--r); }
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input:disabled { background: var(--sunken); color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); margin: -6px 0 16px; }
.flash { font-size: 14px; padding: 10px 14px; border-radius: var(--r); background: var(--accent-soft); border: 1px solid var(--line); margin-bottom: 16px; }
.flash.ok { background: color-mix(in srgb, var(--ok) 9%, var(--raised)); color: var(--ok); }
.flash.warn { background: color-mix(in srgb, var(--wait) 10%, var(--raised)); color: var(--wait); }
.flash.error { background: color-mix(in srgb, var(--fail) 9%, var(--raised)); color: var(--fail); }

/* Pantallas de acceso: lámina de marca a la izquierda, formulario a la derecha */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(300px, 40%) 1fr; gap: 16px; padding: 16px; }
.auth-brand { background: radial-gradient(rgb(255 255 255 / 7%) 1px, transparent 1.4px) 0 0 / 22px 22px, linear-gradient(165deg, var(--navy-2), var(--navy) 70%); color: #fff; border-radius: var(--r-lg); padding: 40px clamp(24px, 4vw, 56px); display: flex; flex-direction: column; justify-content: space-between; gap: 32px; box-shadow: var(--shadow); }
.auth-brand .tile { background: rgb(255 255 255 / 12%); box-shadow: inset 0 0 0 1px rgb(255 255 255 / 18%); }
.auth-brand h1 { font-size: clamp(28px, 3vw, 40px); font-weight: 650; letter-spacing: -0.02em; color: #fff; }
.auth-brand p { margin-top: 8px; color: #c7cff0; font-size: 16px; }
.auth-main { display: flex; align-items: center; justify-content: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 48px clamp(24px, 5vw, 96px); box-shadow: var(--shadow); }
.auth-form { width: 100%; max-width: 420px; }
.auth-form h2 { font-size: 24px; margin-bottom: 22px; }
.totp { display: grid; grid-template-columns: auto 1fr; gap: 20px; align-items: start; margin-bottom: 20px; padding: 14px; background: var(--sunken); border: 1px solid var(--line-soft); border-radius: var(--r); }
#qr { background: #fff; padding: 6px; border: 1px solid var(--line); border-radius: 8px; }
.totp-info dt { font-size: 12px; color: var(--muted); }
.totp-info dd { margin-bottom: 12px; font-size: 14px; }
.key { font-family: var(--mono); font-size: 13px; word-break: break-all; }
.codes { list-style: none; padding: 0; margin: 0 0 24px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; font: 15px var(--mono); }
.codes li { background: var(--sunken); border: 1px solid var(--line-soft); border-radius: var(--r); padding: 9px; text-align: center; }
@media (max-width: 760px) {
  .auth { grid-template-columns: 1fr; min-height: 0; padding: 12px; gap: 12px; }
  .auth-brand { flex-direction: row; align-items: center; justify-content: flex-start; padding: 18px; }
  .auth-brand h1 { font-size: 22px; }
  .auth-brand p { font-size: 14px; margin-top: 2px; }
  .auth-main { padding: 28px 18px; }
  .totp { grid-template-columns: 1fr; justify-items: start; }
}

/* Aplicación a ancho completo: barra lateral y área de trabajo como láminas */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); gap: 16px; padding: 16px; min-height: 100vh; }
.side { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 18px 14px; display: flex; flex-direction: column; gap: 24px; position: sticky; top: 16px; height: calc(100vh - 32px); }
.side-brand { display: flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; padding: 2px 4px; }
.side-name { display: flex; flex-direction: column; line-height: 1.25; font-size: 14px; }
.side-name span { color: var(--muted); font-size: 12.5px; }
.side-nav { display: grid; gap: 2px; }
.side-nav a { color: var(--ink-2); text-decoration: none; padding: 9px 12px; border-radius: var(--r); font-weight: 500; }
.side-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--navy); font-weight: 600; }
.side-status { display: grid; gap: 2px; font-size: 13px; padding: 12px; background: var(--sunken); border: 1px solid var(--line-soft); border-radius: var(--r); }
.side-status dt { color: var(--muted); }
.side-status dt + dd { margin-bottom: 8px; }
.side-status dd:last-child { margin-bottom: 0; }
.side-status dd { display: flex; align-items: center; gap: 7px; color: var(--ink); font-weight: 500; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.conectada { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent); }
.dot.sin_respuesta { background: var(--fail); box-shadow: 0 0 0 3px color-mix(in srgb, var(--fail) 18%, transparent); }
.dot.sin_configurar { background: var(--wait); box-shadow: 0 0 0 3px color-mix(in srgb, var(--wait) 18%, transparent); }
.side-user { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; border-top: 1px solid var(--line-soft); padding: 14px 4px 0; font-size: 14px; }
.side-user span { display: block; color: var(--muted); font-size: 12.5px; }
.side-user .ghost { padding: 6px 8px; }

.content { min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.content-head { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 14px 18px; }
.content-head h1 { font-size: 22px; color: var(--navy); }
.search { flex: 1; display: flex; gap: 10px; min-width: 260px; }
.search input { margin: 0; background: var(--sunken); }
.content > .flash { margin: 0; }

.workspace { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.workspace.with-detail { grid-template-columns: minmax(0, 1fr) minmax(360px, 440px); }
.list { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); min-height: calc(100vh - 128px); overflow: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12.5px; padding: 13px 16px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover td { background: var(--raised); }
.table tbody tr[aria-selected="true"] td { background: var(--accent-soft); }
.table tbody tr[aria-selected="true"] td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.table tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.table .id { font: 12.5px var(--mono); color: var(--ink-2); }
.table .pend { color: var(--wait); font-weight: 600; }
.empty { padding: 72px 16px; text-align: center; color: var(--muted); }
.empty.warn { color: var(--wait); }
.empty.warn::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--wait); margin-right: 8px; vertical-align: 1px; }
.count { padding: 10px 16px; font-size: 12.5px; color: var(--muted); }
.count:empty { display: none; }

.ficha { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow: auto; }
.ficha-head { display: flex; justify-content: space-between; gap: 12px; padding: 20px 20px 16px; }
.ficha-head h2 { font-size: 20px; color: var(--navy); overflow-wrap: anywhere; }
.ficha-head p { color: var(--ink-2); margin-top: 3px; overflow-wrap: anywhere; }
.facts { display: grid; grid-template-columns: 108px minmax(0, 1fr); gap: 9px 12px; margin: 0 14px; padding: 14px; font-size: 14px; background: var(--sunken); border: 1px solid var(--line-soft); border-radius: var(--r); }
.facts dt { color: var(--muted); }
.facts dd { overflow-wrap: anywhere; }
.facts .id { font: 13px var(--mono); }
.chip { font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--raised); border: 1px solid var(--line); }
.chip.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 8%, var(--raised)); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.chip.wait { color: var(--wait); background: color-mix(in srgb, var(--wait) 9%, var(--raised)); border-color: color-mix(in srgb, var(--wait) 35%, transparent); }
.block { margin: 14px; padding: 16px; background: var(--raised); border: 1px solid var(--line-soft); border-radius: var(--r); }
.block h3 { font-size: 15px; margin-bottom: 6px; color: var(--navy); }
.block .hint { margin: 0 0 14px; }
.fields label:last-child { margin-bottom: 16px; }

@media (max-width: 1100px) {
  .workspace.with-detail { grid-template-columns: minmax(0, 1fr); }
  .ficha { position: static; max-height: none; }
  .list { min-height: 0; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; padding: 10px; gap: 10px; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px; }
  .side-nav { display: none; }
  .side-status { flex: 1; grid-template-columns: auto auto; column-gap: 8px; padding: 8px 10px; }
  .side-status dt + dd { margin-bottom: 0; }
  .side-user { margin-top: 0; border-top: 0; padding-top: 0; }
  .search { flex-basis: 100%; }
  .table thead { display: none; }
  .table tr { display: grid; grid-template-columns: 1fr 1fr; padding: 8px 4px; border-bottom: 1px solid var(--line-soft); }
  .table td { border: 0; padding: 2px 12px; }
}

dialog { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--panel); box-shadow: var(--shadow); color: var(--ink); padding: 20px; max-width: 460px; width: calc(100% - 32px); }
dialog::backdrop { background: rgb(28 43 90 / 35%); backdrop-filter: blur(2px); }
dialog p { margin-bottom: 18px; }
.row { display: flex; gap: 8px; justify-content: flex-end; }
