/**
 * Gestão de Entradas — design system partilhado (painéis super admin, entidade e portaria).
 * Baseado no admin do Toduma Customer Care: variáveis estilo shadcn, sidebar escura, fonte Inter.
 */
:root{
  --primary:#1a73e8;
  --primary-hover:#1557b0;
  --primary-foreground:#fff;
  --primary-light:rgba(26,115,232,.10);
  --primary-shadow:rgba(26,115,232,.25);
  --accent:#60a5fa;

  --background:#f6f7fb;
  --foreground:#0f172a;
  --card:#fff;
  --border:#e2e8f0;
  --muted:#f1f5f9;
  --muted-foreground:#64748b;

  --destructive:#da2321;
  --destructive-light:rgba(218,35,33,.10);
  --success:#10b981;
  --success-light:rgba(16,185,129,.12);
  --warning:#f59e0b;
  --warning-light:rgba(245,158,11,.14);
  --info:#0ea5e9;
  --info-light:rgba(14,165,233,.12);

  --radius:12px;
  --radius-sm:8px;
  --radius-lg:16px;
  --shadow-sm:0 1px 2px rgba(15,23,42,.06);
  --shadow:0 4px 16px rgba(15,23,42,.08);
  --shadow-lg:0 20px 50px rgba(15,23,42,.18);

  --sidebar-bg:#0f1729;
  --sidebar-fg:#e5e7eb;
  --sidebar-muted:#94a3b8;
  --sidebar-border:rgba(255,255,255,.08);
  --sidebar-w:264px;
}

*{box-sizing:border-box;margin:0;padding:0}
html,body{min-height:100%}
body{font-family:'Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;color:var(--foreground);background:var(--background);line-height:1.55;font-size:15px;-webkit-font-smoothing:antialiased}
h1,h2,h3,h4{font-weight:700;line-height:1.25}
h1{font-size:1.6rem}h2{font-size:1.25rem}h3{font-size:1.05rem}
a{color:var(--primary);text-decoration:none}
a:hover{text-decoration:underline}
img{max-width:100%;display:block}
[hidden]{display:none!important}
i[data-lucide],svg.lucide{width:18px;height:18px;stroke-width:2;flex-shrink:0}

/* Utilitários */
.flex{display:flex}.grid{display:grid}.items-center{align-items:center}.justify-between{justify-content:space-between}.justify-end{justify-content:flex-end}
.wrap{flex-wrap:wrap}.gap-1{gap:.25rem}.gap-2{gap:.5rem}.gap-3{gap:.75rem}.gap-4{gap:1rem}.gap-6{gap:1.5rem}
.mt-1{margin-top:.25rem}.mt-2{margin-top:.5rem}.mt-3{margin-top:.75rem}.mt-4{margin-top:1rem}.mt-6{margin-top:1.5rem}
.mb-1{margin-bottom:.25rem}.mb-2{margin-bottom:.5rem}.mb-3{margin-bottom:.75rem}.mb-4{margin-bottom:1rem}.mb-6{margin-bottom:1.5rem}
.w-full{width:100%}.grow{flex:1}.text-right{text-align:right}.text-center{text-align:center}
.text-sm{font-size:.875rem}.text-xs{font-size:.75rem}.text-lg{font-size:1.125rem}.text-2xl{font-size:1.5rem}.font-bold{font-weight:700}.font-semibold{font-weight:600}
.text-muted{color:var(--muted-foreground)}.text-danger{color:var(--destructive)}.text-success{color:var(--success)}.text-warning{color:#b45309}
.mono{font-family:ui-monospace,SFMono-Regular,Consolas,monospace;letter-spacing:.02em}
.truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.cols-2{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:1rem}
.cols-3{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:1rem}
.cols-4{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:1rem}
.cols-2>*,.cols-3>*,.cols-4>*{min-width:0}
@media (max-width:900px){.cols-3,.cols-4{grid-template-columns:repeat(2,minmax(0,1fr))}}
@media (max-width:600px){.cols-2,.cols-3,.cols-4{grid-template-columns:minmax(0,1fr)}}

/* ---------- Shell (sidebar + conteúdo) ---------- */
.shell{min-height:100vh;display:grid;grid-template-columns:var(--sidebar-w) 1fr}
.sidebar{position:sticky;top:0;height:100vh;background:var(--sidebar-bg);color:var(--sidebar-fg);display:flex;flex-direction:column;border-right:1px solid var(--sidebar-border);z-index:40}
.sidebar__brand{display:flex;align-items:center;gap:.75rem;padding:1.1rem 1rem;border-bottom:1px solid var(--sidebar-border)}
.sidebar__logo{width:40px;height:40px;border-radius:12px;background:rgba(96,165,250,.14);display:flex;align-items:center;justify-content:center;color:var(--accent)}
.sidebar__title{font-weight:800;color:var(--accent);font-size:1rem;line-height:1.2}
.sidebar__subtitle{font-size:.75rem;color:var(--sidebar-muted)}
.sidebar__nav{flex:1;overflow:auto;padding:.75rem;display:flex;flex-direction:column;gap:.2rem}
.sidebar__group{font-size:.68rem;text-transform:uppercase;letter-spacing:.08em;color:var(--sidebar-muted);padding:.9rem .75rem .35rem}
.nav-item{display:flex;align-items:center;gap:.65rem;padding:.6rem .75rem;border-radius:10px;color:var(--sidebar-fg);border:1px solid transparent;font-size:.9rem;transition:background .15s}
.nav-item:hover{background:rgba(255,255,255,.06);text-decoration:none}
.nav-item.ativo{background:rgba(96,165,250,.12);border-color:rgba(96,165,250,.28);color:#fff}
.nav-item.ativo i,.nav-item.ativo svg{color:var(--accent)}
.sidebar__footer{padding:.9rem 1rem;border-top:1px solid var(--sidebar-border);font-size:.8rem;color:var(--sidebar-muted)}

.main{min-width:0;display:flex;flex-direction:column}
.topbar{position:sticky;top:0;z-index:30;height:60px;display:flex;align-items:center;gap:.75rem;padding:0 1.5rem;background:rgba(255,255,255,.9);backdrop-filter:blur(8px);border-bottom:1px solid var(--border)}
.topbar__title{font-weight:700;font-size:1.05rem;flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.btn.topbar__menu{display:none}
.conteudo{padding:1.5rem;max-width:1400px;width:100%;margin:0 auto}
.page-header{display:flex;align-items:flex-start;justify-content:space-between;gap:1rem;flex-wrap:wrap;margin-bottom:1.25rem}
.page-header p{color:var(--muted-foreground);font-size:.9rem;margin-top:.2rem}

.user-chip{display:flex;align-items:center;gap:.5rem;padding:.3rem .5rem .3rem .3rem;border-radius:999px;border:1px solid var(--border);background:var(--card);cursor:pointer;font-size:.85rem}
.avatar{width:30px;height:30px;border-radius:999px;background:var(--primary-light);color:var(--primary);display:inline-flex;align-items:center;justify-content:center;font-weight:700;font-size:.8rem;flex-shrink:0;overflow:hidden}
.avatar img{width:100%;height:100%;object-fit:cover}
.avatar--lg{width:56px;height:56px;font-size:1.1rem}
.avatar--xl{width:96px;height:96px;font-size:1.6rem}

.menu{position:absolute;right:0;top:calc(100% + 6px);min-width:200px;background:var(--card);border:1px solid var(--border);border-radius:var(--radius);box-shadow:var(--shadow);padding:.35rem;z-index:60}
.menu button,.menu a{display:flex;width:100%;align-items:center;gap:.5rem;padding:.55rem .7rem;border:0;background:none;border-radius:8px;font:inherit;font-size:.9rem;color:var(--foreground);cursor:pointer;text-align:left}
.menu button:hover,.menu a:hover{background:var(--muted);text-decoration:none}

.backdrop{display:none}
@media (max-width:1000px){
  .shell{grid-template-columns:1fr}
  .sidebar{position:fixed;left:0;top:0;bottom:0;width:var(--sidebar-w);transform:translateX(-100%);transition:transform .2s}
  .sidebar.aberta{transform:none}
  .backdrop.aberto{display:block;position:fixed;inset:0;background:rgba(15,23,42,.45);z-index:35}
  .btn.topbar__menu{display:inline-flex}
  .user-chip .truncate{display:none}
  .conteudo{padding:1rem}
  .topbar{padding:0 1rem}
}

/* ---------- Faixas / alertas ---------- */
.alerta{display:flex;gap:.65rem;align-items:flex-start;padding:.8rem 1rem;border-radius:var(--radius);border:1px solid;font-size:.9rem}
.alerta--info{background:var(--info-light);border-color:rgba(14,165,233,.3);color:#075985}
.alerta--sucesso{background:var(--success-light);border-color:rgba(16,185,129,.3);color:#065f46}
.alerta--aviso{background:var(--warning-light);border-color:rgba(245,158,11,.35);color:#92400e}
.alerta--erro{background:var(--destructive-light);border-color:rgba(218,35,33,.3);color:#991b1b}
.faixa{padding:.6rem 1.5rem;font-size:.88rem;display:flex;gap:.75rem;align-items:center;justify-content:center;flex-wrap:wrap}
.faixa--aviso{background:#fef3c7;color:#92400e;border-bottom:1px solid #fde68a}
.faixa--erro{background:#fee2e2;color:#991b1b;border-bottom:1px solid #fecaca}

/* ---------- Cartões ---------- */
.card{background:var(--card);border:1px solid var(--border);border-radius:var(--radius-lg);box-shadow:var(--shadow-sm)}
.card__header{display:flex;align-items:center;justify-content:space-between;gap:.75rem;padding:1rem 1.25rem;border-bottom:1px solid var(--border);flex-wrap:wrap}
.card__header h2,.card__header h3{font-size:1rem}
.card__body{padding:1.25rem}
.card__footer{padding:.9rem 1.25rem;border-top:1px solid var(--border);display:flex;justify-content:flex-end;gap:.5rem;flex-wrap:wrap}
.stat{padding:1.1rem 1.25rem;display:flex;gap:.9rem;align-items:center}
.stat__icone{width:44px;height:44px;border-radius:12px;display:flex;align-items:center;justify-content:center;background:var(--primary-light);color:var(--primary);flex-shrink:0}
.stat__icone--sucesso{background:var(--success-light);color:var(--success)}
.stat__icone--aviso{background:var(--warning-light);color:#b45309}
.stat__icone--info{background:var(--info-light);color:var(--info)}
.stat__valor{font-size:1.5rem;font-weight:800;line-height:1.1}
.stat__rotulo{font-size:.8rem;color:var(--muted-foreground)}
.progresso{height:8px;background:var(--muted);border-radius:999px;overflow:hidden}
.progresso > span{display:block;height:100%;background:var(--primary);border-radius:999px}
.progresso--aviso > span{background:var(--warning)}
.progresso--erro > span{background:var(--destructive)}

/* ---------- Botões ---------- */
.btn{display:inline-flex;align-items:center;justify-content:center;gap:.45rem;padding:.55rem 1rem;border-radius:10px;border:1px solid transparent;font:inherit;font-size:.9rem;font-weight:600;cursor:pointer;white-space:nowrap;transition:background .15s,border-color .15s,box-shadow .15s;background:var(--primary);color:var(--primary-foreground);line-height:1.3}
.btn:hover{background:var(--primary-hover);text-decoration:none}
.btn:focus-visible{outline:none;box-shadow:0 0 0 3px var(--primary-shadow)}
.btn:disabled{opacity:.55;cursor:not-allowed}
.btn--secundario{background:var(--card);color:var(--foreground);border-color:var(--border)}
.btn--secundario:hover{background:var(--muted)}
.btn--fantasma{background:transparent;color:var(--foreground)}
.btn--fantasma:hover{background:var(--muted)}
.btn--perigo{background:var(--destructive)}
.btn--perigo:hover{background:#b91c1c}
.btn--sucesso{background:var(--success)}
.btn--sucesso:hover{background:#059669}
.btn--sm{padding:.35rem .7rem;font-size:.82rem;border-radius:8px}
.btn--lg{padding:.8rem 1.4rem;font-size:1rem;border-radius:12px}
.btn--icone{padding:.45rem;width:36px;height:36px}
.btn--bloco{width:100%}
.btn.a-carregar{position:relative;color:transparent!important;pointer-events:none}
.btn.a-carregar::after{content:"";position:absolute;width:16px;height:16px;border:2px solid rgba(255,255,255,.6);border-top-color:#fff;border-radius:50%;animation:rodar .7s linear infinite}
.btn--secundario.a-carregar::after,.btn--fantasma.a-carregar::after{border-color:rgba(15,23,42,.2);border-top-color:var(--foreground)}
@keyframes rodar{to{transform:rotate(360deg)}}

/* ---------- Formulários ---------- */
.campo{display:flex;flex-direction:column;gap:.35rem;margin-bottom:1rem}
.campo > label,.rotulo{font-size:.85rem;font-weight:600;color:var(--foreground)}
.campo .ajuda{font-size:.78rem;color:var(--muted-foreground)}
.campo .erro-campo{font-size:.78rem;color:var(--destructive)}
.obrigatorio::after{content:" *";color:var(--destructive)}
.input,.select,.textarea{width:100%;padding:.6rem .75rem;border:1px solid var(--border);border-radius:10px;font:inherit;font-size:.92rem;background:#fff;color:var(--foreground);transition:border-color .15s,box-shadow .15s}
.input:focus,.select:focus,.textarea:focus{outline:none;border-color:var(--primary);box-shadow:0 0 0 3px var(--primary-light)}
.input.invalido,.select.invalido,.textarea.invalido{border-color:var(--destructive)}
.textarea{min-height:90px;resize:vertical}
.input--grande{font-size:1.25rem;padding:.85rem 1rem;letter-spacing:.03em}
.check{display:flex;align-items:flex-start;gap:.55rem;font-size:.9rem;cursor:pointer}
.check input{margin-top:.2rem;width:16px;height:16px;accent-color:var(--primary);flex-shrink:0}
.chips{display:flex;flex-wrap:wrap;gap:.4rem}
.chip{display:inline-flex;align-items:center;gap:.35rem;padding:.35rem .7rem;border-radius:999px;border:1px solid var(--border);background:#fff;font-size:.85rem;cursor:pointer;user-select:none}
.chip input{display:none}
.chip.sel,.chip:has(input:checked){background:var(--primary-light);border-color:var(--primary);color:var(--primary);font-weight:600}
.filtros{display:flex;flex-wrap:wrap;gap:.6rem;align-items:flex-end}
.filtros .campo{margin:0;min-width:150px}
.pesquisa{position:relative}
.pesquisa i,.pesquisa svg{position:absolute;left:.7rem;top:50%;transform:translateY(-50%);color:var(--muted-foreground)}
.pesquisa .input{padding-left:2.2rem}

/* ---------- Tabelas ---------- */
.tabela-wrap{overflow-x:auto}
.tabela{width:100%;border-collapse:collapse;font-size:.88rem}
.tabela th{text-align:left;font-weight:600;font-size:.76rem;text-transform:uppercase;letter-spacing:.04em;color:var(--muted-foreground);background:var(--muted);padding:.65rem .9rem;border-bottom:1px solid var(--border);white-space:nowrap}
.tabela td{padding:.7rem .9rem;border-bottom:1px solid var(--border);vertical-align:middle}
.tabela tbody tr:hover{background:#fafbfd}
.tabela tr.clicavel{cursor:pointer}
.tabela .acoes{text-align:right;white-space:nowrap}
.paginacao{display:flex;align-items:center;justify-content:space-between;gap:.75rem;padding:.8rem 1.25rem;font-size:.85rem;color:var(--muted-foreground);flex-wrap:wrap}

/* ---------- Badges ---------- */
.badge{display:inline-flex;align-items:center;gap:.3rem;padding:.18rem .55rem;border-radius:999px;font-size:.74rem;font-weight:600;background:var(--muted);color:var(--muted-foreground);white-space:nowrap}
.badge--primario{background:var(--primary-light);color:var(--primary)}
.badge--sucesso{background:var(--success-light);color:#047857}
.badge--aviso{background:var(--warning-light);color:#b45309}
.badge--erro{background:var(--destructive-light);color:var(--destructive)}
.badge--info{background:var(--info-light);color:#0369a1}
.ponto{width:8px;height:8px;border-radius:999px;display:inline-block;background:currentColor}

/* ---------- Tabs ---------- */
.tabs{display:flex;gap:.25rem;border-bottom:1px solid var(--border);margin-bottom:1rem;overflow-x:auto}
.tab{padding:.6rem .9rem;border:0;background:none;font:inherit;font-size:.9rem;font-weight:600;color:var(--muted-foreground);border-bottom:2px solid transparent;cursor:pointer;white-space:nowrap}
.tab.ativo{color:var(--primary);border-bottom-color:var(--primary)}

/* ---------- Modal ---------- */
.modal-fundo{position:fixed;inset:0;background:rgba(15,23,42,.5);display:flex;align-items:flex-start;justify-content:center;padding:4vh 1rem;z-index:100;overflow:auto;animation:aparecer .15s}
.modal{background:var(--card);border-radius:var(--radius-lg);box-shadow:var(--shadow-lg);width:100%;max-width:560px;display:flex;flex-direction:column;max-height:92vh}
.modal--largo{max-width:820px}
.modal--estreito{max-width:420px}
.modal__header{display:flex;align-items:center;justify-content:space-between;gap:1rem;padding:1rem 1.25rem;border-bottom:1px solid var(--border)}
.modal__header h2{font-size:1.05rem}
.modal__body{padding:1.25rem;overflow:auto}
.modal__footer{padding:.9rem 1.25rem;border-top:1px solid var(--border);display:flex;justify-content:flex-end;gap:.5rem;flex-wrap:wrap}
@keyframes aparecer{from{opacity:0}to{opacity:1}}

/* ---------- Toasts ---------- */
.toasts{position:fixed;right:1rem;bottom:1rem;display:flex;flex-direction:column;gap:.5rem;z-index:200;max-width:min(420px,calc(100vw - 2rem))}
.toast{display:flex;gap:.6rem;align-items:flex-start;padding:.8rem 1rem;border-radius:12px;background:#0f172a;color:#fff;box-shadow:var(--shadow-lg);font-size:.9rem;animation:subir .2s}
.toast--sucesso{background:#065f46}.toast--erro{background:#991b1b}.toast--aviso{background:#92400e}
@keyframes subir{from{transform:translateY(10px);opacity:0}to{transform:none;opacity:1}}

/* ---------- Estados ---------- */
.vazio{padding:2.5rem 1rem;text-align:center;color:var(--muted-foreground)}
.vazio i,.vazio svg{width:40px;height:40px;margin:0 auto .75rem;display:block;opacity:.5}
.carregando{padding:2.5rem;display:flex;justify-content:center}
.spinner{width:28px;height:28px;border:3px solid var(--muted);border-top-color:var(--primary);border-radius:50%;animation:rodar .7s linear infinite}
.esqueleto{background:linear-gradient(90deg,var(--muted),#e9eef5,var(--muted));background-size:200% 100%;animation:brilho 1.2s infinite;border-radius:8px;min-height:1rem}
@keyframes brilho{to{background-position:-200% 0}}

/* ---------- Diversos ---------- */
.lista-def{display:grid;grid-template-columns:max-content 1fr;gap:.45rem 1rem;font-size:.9rem}
.lista-def dt{color:var(--muted-foreground)}
.separador{height:1px;background:var(--border);margin:1rem 0}
.camera{position:relative;background:#0b1220;border-radius:var(--radius-lg);overflow:hidden;aspect-ratio:4/3}
.camera video,.camera img,.camera canvas{width:100%;height:100%;object-fit:cover}
.camera__guia{position:absolute;inset:12% 25%;border:3px dashed rgba(255,255,255,.55);border-radius:50%;pointer-events:none}
.kbd{display:inline-block;padding:.05rem .4rem;border:1px solid var(--border);border-bottom-width:2px;border-radius:6px;font-size:.78rem;background:#fff}

/* Página de autenticação (entrar, registo) */
.auth{min-height:100vh;display:grid;grid-template-columns:1.1fr 1fr}
.auth__lado{background:linear-gradient(145deg,#0f1729 0%,#1a3a7a 60%,#1a73e8 100%);color:#fff;padding:3rem;display:flex;flex-direction:column;justify-content:space-between}
.auth__form{display:flex;align-items:center;justify-content:center;padding:2rem 1rem}
.auth__caixa{width:100%;max-width:420px}
@media (max-width:900px){.auth{grid-template-columns:1fr}.auth__lado{display:none}}
