:root {
  --accent: #5b8def;
  --bg: #f2f4f7;
  --panel: #ffffff;
  --side: #1b2430;
  --side-soft: #263243;
  --text: #1c2530;
  --muted: #6d7b8a;
  --line: #e2e7ee;
  --ok: #2f8f5b;
  --warn: #b7791f;
  --danger: #d4344a;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* El atributo hidden gana siempre. Sin esto, cualquier regla que fije un
   display (flex, grid...) deja visible un elemento marcado como oculto: la
   hoja de entrar tapaba el chat entero sin que se notara en el HTML. */
[hidden] { display: none !important; }


body {
  margin: 0;
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

h1, h2, h3 { margin: 0; font-weight: 600; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

/* --- Entrada --- */

.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, #1b2430, #2c3e57);
}
.login .card {
  background: var(--panel);
  border-radius: 14px;
  padding: 26px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 18px 50px rgba(0,0,0,.28);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login h1 { font-size: 19px; }
.login .sub { margin-bottom: 4px; }

/* --- Estructura --- */

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

.side {
  width: 230px;
  flex: none;
  background: var(--side);
  color: #cfd8e3;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 18px 18px 14px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
}
.brand-icon { width: 20px; height: 20px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }

.nav { display: flex; flex-direction: column; padding: 6px 10px; gap: 2px; overflow-y: auto; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.nav-item svg { width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav-item:hover:not(:disabled) { background: var(--side-soft); color: #fff; }
.nav-item.is-on { background: var(--accent); color: #fff; }
.nav-item:disabled { opacity: .38; cursor: default; }

.side-foot {
  margin-top: auto;
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
}
.who { color: #9fb0c3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot .link { color: #cfd8e3; }

.main { flex: 1 1 auto; min-width: 0; padding: 22px 26px 40px; }

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.top h1 { font-size: 20px; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.view { display: flex; flex-direction: column; gap: 14px; }

/* --- Piezas --- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card h2 { font-size: 15px; margin-bottom: 4px; }
.card + .card { margin-top: 0; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }

.box-card { display: flex; flex-direction: column; gap: 10px; }
.box-card .head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.box-card h3 { font-size: 15px; }
.box-card .key {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
}
.box-card .stats { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); }
.box-card .stats b { color: var(--text); font-weight: 600; }
.box-card .acts { display: flex; gap: 7px; flex-wrap: wrap; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  background: #eef1f5;
  color: var(--muted);
}
.tag.ok { background: #e6f5ec; color: var(--ok); }
.tag.warn { background: #fdf3e2; color: var(--warn); }
.tag.bad { background: #fdeaec; color: var(--danger); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.right, th.right { text-align: right; }
.table-wrap { overflow-x: auto; }
.msg-body { max-width: 420px; word-break: break-word; }
.gone { color: var(--muted); text-decoration: line-through; }

.empty { color: var(--muted); padding: 22px; text-align: center; }

/* --- Formularios --- */

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 500; }
.field input[type=text], .field input[type=email], .field input[type=password],
.field input[type=number], .field select, .field textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  background: #fff;
  color: var(--text);
  width: 100%;
}
.field textarea { min-height: 70px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}
.field .hint { font-size: 11.5px; color: var(--muted); }

.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }

.btn {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 14px;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.wide { width: 100%; padding: 10px; }
.btn.ghost { background: #eef1f5; color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 12.5px; }

.link {
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  padding: 3px;
  text-decoration: underline;
}
.link.danger { color: var(--danger); }

.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border: 0; border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.icon:hover { background: #eef1f5; color: var(--text); }
.icon svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.error { margin: 0; color: var(--danger); font-size: 12.5px; }

/* El interruptor de mantenimiento se guarda solo, sin pasar por "Guardar". */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  flex-wrap: wrap;
}
.switch-row .txt { font-size: 13px; }
.switch-row .txt b { display: block; font-size: 14px; }
.switch {
  position: relative;
  width: 44px; height: 24px;
  flex: none;
  cursor: pointer;
}
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .track {
  position: absolute;
  inset: 0;
  background: #cbd3dd;
  border-radius: 999px;
  transition: background .15s;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform .15s;
}
.switch input:checked + .track { background: var(--warn); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.flash {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  background: #e6f5ec;
  color: var(--ok);
  border: 1px solid #bfe3cd;
}
.flash.bad { background: #fdeaec; color: var(--danger); border-color: #f3c6cd; }

pre.snippet {
  background: #1b2430;
  color: #dfe7f1;
  padding: 14px;
  border-radius: var(--radius);
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
}

.preview {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  height: 440px;
}
.preview iframe { width: 100%; height: 100%; border: 0; display: block; }

.bars { display: flex; align-items: flex-end; gap: 3px; height: 90px; }
.bars .bar { flex: 1 1 auto; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }

/* --- Ventana modal --- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 22, 31, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 50;
}
.modal-card {
  background: var(--panel);
  border-radius: 14px;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { font-size: 15px; }
.modal-body { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }

/* --- Movil --- */

@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .side {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    gap: 6px;
    padding: 6px 8px;
  }
  .brand { padding: 6px 8px; }
  .brand span { display: none; }
  .nav { flex-direction: row; padding: 0; }
  .nav-item span { display: none; }
  .nav-item { padding: 9px; }
  .side-foot { margin-top: 0; border: 0; padding: 6px 8px; }
  .who { display: none; }
  .main { padding: 16px 14px 32px; }
}

/* --- Emojis propios --- */

.emoji-rejilla {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.emoji-ficha {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 10px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}
.emoji-ficha img {
  width: 56px;
  height: 56px;
  object-fit: contain;
}
.emoji-ficha code {
  font-size: 12.5px;
  background: #eef1f5;
  padding: 2px 7px;
  border-radius: 6px;
  word-break: break-all;
}
.emoji-peso { font-size: 11px; color: var(--muted); }

.emoji-previa {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  font-size: 12px;
  color: var(--muted);
}
.emoji-previa img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
  background: #fff;
}

.field .hint.hint-ok { color: var(--ok); font-weight: 500; }

.emoji-frase {
  font-size: 12.5px;
  color: var(--text);
  word-break: break-word;
}

.bandera-tabla {
  width: 20px;
  height: 15px;
  object-fit: cover;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0,0,0,.12);
  display: block;
}
