/* Portal Corporativo — estilo inspirado en Microsoft Fluent UI */
:root {
  --primario: #0078D4;
  --primario-hover: #106EBE;
  --bg: #F3F2F1;
  --card: #FFFFFF;
  --texto: #201F1E;
  --texto-sec: #605E5C;
  --borde: #EDEBE9;
  --sombra: 0 2px 8px rgba(0, 0, 0, 0.1);
  --sombra-lg: 0 8px 24px rgba(0, 0, 0, 0.18);
  --radio: 12px;
  --rojo: #D13438;
  --verde: #107C10;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--texto);
}

/* ---- Header ---- */
.header {
  background: var(--card);
  border-bottom: 1px solid var(--borde);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header .logo {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--primario);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700;
}
.header .titulo { font-size: 1.05rem; font-weight: 600; }
.header .spacer { flex: 1; }
.header .user { display: flex; align-items: center; gap: 10px; color: var(--texto-sec); font-size: .9rem; }
.header .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primario); color: #fff;
  display: grid; place-items: center; font-weight: 600; font-size: .85rem;
}
.btn {
  border: 1px solid var(--borde);
  background: var(--card);
  color: var(--texto);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--bg); }
.btn-primario { background: var(--primario); color: #fff; border-color: var(--primario); }
.btn-primario:hover { background: var(--primario-hover); }
.btn-rojo { background: var(--rojo); color: #fff; border-color: var(--rojo); }
.btn-icono { display: inline-flex; align-items: center; gap: 6px; }

/* ---- Layout ---- */
main { max-width: 1100px; margin: 0 auto; padding: 28px 24px 64px; }
.subtitulo { color: var(--texto-sec); margin: 0 0 22px; font-size: 1rem; }

/* ---- Grid de cards ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}
@media (max-width: 900px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .grid { grid-template-columns: 1fr; } }

.card {
  background: var(--card);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  overflow: hidden;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform .2s, box-shadow .2s;
  border: 1px solid var(--borde);
}
.card:hover { transform: scale(1.05); box-shadow: var(--sombra-lg); }
.card-header {
  height: 64px;
  display: flex;
  align-items: center;
  padding: 0 18px;
}
.card-header svg { width: 36px; height: 36px; }
.card-header .emoji { font-size: 34px; line-height: 1; }
.card-body { padding: 14px 18px 18px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card-body .t { font-weight: 600; font-size: 1.02rem; }
.card-body .d { font-size: .85rem; color: var(--texto-sec); flex: 1; }
.card-body .abrir { font-size: .85rem; color: var(--primario); font-weight: 600; }

/* ---- Sección Herramientas (portal) ---- */
.tools-seccion { margin-top: 40px; }
.tools-titulo { font-size: 1.15rem; font-weight: 600; margin: 0 0 16px; }
.tools-lista {
  list-style: none; margin: 0; padding: 0;
  background: var(--card); border: 1px solid var(--borde);
  border-radius: var(--radio); box-shadow: var(--sombra); overflow: hidden;
}
.tool-item { padding: 14px 18px; border-bottom: 1px solid var(--borde); }
.tool-item:last-child { border-bottom: none; }
.tool-nombre {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--primario); font-weight: 600; font-size: 1rem; text-decoration: none;
}
.tool-nombre:hover { text-decoration: underline; }
.tool-flecha { font-size: .85em; }
.tool-desc { font-size: .85rem; color: var(--texto-sec); margin-top: 4px; }

/* ---- Pestañas del admin ---- */
.tabs { display: flex; gap: 8px; margin-bottom: 22px; border-bottom: 1px solid var(--borde); }
.tab {
  border: none; background: none; padding: 10px 16px; cursor: pointer; font: inherit;
  color: var(--texto-sec); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--texto); }
.tab.activa { color: var(--primario); border-bottom-color: var(--primario); }

/* ---- Footer ---- */
.footer {
  text-align: center;
  color: var(--texto-sec);
  font-size: .8rem;
  padding: 24px;
  border-top: 1px solid var(--borde);
}

/* ---- Estados ---- */
.centro { min-height: 70vh; display: grid; place-items: center; text-align: center; color: var(--texto-sec); }
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--borde); border-top-color: var(--primario);
  animation: girar .8s linear infinite; margin: 0 auto 14px;
}
@keyframes girar { to { transform: rotate(360deg); } }

/* ---- Tabla admin ---- */
table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radio); overflow: hidden; box-shadow: var(--sombra); }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--borde); font-size: .9rem; }
th { color: var(--texto-sec); font-weight: 600; background: #FAF9F8; }
tr:last-child td { border-bottom: none; }
.swatch { width: 22px; height: 22px; border-radius: 5px; display: inline-block; border: 1px solid var(--borde); vertical-align: middle; }
.preview-icono { width: 30px; height: 30px; border-radius: 6px; display: inline-grid; place-items: center; color: #fff; }
.preview-icono svg { width: 18px; height: 18px; }
.drag-handle { cursor: grab; color: var(--texto-sec); user-select: none; }
tr.sortable-ghost { opacity: .4; }
.badge { padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge-on { background: #DFF6DD; color: var(--verde); }
.badge-off { background: #FDE7E9; color: var(--rojo); }
.acciones button { margin-right: 6px; }
.badge { white-space: nowrap; }

/* overflow-x:auto — si la tabla no cabe, hace scroll DENTRO del recuadro (no desborda la página). */
.tabla-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radio); box-shadow: var(--sombra); }
.tabla-wrap > table { border-radius: 0; box-shadow: none; overflow: visible; }
/* Columna Acciones pegada al borde derecho: visible siempre, aunque la tabla tenga scroll. */
.tabla-wrap > table:has(td.acciones) th:last-child,
.tabla-wrap td.acciones { position: sticky; right: 0; z-index: 1; }
.tabla-wrap td.acciones { background: var(--card); white-space: nowrap; box-shadow: -6px 0 8px -6px rgba(0,0,0,.18); }

/* ---- Formulario admin ---- */
/* min-width:0 — sin él, la columna del grid crece con la tabla y empuja la página fuera del viewport. */
.admin-cols { display: grid; grid-template-columns: 1.2fr .8fr; gap: 28px; align-items: start; }
.admin-cols > * { min-width: 0; }
@media (max-width: 820px) { .admin-cols { grid-template-columns: 1fr; } }
.campo { margin-bottom: 16px; }
.campo label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; }
.campo input[type=text], .campo input[type=url], .campo input[type=number] {
  width: 100%; padding: 9px 11px; border: 1px solid var(--borde); border-radius: 6px; font: inherit;
}
.campo input:focus { outline: 2px solid var(--primario); border-color: var(--primario); }
.contador { font-size: .75rem; color: var(--texto-sec); float: right; }
.panel { background: var(--card); border: 1px solid var(--borde); border-radius: var(--radio); padding: 22px; box-shadow: var(--sombra); }

/* selector de iconos */
.icon-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; max-height: 170px; overflow-y: auto; padding: 8px; border: 1px solid var(--borde); border-radius: 8px; }
.icon-grid button { aspect-ratio: 1; border: 1px solid transparent; border-radius: 6px; background: var(--bg); cursor: pointer; display: grid; place-items: center; }
.icon-grid button svg { width: 20px; height: 20px; }
.icon-grid button.sel { border-color: var(--primario); background: #DEECF9; }

/* paleta de colores */
.paleta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.paleta button { width: 26px; height: 26px; border-radius: 6px; border: 2px solid transparent; cursor: pointer; }
.paleta button.sel { border-color: var(--texto); }

/* toggle */
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle input { display: none; }
.toggle .slider { position: absolute; inset: 0; background: #c8c6c4; border-radius: 999px; transition: .2s; }
.toggle .slider::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.toggle input:checked + .slider { background: var(--primario); }
.toggle input:checked + .slider::before { transform: translateX(20px); }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 50; }
.modal { background: var(--card); border-radius: var(--radio); padding: 26px; max-width: 420px; box-shadow: var(--sombra-lg); }
.modal h3 { margin-top: 0; }
.modal .modal-acciones { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.hidden { display: none !important; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; }
.toolbar .spacer { flex: 1; }
.aviso { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: .9rem; }
.aviso-error { background: #FDE7E9; color: var(--rojo); }
.aviso-ok { background: #DFF6DD; color: var(--verde); }

/* ---- Selector de permisos (usuarios) ---- */
.badge-info { background: #DEECF9; color: var(--primario); }
.ayuda-perms { font-size: .78rem; color: var(--texto-sec); margin: 0 0 8px; line-height: 1.4; }
.btn-mini { padding: 4px 10px; font-size: .78rem; }
.perms-acciones { display: flex; gap: 8px; margin: 8px 0; }
.user-filter { width: 100%; padding: 8px 11px; border: 1px solid var(--borde); border-radius: 6px; font: inherit; }
.user-filter:focus { outline: 2px solid var(--primario); border-color: var(--primario); }
.user-list { max-height: 230px; overflow-y: auto; border: 1px solid var(--borde); border-radius: 8px; padding: 4px; }
.user-item { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 6px; cursor: pointer; font-weight: 400; margin: 0; }
.user-item:hover { background: var(--bg); }
.user-item input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primario); flex: none; }
.user-meta { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.user-name { font-size: .88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-mail { font-size: .76rem; color: var(--texto-sec); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Responsive ─────────────────────────────────────────────────────────────
   Header, pestañas y tabla del admin en tablets y celulares. */
.tab, .header .btn { white-space: nowrap; }
.header .titulo { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header .user span { max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 900px) {
  .toolbar { flex-wrap: wrap; }
  .tabla-wrap > table { min-width: 680px; }
}

@media (max-width: 600px) {
  .header { padding: 0 12px; gap: 8px; }
  .header .user span { display: none; }
  .header .btn { padding: 6px 10px; }
  main { padding: 18px 12px 48px; }
  .panel { padding: 16px; }
  .modal { margin: 0 12px; padding: 20px 16px; }
  .icon-grid { grid-template-columns: repeat(6, 1fr); }
  /* La columna fija taparía media pantalla en un celular: se libera y los
     botones se alcanzan con el scroll horizontal de la tabla. */
  .tabla-wrap > table:has(td.acciones) th:last-child,
  .tabla-wrap td.acciones { position: static; box-shadow: none; }
}
