/* ui-improvements.css
   Aditivo sobre styles.css + ferramentas-patch.css + mobile.css.
   Implementa Sprint 1 + parte da Sprint 2 do REVISAO_UX_CORE.md.
   Nada remove ou sobrescreve lógica; apenas eleva a qualidade visual/a11y.
*/

/* ============================================================
   1. DROPDOWNS / SELECTS - Fix principal de legibilidade
   ============================================================ */
select {
  color-scheme: dark;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' stroke='%239B27AF' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 10px;
  padding-right: 32px !important;
}
select option,
select optgroup {
  background: #1c1628;
  color: #fff;
}
select:disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* ============================================================
   2. FOCUS RING GLOBAL (acessibilidade teclado)
   ============================================================ */
button:focus-visible,
a:focus-visible,
[role="button"]:focus-visible,
.view-btn:focus-visible,
.btn-data:focus-visible,
.kanban-col:focus-visible,
.sidebar-nav-item:focus-visible {
  outline: 2px solid #00C4A7;
  outline-offset: 2px;
  border-radius: 6px;
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none;
}

/* ============================================================
   3. AUTOFILL Chrome (evita amarelo sobre dark)
   ============================================================ */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active,
textarea:-webkit-autofill,
select:-webkit-autofill {
  -webkit-text-fill-color: #fff !important;
  -webkit-box-shadow: 0 0 0 1000px #1c1628 inset !important;
  transition: background-color 9999s ease-in-out 0s;
  caret-color: #fff;
}

/* ============================================================
   4. PLACEHOLDERS (contraste)
   ============================================================ */
input::placeholder,
textarea::placeholder {
  color: rgba(255,255,255,.38);
  opacity: 1;
}

/* ============================================================
   5. SCROLLBARS (tema dark da marca)
   ============================================================ */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(155,39,175,.35) rgba(255,255,255,.03);
}
*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-track {
  background: rgba(255,255,255,.02);
  border-radius: 5px;
}
*::-webkit-scrollbar-thumb {
  background: rgba(155,39,175,.35);
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: rgba(155,39,175,.6);
  background-clip: content-box;
  border: 2px solid transparent;
}
*::-webkit-scrollbar-corner {
  background: transparent;
}

/* ============================================================
   6. SELEÇÃO DE TEXTO
   ============================================================ */
::selection {
  background: rgba(0,196,167,.45);
  color: #fff;
}
::-moz-selection {
  background: rgba(0,196,167,.45);
  color: #fff;
}

/* ============================================================
   7. BOTÕES - estado loading + sizes padronizados
   ============================================================ */
button:disabled,
.btn-primary:disabled,
.btn-ghost:disabled,
.btn-danger:disabled {
  opacity: .5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn-loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-top: -8px;
  margin-left: -8px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: btn-spin .7s linear infinite;
}
@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   8. TOAST - melhorias (ícones + close + empilhamento)
   ============================================================ */
#ui-toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 380px;
  pointer-events: none;
}
#ui-toast-container .ui-toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px 12px 14px;
  border-radius: 10px;
  background: #1c1628;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  transform: translateX(120%);
  opacity: 0;
  transition: transform .3s cubic-bezier(.2,.9,.3,1), opacity .3s;
  pointer-events: auto;
  border-left: 3px solid #9B27AF;
  max-width: 100%;
}
#ui-toast-container .ui-toast.show {
  transform: translateX(0);
  opacity: 1;
}
#ui-toast-container .ui-toast.success { border-left-color: #00C4A7; }
#ui-toast-container .ui-toast.error   { border-left-color: #ff4757; }
#ui-toast-container .ui-toast.warning { border-left-color: #ffb84c; }
#ui-toast-container .ui-toast .ui-toast-icon {
  font-size: 16px;
  line-height: 1.2;
  flex-shrink: 0;
}
#ui-toast-container .ui-toast .ui-toast-msg {
  flex: 1;
  min-width: 0;
  word-wrap: break-word;
}
#ui-toast-container .ui-toast .ui-toast-close {
  background: none;
  border: none;
  color: rgba(255,255,255,.6);
  font-size: 16px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  margin-left: 4px;
  flex-shrink: 0;
}
#ui-toast-container .ui-toast .ui-toast-close:hover {
  color: #fff;
}
@media (max-width: 768px) {
  #ui-toast-container {
    left: 12px;
    right: 12px;
    bottom: 80px;
    max-width: none;
  }
}

/* ============================================================
   9. SKELETON LOADING
   ============================================================ */
.skel {
  background: linear-gradient(
    90deg,
    rgba(255,255,255,.04) 0%,
    rgba(255,255,255,.09) 50%,
    rgba(255,255,255,.04) 100%
  );
  background-size: 200% 100%;
  animation: skel-shimmer 1.4s linear infinite;
  border-radius: 6px;
  color: transparent;
  user-select: none;
  pointer-events: none;
  display: inline-block;
  min-height: 1em;
}
.skel-line { width: 100%; height: 12px; margin: 6px 0; border-radius: 4px; }
.skel-line.w-50 { width: 50%; }
.skel-line.w-70 { width: 70%; }
.skel-line.w-30 { width: 30%; }
.skel-box  { width: 100%; height: 80px; border-radius: 10px; }
.skel-circle { width: 32px; height: 32px; border-radius: 50%; }
@keyframes skel-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================================
   10. EMPTY STATE - com ilustração e CTA
   ============================================================ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: rgba(255,255,255,.6);
  min-height: 200px;
}
.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: .6;
  filter: grayscale(.3);
}
.empty-state-title {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 6px;
}
.empty-state-desc {
  font-size: 13px;
  color: rgba(255,255,255,.5);
  margin-bottom: 18px;
  max-width: 320px;
  line-height: 1.5;
}
.empty-state-action {
  background: linear-gradient(135deg, #9B27AF, #00C4A7);
  color: #fff;
  border: none;
  padding: 9px 20px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: opacity .15s;
}
.empty-state-action:hover {
  opacity: .9;
}

/* ============================================================
   11. MODAL - body lock + close hover + animação
   ============================================================ */
body.modal-open {
  overflow: hidden;
}

/* Backdrop click-to-close fica por conta do JS; aqui só visual */
.modal,
.cal-modal,
.cl-modal,
[class*="modal-overlay"] {
  animation: modal-fade .18s ease-out;
}
@keyframes modal-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-content,
.cal-modal-content,
[class*="modal-box"] {
  animation: modal-pop .22s cubic-bezier(.2,.9,.3,1);
}
@keyframes modal-pop {
  from { transform: translateY(14px) scale(.98); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

/* ============================================================
   12. CARDS - hover elevation
   ============================================================ */
.scard,
.cl-card,
.kcard,
.mb-copy-card,
.ferr-card {
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.scard:hover,
.cl-card:hover,
.kcard:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(0,0,0,.28);
}

/* ============================================================
   13. TABELA - hover row + scroll shadow mobile
   ============================================================ */
table tbody tr {
  transition: background-color .12s;
}
table tbody tr:hover {
  background: rgba(255,255,255,.035);
}

@media (max-width: 768px) {
  .data-table,
  table:not(.tp-table) {
    background-image:
      linear-gradient(to right, rgba(0,0,0,.4), transparent 10%, transparent 90%, rgba(0,0,0,.4)),
      linear-gradient(to right, #0e0817, transparent 20px),
      linear-gradient(to left, #0e0817, transparent 20px);
    background-attachment: local, scroll, scroll;
    background-repeat: no-repeat;
    background-size: 100% 100%, 20px 100%, 20px 100%;
    background-position: 0 0, 0 0, 100% 0;
  }
}

/* ============================================================
   14. CALENDARIO - destaque do "hoje"
   ============================================================ */
.cal-cell.today,
.cal-cell[data-today="true"],
.cal-cell.is-today {
  box-shadow: inset 0 0 0 2px #00C4A7;
  background: rgba(0,196,167,.06);
}

/* ============================================================
   15. KANBAN - drop zone + drag feedback
   ============================================================ */
.kanban-col.drag-over,
.kb-col.drag-over {
  outline: 2px dashed rgba(0,196,167,.6);
  outline-offset: -4px;
  background: rgba(0,196,167,.04);
}
.kcard.dragging {
  opacity: .45;
  transform: rotate(1deg);
  cursor: grabbing;
}

/* ============================================================
   16. BADGES - ícone além de cor (acessibilidade)
   ============================================================ */
.badge[data-priority="alta"]::before   { content: "●"; margin-right: 4px; }
.badge[data-priority="media"]::before  { content: "◐"; margin-right: 4px; }
.badge[data-priority="baixa"]::before  { content: "○"; margin-right: 4px; }

/* ============================================================
   17. SIDEBAR - indicador ativo reforçado
   ============================================================ */
.sidebar-nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(180deg, #9B27AF, #00C4A7);
}
.sidebar-nav-item {
  position: relative;
}

/* Tooltip quando sidebar colapsada */
.sidebar.collapsed .sidebar-nav-item {
  position: relative;
}
.sidebar.collapsed .sidebar-nav-item:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 10px;
  background: #1c1628;
  color: #fff;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: nowrap;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
  pointer-events: none;
}

/* ============================================================
   18. REQUIRED FIELD - asterisco vermelho
   ============================================================ */
.field.required > label::after,
.field[data-required="true"] > label::after {
  content: " *";
  color: #ff4757;
  font-weight: 700;
}

/* ============================================================
   19. VALIDATION - input inválido (depois de submit)
   ============================================================ */
.field input.is-invalid,
.field select.is-invalid,
.field textarea.is-invalid,
input.is-invalid,
select.is-invalid,
textarea.is-invalid {
  border-color: #ff4757 !important;
  box-shadow: 0 0 0 3px rgba(255,71,87,.15) !important;
}
.field-error-msg {
  color: #ff4757;
  font-size: 11px;
  margin-top: 4px;
  font-weight: 600;
}

/* ============================================================
   20. HIT TARGET mínimo em mobile
   ============================================================ */
@media (max-width: 768px) {
  button,
  .btn-data,
  .view-btn,
  .cal-nav-btn,
  .cal-hoje-btn {
    min-height: 44px;
    min-width: 44px;
  }
  .modal-close {
    min-width: 44px;
    min-height: 44px;
  }
  /* Espaço pra bottom-nav nativo */
  .main,
  #view-dashboard,
  #view-table,
  #view-kanban,
  #view-clientes,
  #view-financeiro,
  #view-ferramentas {
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
}

/* ============================================================
   21. PÁGINA - animação entrada
   ============================================================ */
[id^="view-"] {
  animation: view-enter .22s cubic-bezier(.2,.9,.3,1);
}
@keyframes view-enter {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   22. CONFIRM DIALOG (usado pelo JS)
   ============================================================ */
#ui-confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 999998;
  display: none;
  align-items: center;
  justify-content: center;
  animation: modal-fade .18s ease-out;
}
#ui-confirm-overlay.show {
  display: flex;
}
#ui-confirm-overlay .ui-confirm-box {
  background: #1c1628;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 12px;
  padding: 22px 24px;
  width: min(420px, 92vw);
  box-shadow: 0 24px 64px rgba(0,0,0,.5);
  animation: modal-pop .22s cubic-bezier(.2,.9,.3,1);
}
#ui-confirm-overlay .ui-confirm-title {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 8px;
}
#ui-confirm-overlay .ui-confirm-msg {
  font-size: 13px;
  color: rgba(255,255,255,.75);
  line-height: 1.5;
  margin-bottom: 18px;
}
#ui-confirm-overlay .ui-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
#ui-confirm-overlay button {
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  border: none;
  font-family: inherit;
}
#ui-confirm-overlay .ui-confirm-cancel {
  background: rgba(255,255,255,.08);
  color: #fff;
  border: 1px solid rgba(255,255,255,.14);
}
#ui-confirm-overlay .ui-confirm-cancel:hover {
  background: rgba(255,255,255,.14);
}
#ui-confirm-overlay .ui-confirm-ok {
  background: linear-gradient(135deg, #9B27AF, #00C4A7);
  color: #fff;
}
#ui-confirm-overlay .ui-confirm-ok.danger {
  background: #ff4757;
}
#ui-confirm-overlay .ui-confirm-ok:hover {
  opacity: .9;
}

/* ============================================================
   23. COMMAND PALETTE (Ctrl+K)
   ============================================================ */
#ui-cmdk-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 999997;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 14vh;
  animation: modal-fade .18s ease-out;
}
#ui-cmdk-overlay.show { display: flex; }
#ui-cmdk-box {
  background: #1c1628;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px;
  width: min(560px, 92vw);
  box-shadow: 0 24px 64px rgba(0,0,0,.5);
  overflow: hidden;
  animation: modal-pop .22s cubic-bezier(.2,.9,.3,1);
}
#ui-cmdk-input {
  width: 100%;
  padding: 14px 18px;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(255,255,255,.08);
  color: #fff;
  font-size: 14px;
  outline: none;
}
#ui-cmdk-input::placeholder { color: rgba(255,255,255,.4); }
#ui-cmdk-list {
  max-height: 50vh;
  overflow-y: auto;
  padding: 6px 0;
}
.ui-cmdk-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  color: rgba(255,255,255,.85);
  font-size: 13px;
}
.ui-cmdk-item .ui-cmdk-icon { font-size: 16px; width: 20px; text-align: center; }
.ui-cmdk-item .ui-cmdk-label { flex: 1; }
.ui-cmdk-item .ui-cmdk-hint {
  font-size: 11px;
  color: rgba(255,255,255,.4);
  background: rgba(255,255,255,.05);
  padding: 2px 8px;
  border-radius: 4px;
}
.ui-cmdk-item:hover,
.ui-cmdk-item.active {
  background: rgba(155,39,175,.16);
  color: #fff;
}
.ui-cmdk-empty {
  padding: 24px;
  text-align: center;
  color: rgba(255,255,255,.4);
  font-size: 13px;
}

/* ============================================================
   24. SKIP LINK (a11y)
   ============================================================ */
.ui-skip-link {
  position: absolute;
  top: -40px;
  left: 8px;
  background: #9B27AF;
  color: #fff;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  z-index: 999999;
  transition: top .15s;
  text-decoration: none;
}
.ui-skip-link:focus {
  top: 8px;
  outline: 2px solid #00C4A7;
  outline-offset: 2px;
}

/* ============================================================
   25. REDUCED MOTION (respeito a preferências do SO)
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
