/* Design system (estilo Apple). Única fonte de cor, raio, sombra, vidro e movimento do sistema.
   Regras do projeto: fonte Space Grotesk, SEM degradê, cartões SEM bordas coloridas. */

:root, [data-tema="claro"] {
  /* Marca */
  --navy: #0B193C;
  --gold: #C4A55A;
  --accent: #0B193C;
  --accent-hover: #1B2D5E;
  --accent-contrast: #FFFFFF;
  --accent-soft: rgba(11, 25, 60, .08);
  --ring: rgba(11, 25, 60, .35);

  /* Superfícies */
  --bg: #F5F5F7;
  --surface: #FFFFFF;
  --elevated: #FFFFFF;
  --fill: rgba(120, 120, 128, .12);
  --fill-strong: rgba(120, 120, 128, .32);
  --hover: rgba(0, 0, 0, .04);

  /* Texto (secundário a 68% para passar WCAG AA sobre o fundo cinza) */
  --text: #1D1D1F;
  --text-2: rgba(29, 29, 31, .68);
  --text-3: rgba(29, 29, 31, .30);
  --sep: rgba(60, 60, 67, .12);

  /* Status */
  --ok: #34C759;
  --warn: #FF9F0A;
  --err: #FF3B30;
  --ok-text: #1A7F4B;
  --warn-text: #9A5B00;
  --err-text: #C4291C;
  --ok-bg: rgba(52, 199, 89, .14);
  --warn-bg: rgba(255, 159, 10, .16);
  --err-bg: rgba(255, 59, 48, .12);

  /* Vidro */
  --glass: rgba(255, 255, 255, .72);
  --glass-borda: rgba(60, 60, 67, .16);
  --glass-filtro: saturate(180%) blur(20px);
  --scrim: rgba(0, 0, 0, .30);

  /* Forma e profundidade */
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-xl: 20px; --r-pill: 999px;
  --sombra-1: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .06);
  --sombra-2: 0 2px 4px rgba(0, 0, 0, .06), 0 14px 36px rgba(0, 0, 0, .10);
  --sombra-knob: 0 2px 4px rgba(0, 0, 0, .22), 0 0 1px rgba(0, 0, 0, .18);

  /* Espaçamento (múltiplos de 4) */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px;

  /* Tipografia */
  --fonte: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
  --t-34: 34px; --t-28: 28px; --t-22: 22px; --t-17: 17px; --t-15: 15px; --t-13: 13px; --t-11: 11px;

  /* Movimento */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --spring: cubic-bezier(0.34, 1.4, 0.64, 1);
  --dur-1: 120ms; --dur-2: 240ms; --dur-3: 380ms; --dur-4: 500ms;
  --deslocar: 8px;
  --apertar: .97;

  --menu-w: 240px;
  --topo-h: 56px;
  color-scheme: light;
}

@supports (transition-timing-function: linear(0, 1)) {
  :root {
    --spring: linear(0, 0.009, 0.035 2.1%, 0.141, 0.281 6.7%, 0.723 12.9%, 0.938 16.7%, 1.017, 1.077, 1.121, 1.149 24.3%, 1.159, 1.163, 1.161, 1.154 29.9%, 1.129 32.8%, 1.051 39.6%, 1.017 43.1%, 0.991, 0.977 51%, 0.974 53.8%, 0.975 57.1%, 0.997 69.8%, 1.003 76.9%, 1);
  }
}

/* Escuro: automático pelo sistema, ou manual pelo botão (data-tema no <html>) */
@media (prefers-color-scheme: dark) {
  :root:not([data-tema="claro"]) {
    --accent: #8FA6E0; --accent-hover: #A7BAEA; --accent-contrast: #0B193C;
    --accent-soft: rgba(143, 166, 224, .16); --ring: rgba(143, 166, 224, .35);
    --bg: #000000; --surface: #1C1C1E; --elevated: #2C2C2E;
    --fill: rgba(120, 120, 128, .24); --fill-strong: rgba(120, 120, 128, .48); --hover: rgba(255, 255, 255, .06);
    --text: #F5F5F7; --text-2: rgba(245, 245, 247, .62); --text-3: rgba(245, 245, 247, .30);
    --sep: rgba(84, 84, 88, .45);
    --ok-text: #30D158; --warn-text: #FFB340; --err-text: #FF6961;
    --glass: rgba(28, 28, 30, .72); --glass-borda: rgba(84, 84, 88, .5); --scrim: rgba(0, 0, 0, .5);
    --sombra-1: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .4);
    --sombra-2: 0 2px 4px rgba(0, 0, 0, .4), 0 14px 36px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}
[data-tema="escuro"] {
  --accent: #8FA6E0; --accent-hover: #A7BAEA; --accent-contrast: #0B193C;
  --accent-soft: rgba(143, 166, 224, .16); --ring: rgba(143, 166, 224, .35);
  --bg: #000000; --surface: #1C1C1E; --elevated: #2C2C2E;
  --fill: rgba(120, 120, 128, .24); --fill-strong: rgba(120, 120, 128, .48); --hover: rgba(255, 255, 255, .06);
  --text: #F5F5F7; --text-2: rgba(245, 245, 247, .62); --text-3: rgba(245, 245, 247, .30);
  --sep: rgba(84, 84, 88, .45);
  --ok-text: #30D158; --warn-text: #FFB340; --err-text: #FF6961;
  --glass: rgba(28, 28, 30, .72); --glass-borda: rgba(84, 84, 88, .5); --scrim: rgba(0, 0, 0, .5);
  --sombra-1: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .4);
  --sombra-2: 0 2px 4px rgba(0, 0, 0, .4), 0 14px 36px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

/* Reduzir movimento: some o deslocamento e a mola, fica só um fade curto */
@media (prefers-reduced-motion: reduce) {
  :root { --deslocar: 0px; --apertar: 1; --dur-1: 100ms; --dur-2: 100ms; --dur-3: 100ms; --dur-4: 100ms;
    --spring: linear; --ease-out: linear; --ease-in-out: linear; }
  .skeleton { animation: none; }
}

/* ---------- Animações (só transform e opacity) ---------- */
@keyframes entra { from { opacity: 0; transform: translateY(var(--deslocar)); } to { opacity: 1; transform: none; } }
@keyframes modal-entra { from { opacity: 0; transform: translateY(24px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes modal-sai { to { opacity: 0; transform: translateY(24px) scale(.98); } }
@keyframes sheet-entra { from { transform: translateY(100%); } to { transform: none; } }
@keyframes sheet-sai { to { transform: translateY(100%); } }
@keyframes fundo-entra { from { opacity: 0; } to { opacity: 1; } }
@keyframes fundo-sai { to { opacity: 0; } }
@keyframes toast-entra { from { opacity: 0; transform: translateY(-24px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toast-sai { to { opacity: 0; transform: translateY(-12px) scale(.98); } }
@keyframes pulso { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
@keyframes gira { to { transform: rotate(360deg); } }

.entra { animation: entra var(--dur-3) var(--ease-out) backwards; animation-delay: calc(var(--i, 0) * 35ms); }

/* ---------- Skeleton (pulso suave; sem degradê) ---------- */
.skeleton { background: var(--fill); border-radius: var(--r-md); animation: pulso 1.6s var(--ease-in-out) infinite; color: transparent; }
.skeleton.linha { height: 14px; margin: 8px 0; }
.skeleton.bloco { height: 96px; border-radius: var(--r-lg); }

/* ---------- Spinner (só dentro de botão) ---------- */
.girando::after { content: ""; width: 14px; height: 14px; margin-left: 8px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; display: inline-block; vertical-align: -2px; animation: gira .7s linear infinite; }

/* ---------- Toggle estilo iOS ---------- */
input[type=checkbox].toggle { appearance: none; -webkit-appearance: none; width: 51px !important; height: 31px; min-height: 31px; padding: 0; margin: 0; border: 0; border-radius: var(--r-pill); background: var(--fill-strong); position: relative; flex: none; cursor: pointer; transition: background var(--dur-2) var(--ease-out); }
input[type=checkbox].toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: var(--sombra-knob); transition: transform var(--dur-3) var(--spring); }
input[type=checkbox].toggle:checked { background: var(--ok); }
input[type=checkbox].toggle:checked::after { transform: translateX(20px); }
input[type=checkbox].toggle:active::after { width: 33px; }
input[type=checkbox].toggle:checked:active::after { transform: translateX(14px); }
input[type=checkbox].toggle:disabled { opacity: .5; cursor: not-allowed; }
input[type=checkbox].toggle:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--ring); }

/* ---------- Segmented control (indicador desliza) ---------- */
.segmented { position: relative; display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--fill); border-radius: var(--r-md); padding: 2px; }
.segmented::before { content: ""; position: absolute; top: 2px; bottom: 2px; left: 0; width: var(--seg-w, 0); transform: translateX(var(--seg-x, 0)); background: var(--elevated); border-radius: 8px; box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 1px 1px rgba(0, 0, 0, .06); transition: transform var(--dur-3) var(--spring), width var(--dur-3) var(--spring); }
.segmented.pronto::before { opacity: 1; }
.segmented:not(.pronto)::before { opacity: 0; }
.segmented > button { position: relative; z-index: 1; background: transparent; border: 0; color: var(--text); border-radius: 8px; padding: 6px 14px; min-height: 32px; font-size: var(--t-13); box-shadow: none; }
.segmented > button:hover { background: transparent; box-shadow: none; transform: none; }
.segmented > button:active { transform: none; }
.segmented > button.ativa { color: var(--text); }

/* ---------- Toasts ---------- */
.toasts { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(92vw, 420px); }
.toast { pointer-events: auto; background: var(--glass); backdrop-filter: var(--glass-filtro); -webkit-backdrop-filter: var(--glass-filtro); border: .5px solid var(--glass-borda); border-radius: var(--r-pill); box-shadow: var(--sombra-2); padding: 10px 18px; font-size: var(--t-15); color: var(--text); display: flex; gap: 10px; align-items: center; animation: toast-entra var(--dur-3) var(--spring); }
.toast.saindo { animation: toast-sai var(--dur-2) var(--ease-in-out) forwards; }
.toast .ponto { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.toast.erro .ponto { background: var(--err); }
.toast.aviso .ponto { background: var(--warn); }

/* ---------- Modal / bottom sheet ---------- */
.modal-fundo { position: fixed; inset: 0; background: var(--scrim); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 50; animation: fundo-entra var(--dur-3) var(--ease-out); }
.modal-fundo.saindo { animation: fundo-sai var(--dur-2) var(--ease-in-out) forwards; }
.modal { background: var(--glass); backdrop-filter: var(--glass-filtro); -webkit-backdrop-filter: var(--glass-filtro); border: .5px solid var(--glass-borda); border-radius: var(--r-xl); box-shadow: var(--sombra-2); padding: var(--s-6); width: min(440px, 92vw); color: var(--text); animation: modal-entra var(--dur-3) var(--spring); }
.modal-fundo.saindo .modal { animation: modal-sai var(--dur-2) var(--ease-in-out) forwards; }
.modal h3 { font-size: var(--t-22); letter-spacing: -0.02em; margin-bottom: var(--s-3); color: var(--text); }
.modal .acoes { margin-top: var(--s-4); justify-content: flex-end; }
.modal .puxador { display: none; }

@media (max-width: 767px) {
  .modal-fundo { align-items: flex-end; }
  .modal { width: 100%; border-radius: var(--r-xl) var(--r-xl) 0 0; padding-top: 28px; padding-bottom: calc(var(--s-6) + env(safe-area-inset-bottom)); animation: sheet-entra var(--dur-3) var(--spring); touch-action: none; position: relative; }
  .modal-fundo.saindo .modal { animation: sheet-sai var(--dur-2) var(--ease-in-out) forwards; }
  .modal::before { content: ""; position: absolute; top: 8px; left: 50%; width: 36px; height: 5px; margin-left: -18px; border-radius: var(--r-pill); background: var(--fill-strong); }
}

/* ---------- Lista agrupada (inset grouped list) ---------- */
.lista-grupo { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--sombra-1); overflow: hidden; }
.lista-grupo > .linha { display: flex; align-items: center; gap: var(--s-3); min-height: 48px; padding: 0 var(--s-4); position: relative; cursor: pointer; transition: background var(--dur-1), transform var(--dur-1); }
.lista-grupo > .linha + .linha::before { content: ""; position: absolute; top: 0; left: var(--s-4); right: 0; height: .5px; background: var(--sep); }
.lista-grupo > .linha:hover { background: var(--hover); }
.lista-grupo > .linha .rotulo { flex: 1; }
.lista-grupo > .linha .valor { color: var(--text-2); }
.lista-grupo > .linha::after { content: "›"; color: var(--text-3); font-size: 22px; line-height: 1; margin-left: var(--s-1); }
.lista-grupo > .linha.sem-seta::after { content: none; }

/* ---------- Alertas do atendente (canto inferior direito) ---------- */
.alertas { position: fixed; right: 16px; bottom: 16px; z-index: 110; display: flex; flex-direction: column; gap: 10px; width: min(92vw, 380px); pointer-events: none; }
.alerta { pointer-events: auto; background: var(--glass); backdrop-filter: var(--glass-filtro); -webkit-backdrop-filter: var(--glass-filtro); border: .5px solid var(--glass-borda); border-radius: var(--r-lg, 16px); box-shadow: var(--sombra-2); padding: 14px 16px; color: var(--text); animation: alerta-entra var(--dur-3) var(--spring); }
.alerta.urgente strong { color: var(--warn); }
.alerta.saindo { animation: alerta-sai var(--dur-2) var(--ease-in-out) forwards; }
.alerta strong { display: block; font-size: var(--t-13, 13px); letter-spacing: .02em; text-transform: uppercase; color: var(--text-2, var(--text)); margin-bottom: 6px; }
.alerta p { margin: 0 0 12px; font-size: var(--t-15); line-height: 1.4; }
.alerta .acoes { display: flex; gap: 8px; align-items: center; }
.alerta .bt-alerta { display: inline-flex; align-items: center; justify-content: center; padding: 6px 14px; border-radius: var(--r-pill); background: var(--accent); color: var(--accent-contrast); font-size: var(--t-14, 14px); font-weight: 600; text-decoration: none; }
@keyframes alerta-entra { from { opacity: 0; transform: translateY(24px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes alerta-sai { to { opacity: 0; transform: translateY(12px) scale(.98); } }
@media (max-width: 600px) { .alertas { right: 8px; left: 8px; bottom: 8px; width: auto; } }
@media (prefers-reduced-motion: reduce) { .alerta, .alerta.saindo { animation-duration: .01s; } }

/* ---------- Transferir: setor -> pessoa ---------- */
.transf-lista { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 14px; max-height: 60vh; overflow-y: auto; }
.transf-item { display: flex; align-items: center; gap: 10px; justify-content: flex-start; text-align: left; width: 100%; }
.transf-item small { color: var(--text-2); }
.bolinha { width: 9px; height: 9px; border-radius: 50%; background: var(--text-3, rgba(128,128,128,.5)); flex: none; }
.bolinha.on { background: var(--ok); }

/* Botão em forma de link (ex.: "Conversar" na lista de Contatos) */
.bt-link { display:inline-flex; align-items:center; justify-content:center; padding:6px 12px; border-radius:var(--r-pill); background:var(--accent); color:var(--accent-contrast); font-size:var(--t-13); font-weight:600; text-decoration:none; white-space:nowrap; }
.bt-link:hover { background:var(--accent-hover); }
