:root {
  --bg: #1c1922;
  --panel: #252030;
  --panel-2: #2e2840;
  --ink: #ece7f5;
  --muted: #a99fc0;
  --accent: #9b5de5;
  --line: #3a3350;
  --green: #38d66b;
  --yellow: #ffcc33;
  --red: #ff5964;
  --gray: #7c748f;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Nunito', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }

/* ---------------- LOGIN (pixel) ---------------- */
.login-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background:
    radial-gradient(120% 120% at 50% 0%, #2b2340 0%, #17141d 70%),
    repeating-linear-gradient(0deg, rgba(255,255,255,.02) 0 2px, transparent 2px 16px),
    repeating-linear-gradient(90deg, rgba(255,255,255,.02) 0 2px, transparent 2px 16px);
}
.login-card {
  width: min(92vw, 360px); background: var(--panel); color: var(--ink);
  border: 4px solid #000; border-radius: 0; padding: 30px 26px 28px;
  box-shadow: 0 0 0 4px var(--accent), 12px 12px 0 4px rgba(0, 0, 0, .55);
  image-rendering: pixelated;
}
.brand { font-family: 'Press Start 2P', monospace; font-size: 20px; margin: 0 0 12px; letter-spacing: -1px; line-height: 1.3; }
.brand span { color: var(--accent); }
.login-sub { color: var(--muted); margin: 0 0 22px; font-size: 13px; }
.login-card label {
  display: block; font-family: 'Press Start 2P', monospace; font-size: 9px;
  color: var(--muted); margin: 16px 0 8px; letter-spacing: .5px; text-transform: uppercase;
}
.login-card select, .login-card input {
  width: 100%; padding: 12px 14px; border-radius: 0;
  border: 3px solid #000; background: var(--panel-2); color: var(--ink);
  font-size: 15px; font-family: inherit; box-shadow: inset 3px 3px 0 rgba(0, 0, 0, .25);
}
.login-card select:focus, .login-card input:focus { outline: none; border-color: var(--accent); }
#login-btn {
  width: 100%; margin-top: 24px; padding: 14px; border: 3px solid #000; border-radius: 0;
  background: var(--accent); color: #fff; font-family: 'Press Start 2P', monospace;
  font-size: 11px; line-height: 1.5;
  box-shadow: 5px 5px 0 0 rgba(0, 0, 0, .55); transition: transform .05s, box-shadow .05s, filter .15s;
}
#login-btn:hover { filter: brightness(1.08); }
#login-btn:active { transform: translate(3px, 3px); box-shadow: 2px 2px 0 0 rgba(0, 0, 0, .55); }
.login-error { color: var(--red); font-size: 13px; min-height: 18px; margin: 14px 0 0; text-align: center; font-weight: 700; }

/* ---------------- TOPBAR ---------------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.topbar-logo { font-family: 'Press Start 2P', monospace; font-size: 13px; }
.topbar-logo b { color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.topbar .me { display: flex; align-items: center; gap: 9px; }
.me-info { display: flex; flex-direction: column; line-height: 1.15; }
.me-name { font-weight: 800; font-size: 14px; }
.me-role { font-size: 11px; color: var(--muted); }

.status-picker { display: flex; gap: 6px; background: var(--panel-2); padding: 5px; border-radius: 12px; }
.chip {
  display: flex; align-items: center; gap: 6px; border: none; background: transparent;
  color: var(--muted); padding: 6px 10px; border-radius: 8px; font-size: 12px; font-weight: 700;
}
.chip.active { background: var(--panel); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.available { background: var(--green); }
.dot.away { background: var(--yellow); }
.dot.meeting { background: var(--red); }
.dot.offline { background: var(--gray); }

.title-input {
  width: 240px; max-width: 42vw; padding: 9px 13px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); font-size: 13px; font-family: inherit;
}

.logout-btn {
  padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--muted); font-size: 13px; font-weight: 700;
  transition: color .15s, border-color .15s;
}
.logout-btn:hover { color: var(--red); border-color: var(--red); }

/* ---------------- BANDEJA DE MENSAJES (campana) ---------------- */
.inbox-wrap { position: relative; }
.inbox-btn {
  position: relative; padding: 8px 11px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); font-size: 16px; line-height: 1;
}
.inbox-btn.blink { animation: bell-blink 1s steps(1, end) infinite; border-color: var(--red); }
@keyframes bell-blink {
  0%, 49% { background: var(--red); box-shadow: 0 0 10px rgba(255, 89, 100, .8); }
  50%, 100% { background: var(--panel-2); box-shadow: none; }
}
.inbox-count {
  position: absolute; top: -7px; right: -7px; min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; font-weight: 800;
  display: grid; place-items: center; border: 2px solid var(--panel);
}
.inbox-panel {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 30; width: 240px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
  box-shadow: var(--shadow);
}
.inbox-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px;
  background: transparent; border: none; border-bottom: 1px solid var(--line); color: var(--ink);
  font-family: inherit; font-size: 14px; text-align: left; cursor: pointer;
}
.inbox-item:last-child { border-bottom: none; }
.inbox-item:hover { background: var(--panel-2); }
.inbox-item .who { flex: 1; font-weight: 700; }
.inbox-item .n {
  background: var(--red); color: #fff; font-size: 11px; font-weight: 800;
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; display: grid; place-items: center;
}
.inbox-empty { padding: 14px; color: var(--muted); font-size: 13px; text-align: center; }

/* Badge de no leídos sobre el personaje */
.sprite .unread-badge {
  position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 5px;
  background: var(--red); color: #fff; font-size: 11px; font-weight: 800; border-radius: 10px;
  display: grid; place-items: center; border: 2px solid var(--panel); z-index: 6;
  animation: badge-pop .25s ease;
}
@keyframes badge-pop { from { transform: scale(.4); } to { transform: scale(1); } }

/* ---------------- MODAL PIXEL ---------------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(10, 8, 14, .72); animation: fadeIn .12s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  width: min(90vw, 360px); background: var(--panel); color: var(--ink);
  border: 4px solid #000; border-radius: 0; padding: 26px 24px 22px; text-align: center;
  box-shadow: 0 0 0 4px var(--accent), 10px 10px 0 4px rgba(0, 0, 0, .55);
  image-rendering: pixelated; animation: popIn .14s cubic-bezier(.2, 1.4, .5, 1);
}
@keyframes popIn { from { transform: translateY(8px) scale(.94); } to { transform: none; } }
.modal-emoji { font-size: 34px; line-height: 1; margin-bottom: 12px; }
.modal-title {
  font-family: 'Press Start 2P', monospace; font-size: 14px; line-height: 1.6;
  margin: 0 0 14px; color: var(--ink);
}
.modal-text { color: var(--muted); font-size: 14px; line-height: 1.45; margin: 0 0 22px; }
.modal-actions { display: flex; gap: 12px; justify-content: center; }
.pixel-btn {
  font-family: 'Press Start 2P', monospace; font-size: 10px; line-height: 1.5;
  padding: 12px 14px; border: 3px solid #000; border-radius: 0; color: #fff;
  box-shadow: 4px 4px 0 0 rgba(0, 0, 0, .55); transition: transform .05s, box-shadow .05s;
}
.pixel-btn:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 0 rgba(0, 0, 0, .55); }
.pixel-btn.danger { background: var(--red); }
.pixel-btn.danger:hover { filter: brightness(1.1); }
.pixel-btn.ghost { background: var(--panel-2); color: var(--muted); }
.pixel-btn.ghost:hover { color: var(--ink); }
.pixel-btn.primary { background: var(--accent); }
.pixel-btn.primary:hover { filter: brightness(1.1); }

/* ---------------- FORMULARIOS (crear / editar) ---------------- */
.login-divider { display: flex; align-items: center; gap: 10px; margin: 18px 0 12px; color: var(--muted); font-size: 12px; }
.login-divider::before, .login-divider::after { content: ''; flex: 1; height: 2px; background: var(--line); }
.link-btn {
  width: 100%; padding: 11px; border: 3px dashed var(--line); border-radius: 0;
  background: transparent; color: var(--muted); font-weight: 800; font-size: 13px; font-family: inherit;
  transition: color .15s, border-color .15s;
}
.link-btn:hover { color: var(--accent); border-color: var(--accent); }

.form-card { text-align: left; max-height: 92vh; overflow-y: auto; }
.form-card .modal-title { text-align: center; }
.f-label {
  display: block; font-family: 'Press Start 2P', monospace; font-size: 8px;
  color: var(--muted); margin: 14px 0 6px; letter-spacing: .5px; text-transform: uppercase;
}
.f-input {
  width: 100%; padding: 11px 13px; border-radius: 0; border: 3px solid #000;
  background: var(--panel-2); color: var(--ink); font-size: 15px; font-family: inherit;
  box-shadow: inset 3px 3px 0 rgba(0, 0, 0, .25);
}
.f-input:focus { outline: none; border-color: var(--accent); }
.form-error { color: var(--red); font-size: 13px; min-height: 18px; margin: 12px 0 4px; font-weight: 700; text-align: center; }

.avatar-edit { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 8px 0 6px; }
.avatar-preview {
  width: 88px; height: 88px; border-radius: 0; border: 3px solid #000;
  background: var(--panel-2) center/cover no-repeat; box-shadow: 4px 4px 0 rgba(0, 0, 0, .5);
  display: grid; place-items: center; color: var(--muted); font-weight: 800; font-size: 26px; image-rendering: pixelated;
}
.file-btn {
  padding: 8px 12px; border: 3px solid #000; background: var(--panel-2); color: var(--ink);
  font-size: 12px; font-weight: 800; cursor: pointer; box-shadow: 3px 3px 0 rgba(0, 0, 0, .5);
}
.file-btn:hover { color: var(--accent); }
.avatar-hint { font-size: 11px; color: var(--muted); font-weight: 700; }
.avatar-gallery {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; width: 100%; max-width: 288px;
}
.avatar-gallery img {
  width: 100%; aspect-ratio: 1; border: 2px solid #000; cursor: pointer; image-rendering: pixelated;
  object-fit: cover; transition: transform .08s, outline-color .1s; outline: 3px solid transparent; outline-offset: -3px;
}
.avatar-gallery img:hover { transform: scale(1.08); }
.avatar-gallery img.selected { outline-color: var(--accent); box-shadow: 0 0 8px var(--accent); }

/* Cabecera "yo" clicable para editar perfil (solo la ficha de la barra, no el sprite) */
.topbar .me { cursor: pointer; padding: 4px 6px; border-radius: 8px; transition: background .15s; }
.topbar .me:hover { background: var(--panel-2); }
.topbar .me::after { content: '✏️'; font-size: 11px; margin-left: 4px; opacity: .5; }

/* ---------------- STAGE ---------------- */
.stage-wrap { flex: 1; overflow: auto; display: grid; place-items: center; padding: 18px; }
.stage {
  position: relative; width: min(1100px, 96vw); aspect-ratio: 16 / 9;
  background: #0d0b12; border-radius: 16px; overflow: hidden;
  box-shadow: var(--shadow); border: 1px solid var(--line);
}
.office-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; }
.sprites { position: absolute; inset: 0; }
.hint {
  position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%);
  margin: 0; font-size: 11px; color: rgba(255,255,255,.75); background: rgba(0,0,0,.4);
  padding: 4px 10px; border-radius: 20px; pointer-events: none; white-space: nowrap;
}

/* ---------------- SPRITE (empleado) ---------------- */
.sprite {
  position: absolute; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  cursor: pointer; user-select: none; transition: filter .15s;
}
.sprite:hover { filter: brightness(1.12); z-index: 5; }
.sprite.me { cursor: grab; }
.sprite.dragging { cursor: grabbing; z-index: 20; }

.sprite .title-bubble {
  max-width: 160px; font-size: 10.5px; font-weight: 800; color: #2b2340;
  background: #ffe9a8; border: 1px solid #e8c766; padding: 3px 8px; border-radius: 8px;
  box-shadow: 0 3px 8px rgba(0,0,0,.3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sprite .title-bubble:empty { display: none; }

.avatar {
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; color: white; font-size: 16px;
  background: var(--accent); border: 3px solid #fff; box-shadow: 0 4px 10px rgba(0,0,0,.4);
  position: relative; background-size: cover; background-position: center;
}
.avatar.sm { width: 34px; height: 34px; font-size: 13px; border-width: 2px; }
.avatar .status-ring {
  position: absolute; right: -2px; bottom: -2px; width: 15px; height: 15px; border-radius: 50%;
  border: 2.5px solid var(--panel);
}
.status-ring.available { background: var(--green); }
.status-ring.away { background: var(--yellow); }
.status-ring.meeting { background: var(--red); }
.status-ring.offline { background: var(--gray); }
.sprite.is-offline .avatar { opacity: .45; filter: grayscale(.6); }

.sprite .nameplate {
  font-size: 11px; font-weight: 800; color: #fff; background: rgba(0,0,0,.55);
  padding: 2px 8px; border-radius: 10px; white-space: nowrap;
}
.sprite .nameplate small { color: var(--muted); font-weight: 600; }
.sprite .nameplate .ai-tag {
  font-size: 8px; font-weight: 800; letter-spacing: .5px; color: #061018;
  background: linear-gradient(90deg, #38bdf8, #22d3ee); padding: 1px 4px; border-radius: 5px;
  vertical-align: middle;
}

/* Personaje de cuerpo entero (PNG transparente) */
.char-wrap { position: relative; display: flex; justify-content: center; }
.char {
  height: 104px; width: auto; image-rendering: pixelated; pointer-events: none;
  filter: drop-shadow(0 6px 4px rgba(0,0,0,.45));
}
.sprite.is-offline .char { opacity: .5; filter: grayscale(.7) drop-shadow(0 6px 4px rgba(0,0,0,.4)); }
/* Punto de estado dentro de la placa del nombre */
.np-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  margin-right: 5px; vertical-align: middle; box-shadow: 0 0 0 1px rgba(0,0,0,.3);
}
.np-dot.available { background: var(--green); }
.np-dot.away { background: var(--yellow); }
.np-dot.meeting { background: var(--red); }
.np-dot.offline { background: var(--gray); }

/* ---------------- CHAT ---------------- */
.chat {
  position: fixed; top: 0; right: 0; height: 100%; width: min(380px, 92vw); z-index: 40;
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: -12px 0 40px rgba(0,0,0,.4);
  display: flex; flex-direction: column; animation: slideIn .18s ease;
}
@keyframes slideIn { from { transform: translateX(20px); opacity: .5; } to { transform: none; opacity: 1; } }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.chat-who { display: flex; flex-direction: column; line-height: 1.2; flex: 1; }
.chat-who span:first-child { font-weight: 800; }
.chat-status { font-size: 11px; color: var(--muted); }
.chat-close { background: transparent; border: none; color: var(--muted); font-size: 18px; }
.chat-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.bubble {
  max-width: 80%; padding: 8px 12px; border-radius: 14px; font-size: 14px; line-height: 1.35; word-wrap: break-word;
}
.bubble .t { display: block; font-size: 9.5px; opacity: .6; margin-top: 3px; text-align: right; }
.bubble.them { align-self: flex-start; background: var(--panel-2); border-bottom-left-radius: 4px; }
.bubble.me { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.chat-day { align-self: center; font-size: 10px; color: var(--muted); background: var(--panel-2); padding: 2px 10px; border-radius: 10px; }
.chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; padding: 11px 14px; border-radius: 22px; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); font-size: 14px; font-family: inherit; }
.chat-form button { width: 44px; border: none; border-radius: 50%; background: var(--accent); color: #fff; font-size: 16px; }

/* ---------------- BOTÓN ADMIN ---------------- */
.admin-btn {
  padding: 8px 11px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); font-size: 16px; line-height: 1; transition: border-color .15s, filter .15s;
}
.admin-btn:hover { border-color: var(--accent); filter: brightness(1.15); }

/* ---------------- SELECTOR DE PERSONAJE (cuerpo entero) ---------------- */
.char-pick { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 8px 0 4px; }
.char-preview {
  width: 72px; height: 108px; border: 3px solid #000; background: var(--panel-2) center/contain no-repeat;
  box-shadow: 4px 4px 0 rgba(0,0,0,.5); image-rendering: pixelated;
  display: grid; place-items: center; color: var(--muted); font-size: 26px;
}
.char-preview:empty::before { content: '🧍'; opacity: .5; }
.char-gallery {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; width: 100%; max-width: 300px;
  max-height: 168px; overflow-y: auto; padding: 2px;
}
.char-gallery .char-cell {
  aspect-ratio: 2/3; border: 2px solid #000; cursor: pointer; image-rendering: pixelated;
  background: var(--panel-2) center/contain no-repeat; transition: transform .08s, outline-color .1s;
  outline: 3px solid transparent; outline-offset: -3px;
}
.char-gallery .char-cell:hover { transform: scale(1.08); }
.char-gallery .char-cell.selected { outline-color: var(--accent); box-shadow: 0 0 8px var(--accent); }
.pick-or { display: flex; align-items: center; gap: 10px; margin: 10px 0 6px; color: var(--muted); font-size: 11px; }
.pick-or::before, .pick-or::after { content: ''; flex: 1; height: 2px; background: var(--line); }

/* Casilla de administrador */
.check-row {
  display: flex; align-items: center; gap: 9px; margin: 14px 0 2px; font-weight: 800; font-size: 13px; cursor: pointer;
  color: var(--ink);
}
.check-row input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------------- PANEL DE ADMINISTRACIÓN ---------------- */
.admin-card { width: min(94vw, 460px); }
.admin-tabs { display: flex; gap: 8px; margin: 6px 0 14px; }
.admin-tab {
  flex: 1; padding: 10px; border: 3px solid #000; background: var(--panel-2); color: var(--muted);
  font-family: 'Press Start 2P', monospace; font-size: 9px; box-shadow: 3px 3px 0 rgba(0,0,0,.5);
}
.admin-tab.active { background: var(--accent); color: #fff; }
.admin-section { animation: fadeIn .12s ease; }
.row-inline { display: flex; gap: 8px; align-items: stretch; }
.row-inline .f-input { flex: 1; }
.btn-sm { padding: 10px 12px; font-size: 9px; }

.bg-gallery { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 4px; }
.bg-cell {
  border: 3px solid #000; cursor: pointer; position: relative; image-rendering: pixelated;
  background: var(--panel-2) center/cover no-repeat; aspect-ratio: 16/9; box-shadow: 3px 3px 0 rgba(0,0,0,.5);
  transition: transform .08s; outline: 3px solid transparent; outline-offset: -3px;
}
.bg-cell:hover { transform: scale(1.03); }
.bg-cell.selected { outline-color: var(--accent); box-shadow: 0 0 10px var(--accent); }
.bg-cell span {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 3px 6px; font-size: 10px; font-weight: 800;
  color: #fff; background: rgba(0,0,0,.6); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.user-list { display: flex; flex-direction: column; gap: 8px; max-height: 46vh; overflow-y: auto; }
.user-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 2px solid var(--line);
  border-radius: 8px; background: var(--panel-2);
}
.user-row .u-av { width: 34px; height: 34px; border-radius: 50%; background: var(--accent) center/cover no-repeat; flex: none; border: 2px solid #000; }
.user-row .u-info { flex: 1; min-width: 0; line-height: 1.25; }
.user-row .u-name { font-weight: 800; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.user-row .u-role { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.u-badge { font-size: 9px; background: var(--accent); color: #fff; padding: 1px 5px; border-radius: 6px; font-weight: 800; }
.user-row .u-dept {
  margin-top: 4px; font-size: 11px; padding: 3px 6px; max-width: 150px;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; font-family: inherit;
}
.user-row .u-actions { display: flex; gap: 6px; flex: none; }
.u-btn {
  border: 2px solid #000; background: var(--panel); color: var(--ink); font-size: 14px; line-height: 1;
  width: 30px; height: 30px; border-radius: 6px; display: grid; place-items: center;
}
.u-btn:hover { filter: brightness(1.2); border-color: var(--accent); }
.u-btn.danger:hover { border-color: var(--red); color: var(--red); }
.admin-hint { font-size: 11px; color: var(--muted); margin: 10px 0 0; text-align: center; }

@media (max-width: 720px) {
  .topbar { gap: 8px; }
  .title-input { width: 100%; max-width: none; order: 3; }
  .hint { font-size: 10px; }
  .bg-gallery { grid-template-columns: 1fr; }
}
