/*
 * Kit v2 - camadas: menu de acoes ⋯ (lista flutuante posicionada pelo
 * kit.js, nao e' cortada por tabela com rolagem), janela de confirmacao
 * (<dialog> do TKI.kit.confirmar), toasts (TKI.kit.toast) e a gaveta
 * lateral (offcanvas do Bootstrap com .tki-drawer).
 * O modal padrao e' o .modal do Bootstrap (visual em modais.css).
 */

/* ----------------------------------------------------------- menu ⋯ */

html.tki-layout .tki-menu { position: relative; display: inline-flex; vertical-align: middle; }
html.tki-layout .tki-menu-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--tki-muted);
  cursor: pointer;
}
html.tki-layout .tki-menu-btn::after { content: ''; position: absolute; inset: -4px; }
html.tki-layout .tki-menu-btn:hover,
html.tki-layout .tki-menu-btn[aria-expanded='true'] { background: var(--tki-hover); border-color: var(--tki-border); color: var(--tki-fg); }
html.tki-layout .tki-menu-btn svg { width: 17px; height: 17px; }
html.tki-layout .tki-menu-list {
  position: fixed;
  z-index: 1070;
  min-width: 200px;
  max-width: min(300px, calc(100vw - 24px));
  max-height: min(420px, calc(100vh - 24px));
  overflow-y: auto;
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--tki-border);
  background: var(--tki-card);
  box-shadow: var(--tki-shadow-pop);
  animation: tki-menu-entra 0.12s ease-out;
}
html.tki-layout .tki-menu-list[hidden] { display: none; }
@keyframes tki-menu-entra { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
html.tki-layout .tki-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 36px;
  margin: 0;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--tki-fg-2);
  font: 500 14px 'DM Sans', ui-sans-serif, system-ui, sans-serif;
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
html.tki-layout .tki-menu-item:hover,
html.tki-layout .tki-menu-item:focus-visible { background: var(--tki-hover); color: var(--tki-fg); outline: 0; }
html.tki-layout .tki-menu-item svg { width: 16px; height: 16px; color: var(--tki-muted); }
html.tki-layout .tki-menu-item.danger,
html.tki-layout .tki-menu-item.danger svg { color: var(--tki-danger-text); }
html.tki-layout .tki-menu-item.danger:hover { background: var(--tki-soft-danger-bg); color: var(--tki-soft-danger-fg); }
html.tki-layout .tki-menu-item:is(:disabled, .disabled) { opacity: 0.5; pointer-events: none; }
html.tki-layout .tki-menu-sep { height: 1px; margin: 4px -4px; background: var(--tki-border); }
@media (max-width: 767.98px) {
  html.tki-layout .tki-menu-item { min-height: 44px; }
}

/* ------------------------------------------------ janela de confirmacao */

html.tki-layout dialog.tki-dialog {
  width: min(440px, calc(100vw - 32px));
  max-width: none;
  margin: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--tki-fg);
  overflow: visible;
}
html.tki-layout dialog.tki-dialog::backdrop { background: rgba(15, 23, 42, 0.5); }
html.tki-layout[data-bs-theme='dark'] dialog.tki-dialog::backdrop { background: rgba(0, 0, 0, 0.65); }
html.tki-layout dialog.tki-dialog[open] .tki-dialog-box { animation: tki-dialogo-entra 0.16s ease-out; }
@keyframes tki-dialogo-entra { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
html.tki-layout .tki-dialog-box {
  padding: 24px;
  border-radius: 16px;
  border: 1px solid var(--tki-border);
  background: var(--tki-card);
  box-shadow: var(--tki-shadow-pop);
  font-family: 'DM Sans', ui-sans-serif, system-ui, sans-serif;
}
html.tki-layout .tki-dialog-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: var(--tki-soft-primary-bg);
  color: var(--tki-primary-text);
}
html.tki-layout .tki-dialog-icon.danger { background: var(--tki-soft-danger-bg); color: var(--tki-soft-danger-fg); }
html.tki-layout .tki-dialog-icon.warning { background: var(--tki-soft-warning-bg); color: var(--tki-soft-warning-fg); }
html.tki-layout .tki-dialog-icon svg { width: 20px; height: 20px; }
html.tki-layout .tki-dialog-title { margin: 16px 0 6px; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; color: var(--tki-fg); }
html.tki-layout .tki-dialog-text { margin: 0; font-size: 14px; line-height: 1.55; color: var(--tki-muted); white-space: pre-line; }
html.tki-layout .tki-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
/* Resumo antes de confirmar (confirmar({resumo: [...]})). */
html.tki-layout .tki-dialog-box .tki-dl {
  margin-top: 16px;
  padding: 4px 14px;
  border-radius: 12px;
  border: 1px solid var(--tki-border);
  background: var(--tki-surface-2);
}
html.tki-layout .tki-dialog-box .tki-dl-row { min-height: 40px; padding: 8px 0; }
html.tki-layout .tki-dialog-box .tki-dl :is(dt, dd) { font-size: 13.5px; }
@media (max-width: 575.98px) {
  html.tki-layout .tki-dialog-box { padding: 20px; }
  html.tki-layout .tki-dialog-actions .tki-btn { flex: 1; }
}

/* ---------------------------------------------------------------- toasts */

html.tki-layout .tki-notices {
  position: fixed;
  z-index: 1090;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
html.tki-layout.tki-savebar-open .tki-notices { bottom: 92px; }
html.tki-layout:has(#tki-aviso-preview) .tki-notices { bottom: 84px; }
html.tki-layout.tki-savebar-open:has(#tki-aviso-preview) .tki-notices { bottom: 160px; }
html.tki-layout .tki-notice {
  --b-fg: var(--tki-muted);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 12px 10px 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--tki-border);
  background: var(--tki-card);
  color: var(--tki-fg);
  box-shadow: var(--tki-shadow-pop);
  font-size: 14px;
  line-height: 1.45;
  pointer-events: auto;
  animation: tki-toast-entra 0.18s ease-out;
}
html.tki-layout .tki-notice.saindo { animation: tki-toast-sai 0.16s ease-in forwards; }
@keyframes tki-toast-entra { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes tki-toast-sai { to { opacity: 0; transform: translateY(6px); } }
html.tki-layout .tki-notice-icon { display: grid; place-items: center; width: 20px; height: 20px; margin-top: 1px; color: var(--b-fg); flex-shrink: 0; }
html.tki-layout .tki-notice-icon svg { width: 18px; height: 18px; stroke-width: 2.25; }
html.tki-layout .tki-notice-text { flex: 1; min-width: 0; padding-top: 1px; overflow-wrap: anywhere; }
html.tki-layout .tki-notice-close {
  position: relative;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin: -4px 0 -4px 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--tki-muted);
  cursor: pointer;
  flex-shrink: 0;
}
html.tki-layout .tki-notice-close::after { content: ''; position: absolute; inset: -6px; }
html.tki-layout .tki-notice-close:hover { background: var(--tki-hover); color: var(--tki-fg); }
html.tki-layout .tki-notice-close svg { width: 15px; height: 15px; }
@media (max-width: 575.98px) {
  html.tki-layout .tki-notices { left: 12px; right: 12px; bottom: 12px; width: auto; }
  html.tki-layout:has(#tki-aviso-preview) .tki-notices { bottom: 140px; }
  html.tki-layout.tki-savebar-open .tki-notices { bottom: 128px; }
  html.tki-layout.tki-savebar-open:has(#tki-aviso-preview) .tki-notices { bottom: 256px; }
}
@media (prefers-reduced-motion: reduce) {
  html.tki-layout .tki-notice,
  html.tki-layout .tki-notice.saindo,
  html.tki-layout dialog.tki-dialog[open] .tki-dialog-box,
  html.tki-layout .tki-menu-list { animation: none; }
}

/* ------------------------------------------ gaveta lateral (offcanvas) */

html.tki-layout .offcanvas.tki-drawer {
  --bs-offcanvas-width: 480px;
  border-left: 1px solid var(--tki-border) !important;
  box-shadow: var(--tki-shadow-pop);
}
html.tki-layout .tki-drawer .offcanvas-header {
  align-items: flex-start;
  gap: 12px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--tki-border);
}
html.tki-layout .tki-drawer .offcanvas-title { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; color: var(--tki-fg); }
html.tki-layout .tki-drawer-sub { margin: 4px 0 0; font-size: 13.5px; color: var(--tki-muted); }
html.tki-layout .tki-drawer .offcanvas-header .btn-close { margin: 2px -4px 0 auto; }
html.tki-layout .tki-drawer .offcanvas-body { padding: 20px 24px; }
html.tki-layout .tki-drawer-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 24px;
  border-top: 1px solid var(--tki-border);
  background: var(--tki-surface-2);
}
html.tki-layout .offcanvas-backdrop.show { opacity: 0.5; }
/* Gaveta com formulario: o <form> ocupa a altura toda, o corpo rola e o
   rodape com os botoes fica sempre visivel. */
html.tki-layout .tki-drawer-form { display: flex; flex-direction: column; height: 100%; min-height: 0; margin: 0; }
html.tki-layout .tki-drawer-form > .offcanvas-body { flex: 1 1 auto; overflow-y: auto; }
@media (max-width: 575.98px) {
  html.tki-layout .offcanvas.tki-drawer { --bs-offcanvas-width: 100vw; }
  html.tki-layout .tki-drawer .offcanvas-header,
  html.tki-layout .tki-drawer .offcanvas-body { padding-left: 18px; padding-right: 18px; }
  html.tki-layout .tki-drawer-foot { padding: 12px 18px; }
  html.tki-layout .tki-drawer-foot .tki-btn { flex: 1; }
}

/* Campo de texto dentro do modal (kit.perguntar, no lugar do prompt()). */
html.tki-layout .tki-dialog-campo { display: block; margin: 14px 0 0; text-align: left; }
html.tki-layout .tki-dialog-campo .tki-label { display: block; margin-bottom: 6px; }
html.tki-layout .tki-dialog-campo textarea { display: block; width: 100%; max-width: 100%; box-sizing: border-box; resize: vertical; }
