/*
  Estilos del panel. Escritos a mano y servidos desde el propio dominio, sin CDN.

  Antes el panel cargaba Tailwind y Select2 desde CDNs, lo que obligaba a permitir
  'unsafe-eval' y tres origenes externos en la Content-Security-Policy: quien controlara uno
  de esos CDNs podia ejecutar codigo en la pagina donde se administran las credenciales.
  Vendorizar los estilos es lo que permite cerrar esa puerta.
*/

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --ok: #059669;
  --ok-bg: #ecfdf5;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --sidebar: #0f172a;
  --sidebar-muted: #94a3b8;
  --radius: 8px;
  --shadow: 0 1px 3px rgb(15 23 42 / 8%), 0 1px 2px rgb(15 23 42 / 4%);
  --shadow-lg: 0 10px 30px rgb(15 23 42 / 18%);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

h1 { font-size: 1.5rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
p  { margin: 0 0 .75rem; }
a  { color: var(--accent); }

/* ---------- Estructura ---------- */

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--sidebar);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid rgb(255 255 255 / 8%);
}

.brand__mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: .75rem;
}

.brand__text { font-weight: 600; letter-spacing: -.01em; }

.content { flex: 1; min-width: 0; padding: 1.75rem 2rem 3rem; }

/* ---------- Navegacion ---------- */

.nav { flex: 1; overflow-y: auto; padding: .75rem 0; }

.nav__section {
  padding: 1rem 1.25rem .35rem;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--sidebar-muted);
  font-weight: 600;
}

.nav__link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .5rem 1.25rem;
  color: #cbd5e1;
  text-decoration: none;
  font-size: .875rem;
  border-left: 3px solid transparent;
}

.nav__link:hover { background: rgb(255 255 255 / 6%); color: #fff; }

.nav__link.active {
  background: rgb(37 99 235 / 18%);
  border-left-color: var(--accent);
  color: #fff;
  font-weight: 500;
}

.nav__icon { width: 1.1rem; text-align: center; opacity: .85; }

.sidebar__foot {
  padding: .9rem 1.25rem;
  border-top: 1px solid rgb(255 255 255 / 8%);
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.who { display: flex; flex-direction: column; gap: .3rem; }
.who__name { font-size: .85rem; font-weight: 600; color: #fff; }

/* ---------- Cabecera de pagina ---------- */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.page-head__sub { color: var(--muted); margin: 0; max-width: 70ch; }

/* ---------- Tarjetas y paneles ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.panel--message { max-width: 34rem; margin: 3rem auto; text-align: center; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

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

.card__label {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  font-weight: 600;
}

.card__value { font-size: 1.75rem; font-weight: 700; letter-spacing: -.02em; }
.card__hint { font-size: .78rem; color: var(--muted); }

/* ---------- Tablas ---------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

table { width: 100%; border-collapse: collapse; font-size: .875rem; }

thead th {
  text-align: left;
  padding: .6rem .85rem;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

tbody td { padding: .6rem .85rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

/* Cabecera ordenable. El boton se despoja de su apariencia propia y hereda la del th,
   para que poder ordenar no cambie el aspecto de la cabecera. */
.th-sort {
  all: unset;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
}

.th-sort:hover { color: var(--accent); }
.th-sort:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* ---------- Paginador ---------- */

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .4rem;
  margin-top: .75rem;
  flex-wrap: wrap;
}

.pager__estado { font-size: .8rem; color: var(--muted); margin: 0 .5rem; }

.row--inactive { opacity: .55; }
.cell--actions { white-space: nowrap; text-align: right; }
.cell--num { text-align: right; font-variant-numeric: tabular-nums; }

.mono {
  font-family: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace;
  font-size: .82rem;
}

.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }

/* ---------- Botones ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .45rem .85rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: .84rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { background: var(--accent-dark); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--sm { padding: .3rem .6rem; font-size: .78rem; }

.btn--ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn--ghost:hover { background: #f1f5f9; }

.sidebar .btn--ghost { border-color: rgb(255 255 255 / 18%); color: #cbd5e1; }
.sidebar .btn--ghost:hover { background: rgb(255 255 255 / 8%); color: #fff; }

.btn--danger { background: var(--danger); }
.btn--danger:hover { background: #b91c1c; }

.btn--link {
  background: none;
  border: none;
  color: var(--accent);
  padding: .2rem .35rem;
  cursor: pointer;
  font-size: .82rem;
  font-family: inherit;
}

.btn--link:hover { text-decoration: underline; background: none; }
.btn--link.danger { color: var(--danger); }

.toolbar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar__spacer { flex: 1; }

/* ---------- Formularios ---------- */

.field { margin-bottom: .9rem; }

.field label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: .3rem; }
.field__hint { font-size: .75rem; color: var(--muted); margin-top: .25rem; }

/*
  Se selecciona por elemento y no por [type=...] a proposito.

  InputText y los demas componentes de formulario de Blazor NO renderizan un atributo type si
  no se les pasa uno: <InputText @bind-Value="x" /> sale como <input> a secas. Con una lista
  de selectores por tipo, ese campo no encaja en ninguno y se queda con el ancho por defecto
  del navegador, mientras que el de al lado —al que si se le paso type="password"— ocupa el
  100%. Los dos se ven de tamaños distintos sin que nada en el marcado lo explique.
*/
input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%;
  padding: .45rem .6rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: .875rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid rgb(37 99 235 / 35%);
  outline-offset: -1px;
  border-color: var(--accent);
}

input:disabled, select:disabled { background: #f1f5f9; color: var(--muted); }

.field--check { display: flex; align-items: center; gap: .5rem; }
.field--check input { width: auto; }
.field--check label { margin: 0; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }

.filters { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1rem; }
.filters .field { margin-bottom: 0; min-width: 170px; }

.validation-message { color: var(--danger); font-size: .78rem; display: block; margin-top: .25rem; }

/* ---------- Distintivos ---------- */

.badge {
  display: inline-block;
  padding: .12rem .5rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  background: #e2e8f0;
  color: #334155;
  white-space: nowrap;
}

.badge--ok     { background: var(--ok-bg);     color: var(--ok); }
.badge--warn   { background: var(--warn-bg);   color: var(--warn); }
.badge--danger { background: var(--danger-bg); color: var(--danger); }
.badge--admin  { background: rgb(37 99 235 / 22%); color: #bfdbfe; }

/* ---------- Avisos ---------- */

.alert {
  padding: .7rem .9rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  border: 1px solid transparent;
  font-size: .875rem;
}

.alert--ok    { background: var(--ok-bg);     border-color: #a7f3d0; color: #065f46; }
.alert--error { background: var(--danger-bg); border-color: #fecaca; color: #991b1b; }
.alert--warn  { background: var(--warn-bg);   border-color: #fde68a; color: #92400e; }

.alert__title { font-weight: 700; display: block; margin-bottom: .2rem; }

/* Bloque para mostrar un secreto una sola vez. */
.secret {
  background: #0f172a;
  color: #86efac;
  padding: .75rem .9rem;
  border-radius: 6px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: .82rem;
  word-break: break-all;
  user-select: all;
  margin: .5rem 0;
}

/* ---------- Dialogo ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(15 23 42 / 55%);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 3rem 1rem;
  z-index: 50;
  overflow-y: auto;
}

.modal {
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
}

.modal--wide { max-width: 780px; }

.modal__head {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.modal__title { font-size: 1rem; font-weight: 600; margin: 0; }
.modal__body { padding: 1.25rem; }

.modal__foot {
  padding: .9rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  background: #f8fafc;
  border-radius: 0 0 10px 10px;
}

.modal__close {
  background: none;
  border: none;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0 .25rem;
}

/* ---------- Ingreso ---------- */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: var(--sidebar);
}

.login__card {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}

.login__brand { display: flex; align-items: center; gap: .6rem; margin-bottom: 1.5rem; }

/* ---------- Subida de archivos ---------- */

.drop {
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius);
  padding: 1.75rem 1rem;
  text-align: center;
  color: var(--muted);
  background: #f8fafc;
}

.drop input { margin-top: .6rem; }

/* ---------- Aviso de desconexion de Blazor ---------- */

#blazor-error-ui {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: #fef3c7;
  border-top: 1px solid #fcd34d;
  color: #92400e;
  padding: .7rem 1.25rem;
  box-shadow: 0 -2px 10px rgb(15 23 42 / 12%);
}

#blazor-error-ui .reload { margin-left: .5rem; font-weight: 600; }

.loading { color: var(--muted); padding: 1.5rem; text-align: center; }

/* ---------- Pantallas estrechas ---------- */

@media (max-width: 820px) {
  .app { flex-direction: column; }

  .sidebar { width: 100%; flex: none; height: auto; position: static; }

  .nav { display: flex; flex-wrap: wrap; padding: .5rem; }
  .nav__link { border-left: none; border-bottom: 3px solid transparent; padding: .45rem .7rem; }
  .nav__link.active { border-left: none; border-bottom-color: var(--accent); }
  .nav__section { width: 100%; padding: .5rem .7rem .1rem; }
  .content { padding: 1.25rem 1rem 2.5rem; }
}
