:root {
  --primary-color: #00bec8;
  --primary-color-dark: #009aa3;
  --contrast-for-primary: #fff;
  --text-color: #333;
  --secondary-color: #dd2c42;
  --dark-color: #213546;
  --header-background: linear-gradient(
    to right,
    #14171d,
    #18232d,
    #192f3c,
    #153d4b,
    #0d4b57,
    #0e4c59,
    #0e4e5a,
    #0f4f5c,
    #194353,
    #1f3847,
    #212e3a,
    #1f242d
  );
  --navy: #213546;
  --gold: #00bec8;
  --gold-lt: #33cdd5;
  --cream: #f7f9fb;
  --slate: #4a5568;
  --leaf: #00bec8;
  --leaf-dark: #009aa3;
  --mist: #c8d4e0;

  --bg: #e8eef3;
  --panel: #b1c8de;
  --sidebar: #18232d;
  --line: #c8d4e0;
  --text: var(--text-color);
  --muted: var(--slate);
  --accent: var(--primary-color);
  --accent-2: var(--primary-color-dark);
  --ok: var(--primary-color);
  --warn: #e8a317;
  --danger: var(--secondary-color);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  -webkit-tap-highlight-color: transparent;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--cream);
  color: var(--text);
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px 18px;
  border-radius: 14px;
  background: var(--header-background);
  color: #fff;
}

h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
}

.subtitle {
  color: var(--gold-lt);
  font-size: 0.8rem;
  margin-top: 2px;
}

.badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border: 1px solid var(--primary-color);
  color: var(--primary-color);
  border-radius: 999px;
  padding: 4px 10px;
  background: rgba(0, 190, 200, 0.12);
  white-space: nowrap;
  flex-shrink: 0;
}

.shell {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 14px;
  align-items: start;
}

.queue-panel {
  background: var(--panel);
  border: 1px solid var(--mist);
  border-radius: 16px;
  padding: 14px;
  min-height: 70vh;
  box-shadow: 0 8px 24px rgba(33, 53, 70, 0.08);
}

.now-card {
  background: var(--header-background);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
  color: #fff;
}

.now-label {
  display: block;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold-lt);
}

.now-name {
  font-size: 1.55rem;
  font-weight: 700;
  margin: 6px 0 10px;
  color: #fff;
}

.now-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: #e2eef2;
}

.live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: var(--primary-color);
  box-shadow: 0 0 8px var(--primary-color);
}

.count {
  opacity: 0.9;
}

.list-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 4px 2px 8px;
  font-size: 0.78rem;
  color: var(--navy);
}

.hint {
  color: var(--muted);
  font-size: 0.72rem;
}

.sync-status {
  margin: 0 2px 8px;
  font-size: 0.7rem;
  color: var(--muted);
}

.sync-status.is-error {
  color: var(--danger);
  font-weight: 600;
}

.nav-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.queue-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: calc(100vh - 280px);
  overflow-y: auto;
}

.agent-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  background: var(--cream);
  border: 1px solid var(--mist);
  border-radius: 10px;
  cursor: pointer;
}

.agent-item.is-now {
  border-color: var(--primary-color);
  background: #e6f8f9;
}

/* Nome tocado/clicado para usar no admin */
.agent-item.is-selected {
  border-color: var(--navy);
  box-shadow: inset 0 0 0 1px var(--navy);
}

.agent-main {
  min-width: 0;
  overflow-wrap: anywhere;
}

.agent-pos {
  font-size: 0.75rem;
  color: var(--slate);
  text-align: center;
}

.agent-name {
  font-size: 0.9rem;
  color: var(--navy);
  font-weight: 600;
}

.agent-meta {
  font-size: 0.7rem;
  color: var(--muted);
}

.agent-chip {
  font-size: 0.68rem;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--mist);
  color: var(--slate);
}

.chip-now {
  border-color: var(--primary-color);
  color: var(--primary-color-dark);
  background: #e6f8f9;
}

.chip-next {
  border-color: var(--navy);
  color: var(--navy);
}

.sidebar {
  background: var(--header-background);
  border: 1px solid #1f3847;
  border-radius: 18px;
  padding: 16px 14px;
  position: sticky;
  top: 12px;
  min-height: 70vh;
  color: #fff;
}

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

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--primary-color);
  color: var(--contrast-for-primary);
  box-shadow: 0 8px 18px rgba(0, 190, 200, 0.35);
}

.brand-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
}

.brand-sub {
  color: var(--gold-lt);
  font-size: 0.72rem;
  margin-top: 1px;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: #dbe7ee;
  background: rgba(15, 79, 92, 0.45);
  border: 1px solid #1f4a56;
  border-radius: 999px;
  padding: 6px 10px;
  margin-bottom: 14px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: var(--warn);
  box-shadow: 0 0 8px var(--warn);
}

.sidebar.is-open .status-dot {
  background: var(--primary-color);
  box-shadow: 0 0 8px var(--primary-color);
}

.login-copy {
  color: #b7c8d2;
  font-size: 0.78rem;
  line-height: 1.4;
  margin-bottom: 10px;
}

.login-box label,
.group-label {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--primary-color);
  margin-bottom: 7px;
}

.input-row {
  display: flex;
  gap: 6px;
}

input[type="password"],
input[type="text"] {
  width: 100%;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid #2a5560;
  background: rgba(15, 24, 32, 0.45);
  color: #fff;
  font-size: 0.85rem;
}

input[type="password"]:focus,
input[type="text"]:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 1px;
  border-color: var(--primary-color);
}

input::placeholder {
  color: #8aa0ad;
}

.admin-actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.admin-actions[hidden],
.login-box[hidden] {
  display: none !important;
}

.group {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding-top: 12px;
  border-top: 1px solid rgba(200, 212, 224, 0.18);
}

.nav-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  border: 1px solid rgba(200, 212, 224, 0.2);
  border-radius: 12px;
  padding: 9px 10px;
  background: rgba(15, 24, 32, 0.35);
  color: #fff;
  cursor: pointer;
}

@media (hover: hover) {
  .nav-btn:hover {
    border-color: var(--primary-color);
    background: rgba(0, 190, 200, 0.12);
  }

  .agent-item:hover {
    border-color: var(--primary-color);
  }
}

.nav-btn:active {
  transform: scale(0.99);
}

.nav-ico {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #213546;
  font-size: 0.85rem;
  flex-shrink: 0;
  color: #fff;
}

.nav-txt {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.nav-txt strong {
  font-size: 0.84rem;
  font-weight: 650;
  color: #fff;
}

.nav-txt small {
  font-size: 0.7rem;
  color: #a8bbc6;
}

.nav-advance {
  border-color: var(--primary-color);
  background: linear-gradient(90deg, rgba(0, 190, 200, 0.28), transparent);
}

.nav-advance .nav-ico {
  background: var(--primary-color);
  color: var(--contrast-for-primary);
}

.nav-shuffle {
  border-color: #33cdd5;
}

.nav-shuffle .nav-ico {
  background: var(--primary-color-dark);
}

.nav-add .nav-ico {
  background: var(--primary-color-dark);
}

.nav-remove {
  border-color: rgba(221, 44, 66, 0.5);
}

.nav-remove .nav-ico,
.nav-reset .nav-ico {
  background: var(--secondary-color);
}

.nav-reset {
  border-color: rgba(221, 44, 66, 0.5);
}

.nav-sair {
  border-style: dashed;
}

.btn {
  width: auto;
  border: none;
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--contrast-for-primary);
  background: var(--navy);
}

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

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

.btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

/* ---------- Tablet e celular ---------- */
@media (max-width: 900px) {
  .app {
    padding: 12px;
  }

  .shell {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  /* A fila aparece primeiro; o painel admin vem logo abaixo */
  .queue-panel {
    order: -1;
    min-height: auto;
  }

  .queue-list {
    max-height: none;
    overflow: visible;
  }

  .sidebar {
    position: static;
    min-height: 0;
    width: 100%;
  }

  /* O topo já mostra "Vinutto", não precisa repetir */
  .brand {
    display: none;
  }

  /* Botões em grade de 2 colunas */
  .group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .group-label,
  .group input[type="text"] {
    grid-column: 1 / -1;
  }

  .group-label {
    margin-bottom: 0;
  }

  .nav-btn {
    min-height: 52px;
    padding: 10px;
    touch-action: manipulation;
  }

  .nav-advance {
    grid-column: 1 / -1;
    min-height: 60px;
  }

  .nav-advance .nav-txt strong {
    font-size: 1rem;
  }

  /* 16px evita o zoom automático do iPhone ao tocar no campo */
  input[type="password"],
  input[type="text"] {
    font-size: 16px;
    min-height: 46px;
  }

  .btn {
    min-height: 46px;
    padding: 10px 16px;
    font-size: 0.95rem;
  }

  .agent-item {
    min-height: 52px;
    padding: 10px 12px;
  }

  .agent-name {
    font-size: 0.95rem;
  }

  /* "Avançar fila" fica fixo no rodapé enquanto o painel está liberado
     (celular em pé, deitado e tablet) */
  body.admin-open .nav-advance {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: auto;
    max-width: 560px;
    margin: 0 auto;
    z-index: 20;
    background: var(--primary-color-dark);
    border-color: var(--primary-color);
    box-shadow: 0 10px 30px rgba(20, 23, 29, 0.35);
  }

  body.admin-open .nav-advance .nav-ico {
    background: #fff;
    color: var(--primary-color-dark);
  }

  body.admin-open .nav-advance small {
    color: #e2f7f8;
  }

  body.admin-open .app {
    padding-bottom: calc(96px + env(safe-area-inset-bottom));
  }

  /* Com o teclado aberto (digitando um nome), o botão fixo sai da frente */
  body.admin-open:has(input:focus) .nav-advance {
    visibility: hidden;
  }
}

/* Celular deitado: pouca altura, botão fixo mais baixo */
@media (max-width: 900px) and (max-height: 500px) {
  body.admin-open .nav-advance {
    min-height: 50px;
    bottom: calc(8px + env(safe-area-inset-bottom));
  }

  body.admin-open .app {
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
  }
}

/* ---------- Celular ---------- */
@media (max-width: 600px) {
  .topbar {
    padding: 12px 14px;
    margin-bottom: 12px;
  }

  .now-card {
    padding: 14px;
  }

  .now-name {
    font-size: clamp(1.35rem, 7vw, 1.8rem);
    line-height: 1.2;
    overflow-wrap: anywhere;
  }

  .list-head .hint {
    display: none;
  }

  /* Botões compactos: ícone + título, sem a descrição */
  .nav-btn {
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    text-align: center;
  }

  .nav-txt small {
    display: none;
  }

  .nav-txt strong {
    font-size: 0.82rem;
    line-height: 1.2;
  }

  .nav-advance {
    flex-direction: row;
    gap: 10px;
  }

  .nav-advance .nav-txt small {
    display: block;
  }

  .nav-advance .nav-txt {
    text-align: left;
  }
}

/* Efeito de hover só em quem tem mouse; no toque dá feedback ao pressionar */
@media (hover: none) {
  .nav-btn:active {
    transform: scale(0.97);
    background: rgba(0, 190, 200, 0.2);
  }

  .agent-item:active {
    border-color: var(--primary-color);
  }
}
