:root {
  --bg: #F4F5F7;
  --surface: #FFFFFF;
  --border: #E2E5EA;
  --border-strong: #CDD1D9;
  --text: #1B1D22;
  --muted: #5A5F6B;
  --avatar-bg: #E3E7F7;
  --avatar-fg: #2B3A8C;
  --focus: #3346B8;
  --chip-on-bg: #1B1D22;
  --chip-on-fg: #FFFFFF;
  --banner-bg: #FDF3D6;
  --banner-border: #EBCB73;
  --banner-fg: #4D3600;

  --available: #1F8A4C; --available-fg: #16663A; --available-tint: #E3F4EA;
  --busy: #C4314B;      --busy-fg: #9E2238;      --busy-tint: #FBE7EA;
  --away: #E0A100;      --away-fg: #7A5600;      --away-tint: #FDF3D6;
  --offline: #9AA0AA;   --offline-fg: #4A4F5A;   --offline-tint: #EEF0F3;

  color-scheme: light;
}

/* Tema oscuro de Teams */
:root[data-theme="dark"] {
  --bg: #1F1F1F;
  --surface: #2B2B2B;
  --border: #3B3B3B;
  --border-strong: #565656;
  --text: #F2F2F2;
  --muted: #B8BCC4;
  --avatar-bg: #39407A;
  --avatar-fg: #E3E7F7;
  --focus: #9AA8FF;
  --chip-on-bg: #F2F2F2;
  --chip-on-fg: #1B1D22;
  --banner-bg: #4A3A0E;
  --banner-border: #7A5F14;
  --banner-fg: #FBE7B0;

  --available: #4CC27F; --available-fg: #8FE0B1; --available-tint: #1D3B2A;
  --busy: #F0687F;      --busy-fg: #F7A6B4;      --busy-tint: #46222A;
  --away: #F2C14E;      --away-fg: #F7D98C;      --away-tint: #44391A;
  --offline: #8A9099;   --offline-fg: #C6CAD1;   --offline-tint: #363A40;

  color-scheme: dark;
}

/* Tema de alto contraste de Teams */
:root[data-theme="contrast"] {
  --bg: #000000; --surface: #000000; --border: #FFFFFF; --border-strong: #FFFFFF;
  --text: #FFFFFF; --muted: #FFFFFF; --avatar-bg: #000000; --avatar-fg: #FFFFFF;
  --focus: #FFFF00; --chip-on-bg: #FFFF00; --chip-on-fg: #000000;
  --banner-bg: #000000; --banner-border: #FFFF00; --banner-fg: #FFFF00;
  --available: #3FF23F; --available-fg: #3FF23F; --available-tint: #000000;
  --busy: #FF6B6B;      --busy-fg: #FF6B6B;      --busy-tint: #000000;
  --away: #FFFF00;      --away-fg: #FFFF00;      --away-tint: #000000;
  --offline: #FFFFFF;   --offline-fg: #FFFFFF;   --offline-tint: #000000;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* El atributo hidden siempre oculta, aunque la clase defina display (p. ej. .areas es flex). */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Encabezado */
.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.titles { display: flex; flex-direction: column; gap: 4px; }
.eyebrow { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); }
h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -0.01em; }
.actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.updated { margin: 0; font-size: 13px; color: var(--muted); }

.btn {
  min-height: 44px; padding: 0 16px; display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer;
}
.btn:disabled { opacity: 0.6; cursor: progress; }

.banner {
  background: var(--banner-bg); border: 1px solid var(--banner-border); color: var(--banner-fg);
  border-radius: 10px; padding: 12px 16px;
}

.message {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 28px; max-width: 640px;
}
.message h2 { margin: 0 0 6px; font-size: 18px; }
.message p { margin: 0; color: var(--muted); }

#content { display: flex; flex-direction: column; gap: 22px; }

/* Resumen */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; display: flex; flex-direction: column; gap: 8px;
}
.stat-label { margin: 0; font-weight: 500; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.stat-value { margin: 0; font-size: 34px; font-weight: 700; line-height: 1; }
.stat-total { font-size: 16px; font-weight: 500; color: var(--muted); }

/* Indicador de estado */
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }
[data-status="available"] { --s: var(--available); --s-fg: var(--available-fg); --s-tint: var(--available-tint); }
[data-status="busy"]      { --s: var(--busy);      --s-fg: var(--busy-fg);      --s-tint: var(--busy-tint); }
[data-status="away"]      { --s: var(--away);      --s-fg: var(--away-fg);      --s-tint: var(--away-tint); }
[data-status="offline"]   { --s: var(--offline);   --s-fg: var(--offline-fg);   --s-tint: var(--offline-tint); }
.dot[data-status] { background: var(--s); }

/* Filtros y búsqueda */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--chip-on-bg); color: var(--chip-on-fg); border-color: var(--chip-on-bg); }

.search {
  display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface);
  color: var(--muted); flex: 0 1 280px;
}
.search input { border: 0; outline: none; font: inherit; background: transparent; color: var(--text); width: 100%; }
.search:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Selector de vista: Lista / Oficina */
.views { display: inline-flex; padding: 3px; gap: 3px; border-radius: 10px; background: var(--border); }
.view {
  min-height: 38px; padding: 0 16px; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font: inherit; font-weight: 600; cursor: pointer;
}
.view[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
:root[data-theme="contrast"] .view[aria-pressed="true"] { outline: 2px solid var(--focus); }

/* Vista Oficina (pixel art en canvas, ver office.js) */
.office {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px; overflow: hidden;
}
.office-bar { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.office canvas { display: block; image-rendering: pixelated; touch-action: manipulation; }
.office-tip {
  position: absolute; transform: translate(-50%, -100%); pointer-events: none; z-index: 1;
  display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: 8px;
  background: var(--chip-on-bg); color: var(--chip-on-fg); font-size: 12px; white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.office-tip[hidden] { display: none; }
.office-tip strong { font-size: 13px; }
.office-tip-status { font-weight: 600; }

/* Lista agrupada por área */
.areas { display: flex; flex-direction: column; gap: 24px; }
.area { display: flex; flex-direction: column; gap: 12px; }
.area-title {
  margin: 0; font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 12px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.area-count { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }

/* Tarjetas */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; display: flex; gap: 14px; align-items: center; min-width: 0;
}
.avatar-wrap { position: relative; flex: 0 0 auto; }
.avatar {
  width: 52px; height: 52px; border-radius: 50%; background: var(--avatar-bg); color: var(--avatar-fg);
  font-weight: 600; font-size: 17px; display: flex; align-items: center; justify-content: center;
}
.avatar-wrap .dot {
  position: absolute; right: -1px; bottom: -1px; width: 16px; height: 16px;
  border: 3px solid var(--surface);
}

/* Avatar animado según el estado. --phase sincroniza la animación con el reloj. */
.avatar-wrap::before {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  border: 2px solid var(--s); opacity: 0; pointer-events: none;
}
.avatar-wrap[data-status="available"]::before { animation: breathe 3s ease-in-out var(--phase) infinite; }
.avatar-wrap[data-status="busy"]::before { opacity: 0.8; }
.avatar-wrap[data-call]::before { animation: ripple 1.5s ease-out var(--phase) infinite; }
.avatar-wrap[data-status="away"] .avatar { opacity: 0.75; }
.avatar-wrap[data-status="offline"] .avatar { filter: grayscale(1); opacity: 0.55; }
.avatar-wrap.changed .avatar { animation: pop 0.6s ease-out; }

/* Ecualizador: en llamada o reunión */
.waves {
  position: absolute; left: -5px; top: -5px; height: 20px; padding: 4px 5px;
  display: flex; align-items: flex-end; gap: 2px;
  border-radius: 10px; background: var(--s); border: 2px solid var(--surface);
}
.waves i {
  width: 2px; height: 100%; border-radius: 1px; background: #FFFFFF;
  transform-origin: bottom; animation: wave 0.9s ease-in-out infinite;
}
.waves i:nth-child(2) { animation-delay: -0.3s; }
.waves i:nth-child(3) { animation-delay: -0.6s; }

/* "z" flotando: ausente */
.zz {
  position: absolute; right: -4px; top: -10px; font-size: 13px; font-weight: 700;
  color: var(--s-fg); animation: float 2.4s ease-in-out var(--phase) infinite;
}

@keyframes breathe { 0%, 100% { opacity: 0.15; transform: scale(1); } 50% { opacity: 0.7; transform: scale(1.07); } }
@keyframes ripple  { 0% { opacity: 0.8; transform: scale(1); } 100% { opacity: 0; transform: scale(1.35); } }
@keyframes wave    { 0%, 100% { transform: scaleY(0.3); } 50% { transform: scaleY(1); } }
@keyframes float   { 0% { opacity: 0; transform: translate(0, 4px); } 30% { opacity: 1; } 100% { opacity: 0; transform: translate(6px, -8px); } }
@keyframes pop     { 0%, 100% { transform: scale(1); } 40% { transform: scale(1.15); } }

@media (prefers-reduced-motion: reduce) {
  .avatar-wrap::before, .avatar-wrap *, .avatar-wrap .avatar { animation: none !important; }
  .avatar-wrap[data-status="available"]::before { opacity: 0.5; }
  .avatar-wrap[data-call]::before { opacity: 0.8; }
  .zz { opacity: 1; }
}

.info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.name { margin: 0; font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role { margin: 0; font-size: 13px; color: var(--muted); }
.status { margin: 4px 0 0; font-size: 13px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.pill { padding: 3px 10px; border-radius: 999px; font-weight: 600; background: var(--s-tint); color: var(--s-fg); }
:root[data-theme="contrast"] .pill { border: 1px solid var(--s); }
.detail { color: var(--muted); }

.empty { margin: 0; padding: 20px; color: var(--muted); }
.footnote { margin: 0; font-size: 12px; color: var(--muted); }

@media (max-width: 520px) {
  h1 { font-size: 22px; }
  .search { flex: 1 1 100%; }
}
