/* Design system inspirado em Binance.US
   Amarelo #F0B90B como único acento; verde/vermelho apenas semântico. */

:root {
  --yellow: #F0B90B;
  --yellow-active: #D0980B;
  --gold: #FFD000;
  --focus-blue: #1EAEDB;

  --white: #FFFFFF;
  --snow: #F5F5F5;
  --dark: #222126;
  --dark-card: #2B2F36;

  --ink: #1E2026;
  --text-2: #32313A;
  --slate: #848E9C;
  --muted: #777E90;

  --green: #0ECB81;
  --red: #F6465D;
  --border: #E6E8EA;

  /* Cores fixas independentes do tema (texto sobre amarelo, seção escura) */
  --on-yellow: #1E2026;
  --on-dark: #FFFFFF;

  --shadow-card: rgba(32, 32, 37, 0.05) 0px 3px 5px 0px;
  --shadow-card-hover: rgba(8, 8, 8, 0.05) 0px 3px 5px 5px;
  --shadow-pill: rgb(153, 153, 153) 0px 2px 10px -3px;

  --font: "Inter", Arial, sans-serif;

  color-scheme: light;
}

/* ---------- Tema escuro ----------
   As variáveis têm papel semântico: --white = superfície, --snow = fundo
   sutil, --ink = texto principal. Só trocamos os valores. */
html[data-theme="dark"] {
  --white: #1E2329;
  --snow: #14161A;
  --dark: #101216;
  --dark-card: #181B20;

  --ink: #EAECEF;
  --text-2: #D5D9E0;
  --slate: #9AA4B2;
  --muted: #848E9C;

  --border: #2E353F;

  --shadow-card: rgba(0, 0, 0, 0.25) 0px 3px 5px 0px;
  --shadow-card-hover: rgba(0, 0, 0, 0.35) 0px 3px 5px 5px;
  --shadow-pill: rgba(0, 0, 0, 0.45) 0px 2px 10px -3px;

  color-scheme: dark;
}

html[data-theme="dark"] body {
  background: var(--snow);
}

html[data-theme="dark"] .topnav {
  background: var(--snow);
}

* {
  box-sizing: border-box;
}

/* Garante que [hidden] vença regras como display: grid/flex */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--ink);
  background: var(--white);
  font-feature-settings: "tnum";
}

.container {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding-inline: 32px;
}

/* ---------- Navegação ---------- */

.topnav {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--white);
  border-bottom: 1px solid var(--border);
}

.nav-inner {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: var(--yellow);
  color: var(--on-yellow);
  font-weight: 700;
  font-size: 18px;
  line-height: 1;
}

.brand-word {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.nav-tag {
  font-size: 14px;
  font-weight: 500;
  color: var(--slate);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.theme-toggle {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: transparent;
  color: var(--slate);
  cursor: pointer;
  transition: color 200ms ease, border-color 200ms ease, background 200ms ease;
}

.theme-toggle:hover {
  color: var(--ink);
  border-color: var(--slate);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
}

/* Mostra a lua no claro (ação: escurecer) e o sol no escuro */
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
html[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ---------- Botões ---------- */

.btn {
  appearance: none;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.16px;
  line-height: 1.25;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 200ms ease, color 200ms ease, border-color 200ms ease;
}

.btn.pill {
  border-radius: 50px;
  padding: 12px 32px;
  min-height: 48px;
}

.btn.square {
  border-radius: 6px;
  padding: 12px 32px;
}

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

.btn.pill.primary {
  box-shadow: var(--shadow-pill);
}

.btn.primary:hover {
  background: var(--focus-blue);
  color: var(--on-dark);
}

.btn.primary:active {
  background: var(--yellow-active);
  color: var(--on-yellow);
}

.btn.outline {
  background: var(--white);
  color: var(--ink);
  border-color: var(--border);
}

.btn.pill.outline {
  box-shadow: var(--shadow-pill);
}

.btn.outline:hover {
  background: var(--focus-blue);
  border-color: var(--focus-blue);
  color: var(--on-dark);
}

.btn.ghost {
  background: transparent;
  color: var(--slate);
  font-size: 14.4px;
  letter-spacing: 0.72px;
  padding: 10px 12px;
}

.btn.ghost:hover {
  color: var(--ink);
}

.btn.block {
  width: 100%;
}

.btn:disabled {
  background: var(--border);
  color: var(--slate);
  cursor: not-allowed;
  box-shadow: none;
}

.btn:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
}

/* ---------- Gate (hero + card) ---------- */

.gate {
  padding: 80px 0 64px;
}

.gate-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 48px;
  align-items: start;
}

.hero-title {
  margin: 0;
  font-size: clamp(38px, 6vw, 60px);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.hero-title .hl {
  color: var(--yellow);
}

.hero-sub {
  margin: 20px 0 0;
  max-width: 30em;
  font-size: 20px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--slate);
}

.gate-hint {
  margin: 20px 0 0;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--yellow);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-2);
  background: var(--snow);
}

/* ---------- Cards ---------- */

.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-card);
  padding: 24px;
}

.card-title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--ink);
}

.card-copy {
  margin: 8px 0 20px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.43;
  color: var(--slate);
}

.card-copy.small {
  margin-bottom: 12px;
  font-size: 12px;
}

/* ---------- Formulários ---------- */

.form {
  display: grid;
  gap: 16px;
  margin-top: 20px;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--slate);
}

.field input {
  width: 100%;
  background: var(--snow);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: var(--font);
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
  transition: border-color 200ms ease;
}

.field input::placeholder {
  color: var(--slate);
  font-weight: 500;
}

.field input:focus {
  outline: 1px solid var(--ink);
  border-color: var(--ink);
}

#otpInput {
  letter-spacing: 0.4em;
  text-align: center;
}

.emergency {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.emergency-label {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--slate);
}

.status {
  min-height: 1.5em;
  margin: 16px 0 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--slate);
}

.status.error {
  color: var(--red);
}

/* ---------- Barra do feed ---------- */

.feed-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  padding-top: 48px;
  padding-bottom: 24px;
}

.page-title {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.session-meta {
  margin: 8px 0 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--slate);
}

.feed-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.feed-actions .btn.pill {
  padding: 8px 24px;
  min-height: 44px;
  font-size: 14.4px;
}

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

.number-picker select {
  appearance: none;
  font-family: var(--font);
  font-size: 14.4px;
  font-weight: 600;
  color: var(--ink);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 10px 36px 10px 20px;
  min-height: 44px;
  cursor: pointer;
  box-shadow: var(--shadow-pill);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23848E9C' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
}

.number-picker select:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
}

/* ---------- Seção escura: WhatsApp ---------- */

.dark-section {
  background: var(--dark);
  padding: 32px 0;
}

.waha-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.waha-label {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--slate);
}

.waha-status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0 0;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--on-dark);
}

.waha-status::before {
  content: "";
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--slate);
}

.waha-status.is-ok::before {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(14, 203, 129, 0.15);
}

.waha-status.is-warn::before {
  background: var(--yellow);
  box-shadow: 0 0 0 4px rgba(240, 185, 11, 0.15);
  animation: pulse 1.6s ease-in-out infinite;
}

.waha-status.is-bad::before {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(246, 70, 93, 0.15);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.waha-hint {
  margin: 8px 0 0;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.43;
  color: var(--slate);
  max-width: 44em;
}

.waha-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.waha-actions .btn.pill {
  padding: 10px 28px;
  min-height: 44px;
  font-size: 14.4px;
}

.dark-section .btn.ghost:hover {
  color: var(--on-dark);
}

.btn.ghost.danger {
  color: var(--red);
}

.btn.ghost.danger:hover {
  color: var(--red);
  text-decoration: underline;
}

/* QR sobre brilho dourado, dentro da seção escura */

.waha-qr {
  margin-top: 24px;
  display: grid;
  gap: 16px;
  justify-items: center;
}

.qr-glow {
  display: grid;
  place-items: center;
  padding: 32px;
  border-radius: 12px;
  background: radial-gradient(closest-side, var(--yellow), #F8D12F 70%, rgba(248, 209, 47, 0.35));
}

.qr-frame {
  /* Fundo branco fixo: o QR precisa de contraste para o scanner */
  background: #FFFFFF;
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow-pill);
}

.qr-frame img {
  display: block;
  width: min(60vw, 220px);
  height: auto;
}

.qr-steps {
  margin: 0;
  max-width: 36em;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  color: var(--slate);
}

.qr-steps strong {
  color: var(--on-dark);
  font-weight: 600;
}

/* ---------- Feed de mensagens ---------- */

.feed {
  padding-top: 32px;
  padding-bottom: 80px;
}

.list {
  display: grid;
  gap: 16px;
}

.msg {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-card);
  padding: 20px 24px;
  transition: box-shadow 200ms ease;
}

.msg:hover {
  box-shadow: var(--shadow-card-hover);
}

.msg-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.msg-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Semântica pela cor do texto: apagada = vermelho, editada = amarelo */
.msg-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--red);
  background: var(--white);
}

.msg.kind-edited .msg-badge {
  color: var(--yellow-active);
}

.msg-badge.neutral {
  color: var(--slate);
}

/* Origem (número) — usado na visão "Todos os números" da master */
.msg-badge.number {
  color: var(--ink);
  background: var(--snow);
  text-transform: none;
  letter-spacing: 0;
}

.msg-when {
  font-size: 14px;
  font-weight: 500;
  color: var(--slate);
  white-space: nowrap;
}

.msg-who {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ink);
}

.msg-who .chat {
  font-weight: 500;
  color: var(--slate);
}

.msg-who .chat::before {
  content: "·";
  margin: 0 8px;
  color: var(--slate);
}

.msg-body {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text-2);
}

/* Antes / Depois em edições */

.msg-compare {
  display: grid;
  gap: 12px;
}

.msg-version .label {
  display: block;
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--slate);
}

.msg-version .text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.5;
}

.msg-version.before .text {
  color: var(--slate);
  text-decoration: line-through;
  text-decoration-color: var(--red);
  text-decoration-thickness: 1.5px;
}

.msg-version.after .text {
  color: var(--ink);
  font-weight: 600;
}

.msg-time {
  margin: 12px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
  color: var(--slate);
}

/* Mídia */

.media {
  margin-top: 12px;
}

.media img,
.media video {
  max-width: min(100%, 420px);
  border-radius: 8px;
  display: block;
  border: 1px solid var(--border);
}

.media audio {
  width: min(100%, 420px);
  display: block;
}

.media a {
  color: var(--ink);
  font-weight: 600;
  text-decoration-color: var(--yellow);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.media-note {
  margin: 12px 0 0;
  font-size: 14px;
  color: var(--slate);
}

.empty {
  margin: 48px 0 0;
  text-align: center;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--slate);
}

/* ---------- Responsivo ---------- */

@media (max-width: 896px) {
  .container {
    padding-inline: 16px;
  }

  .gate {
    padding: 48px 0 32px;
  }

  .gate-grid {
    grid-template-columns: 1fr;
    gap: 32px;
  }

  .nav-tag {
    display: none;
  }

  .feed-bar {
    flex-direction: column;
    align-items: flex-start;
    padding-top: 32px;
  }

  .waha-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .msg {
    padding: 16px;
  }
}

/* ---------- Painel de instâncias WAHA (master) ---------- */

.admin-section {
  margin: 8px auto 24px;
  display: grid;
  gap: 16px;
}

/* Monitor da instância WAHA ativa */

.monitor-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.monitor-stat {
  display: grid;
  gap: 4px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--snow);
}

.monitor-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--slate);
}

.monitor-value {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.monitor-value::before {
  content: none;
}

.monitor-value.is-ok::before,
.monitor-value.is-bad::before {
  content: "";
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.monitor-value.is-ok::before {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(14, 203, 129, 0.15);
}

.monitor-value.is-bad::before {
  background: var(--red);
  box-shadow: 0 0 0 3px rgba(246, 70, 93, 0.15);
}

@media (max-width: 720px) {
  .monitor-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.admin-card {
  display: grid;
  gap: 20px;
}

.admin-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.admin-head .card-copy {
  margin-bottom: 0;
}

.inst-list {
  display: grid;
  gap: 10px;
}

.inst-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--snow);
}

.inst-row.is-active {
  border-color: var(--green);
}

.inst-info {
  min-width: 0;
}

.inst-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.inst-meta {
  margin: 2px 0 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--slate);
  overflow-wrap: anywhere;
}

.inst-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--border);
  color: var(--ink);
}

.inst-badge.active {
  background: var(--green);
  color: var(--on-dark);
}

.inst-badge.ok {
  background: var(--green);
  color: var(--on-dark);
}

.inst-badge.warn {
  background: var(--yellow);
  color: var(--on-yellow);
}

.inst-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.inst-form {
  margin-top: 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.inst-grid {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  gap: 12px;
}

.inst-form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.inst-sessions {
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 12px;
}

@media (max-width: 720px) {
  .inst-grid {
    grid-template-columns: 1fr;
  }

  .inst-row {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Aviso de histórico arquivado (login OTP) */

.archived-notice {
  margin: 0 0 16px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--yellow);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.45;
  color: var(--slate);
  background: var(--snow);
}

/* Exclusão definitiva local de um item do feed */

.msg-side {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.msg-forget {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--slate);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.msg-forget:hover {
  color: var(--red);
  border-color: var(--red);
  background: transparent;
}

.msg-forget:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---------- Modal (substitui alert/confirm nativos) ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(12, 14, 18, 0.55);
  backdrop-filter: blur(3px);
  animation: modal-fade 160ms ease;
}

.modal {
  width: min(480px, 100%);
  max-height: min(80vh, 640px);
  overflow: auto;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: rgba(0, 0, 0, 0.35) 0px 18px 50px -12px;
  padding: 24px;
  animation: modal-pop 180ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
}

.modal-message {
  margin: 12px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14.5px;
  font-weight: 500;
  line-height: 1.55;
  color: var(--text-2);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
}

.modal-actions .btn.square {
  padding: 10px 24px;
}

.btn.square.danger {
  background: var(--red);
  color: var(--on-dark);
}

.btn.square.danger:hover {
  background: #D93A50;
  color: var(--on-dark);
}

@keyframes modal-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-pop {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .modal-overlay,
  .modal {
    animation: none;
  }
}
