/* ============================================================
   admin.georincon.com — dashboard interno
   Paleta Bosque Vivo (coherente con georincon.com)
   ============================================================ */

:root {
  --forest-900: #0F2419;
  --forest-700: #1F4A37;
  --forest-500: #2D6A4F;
  --forest-300: #52B788;
  --coral-500: #FF7A45;
  --coral-300: #FFA47A;
  --amber-500: #E9B44C;
  --red-500: #C9462C;
  --red-300: #E88E78;
  --cream: #F1ECE2;
  --cream-soft: #F8F4EC;
  --charcoal-900: #1A1F1B;
  --charcoal-700: #3F4642;
  --charcoal-500: #6B736E;
  --charcoal-300: #A8AEA9;
  --white: #FFFFFF;

  --shadow-soft: 0 4px 12px rgba(15, 36, 25, 0.06);
  --shadow-medium: 0 12px 28px rgba(15, 36, 25, 0.10);
  --shadow-strong: 0 24px 48px rgba(15, 36, 25, 0.16);

  --radius-card: 18px;
  --radius-pill: 999px;

  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, system-ui, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  /* Semáforo */
  --traffic-green-bg: rgba(82, 183, 136, 0.14);
  --traffic-green-fg: #1F4A37;
  --traffic-green-bar: #52B788;
  --traffic-amber-bg: rgba(233, 180, 76, 0.18);
  --traffic-amber-fg: #8B6B1E;
  --traffic-amber-bar: #E9B44C;
  --traffic-red-bg: rgba(201, 70, 44, 0.14);
  --traffic-red-fg: #8C3220;
  --traffic-red-bar: #C9462C;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

/* CRÍTICO: forzar que el atributo HTML `hidden` siempre oculte, incluso
 * sobre elementos con `display: flex` u otros (.modal, .email-form, .view).
 * Sin esto, [hidden] no funciona y todos los elementos aparecen visibles
 * al cargar. Bug detectado 2026-06-24 con modal "Cambiar rol" sobre login.
 */
[hidden] { display: none !important; }
body {
  font-family: var(--font-body);
  background: var(--cream);
  color: var(--charcoal-900);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ─── LOGIN ──────────────────────────────────────────── */
.view-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(800px 500px at 30% -10%, rgba(82, 183, 136, 0.18), transparent 60%),
    radial-gradient(600px 400px at 80% 110%, rgba(255, 122, 69, 0.10), transparent 60%);
}
.login-box {
  width: 100%;
  max-width: 380px;
  background: var(--white);
  padding: 36px 28px;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-medium);
  animation: fadeUp 0.4s ease-out;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.brand-mark {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: block;
  object-fit: cover;
  box-shadow: 0 4px 12px rgba(45, 106, 79, 0.25);
  /* Fallback styles si el img falla (ej. div con texto) */
  background: linear-gradient(135deg, var(--forest-500), var(--forest-700));
  color: var(--cream);
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  line-height: 40px;
}
.brand h1 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}
.brand h1 span {
  color: var(--forest-500);
  font-style: italic;
  font-weight: 400;
}
.login-sub {
  color: var(--charcoal-500);
  font-size: 13px;
  margin: 12px 0 24px;
}
.btn {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 12px;
  border: 0;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--forest-500);
  color: var(--cream);
  box-shadow: 0 4px 12px rgba(45, 106, 79, 0.25);
  margin-bottom: 10px;
}
.btn-primary:hover { background: var(--forest-700); box-shadow: var(--shadow-medium); }
.btn-secondary {
  background: var(--cream-soft);
  color: var(--charcoal-700);
  border: 1px solid rgba(15, 36, 25, 0.10);
}
.btn-secondary:hover { background: rgba(15, 36, 25, 0.04); }
.email-form {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.email-form input {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(15, 36, 25, 0.12);
  font-size: 14px;
  font-family: inherit;
  background: var(--cream-soft);
}
.email-form input:focus { outline: 2px solid var(--forest-300); }
.login-error {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--traffic-red-bg);
  color: var(--traffic-red-fg);
  border-radius: 8px;
  font-size: 13px;
}

/* ─── APP ─────────────────────────────────────────────── */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.topbar {
  background: var(--white);
  border-bottom: 1px solid rgba(15, 36, 25, 0.06);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: blur(10px);
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}
.topbar-brand .brand-mark { width: 30px; height: 30px; font-size: 16px; line-height: 30px; border-radius: 8px; }
.topbar-brand em { color: var(--forest-500); font-weight: 400; font-style: italic; font-size: 13px; }
.topnav {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
}
.topnav-btn {
  padding: 8px 14px;
  background: transparent;
  border: 0;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--charcoal-700);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.topnav-btn:hover { background: var(--cream-soft); }
.topnav-btn.is-active {
  background: var(--forest-500);
  color: var(--cream);
}
.topbar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.role-pill {
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--cream-soft);
  color: var(--charcoal-700);
}
.role-pill.is-superadmin {
  background: linear-gradient(135deg, var(--coral-500), var(--coral-300));
  color: var(--white);
}
.role-pill.is-admin {
  background: linear-gradient(135deg, var(--forest-500), var(--forest-300));
  color: var(--white);
}
.icon-btn {
  width: 32px; height: 32px;
  border: 0; background: var(--cream-soft);
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  color: var(--charcoal-700);
}
.icon-btn:hover { background: rgba(15, 36, 25, 0.06); }

/* ─── VISTAS ─────────────────────────────────────────── */
.view {
  padding: 24px 20px 64px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  animation: fadeUp 0.3s ease-out;
}
.view-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.view-header h2 {
  font-family: var(--font-display);
  font-size: clamp(22px, 4.5vw, 28px);
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.015em;
}
.muted { color: var(--charcoal-500); font-size: 13px; margin: 4px 0 0; }
.muted.small { font-size: 11.5px; margin-top: 16px; }
.link-btn {
  background: transparent;
  border: 0;
  color: var(--forest-500);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}
.link-btn:hover { text-decoration: underline; }
.link-btn:disabled { color: var(--charcoal-300); cursor: not-allowed; }

/* ─── METRICS GRID (semáforo) ─────────────────────────── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.metric-card {
  background: var(--white);
  border-radius: var(--radius-card);
  padding: 18px;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(15, 36, 25, 0.04);
  position: relative;
  overflow: hidden;
  animation: fadeUp 0.4s ease-out backwards;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.metric-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-medium); }

/* Icono "ⓘ" pequeño junto al label (señaliza que la card es expandible) */
.metric-info {
  display: inline-block;
  font-size: 11px;
  color: var(--charcoal-300);
  margin-left: 4px;
  transition: color 0.15s ease;
  vertical-align: middle;
  position: relative;
  top: -1px;
}
.metric-card:hover .metric-info { color: var(--forest-500); }

/* Panel expandible descripción — universal (móvil + desktop). El click
 * en la card toggle is-expanded y aparece el panel. En desktop el
 * tooltip-on-hover ::after sigue funcionando para feedback rápido. */
.metric-card { cursor: pointer; }
.metric-desc-mobile {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  margin-top: 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--charcoal-700);
  transition: max-height 0.32s ease, opacity 0.25s ease, margin-top 0.25s ease;
}
.metric-card.is-expanded .metric-desc-mobile {
  max-height: 220px;
  opacity: 1;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed rgba(15, 36, 25, 0.10);
}

@media (hover: none) {
  /* En touch: el iconito ⓘ destaca más para indicar "tap me" */
  .metric-info {
    color: var(--forest-500) !important;
    font-size: 13px;
    background: rgba(82, 183, 136, 0.14);
    padding: 1px 5px;
    border-radius: 999px;
    margin-left: 6px;
  }
}

/* Caret animado a la derecha del label (universal) */
.metric-label::after {
  content: "▾";
  float: right;
  font-size: 10px;
  color: var(--charcoal-300);
  transition: transform 0.2s ease;
  margin-top: 2px;
}
.metric-card.is-expanded .metric-label::after {
  transform: rotate(180deg);
  color: var(--forest-500);
}
.metric-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--charcoal-300);
}
.metric-card.is-green::before { background: var(--traffic-green-bar); }
.metric-card.is-amber::before { background: var(--traffic-amber-bar); }
.metric-card.is-red::before { background: var(--traffic-red-bar); }
.metric-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--charcoal-500);
  margin-bottom: 4px;
}
.metric-value {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 700;
  color: var(--charcoal-900);
  letter-spacing: -0.02em;
  line-height: 1.05;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.metric-value .unit {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  color: var(--charcoal-500);
}
.metric-trafficlight {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  font-weight: 600;
}
.metric-trafficlight .pill {
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.metric-card.is-green .pill { background: var(--traffic-green-bg); color: var(--traffic-green-fg); }
.metric-card.is-amber .pill { background: var(--traffic-amber-bg); color: var(--traffic-amber-fg); }
.metric-card.is-red .pill { background: var(--traffic-red-bg); color: var(--traffic-red-fg); }
.metric-trafficlight .threshold {
  color: var(--charcoal-500);
  font-size: 10.5px;
}

/* Indicador minigauge bajo el valor */
.metric-gauge {
  margin-top: 14px;
  height: 6px;
  background: rgba(15, 36, 25, 0.06);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.metric-gauge-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  transition: width 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}
.metric-card.is-green .metric-gauge-fill { background: var(--traffic-green-bar); }
.metric-card.is-amber .metric-gauge-fill { background: var(--traffic-amber-bar); }
.metric-card.is-red .metric-gauge-fill { background: var(--traffic-red-bar); }

.dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 2px;
}
.dot.red { background: var(--traffic-red-bar); }
.dot.amber { background: var(--traffic-amber-bar); }
.dot.green { background: var(--traffic-green-bar); }

/* ─── USERS TABLE ─────────────────────────────────────── */
.search-input {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(15, 36, 25, 0.10);
  font-size: 13.5px;
  font-family: inherit;
  background: var(--white);
  min-width: 240px;
}
.search-input:focus { outline: 2px solid var(--forest-300); }
.table-wrap {
  background: var(--white);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-soft);
  overflow-x: auto;
  margin-bottom: 16px;
}
.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 640px;
}
.users-table th,
.users-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid rgba(15, 36, 25, 0.04);
}
.users-table th {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--charcoal-500);
  font-weight: 700;
  background: var(--cream-soft);
}
.users-table tbody tr:hover { background: var(--cream-soft); }
.users-table .user-cell {
  display: flex; align-items: center; gap: 10px;
}
.users-table .user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--forest-300), var(--forest-700));
  color: var(--white);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  object-fit: cover;
}
.users-table .role-tag {
  font-size: 10.5px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.users-table .role-tag.user { background: var(--cream-soft); color: var(--charcoal-700); }
.users-table .role-tag.admin { background: var(--traffic-green-bg); color: var(--traffic-green-fg); }
.users-table .role-tag.superadmin { background: linear-gradient(135deg, var(--coral-500), var(--coral-300)); color: var(--white); }
.users-table .th-actions { width: 100px; }
.users-table .row-action {
  background: transparent;
  border: 1px solid rgba(15, 36, 25, 0.10);
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 11.5px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  color: var(--forest-500);
}
.users-table .row-action:hover { background: var(--forest-500); color: var(--white); border-color: var(--forest-500); }
.users-table .loading {
  text-align: center; color: var(--charcoal-500); padding: 32px;
}
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
  font-size: 12.5px;
  color: var(--charcoal-500);
}

/* ─── AUDIT LIST ─────────────────────────────────────── */
.audit-list {
  background: var(--white);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}
.audit-entry {
  padding: 14px 18px;
  border-bottom: 1px solid rgba(15, 36, 25, 0.04);
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.audit-entry:last-child { border-bottom: 0; }
.audit-entry:hover { background: var(--cream-soft); }
.audit-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--cream-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.audit-body { flex: 1; font-size: 13px; }
.audit-body .audit-title { font-weight: 700; color: var(--charcoal-900); margin-bottom: 2px; }
.audit-body .audit-detail { color: var(--charcoal-500); font-size: 12px; }
.audit-time { font-size: 11px; color: var(--charcoal-500); font-family: var(--font-mono); }

/* ─── MODAL CAMBIO ROL ───────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  background: rgba(15, 36, 25, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 24px;
  animation: fadeIn 0.2s ease-out;
}
.modal-box {
  background: var(--white);
  padding: 28px;
  border-radius: var(--radius-card);
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-strong);
  animation: scaleIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal-box h3 {
  font-family: var(--font-display);
  font-size: 20px;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.role-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 20px 0;
}
.role-opt {
  padding: 12px 14px;
  border: 1px solid rgba(15, 36, 25, 0.10);
  background: var(--cream-soft);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: all 0.15s;
}
.role-opt:hover { background: var(--forest-500); color: var(--white); border-color: var(--forest-500); transform: translateX(2px); }
#role-modal-cancel { width: 100%; text-align: center; padding: 8px; }

/* ─── TOAST ─────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--charcoal-900);
  color: var(--white);
  padding: 12px 18px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  z-index: 200;
  box-shadow: var(--shadow-strong);
  animation: slideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.toast.is-error { background: var(--red-500); }
.toast.is-success { background: var(--forest-500); }

/* ─── ANIMACIONES ────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes slideUp {
  from { opacity: 0; transform: translate(-50%, 14px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* Stagger fadeUp en metric cards (más vivas) */
.metric-card:nth-child(1) { animation-delay: 0.04s; }
.metric-card:nth-child(2) { animation-delay: 0.08s; }
.metric-card:nth-child(3) { animation-delay: 0.12s; }
.metric-card:nth-child(4) { animation-delay: 0.16s; }
.metric-card:nth-child(5) { animation-delay: 0.20s; }
.metric-card:nth-child(6) { animation-delay: 0.24s; }
.metric-card:nth-child(7) { animation-delay: 0.28s; }
.metric-card:nth-child(8) { animation-delay: 0.32s; }
.metric-card:nth-child(9) { animation-delay: 0.36s; }
.metric-card:nth-child(10) { animation-delay: 0.40s; }
.metric-card:nth-child(11) { animation-delay: 0.44s; }
.metric-card:nth-child(12) { animation-delay: 0.48s; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
  .topnav { width: 100%; order: 99; gap: 2px; }
  .topnav-btn { padding: 7px 10px; font-size: 12px; }
  .view { padding: 18px 14px; }
  .metric-value { font-size: 28px; }
  .view-header { flex-direction: column; align-items: stretch; }
  .search-input { min-width: 0; }
}

@media (max-width: 480px) {
  /* En móvil estrecho, el wordmark del brand "georincon · admin" no
   * cabe junto al role-pill y el botón logout. Lo escondemos dejando
   * solo el logo + un "admin" minimalista. */
  .topbar-brand span { display: none; }
  .topbar-brand::after {
    content: "admin";
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 400;
    font-size: 14px;
    color: var(--forest-500);
  }
  /* Role pill solo el primer carácter + color para que quepa */
  .role-pill {
    font-size: 0;
    padding: 0;
    width: 24px; height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
  }
  .role-pill::before {
    font-size: 12px;
    font-weight: 800;
    color: var(--white);
  }
  .role-pill.is-superadmin::before { content: "S"; }
  .role-pill.is-admin::before { content: "A"; }
  .role-pill::before { content: "U"; color: var(--charcoal-700); }
}
