:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f5f6f8;
  --surface-2: #eceef2;
  --surface-3: #dfe2e8;
  --line: #d5d9e0;
  --text: #1a1d23;
  --muted: #5b6472;
  --accent: #2563eb;
  --accent-hover: #1d4fd8;
  --on-accent: #ffffff;
  --danger: #d92d32;
  --danger-hover: #b9242a;
  --error: #b3261e;
  --speaking: #0f9d6e;
  --overlay: rgb(255 255 255 / 0.9);
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

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

h1, h2, p, ol, ul { margin: 0; padding: 0; }
ol, ul { list-style: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
code { font: 0.95em ui-monospace, SFMono-Regular, Menlo, monospace; }

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

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.muted { color: var(--muted); }

.button {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  padding: 10px 18px;
  font-weight: 600;
  white-space: nowrap;
}
.button:hover { background: var(--surface-3); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.button.primary:hover { background: var(--accent-hover); }
.button:disabled { opacity: 0.6; cursor: default; }
.button:disabled:not(.primary) { background: var(--surface-2); color: var(--muted); }

input, select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 10px 12px;
}
select:disabled { color: var(--muted); }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }

.form-message { color: var(--error); font-size: 0.9rem; }
.form-message:empty { display: none; }

/* Inicio */
.home {
  min-height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  padding: 32px 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.home h1 { font-size: clamp(2rem, 6vw, 3rem); line-height: 1.1; letter-spacing: -0.02em; }
.lead { color: var(--muted); font-size: 1.15rem; }
.home-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; }
.join-form { display: flex; gap: 8px; flex: 1 1 260px; }
a { color: var(--accent); }

/* Acceso y panel del anfitrión */
.login-form {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}
.login-form label { color: var(--muted); font-size: 0.9rem; margin-top: 8px; }
.login-form .button { margin-top: 8px; }

.dashboard { max-width: 1040px; margin: 0 auto; padding: 16px; }
.dashboard-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.dashboard-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.dashboard-body {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 32px;
  align-items: start;
  padding-top: 24px;
}
.dashboard h2 { font-size: 1.15rem; margin-bottom: 10px; }
.meeting-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.meeting-form label { margin-top: 8px; font-size: 0.9rem; color: var(--muted); }
.meeting-form input, .meeting-form select { background: var(--bg); }
.meeting-form .checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
}
.meeting-form .checkbox input { width: 18px; height: 18px; flex: none; accent-color: var(--accent); }
.schedule { display: flex; flex-direction: column; gap: 6px; }
.schedule:disabled { opacity: 0.55; }
.meeting-form .schedule:disabled input, .meeting-form .schedule:disabled select { background: var(--surface-3); color: var(--muted); }
.field-row { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 8px; }
.form-actions { display: flex; gap: 8px; margin-top: 12px; }
.form-actions .primary { flex: 1; }
.meeting-lists { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.tabs { display: flex; gap: 20px; box-shadow: inset 0 -1px 0 var(--line); overflow-x: auto; }
.tab {
  padding: 8px 2px 10px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected='true'] { color: var(--accent); border-bottom-color: var(--accent); }
.meeting-list { display: flex; flex-direction: column; gap: 8px; }
.meeting-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.meeting-info { min-width: 0; flex: 1 1 220px; }
.meeting-info strong { display: block; overflow-wrap: anywhere; }
.meeting-info span { color: var(--muted); font-size: 0.9rem; }
.meeting-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.meeting-buttons .button { padding: 6px 12px; font-size: 0.875rem; }
.meeting-buttons a.button { color: var(--on-accent); }
.button.danger { color: var(--error); }
a.button { display: inline-block; text-decoration: none; color: inherit; }
.button.icon-only { display: grid; place-items: center; padding: 10px 12px; }

.settings {
  width: min(480px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.14);
}
.settings::backdrop { background: rgb(120 126 138 / 0.35); }
.setting {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  padding: 16px;
}
.setting > div { flex: 1 1 220px; min-width: 0; }
.setting h3 { margin: 0 0 2px; font-size: 1rem; }
.meeting-buttons .button.icon-only { padding: 4px 8px; }
.meeting-buttons .icon-only svg { width: 20px; height: 20px; }
.share-body { display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.share-body progress { width: 100%; accent-color: var(--accent); }
.share-row { display: flex; gap: 8px; }
.upload-status {
  position: fixed;
  z-index: 3;
  right: 16px;
  bottom: 16px;
  max-width: calc(100vw - 32px);
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.14);
  font-size: 0.9rem;
}
.meeting:not([hidden]) ~ .upload-status { bottom: 88px; }
.shared { max-width: 860px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.shared h1 { font-size: 1.75rem; overflow-wrap: anywhere; }
.shared-list { display: flex; flex-direction: column; gap: 32px; }
.shared-item { display: flex; flex-direction: column; gap: 10px; }
.shared-item video { width: 100%; max-height: 70vh; border-radius: var(--radius); background: var(--surface-2); }
#folder-status { overflow-wrap: anywhere; }
.setting-form { display: flex; flex-direction: column; gap: 6px; padding: 16px; border-top: 1px solid var(--line); }
.setting-form label { margin-top: 6px; color: var(--muted); font-size: 0.9rem; }
.setting-form .button { align-self: flex-start; margin-top: 10px; }

/* Sala de espera */
.lobby {
  min-height: 100dvh;
  max-width: 1040px;
  margin: 0 auto;
  padding: 24px 16px;
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(280px, 1fr);
  gap: 32px;
  align-items: center;
}
.preview {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface-2);
}
.preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
.preview-off {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.preview-tools {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 14px;
  display: flex;
  justify-content: center;
  gap: 12px;
}
.round {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--overlay);
}
.round:hover { background: var(--bg); }
.round.off { background: var(--danger); color: #fff; }
.round.off:hover { background: var(--danger-hover); }
.lobby-form { display: flex; flex-direction: column; gap: 6px; }
.lobby-form h1 { font-size: 1.75rem; line-height: 1.2; }
.lobby-form label { margin-top: 10px; font-size: 0.9rem; color: var(--muted); }
.lobby-form .button { margin-top: 16px; }

/* Reunión */
.meeting {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: minmax(0, 1fr) auto;
}
.stage {
  --cols: 1;
  grid-column: 1;
  grid-row: 1;
  min-height: 0;
  display: grid;
  gap: 8px;
  padding: 8px;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
}
.stage[data-count='2'], .stage[data-count='3'], .stage[data-count='4'] { --cols: 2; }
.stage[data-count='5'], .stage[data-count='6'] { --cols: 3; }

.stage.spotlight {
  grid-template-columns: minmax(0, 1fr) 220px;
  grid-template-rows: repeat(5, minmax(0, 1fr));
}
.stage.spotlight .tile.featured { grid-column: 1; grid-row: 1 / -1; }

.tile {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface-2);
}
.tile::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: inset 0 0 0 3px transparent;
  transition: box-shadow 120ms;
}
.tile.speaking::after { box-shadow: inset 0 0 0 3px var(--speaking); }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile.self:not(.sharing) video { transform: scaleX(-1); }
.tile.sharing video { object-fit: contain; background: var(--surface-2); }
.tile.no-video video { visibility: hidden; }
.avatar {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  width: clamp(56px, 22%, 112px);
  aspect-ratio: 1;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-3);
  font-size: clamp(1.25rem, 3vw, 2.25rem);
  font-weight: 600;
}
.tile.no-video .avatar { display: grid; }
.tile-label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  max-width: calc(100% - 16px);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 8px;
  background: var(--overlay);
  font-size: 0.875rem;
}
.tile-label svg { width: 16px; height: 16px; color: var(--error); }
.tile-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-status {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  width: fit-content;
  padding: 3px 9px;
  border-radius: 8px;
  background: var(--overlay);
  font-size: 0.8rem;
  color: var(--muted);
}

.rec-badge {
  position: fixed;
  z-index: 1;
  top: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 600;
}
.rec-badge::before {
  content: '';
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #fff;
}

.panel {
  grid-column: 2;
  grid-row: 1 / -1;
  width: 340px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--line);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px 10px 16px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { font-size: 1.05rem; }
.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 8px;
  background: none;
}
.icon-button:hover { background: var(--surface-2); }
.panel-chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
}
.message-meta { font-size: 0.8rem; color: var(--muted); }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat-form input { background: var(--bg); }
.people { overflow-y: auto; padding: 8px; }
.people li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 8px; }
.people .person-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people svg { color: var(--muted); }
.people svg.off { color: var(--error); }
.person-actions { flex-basis: 100%; display: flex; gap: 6px; }
.person-actions .button { padding: 4px 10px; font-size: 0.8rem; }
.mic-request {
  position: fixed;
  top: 64px;
  left: 50%;
  z-index: 20;
  width: min(380px, calc(100vw - 32px));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.14);
}
.mic-request-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.toolbar {
  grid-column: 1;
  grid-row: 2;
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tool {
  position: relative;
  min-width: 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  border: 0;
  border-radius: 10px;
  background: none;
  font-size: 0.75rem;
  color: var(--muted);
}
.tool svg { color: var(--text); }
.tool:hover { background: var(--surface-2); color: var(--text); }
.tool[aria-expanded='true'], .tool.active { background: var(--surface-3); color: var(--text); }
.tool.off svg, .tool.off { color: var(--error); }
.tool.recording, .tool.recording svg { color: var(--danger); }
.tool.leave { color: #fff; background: var(--danger); margin-left: 12px; }
.tool.leave svg { color: #fff; }
.tool.leave:hover { background: var(--danger-hover); }
.badge {
  position: absolute;
  top: 2px;
  right: 14px;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.7rem;
  line-height: 18px;
}

/* Fin */
.ended {
  min-height: 100dvh;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
}
.ended h1 { font-size: 1.75rem; }

.toast {
  position: fixed;
  z-index: 3;
  left: 50%;
  top: 16px;
  translate: -50% 0;
  max-width: calc(100vw - 32px);
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.14);
  font-size: 0.9rem;
}

@media (max-width: 800px) {
  .lobby { grid-template-columns: minmax(0, 1fr); gap: 20px; align-content: center; }
  .dashboard-body { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .dashboard-actions { flex-wrap: nowrap; }
  .dashboard-actions .button { padding: 8px 12px; }
  .meeting { grid-template-columns: minmax(0, 1fr); }
  .panel {
    position: fixed;
    inset: 0;
    z-index: 2;
    width: auto;
    border-left: 0;
  }
  .stage[data-count='2'] { --cols: 1; }
  .stage[data-count='5'], .stage[data-count='6'] { --cols: 2; }
  .stage.spotlight {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: minmax(0, 1fr);
    grid-auto-rows: 96px;
  }
  .stage.spotlight .tile.featured { grid-column: 1 / -1; grid-row: 1; }
  .toolbar { justify-content: space-between; gap: 0; }
  .tool { min-width: 0; flex: 1; padding: 8px 2px; }
  .tool span { font-size: 0.68rem; }
  .tool.leave { margin-left: 4px; }
  .badge { right: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  .tile::after { transition: none; }
}
