/* ============================================================
   MonTech · Base + estructura de la aplicación
   ============================================================ */

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

html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-14);
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

h1, h2, h3, h4, h5 { margin: 0; font-weight: 700; letter-spacing: -0.01em; line-height: 1.25; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--text-brand); text-decoration: none; }
table { border-collapse: collapse; width: 100%; }
svg { display: block; }
ul, ol { margin: 0; padding: 0; list-style: none; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

::selection { background: var(--brand-soft); color: var(--brand-ink); }

/* Barras de desplazamiento discretas */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--r-full); border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-muted); background-clip: content-box; }

/* ============================================================
   Pantalla de acceso
   ============================================================ */
.login {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: var(--s-3);
  padding: var(--s-3);
  background: var(--bg-app);
  animation: fadeIn 400ms ease both;
}
.login.is-out { animation: fadeOut 420ms ease both; pointer-events: none; }

.login__art {
  position: relative;
  overflow: hidden;
  border-radius: var(--r-xl);
  background:
    radial-gradient(120% 90% at 100% 0%, rgba(26, 135, 136, 0.55) 0%, rgba(26, 135, 136, 0) 60%),
    linear-gradient(160deg, #00404c 0%, #00343e 100%);
  color: #fff;
  padding: var(--s-9) var(--s-8) var(--s-7);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
/* trama de puntos, como un plano quirúrgico */
.login__grid {
  position: absolute; inset: 0; pointer-events: none;
  background-image: radial-gradient(rgba(255, 255, 255, 0.12) 1px, transparent 1.2px);
  background-size: 18px 18px;
  -webkit-mask-image: linear-gradient(200deg, #000 0%, transparent 55%);
  mask-image: linear-gradient(200deg, #000 0%, transparent 55%);
}
.login__iso {
  position: absolute; right: -110px; bottom: -100px;
  width: 460px; opacity: 0.08;
}
.login__artInner { position: relative; z-index: 2; max-width: 480px; }
.login__eyebrow {
  display: inline-flex; align-items: center; gap: var(--s-2);
  font-size: var(--fs-12); font-weight: 600; letter-spacing: 0.04em;
  color: #cfeeee; margin: 0 0 var(--s-6);
  padding: 5px 12px 5px 10px; border-radius: var(--r-full);
  background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.14);
}
.login__eyebrow::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: #5fd0cf;
}
.login__title { font-size: 44px; line-height: 1.08; letter-spacing: -0.03em; font-weight: 700; text-wrap: balance; }
.login__title span { color: #7fd6d5; }
.login__sub {
  margin-top: var(--s-5); font-size: var(--fs-16); line-height: 1.6;
  color: rgba(255, 255, 255, 0.72); max-width: 440px;
}
.login__stats { position: relative; z-index: 2; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-3); }
.login__stat {
  padding: var(--s-4); border-radius: var(--r-lg);
  background: rgba(255, 255, 255, 0.07); border: 1px solid rgba(255, 255, 255, 0.12);
}
.login__stat b { display: block; font-size: var(--fs-16); color: #fff; font-weight: 700; letter-spacing: -0.01em; }
.login__stat span { display: block; margin-top: 2px; font-size: var(--fs-12); color: rgba(255, 255, 255, 0.6); line-height: 1.4; }

.login__panel {
  display: flex; flex-direction: column; align-items: center;
  padding: var(--s-8); overflow-y: auto;
  background: var(--bg-surface); border-radius: var(--r-xl); border: 1px solid var(--border);
}
/* centrado si cabe; si no (pantalla baja, segundo paso con QR), se desplaza */
.login__form { width: 100%; max-width: 372px; margin-block: auto; }
.login__logo { width: 190px; margin-bottom: var(--s-7); }
.login__welcome { font-size: var(--fs-24); letter-spacing: -0.02em; }
.login__hint { color: var(--text-muted); margin-top: var(--s-2); margin-bottom: var(--s-5); font-size: var(--fs-14); }
.login__foot { margin-top: var(--s-7); font-size: var(--fs-12); color: var(--text-muted); text-align: center; }

/* ============================================================
   Estructura principal
   ============================================================ */
.app { display: none; height: 100vh; height: 100dvh; grid-template-columns: var(--nav-w) minmax(0, 1fr); }
.nav-backdrop { display: none; }
.app.is-ready { display: grid; }
.app.is-collapsed { grid-template-columns: var(--nav-w-collapsed) minmax(0, 1fr); }

/* ---- Barra lateral ---- */
.nav {
  background: var(--bg-nav);
  color: var(--text-nav);
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border-nav);
  overflow: hidden;
  min-width: 0;
}
.nav__brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 var(--s-3) 0 var(--s-5); height: var(--topbar-h); flex: 0 0 auto;
}
.nav__iso { width: 30px; height: 30px; flex: 0 0 auto; border-radius: 8px; }
.nav__word { flex: 1 1 auto; min-width: 0; font-size: var(--fs-18); font-weight: 700; color: var(--text-primary); letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav__toggle {
  flex: 0 0 auto; width: 32px; height: 32px; display: grid; place-items: center; padding: 0;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--text-muted);
  transition: background var(--t-fast), color var(--t-fast);
}
.nav__toggle:hover { background: var(--bg-nav-hover); color: var(--text-primary); }
.nav__toggle svg { width: 18px; height: 18px; }

.nav__scroll { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; padding: var(--s-2) var(--s-3) var(--s-3); }
.nav__sep { height: 1px; background: var(--border-nav); margin: var(--s-3) var(--s-2); }
.nav__item {
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 40px; padding: 8px 12px; border-radius: var(--r); margin-bottom: 2px;
  color: var(--text-nav); font-size: var(--fs-14); font-weight: 500;
  border: none; background: none; width: 100%; text-align: left;
  position: relative; transition: background var(--t-fast), color var(--t-fast);
}
.nav__item svg { width: 18px; height: 18px; flex: 0 0 auto; color: var(--text-muted); transition: color var(--t-fast); }
.nav__item:hover { background: var(--bg-nav-hover); color: var(--text-primary); }
.nav__item:hover svg { color: var(--text-secondary); }
.nav__item.is-active { background: var(--bg-nav-active); color: var(--text-nav-active); font-weight: 600; }
.nav__item.is-active svg { color: var(--brand); }
.nav__item.is-active::before {
  content: ""; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 22px; border-radius: 0 3px 3px 0; background: var(--brand);
}
.nav__label { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav__badge {
  min-width: 22px; height: 20px; padding: 0 7px; border-radius: var(--r-full);
  background: var(--danger-soft); color: var(--danger-ink); font-size: var(--fs-11); font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums;
}
.nav__badge--warn { background: var(--warn-soft); color: var(--warn-ink); }

.nav__bottom { flex: 0 0 auto; padding: 0 var(--s-3); }
.nav__bottom:empty { display: none; }
.nav__bottom .nav__item.is-active::before { left: -12px; }

/* Tarjeta al pie: modo presentación */
.nav__card {
  position: relative; overflow: hidden; flex: 0 0 auto;
  margin: var(--s-3); padding: var(--s-4);
  border-radius: var(--r-lg); color: #fff;
  background:
    radial-gradient(110% 80% at 100% 0%, rgba(95, 208, 207, 0.35) 0%, rgba(95, 208, 207, 0) 60%),
    linear-gradient(160deg, #0c5a63 0%, #00404c 100%);
}
.nav__card::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: radial-gradient(rgba(255, 255, 255, 0.14) 1px, transparent 1.2px);
  background-size: 12px 12px;
  -webkit-mask-image: linear-gradient(215deg, #000 0%, transparent 50%);
  mask-image: linear-gradient(215deg, #000 0%, transparent 50%);
}
.nav__card-ico {
  position: relative; z-index: 1;
  width: 32px; height: 32px; display: grid; place-items: center; padding: 0;
  border: 0; border-radius: 9px; background: rgba(255, 255, 255, 0.92); color: #00404c;
}
.nav__card-ico svg { width: 15px; height: 15px; }
.nav__card b { position: relative; z-index: 1; display: block; margin-top: var(--s-3); font-size: var(--fs-14); font-weight: 700; }
.nav__card p { position: relative; z-index: 1; margin-top: 2px; font-size: var(--fs-12); line-height: 1.45; color: rgba(255, 255, 255, 0.7); }
.nav__card-btn {
  position: relative; z-index: 1; display: block; width: 100%; margin-top: var(--s-3);
  height: 34px; border: 0; border-radius: var(--r-full);
  background: #fff; color: #00404c; font-size: var(--fs-12); font-weight: 700;
  transition: background var(--t-fast);
}
.nav__card-btn:hover { background: #e3f4f4; }

/* Menú contraído (riel de íconos) */
.app.is-collapsed .nav__word, .app.is-collapsed .nav__label,
.app.is-collapsed .nav__badge, .app.is-collapsed .nav__card { display: none; }
.app.is-collapsed .nav__brand { padding: 0; justify-content: center; }
.app.is-collapsed .nav__toggle { display: none; }
.app.is-collapsed .nav__brand:hover .nav__iso { display: none; }
.app.is-collapsed .nav__brand:hover .nav__toggle { display: grid; }
.app.is-collapsed .nav__item { justify-content: center; padding-inline: 0; }
.app.is-collapsed .nav__item.is-active::before { left: -12px; }
@media (hover: none) {
  .app.is-collapsed .nav__iso { display: none; }
  .app.is-collapsed .nav__toggle { display: grid; }
}

/* ---- Área principal ---- */
.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; background: var(--bg-app); }

.topbar {
  height: var(--topbar-h); flex: 0 0 auto;
  display: flex; align-items: center; gap: var(--s-3);
  padding: 0 var(--s-7);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}
.topbar .topbar__menu { display: none; }
.topbar__search { flex: 0 1 360px; min-width: 0; position: relative; }
.topbar__search input {
  width: 100%; height: 40px; padding: 0 56px 0 40px;
  border-radius: var(--r-full); border: 1px solid var(--border);
  background: var(--bg-surface); font-size: var(--fs-13);
  transition: border-color var(--t-fast), box-shadow var(--t-fast); outline: none;
  -webkit-appearance: none; appearance: none;
}
.topbar__search input::placeholder { color: var(--text-muted); }
.topbar__search input:hover { border-color: var(--border-strong); }
.topbar__search input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.topbar__search > svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-muted); pointer-events: none; }
.topbar__kbd {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  padding: 2px 7px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg-muted); color: var(--text-muted);
  font: 600 11px/1.5 var(--font); pointer-events: none; white-space: nowrap;
}
.topbar__search input:focus ~ .topbar__kbd { display: none; }
@media (hover: none) { .topbar__kbd { display: none; } .topbar__search input { padding-right: 14px; } }

.topbar__actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.iconbtn {
  width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r); border: 1px solid transparent; background: transparent;
  color: var(--text-secondary); position: relative; transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
  padding: 0; flex: 0 0 auto;
}
.iconbtn:hover { background: var(--bg-inset); color: var(--text-primary); }
.iconbtn svg { width: 19px; height: 19px; }
/* botones redondos con borde fino de la barra superior */
.iconbtn--ring { width: 40px; height: 40px; border-radius: var(--r-full); border-color: var(--border); background: var(--bg-surface); }
.iconbtn--ring:hover { background: var(--bg-muted); border-color: var(--border-strong); }
.iconbtn--ring svg { width: 18px; height: 18px; }
.iconbtn__dot {
  position: absolute; top: -3px; right: -3px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: var(--r-full); background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--bg-surface); font-variant-numeric: tabular-nums;
}

.topbar__user {
  width: 40px; height: 40px; flex: 0 0 auto; padding: 0; position: relative;
  display: grid; place-items: center;
  border-radius: var(--r-full); border: 1px solid var(--border); background: var(--bg-surface);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.topbar__user:hover { border-color: var(--border-strong); box-shadow: 0 0 0 3px var(--bg-inset); }
.topbar__user .avatar { width: 32px; height: 32px; border-radius: var(--r-full); font-size: var(--fs-12); }
/* sin conexión con el servidor: punto gris */
.topbar__user.is-offline::after {
  content: ""; position: absolute; right: 0; bottom: 0; width: 11px; height: 11px;
  border-radius: 50%; background: var(--text-muted); border: 2px solid var(--bg-surface);
}

.view { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; scroll-behavior: smooth; }
.view__inner { max-width: var(--maxw); margin: 0 auto; padding: var(--s-6) var(--s-7) var(--s-9); }
.view--enter { animation: viewIn 260ms cubic-bezier(0.22, 1, 0.36, 1) both; }

/* ---- Encabezado de página ---- */
.page-head { display: flex; align-items: center; gap: var(--s-3) var(--s-4); margin-bottom: var(--s-5); flex-wrap: wrap; }
.page-head__text { flex: 1 1 320px; min-width: 0; }
.page-head h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.025em; text-wrap: balance; }
.page-head p { color: var(--text-muted); font-size: var(--fs-13); margin-top: 3px; }
.page-head__actions { display: flex; gap: var(--s-2); flex-wrap: wrap; align-items: center; }

/* ---- Rejillas ---- */
.grid { display: grid; gap: var(--s-4); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid--2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid--3-2 { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }

@media (max-width: 1400px) {
  .grid--5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1200px) {
  .grid--4, .grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid--2-1, .grid--3-2 { grid-template-columns: minmax(0, 1fr); }
  .topbar, .view__inner { padding-left: var(--s-6); padding-right: var(--s-6); }
}
@media (max-width: 860px) {
  .app, .app.is-collapsed { grid-template-columns: var(--nav-w-collapsed) minmax(0, 1fr); }
  .nav__word, .nav__label, .nav__badge, .nav__toggle, .nav__card { display: none; }
  /* aquí el ☰ de la barra superior manda: el botón de contraer no aplica */
  .app.is-collapsed .nav__toggle, .app.is-collapsed .nav__brand:hover .nav__toggle { display: none; }
  .app.is-collapsed .nav__iso, .app.is-collapsed .nav__brand:hover .nav__iso { display: block; }
  .nav__brand { padding: 0; justify-content: center; }
  .nav__item { justify-content: center; padding-inline: 0; }
  .grid--2, .grid--3, .grid--4, .grid--5 { grid-template-columns: minmax(0, 1fr); }
  .login { grid-template-columns: minmax(0, 1fr); padding: 0; }
  .login__art { display: none; }
  .login__panel { border-radius: 0; border: 0; }
  .view__inner { padding: var(--s-4); }
  .topbar { padding: 0 var(--s-4); }
  .topbar .topbar__menu { display: inline-flex; }
}

/* ---- Tableta y teléfono: el botón ☰ abre el menú completo encima de la pantalla ---- */
@media (max-width: 860px) {
  .app.is-menu .nav { position: fixed; top: 0; bottom: 0; left: 0; z-index: 700; width: min(290px, 86vw); box-shadow: var(--sh-3); }
  .app.is-menu .nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 690;
    background: var(--scrim); animation: fadeIn 160ms ease both;
  }
  /* dentro del menú abierto se ven otra vez los nombres (cerrado queda solo el ícono) */
  .app.is-menu .nav__word, .app.is-menu .nav__label { display: block; }
  .app.is-menu .nav__badge { display: inline-flex; }
  .app.is-menu .nav__card { display: block; }
  .app.is-menu .nav__iso { display: block; }
  .app.is-menu .nav__brand { padding: 0 var(--s-5); justify-content: flex-start; }
  .app.is-menu .nav__item { justify-content: flex-start; padding: 10px 12px; }
}
@media (min-width: 641px) and (max-width: 860px) {
  .app.is-menu .main { grid-column: 2; }   /* el riel de íconos conserva su espacio */
}

/* ---- Teléfono: sin riel; el menú entra deslizándose desde la izquierda ---- */
@media (max-width: 640px) {
  .app, .app.is-collapsed { grid-template-columns: minmax(0, 1fr); }
  .nav {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 700;
    width: min(290px, 86vw);
    transform: translateX(-100%); visibility: hidden;
    transition: transform 240ms cubic-bezier(0.22, 1, 0.36, 1), visibility 0s linear 240ms;
  }
  .app.is-menu .nav { transform: none; visibility: visible; transition: transform 240ms cubic-bezier(0.22, 1, 0.36, 1); }

  :root { --topbar-h: 60px; }
  .topbar { padding: 0 var(--s-3); gap: var(--s-2); }
  .topbar__search { flex: 1 1 auto; }
  .topbar__search input { height: 38px; padding-right: 12px; padding-left: 36px; }
  .topbar__search > svg { left: 12px; }
  .topbar__kbd { display: none; }
  .topbar__actions { gap: 6px; }
  /* el tema pasa al menú de la cuenta, para que el buscador tenga espacio */
  .topbar #btnTema { display: none; }
  .iconbtn--ring, .topbar__user { width: 36px; height: 36px; }
  .topbar__user .avatar { width: 28px; height: 28px; font-size: var(--fs-11); }

  .page-head { margin-bottom: var(--s-4); }
  .page-head h1 { font-size: var(--fs-20); }
  .view__inner { padding: var(--s-4) var(--s-4) var(--s-8); }
}

/* ---- Utilidades ---- */
.u-row { display: flex; align-items: center; gap: var(--s-3); }
.u-row--between { justify-content: space-between; }
.u-row--wrap { flex-wrap: wrap; }
.u-col { display: flex; flex-direction: column; gap: var(--s-3); }
.u-grow { flex: 1 1 auto; min-width: 0; }
.u-right { margin-left: auto; }
.u-mt-2 { margin-top: var(--s-2); } .u-mt-3 { margin-top: var(--s-3); }
.u-mt-4 { margin-top: var(--s-4); } .u-mt-5 { margin-top: var(--s-5); } .u-mt-6 { margin-top: var(--s-6); }
.u-mb-2 { margin-bottom: var(--s-2); } .u-mb-3 { margin-bottom: var(--s-3); }
.u-mb-4 { margin-bottom: var(--s-4); } .u-mb-5 { margin-bottom: var(--s-5); } .u-mb-6 { margin-bottom: var(--s-6); }
.u-muted { color: var(--text-muted); }
.u-secondary { color: var(--text-secondary); }
.u-strong { font-weight: 700; }
.u-mono { font-family: var(--font-mono); font-size: 0.92em; letter-spacing: -0.02em; }
.u-nowrap { white-space: nowrap; }
.u-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.u-center { text-align: center; }
.u-tright { text-align: right; }
.u-11 { font-size: var(--fs-11); } .u-12 { font-size: var(--fs-12); } .u-13 { font-size: var(--fs-13); }
.u-16 { font-size: var(--fs-16); } .u-18 { font-size: var(--fs-18); } .u-20 { font-size: var(--fs-20); }
.u-24 { font-size: var(--fs-24); } .u-30 { font-size: var(--fs-30); }
.u-hide { display: none !important; }
.u-danger { color: var(--danger); } .u-warn { color: var(--warn); } .u-ok { color: var(--ok); }
.u-brand { color: var(--text-brand); }
.u-cap { text-transform: uppercase; letter-spacing: 0.06em; font-size: var(--fs-11); font-weight: 700; }

/* ---- Animaciones ---- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; visibility: hidden; } }
@keyframes viewIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes floaty { 0%, 100% { transform: translateY(0) rotate(0deg); } 50% { transform: translateY(-22px) rotate(4deg); } }
@keyframes slideInRight { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes popIn { from { opacity: 0; transform: translateY(10px) scale(0.985); } to { opacity: 1; transform: none; } }

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