/* Escuro por padrão; o claro é escolha do usuário (menu ⋯, guardado no navegador, aplicado por theme.js). */
:root {
  color-scheme: dark;
  --bg: #0f141b;
  --card: #18202a;
  --card-hover: #1f2935;
  --text: #e6ebf1;
  --muted: #9aa6b4;
  --accent: #3b82f6;
  --accent-soft: rgba(59,130,246,.16);
  --accent-text: #ffffff;
  --border: #2a3441;
  --bar: #0b0f14;
  --bar-text: #e9eef5;
  --title: #222c38;
  --title-active: #2563eb;
  --error: #ff8a80;
  --ok: #56d364;
  --warn: #e3b341;
  --brand: #2f6fdb;   /* cor da empresa (whitelabel): o app.js troca esta e a --accent pela cor do Gerenciador */
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f1f4f8;
  --card: #ffffff;
  --card-hover: #f7f9fc;
  --text: #1c2430;
  --muted: #5f6b7a;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --border: #d5dce5;
  --bar: #0f172a;
  --title: #2b3a4d;
  --error: #b42318;
  --ok: #1a7f37;
  --warn: #9a6700;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.4 "Segoe UI", system-ui, sans-serif; }
[hidden] { display: none !important; }
button { font: inherit; padding: 5px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--card); color: var(--text); cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input { font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--card); color: var(--text); width: 100%; }
.muted { color: var(--muted); }
.error { color: var(--error); min-height: 1.4em; }

.login { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 24px; width: min(380px, 100%); display: grid; gap: 8px; }
.card h1 { margin: 0; font-size: 22px; }
.card h2 { margin: 0; font-size: 17px; }
.card .buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.card button.primary[type=submit] { margin-top: 6px; }

#workspace { display: flex; position: relative; z-index: 0; flex-direction: column; height: 100%; }
/* Rodapé discreto (o foco é o aplicativo): fica embaixo, baixo contraste até o mouse passar; os menus abrem para cima. */
.bar { order: 2; display: flex; align-items: center; gap: 6px; height: 30px; padding: 0 8px; background: var(--bar); color: var(--bar-text);
  border-top: 1px solid #1c2531; font-size: 12px; opacity: .72; transition: opacity .15s; }
.bar:hover, .bar:focus-within { opacity: 1; }
.bar .dropdown { top: auto; bottom: 100%; margin: 0 0 4px; }
.bar button { background: transparent; color: var(--bar-text); border-color: transparent; padding: 2px 8px; font-size: 12px; }
.bar button:hover { background: rgba(255,255,255,.08); }
.bar .pill { font-size: 11px; padding: 0 7px; }
.bar .brand { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-right: 4px; }
.logo-mini { width: 18px; height: 18px; border-radius: 5px; font-size: 11px !important; display: grid; place-items: center; background: var(--accent); color: var(--accent-text); font-size: 13px; font-weight: 700; }
.bar button.icon { width: 28px; height: 24px; padding: 0; font-size: 14px; line-height: 1; }
.dropdown.right { left: auto; right: 0; min-width: 260px; }
.menu-who { margin: 4px 8px 6px; padding-bottom: 8px; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.menu-who strong { color: var(--text); }
.dropdown .menu-item { display: block; width: 100%; text-align: left; padding: 7px 12px; border: 0; border-radius: 6px; background: transparent; color: var(--text); text-decoration: none; font-size: 14px; }
.dropdown .menu-item:hover, .dropdown .menu-item:focus-visible { background: var(--card-hover); }
.dropdown .menu-item.danger { color: var(--error); }

/* Tela inicial (igual ao cliente desktop): busca e cartões dos aplicativos */
.home { position: absolute; top: 0; right: 0; bottom: 0; left: 0; overflow: auto; padding: 40px clamp(16px, 6vw, 80px); display: flex; flex-direction: column; align-items: center; gap: 16px; }
.home > * { width: min(720px, 100%); }
.home.over { z-index: 150000; background: var(--bg); background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(3px); }
.bar .brand[aria-pressed="true"] { background: rgba(255,255,255,.12); }
.home h1 { margin: 0; font-size: 22px; font-weight: 600; }
.home input[type=search] { padding: 10px 12px; font-size: 15px; border-radius: 8px; }
.app-cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.app-card { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--card); color: var(--text); text-align: left; font-size: 15px; transition: border-color .12s, background .12s; }
.app-card:hover, .app-card:focus-visible { border-color: var(--accent); background: var(--card-hover); }
.app-card .mono { flex: none; width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 17px; }
.app-card span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .spacer { flex: 1; }
.bar .muted { color: #9fb0c3; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid #3a4757; white-space: nowrap; }
@media (max-width: 760px) { #agent-state { display: none; } }
.pill.ok { border-color: var(--ok); color: var(--ok); }
.pill.warn { border-color: var(--warn); color: var(--warn); }
.pill.bad { border-color: var(--error); color: var(--error); }
.menu { position: relative; }
.dropdown { position: absolute; top: 100%; left: 0; z-index: 300000; margin: 4px 0 0; padding: 4px; list-style: none; min-width: 240px; max-height: 70vh; overflow: auto;
  background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.dropdown button { width: 100%; text-align: left; border: 0; background: transparent; color: var(--text); }
.dropdown button:hover, .dropdown button:focus-visible { background: var(--bg); }
.dropdown .empty { padding: 6px 12px; color: var(--muted); }

.desk { position: relative; flex: 1; overflow: hidden; outline: none; touch-action: none; }   /* toque: a página faz zoom e arrasto (app.js) */
.stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.win { position: absolute; display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 6px 6px 0 0; box-shadow: 0 6px 20px rgba(0,0,0,.25); background: #000; }
.win.keyed { background: transparent; border-color: transparent; box-shadow: none; }
.win.popup { border: 0; border-radius: 0; box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.win .title { display: flex; align-items: center; gap: 6px; height: 30px; padding: 0 4px 0 10px; background: var(--title); color: #fff; user-select: none; cursor: default; border-radius: 6px 6px 0 0; touch-action: none; }
.win.active .title { background: var(--title-active); }
.win .title span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.win .title img { width: 16px; height: 16px; }
.win .title button { padding: 0 10px; height: 24px; border: 0; background: transparent; color: #fff; }
.win .title button:hover { background: rgba(255,255,255,.18); }
.win canvas { display: block; touch-action: none; image-rendering: pixelated; }
.win .grip { position: absolute; right: 0; bottom: 0; width: 14px; height: 14px; cursor: nwse-resize; touch-action: none; }
.win .held { position: absolute; top: 30px; right: 0; bottom: 0; left: 0; display: grid; place-items: center; background: rgba(0,0,0,.45); color: #fff; text-align: center; padding: 12px; }
.win.popup .held { top: 0; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 200000; max-width: min(420px, calc(100% - 32px)); }
.toast { background: var(--card); color: var(--text); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 6px; padding: 10px 12px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.warn { border-left-color: var(--warn); }
.toast.bad { border-left-color: var(--error); }
.toast-action { display: block; margin-top: 8px; }

dialog { border: 0; padding: 0; background: transparent; }
dialog::backdrop { background: rgba(0,0,0,.4); }

/* ---- portal de entrada ---- */
.portal { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); min-height: 100%; }
.portal-brand { display: flex; flex-direction: column; justify-content: center; gap: 12px; padding: 48px clamp(24px, 6vw, 96px);
  background: linear-gradient(135deg, #1f3b73 0%, #2f6fdb 60%, #3f8cff 100%);
  background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 55%, #000) 0%, var(--brand) 60%, color-mix(in srgb, var(--brand) 80%, #fff) 100%);
  color: var(--brand-text, #fff); }
.portal-brand .logo.has-img, .logo-mini.has-img { background: transparent; border: 0; width: auto; max-width: 220px; }
.portal-brand .logo.has-img { height: 72px; }
.logo-mini.has-img { max-width: 72px; }
[data-brand-logo] img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; }
.credit { margin: 6px 0 0; font-size: 11px; opacity: .8; text-align: center; }
.home .credit { margin-top: auto; padding-top: 16px; }
.portal-brand .logo { width: 64px; height: 64px; border-radius: 16px; display: grid; place-items: center; font-size: 34px; font-weight: 700;
  background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.35); }
.portal-brand h1 { margin: 0; font-size: clamp(28px, 4vw, 42px); }
.portal-brand p { margin: 0; font-size: 17px; opacity: .92; max-width: 34ch; }
.portal-brand ul { margin: 12px 0 0; padding: 0; list-style: none; display: grid; gap: 8px; opacity: .9; }
.portal-brand li::before { content: "✓"; margin-right: 8px; }
.portal-form { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 32px 16px; }
.login-card { width: min(380px, 100%); display: grid; gap: 14px; background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 28px; box-shadow: 0 10px 30px rgba(15,30,60,.10); }
.login-card h2 { margin: 0; font-size: 22px; }
.login-card .muted { margin: -6px 0 0; }
.field { display: grid; gap: 6px; }
.field label { font-weight: 600; }
.password { display: flex; gap: 6px; }
.password input { flex: 1; }
button.ghost { background: transparent; color: var(--accent); border-color: var(--border); white-space: nowrap; }
button.wide { width: 100%; padding: 9px; font-weight: 600; }
button:disabled { opacity: .6; cursor: progress; }
.check { display: flex; align-items: center; gap: 8px; font-weight: normal; }
.check input { width: auto; }
.hint { margin: 0; font-size: 12px; color: var(--muted); }
.hint.warn { color: var(--warn); }
.error:empty { display: none; }
.error { margin: 0; padding: 8px 10px; border-radius: 6px; background: rgba(255,80,80,.12); background: color-mix(in srgb, var(--error) 12%, transparent); }
.portal-form footer { font-size: 12px; }
.portal-loading { display: grid; place-items: center; align-content: center; gap: 12px; min-height: 100%; padding: 16px; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid var(--border); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* Aba de um aplicativo enquanto ele abre: no lugar da lista, some esmaecendo quando a janela chega . */
.launch { position: absolute; inset: 0; z-index: 140000; display: grid; place-items: center; align-content: center; gap: 14px; padding: 16px; text-align: center;
  background: var(--bg); transition: opacity 0.25s ease; animation: fade-in 0.2s ease; }
.launch.done { opacity: 0; pointer-events: none; }
.launch h1 { margin: 0; font-size: 20px; font-weight: 600; }
.launch p { margin: 0; }
.launch .mono { width: 64px; height: 64px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 30px; border-radius: 16px; }
@keyframes fade-in { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .launch { animation: none; transition: none; } }
@media (max-width: 760px) {
  .portal { grid-template-columns: 1fr; }
  .portal-brand { padding: 24px 16px; }
  .portal-brand ul, .portal-brand p { display: none; }
}
.sink { position: fixed; left: -1000px; top: 0; width: 10px; height: 10px; opacity: 0; font-size: 16px; }   /* 16px: o iOS não dá zoom ao focar */
.alt-actions { display: grid; gap: 6px; }
.button-link { display: block; text-align: center; padding: 7px; border: 1px solid var(--border); border-radius: 6px; color: var(--accent); text-decoration: none; }
.button-link:hover { background: var(--bg); }
.bar-link { color: var(--bar-text); font-size: 12px; }

/* ---- navegadores antigos ---- */
/* <dialog> sem suporte (iOS < 15.4): o shim do app.js só põe/tira o atributo open. */
dialog:not([open]) { display: none; }
dialog[open] { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 400000; margin: 0; width: min(380px, calc(100% - 32px)); }

/* ---- estado da conexão: um ponto colorido e texto curto ---- */
.pill::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: currentColor; vertical-align: 1px; }
.pill.ok { border-color: transparent; }   /* tudo certo não chama atenção; aviso e erro ficam com borda */
.touch-only { display: none; }

/* ---- celular e tablet ---- */
.bar-handle { display: none; }
@media (pointer: coarse) {
  /* App aberto: ele ocupa a tela toda; o rodapé fica escondido e aparece pelo botão ⋯ do canto (por cima do app). */
  #workspace.immersive .bar { position: absolute; left: 0; right: 0; bottom: 0; z-index: 250000; transform: translateY(110%); transition: transform .18s; }
  #workspace.immersive.bar-open .bar { transform: none; }
  #workspace.immersive:not(.bar-open) .bar-handle { display: grid; place-items: center; position: fixed; right: 6px;
    bottom: calc(6px + env(safe-area-inset-bottom)); z-index: 250001; width: 34px; height: 34px; padding: 0; border: 0; border-radius: 50%;
    background: rgba(15, 20, 27, .45); color: #fff; font-size: 18px; line-height: 1; }
  #workspace.immersive .toasts { bottom: 48px; }
  .win .title, .win .grip { display: none; }   /* sem barra de título no celular (TITLE_H = 0 no app.js) */
  .win, .win .held { border-radius: 0; }
  .win .held { top: 0; }
  .touch-only { display: inline-block; }
  .bar { height: 44px; padding: 0 max(8px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(8px, env(safe-area-inset-left));
    box-sizing: content-box; opacity: 1; }
  .bar button.icon { width: 40px; height: 36px; font-size: 18px; }
  .bar .brand { padding: 4px 10px; min-height: 36px; }
  .dropdown .menu-item { padding: 12px 14px; }
  input, .home input[type=search] { font-size: 16px; }   /* menor que 16px o iOS dá zoom ao focar */
  .win .title { height: 30px; }
  .win .title button { min-width: 40px; }
  .win .grip { width: 24px; height: 24px; }
  .toasts { bottom: 56px; }
}
@media (max-width: 760px) {
  .bar .brand .label { display: none; }
  .bar .pill { font-size: 0; padding: 0 4px; border: 0; }   /* só o ponto; o texto continua no title e no leitor de tela */
  .bar .pill::before { width: 10px; height: 10px; margin: 0; }
  .toasts { left: 12px; right: 12px; max-width: none; }
  .home { padding: 20px 12px; }
  .home h1 { font-size: 19px; }
  .app-cards { grid-template-columns: 1fr; }
  .app-card { padding: 14px; min-height: 56px; }
  .login-card { padding: 20px; }
}

/* Cursor de texto do app (recurso 'caret'): invertido sobre o fundo e piscando como o do Windows (530 ms). */
.win .caret { position: absolute; pointer-events: none; background: #fff; mix-blend-mode: difference; animation: caret-blink 1.06s steps(1) infinite; }
@keyframes caret-blink { 50% { opacity: 0; } }
/* Celular deitado: a altura é pouca, o rodapé encolhe para sobrar mais para o aplicativo. */
@media (pointer: coarse) and (max-height: 480px) {
  .bar { height: 32px; }
  .bar button.icon { height: 30px; }
  .bar .brand { min-height: 30px; padding: 2px 8px; }
  .toasts { bottom: 40px; }
}
