/* Charla — base compartida: paleta, tipografía, controles, diálogos, menús y avisos. */

:root {
  color-scheme: light dark;

  --app-bg: #eae6df;
  --panel: #ffffff;
  --header: #f0f2f5;
  --chat-bg: #efeae2;
  --out: #d9fdd3;
  --in: #ffffff;
  --text: #111b21;
  --text-2: #667781;
  /* Variante del color secundario con contraste AA sobre todos los fondos claros. */
  --text-2-aa: #5b6a73;
  --accent: #00a884;
  --badge: #25d366;
  --badge-text: #111b21;
  --read: #53bdeb;
  --sep: #e9edef;

  --accent-text: #00755e;
  --icon: #54656f;
  --hover: #f5f6f6;
  --active: #f0f2f5;
  --search-bg: #f0f2f5;
  --input-bg: #ffffff;
  --input-border: #d1d7db;
  --btn: #008069;
  --btn-hover: #017561;
  --btn-text: #ffffff;
  --danger: #d4003a;
  --danger-bg: #fde8ec;
  --pill: #ffffff;
  --pill-text: #5b6a73;
  --meta: #5b6a73;
  --meta-out: #5b6a73;
  --overlay: rgba(11, 20, 26, 0.45);
  --shadow-bubble: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --shadow-pop: 0 2px 5px rgba(11, 20, 26, 0.26), 0 2px 10px rgba(11, 20, 26, 0.16);
  --focus: #027eb5;
  --warning-bg: #fff3c4;
  --warning-text: #54460a;
  --chip-bg: #e9edef;
  --scroll-thumb: rgba(11, 20, 26, 0.2);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --app-bg: #0c1317;
    --panel: #111b21;
    --header: #202c33;
    --chat-bg: #0b141a;
    --out: #005c4b;
    --in: #202c33;
    --text: #e9edef;
    --text-2: #8696a0;
    --text-2-aa: #97a6b0;
    --accent: #00a884;
    --badge: #00a884;
    --badge-text: #111b21;
    --read: #53bdeb;
    --sep: #222d34;

    --accent-text: #00a884;
    --icon: #aebac1;
    --hover: #202c33;
    --active: #2a3942;
    --search-bg: #202c33;
    --input-bg: #2a3942;
    --input-border: #3b4a54;
    --btn: #00a884;
    --btn-hover: #06cf9c;
    --btn-text: #111b21;
    --danger: #f15c6d;
    --danger-bg: #3a1f25;
    --pill: #182229;
    --pill-text: #97a6b0;
    --meta: #97a6b0;
    --meta-out: rgba(233, 237, 239, 0.8);
    --overlay: rgba(0, 0, 0, 0.6);
    --shadow-bubble: 0 1px 0.5px rgba(11, 20, 26, 0.13);
    --shadow-pop: 0 2px 5px rgba(0, 0, 0, 0.5), 0 2px 10px rgba(0, 0, 0, 0.3);
    --focus: #53bdeb;
    --warning-bg: #3d3610;
    --warning-text: #f5e6a3;
    --chip-bg: #2a3942;
    --scroll-thumb: rgba(233, 237, 239, 0.16);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
  color: var(--text);
  background: var(--app-bg);
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

a {
  color: var(--accent-text);
}

img {
  max-width: 100%;
}

h1, h2, h3, p {
  margin: 0;
}

:focus {
  outline: none;
}

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

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

/* Scrollbars finos */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) transparent;
}

/* ---------- Iconos ---------- */
.icon {
  width: 24px;
  height: 24px;
  flex: none;
  display: block;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--icon);
  flex: none;
  transition: background-color 0.15s ease;
}

.icon-btn:hover:not(:disabled) {
  background: rgba(11, 20, 26, 0.07);
}

@media (prefers-color-scheme: dark) {
  .icon-btn:hover:not(:disabled) {
    background: rgba(233, 237, 239, 0.08);
  }
}

.icon-btn[aria-expanded="true"] {
  background: rgba(11, 20, 26, 0.1);
}

@media (prefers-color-scheme: dark) {
  .icon-btn[aria-expanded="true"] {
    background: rgba(233, 237, 239, 0.12);
  }
}

.icon-btn:disabled {
  opacity: 0.45;
}

/* ---------- Botones ---------- */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  background: transparent;
  color: var(--accent-text);
  transition: background-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}

.btn--primary {
  background: var(--btn);
  color: var(--btn-text);
}

.btn--primary:hover:not(:disabled) {
  background: var(--btn-hover);
  box-shadow: 0 1px 3px rgba(11, 20, 26, 0.2);
}

.btn--secondary {
  border-color: var(--input-border);
  color: var(--accent-text);
  background: var(--panel);
}

.btn--secondary:hover:not(:disabled) {
  background: var(--hover);
}

.btn--text:hover:not(:disabled) {
  background: var(--hover);
}

.btn--danger {
  background: var(--danger);
  color: #ffffff;
}

.btn--danger:hover:not(:disabled) {
  filter: brightness(0.95);
}

.btn--block {
  width: 100%;
}

.btn--lg {
  min-height: 46px;
  font-size: 15px;
}

.btn--sm {
  min-height: 32px;
  padding: 0 12px;
  font-size: 13px;
}

.btn:disabled {
  opacity: 0.6;
}

.btn.is-loading {
  color: transparent !important;
}

.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--btn-text);
  border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}

.btn--text.is-loading::after,
.btn--secondary.is-loading::after {
  border-color: var(--accent-text);
  border-right-color: transparent;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}

.spinner--sm {
  width: 20px;
  height: 20px;
  border-width: 2px;
}

/* ---------- Campos ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field__label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.field__help {
  font-size: 12.5px;
  color: var(--text-2-aa);
}

.field__error {
  font-size: 13px;
  color: var(--danger);
}

.field__row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.field__row .input {
  flex: 1 1 auto;
  min-width: 0;
}

.input {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font-size: 15px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input::placeholder {
  color: var(--text-2-aa);
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.input[aria-invalid="true"] {
  border-color: var(--danger);
}

.input[readonly] {
  opacity: 0.85;
}

.form-error {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 14px;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  cursor: pointer;
  font-size: 14px;
}

.checkbox input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

/* Interruptor */
.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 44px;
  cursor: pointer;
}

.switch__input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch__track {
  position: relative;
  flex: none;
  width: 40px;
  height: 22px;
  border-radius: 11px;
  background: var(--input-border);
  transition: background-color 0.15s ease;
}

.switch__track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s ease;
}

.switch__input:checked + .switch__track {
  background: var(--accent);
}

.switch__input:checked + .switch__track::after {
  transform: translateX(18px);
}

.switch__input:focus-visible + .switch__track {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.switch__input:disabled + .switch__track {
  opacity: 0.6;
}

/* ---------- Avatares ---------- */
.avatar {
  --avatar-size: 40px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: var(--avatar-size);
  height: var(--avatar-size);
  border-radius: 50%;
  overflow: hidden;
  background: #dfe5e7;
  color: #ffffff;
  user-select: none;
}

.avatar__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar__initials {
  font-size: calc(var(--avatar-size) * 0.4);
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.02em;
}

.avatar--group {
  background: #dfe5e7;
  color: #ffffff;
}

.avatar--group .icon {
  width: 58%;
  height: 58%;
}

@media (prefers-color-scheme: dark) {
  .avatar,
  .avatar--group {
    background: #6a7175;
    color: #cfd4d6;
  }
}

.avatar.avatar--c0 { background: #0f7b6c; color: #fff; }
.avatar.avatar--c1 { background: #1f6fc5; color: #fff; }
.avatar.avatar--c2 { background: #a3398a; color: #fff; }
.avatar.avatar--c3 { background: #b5571a; color: #fff; }
.avatar.avatar--c4 { background: #6a4fbf; color: #fff; }
.avatar.avatar--c5 { background: #c2334d; color: #fff; }
.avatar.avatar--c6 { background: #3f7d20; color: #fff; }
.avatar.avatar--c7 { background: #0e7490; color: #fff; }
.avatar.avatar--c8 { background: #8a5a00; color: #fff; }
.avatar.avatar--c9 { background: #4b5e9c; color: #fff; }

.avatar.avatar--photo {
  background: #dfe5e7;
}

/* ---------- Diálogos ---------- */
.dialog {
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-pop);
  overflow: auto;
}

.dialog::backdrop {
  background: var(--overlay);
}

.dialog__form {
  padding: 22px 24px 18px;
}

.dialog__title {
  font-size: 18px;
  font-weight: 500;
  margin-bottom: 10px;
}

.dialog__message {
  color: var(--text-2-aa);
  font-size: 14.5px;
  margin-bottom: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.dialog__body:empty {
  display: none;
}

.dialog__body {
  margin-bottom: 8px;
}

.dialog__error {
  margin: 4px 0 10px;
  color: var(--danger);
  font-size: 13.5px;
}

.dialog__actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.copy-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--search-bg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.copy-box__text {
  flex: 1 1 auto;
  min-width: 0;
}

/* ---------- Menús ---------- */
.menu {
  position: fixed;
  z-index: 1000;
  min-width: 190px;
  max-width: min(320px, calc(100vw - 16px));
  padding: 8px 0;
  border-radius: 6px;
  background: var(--panel);
  box-shadow: var(--shadow-pop);
  animation: menu-in 0.12s ease-out;
}

@media (prefers-color-scheme: dark) {
  .menu {
    background: #233138;
  }
}

@keyframes menu-in {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.menu__item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 40px;
  padding: 0 24px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 14.5px;
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
}

.menu__item:hover:not(:disabled),
.menu__item:focus-visible {
  background: var(--hover);
  outline: none;
}

@media (prefers-color-scheme: dark) {
  .menu__item:hover:not(:disabled),
  .menu__item:focus-visible {
    background: #182229;
  }
}

.menu__item--danger {
  color: var(--danger);
}

.menu__item:disabled {
  opacity: 0.5;
}

/* ---------- Avisos ---------- */
.toast-region {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100vw - 32px);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  max-width: 100%;
  padding: 12px 18px;
  border-radius: 8px;
  background: #3b4a54;
  color: #ffffff;
  font-size: 14px;
  box-shadow: var(--shadow-pop);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  overflow-wrap: anywhere;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast--error {
  background: #b3261e;
}

.toast--success {
  background: #00785f;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
