/* ============================================================================
   NextLayer — Componentes reutilizáveis
   ========================================================================== */

/* ---- Botões ------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-2);
  height: 36px; padding: 0 var(--space-4);
  font-size: var(--text-sm); font-weight: var(--fw-medium);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
  user-select: none;
}
.btn:active { transform: translateY(0.5px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn .icon { width: 16px; height: 16px; }

.btn-primary { background: var(--brand); color: var(--brand-contrast); box-shadow: var(--shadow-1); }
.btn-primary:hover { background: var(--brand-hover); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-1); }
.btn-secondary:hover { background: var(--surface-2); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { filter: brightness(0.97); }

.btn-sm { height: 30px; padding: 0 var(--space-3); font-size: var(--text-xs); border-radius: var(--radius-sm); }
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 30px; }

/* ---- Inputs ------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field label { font-size: var(--text-sm); font-weight: var(--fw-medium); color: var(--text); }
/* Tooltip (hover/foco) com bolha multi-linha */
.tip { position: relative; display: inline-flex; vertical-align: middle; color: var(--text-faint); cursor: help; outline: none; }
.tip:hover, .tip:focus { color: var(--text-muted); }
.tip .icon { width: 14px; height: 14px; }
.tip-bubble {
  position: absolute; left: 0; top: calc(100% + 6px); z-index: 80; width: max-content; max-width: 300px;
  white-space: pre-line; font-size: var(--text-xs); font-weight: var(--fw-regular); line-height: 1.5; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-3); padding: var(--space-3); opacity: 0; visibility: hidden;
  transition: opacity var(--dur-fast) var(--ease); pointer-events: none;
}
.tip:hover .tip-bubble, .tip:focus .tip-bubble { opacity: 1; visibility: visible; }
.field .hint { font-size: var(--text-xs); color: var(--text-faint); }

.input, .select, .textarea {
  width: 100%;
  height: 38px; padding: 0 var(--space-3);
  font-size: var(--text-sm);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.textarea { height: auto; min-height: 80px; padding: var(--space-3); resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.select { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%239a968d' stroke-width='1.4' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px;
}

.input-search { position: relative; }
.input-search .input { padding-left: 34px; }
.input-search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-faint); pointer-events: none; }

/* Toggle / switch */
.switch { position: relative; display: inline-flex; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; border-radius: 999px;
  background: var(--border-strong); transition: background var(--dur) var(--ease);
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: var(--shadow-1); transition: transform var(--dur) var(--ease);
}
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--brand-soft); }

/* ---- Cards -------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  min-width: 0; /* permite encolher dentro de grid/flex (evita estouro por tabela larga) */
}
.card-pad { padding: var(--space-5); }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}
.card-head h3 { font-size: var(--text-md); }

/* ---- Badges & chips ----------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 9px;
  font-size: var(--text-xs); font-weight: var(--fw-medium);
  border-radius: var(--radius-full);
  background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge .badge-ic { width: 13px; height: 13px; flex: none; opacity: 0.8; }
/* Chip de consumo pessoal no topbar */
.usage-chip { height: 28px; padding: 0 10px; cursor: default; flex: none; }
.usage-chip .icon { width: 14px; height: 14px; flex: none; }
.badge-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-warn    { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-danger  { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge-info    { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge-brand   { background: var(--brand-soft); color: var(--brand); border-color: transparent; }

/* ---- Tabelas ------------------------------------------------------------ */
.table-wrap { overflow-x: auto; max-width: 100%; border-radius: var(--radius-lg); border: 1px solid var(--border); background: var(--surface); }
table.tbl { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.tbl thead th {
  text-align: left; font-weight: var(--fw-medium); color: var(--text-muted);
  font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border); background: var(--surface-2);
  white-space: nowrap;
}
.tbl tbody td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr { transition: background var(--dur-fast) var(--ease); }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl .col-actions { text-align: right; white-space: nowrap; }
/* tabela que rola na horizontal no mobile em vez de quebrar células */
.tbl-nowrap tbody td { white-space: nowrap; }

/* ---- Linha "info à esquerda + ações à direita" (responsiva) ------------- */
/* Usada em SSO, sessões, templates, preferências, etc. O bloco de texto
   encolhe e trunca; as ações nunca se deformam e quebram para baixo no mobile. */
.info-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4); flex-wrap: wrap;
}
.info-id { display: flex; align-items: center; gap: var(--space-3); flex: 1 1 200px; min-width: 0; }
.info-id .col { min-width: 0; }
.info-id strong, .info-id .ir-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.info-actions { display: flex; align-items: center; gap: var(--space-3); flex: none; }
@media (max-width: 560px) {
  .info-actions { width: 100%; justify-content: flex-start; }
  .info-actions .switch { margin-left: auto; }
}

/* SSO usa o mesmo padrão (mantido por compatibilidade do markup atual) */
.sso-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4); flex-wrap: wrap;
  padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border);
}
.sso-id { display: flex; align-items: center; gap: var(--space-3); flex: 1 1 200px; min-width: 0; }
.sso-actions { display: flex; align-items: center; gap: var(--space-3); flex: none; }
@media (max-width: 560px) {
  .sso-actions { width: 100%; justify-content: flex-start; }
  .sso-actions .switch { margin-left: auto; }
}

/* ---- Avatar ------------------------------------------------------------- */
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: var(--text-xs); font-weight: var(--fw-semibold);
  background: var(--brand-soft); color: var(--brand);
  letter-spacing: 0.02em;
}
.avatar-sm { width: 24px; height: 24px; font-size: 10px; }
.avatar-lg { width: 44px; height: 44px; font-size: var(--text-sm); }

/* ---- Tabs --------------------------------------------------------------- */
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; flex: none; padding: var(--space-3) var(--space-3) calc(var(--space-3) - 1px);
  font-size: var(--text-sm); font-weight: var(--fw-medium); color: var(--text-muted);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--brand); }

/* ---- Segmented control -------------------------------------------------- */
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: var(--radius-md); border: 1px solid var(--border); }
.segmented button {
  padding: 5px 12px; font-size: var(--text-xs); font-weight: var(--fw-medium);
  border-radius: var(--radius-sm); color: var(--text-muted);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

/* ---- Modal -------------------------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(20,18,15,0.40);
  display: flex; align-items: center; justify-content: center; padding: var(--space-4);
  animation: fade-in var(--dur) var(--ease);
}
.modal {
  width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-3);
  animation: modal-in var(--dur) var(--ease);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-5) var(--space-5) var(--space-3); }
.modal-body { padding: 0 var(--space-5) var(--space-3); display: flex; flex-direction: column; gap: var(--space-4); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--space-3); padding: var(--space-4) var(--space-5) var(--space-5); }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.99); } to { opacity: 1; transform: none; } }

/* ---- Toasts ------------------------------------------------------------- */
.toast-stack { position: fixed; bottom: var(--space-5); right: var(--space-5); z-index: 200; display: flex; flex-direction: column; gap: var(--space-2); }
.toast {
  display: flex; align-items: center; gap: var(--space-3);
  min-width: 260px; max-width: 380px; padding: var(--space-3) var(--space-4);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-3);
  font-size: var(--text-sm);
  animation: toast-in var(--dur) var(--ease);
}
.toast .bar { width: 3px; align-self: stretch; border-radius: 3px; background: var(--brand); }
.toast.success .bar { background: var(--success); }
.toast.danger .bar { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

/* ---- Dropdown / menu ---------------------------------------------------- */
/* ---- Multi-select com busca -------------------------------------------- */
.msel { position: relative; }
.msel-control { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; min-height: 38px; padding: 4px 8px; border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--surface); cursor: text; }
.msel-control:focus-within { border-color: var(--brand); }
.msel-tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 8px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: var(--text-xs); }
.msel-tag button { display: inline-flex; color: var(--text-faint); }
.msel-tag button:hover { color: var(--danger); }
.msel-tag .icon { width: 12px; height: 12px; }
.msel-input { flex: 1; min-width: 90px; border: none; outline: none; background: transparent; font-size: var(--text-sm); padding: 3px 2px; color: var(--text); }
.msel-menu { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 70; max-height: 200px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-3); padding: 4px; }
.msel-opt { display: flex; align-items: center; gap: var(--space-2); padding: 6px 8px; border-radius: var(--radius-sm); font-size: var(--text-sm); cursor: pointer; }
.msel-opt:hover { background: var(--surface-2); }
.msel-opt.sel { color: var(--brand); font-weight: var(--fw-medium); }
.msel-opt .check { margin-left: auto; opacity: 0; }
.msel-opt .check .icon { width: 14px; height: 14px; }
.msel-opt.sel .check { opacity: 1; }
.msel-empty { padding: 6px 8px; font-size: var(--text-xs); color: var(--text-faint); }
.msel-group { padding: 8px 8px 3px; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint); font-weight: var(--fw-medium); }
.msel-group:first-child { padding-top: 3px; }

/* ---- Autocomplete (single-select com busca) ---------------------------- */
.ac { position: relative; }
.ac-control { position: relative; }
.ac-control .ac-input { padding-right: 30px; }
.ac-clear { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; color: var(--text-faint); }
.ac-clear:hover { background: var(--surface-2); color: var(--text); }
.ac-clear .icon { width: 13px; height: 13px; }
.ac-menu { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 70; max-height: 220px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-3); padding: 4px; }
.ac-opt { display: flex; align-items: center; gap: var(--space-2); padding: 7px 8px; border-radius: var(--radius-sm); font-size: var(--text-sm); cursor: pointer; }
.ac-opt:hover { background: var(--surface-2); }
.ac-opt.sel { color: var(--brand); font-weight: var(--fw-medium); }
.ac-opt .check { margin-left: auto; display: inline-flex; }
.ac-opt .check .icon { width: 14px; height: 14px; }

.menu {
  position: absolute; z-index: 60; min-width: 200px;
  max-height: 60vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-3);
  padding: var(--space-1); animation: modal-in var(--dur-fast) var(--ease);
}
.menu-item {
  display: flex; align-items: center; gap: var(--space-3); width: 100%;
  padding: var(--space-2) var(--space-3); font-size: var(--text-sm);
  border-radius: var(--radius-sm); color: var(--text); text-align: left;
}
.menu-item:hover { background: var(--surface-2); }
.menu-item .icon { width: 16px; height: 16px; color: var(--text-muted); }
.menu-item.danger { color: var(--danger); }
.menu-sep { height: 1px; background: var(--border); margin: var(--space-1) 0; }
.menu-label { padding: var(--space-2) var(--space-3) var(--space-1); font-size: var(--text-xs); color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; }

/* ---- Empty state -------------------------------------------------------- */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--space-3); padding: var(--space-8) var(--space-4); text-align: center; color: var(--text-muted);
}
.empty .icon-circle {
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); color: var(--text-faint);
}
.empty .icon-circle .icon { width: 24px; height: 24px; }

/* ---- Notificações: centro (dropdown) ------------------------------------ */
.notif-center { width: 348px; max-width: calc(100vw - 24px); padding: 0; overflow: hidden; }
.notif-head { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); }
.notif-scroll { max-height: 380px; overflow-y: auto; }
.notif-foot { width: 100%; padding: var(--space-3); font-size: var(--text-sm); font-weight: var(--fw-medium); color: var(--brand); border-top: 1px solid var(--border); text-align: center; }
.notif-foot:hover { background: var(--surface-2); }
.notif-item {
  display: flex; gap: var(--space-3); padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border); cursor: pointer; transition: background var(--dur-fast) var(--ease); text-align: left;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--surface-2); }
.notif-item.unread { background: color-mix(in srgb, var(--brand-soft) 50%, transparent); }
.notif-ic {
  width: 32px; height: 32px; border-radius: var(--radius-md); flex: none;
  display: grid; place-items: center; background: var(--surface-2); color: var(--text-muted);
}
.notif-ic .icon { width: 16px; height: 16px; }
.notif-ic.badge-warn { background: var(--warn-soft); color: var(--warn); }
.notif-ic.badge-danger { background: var(--danger-soft); color: var(--danger); }
.notif-ic.badge-brand { background: var(--brand-soft); color: var(--brand); }
.notif-ic.badge-info { background: var(--info-soft); color: var(--info); }
.notif-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); flex: none; margin-top: 5px; }

/* badge de contagem no sino */
.notif-badge {
  position: absolute; top: 4px; right: 4px; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 999px; background: var(--danger); color: #fff;
  font-size: 10px; font-weight: var(--fw-semibold); display: grid; place-items: center;
  border: 2px solid var(--bg);
}
.notif-btn-wrap { position: relative; }

/* ---- FAQ accordion ------------------------------------------------------ */
.faq-item:last-child { border-bottom: none !important; }
.faq-q:hover { background: var(--surface-2); }
.faq-caret { transition: transform var(--dur) var(--ease); }
.faq-item.open .faq-caret { transform: rotate(180deg); }
/* estado fechado/aberto da resposta (no CSS p/ que .open vença por especificidade) */
.faq-a { max-height: 0; overflow: hidden; transition: max-height var(--dur) var(--ease); }
.faq-item.open .faq-a { max-height: 400px; }

/* ---- Tour guiado -------------------------------------------------------- */
.tour { position: fixed; inset: 0; z-index: 300; display: none; }
.tour-spot {
  position: absolute; border-radius: var(--radius-md);
  box-shadow: 0 0 0 9999px rgba(20,18,15,0.55); transition: all var(--dur) var(--ease);
  pointer-events: none;
}
.tour-pop {
  position: absolute; width: 300px; padding: var(--space-4) var(--space-4) var(--space-3);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-3);
  animation: modal-in var(--dur) var(--ease);
}
.tour-step-num { font-size: var(--text-xs); color: var(--brand); font-weight: var(--fw-semibold); margin-bottom: var(--space-1); }
.tour-pop h4 { font-size: var(--text-md); margin-bottom: var(--space-1); }
.tour-pop p { font-size: var(--text-sm); color: var(--text-muted); margin-bottom: var(--space-4); }
.tour-actions { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }

/* ---- Version history (M5) ----------------------------------------------- */
.ver-item { display: flex; gap: var(--space-3); padding: var(--space-3) 0; border-bottom: 1px solid var(--border); }
.ver-item:last-child { border-bottom: none; }
.ver-badge { width: 28px; height: 28px; border-radius: 50%; flex: none; display: grid; place-items: center; background: var(--surface-2); color: var(--text-muted); font-size: var(--text-xs); font-weight: var(--fw-semibold); font-family: var(--font-mono); }
.ver-item.current .ver-badge { background: var(--brand-soft); color: var(--brand); }

/* ---- Misc --------------------------------------------------------------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.row { display: flex; align-items: center; gap: var(--space-3); }
.col { display: flex; flex-direction: column; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); }
.grid { display: grid; gap: var(--space-4); }
.grid > * { min-width: 0; } /* evita overflow de itens de grid com conteúdo largo (tabelas) */
.gap-2 { gap: var(--space-2); } .gap-3 { gap: var(--space-3); }
.wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }

/* Chips de porcentagem (alertas) — seleção clara (preenchido) */
.pct-chip { display: inline-flex; align-items: center; gap: 5px; height: 32px; padding: 0 14px; border-radius: var(--radius-full); font-size: var(--text-sm); font-weight: var(--fw-medium); background: var(--surface); color: var(--text-muted); border: 1px solid var(--border-strong); cursor: pointer; transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease); }
.pct-chip:hover { background: var(--surface-2); color: var(--text); }
.pct-chip.active { background: var(--brand); color: var(--brand-contrast); border-color: var(--brand); }
.pct-chip .icon { width: 13px; height: 13px; }

/* Ranking (Visão geral): top 5 + ver mais */
.rk-list .rk-extra { display: none; }
.rk-list.expanded .rk-extra { display: flex; }
.rk-list.bars.expanded .rk-extra { display: block; }
