@import "tailwindcss";

/* Touch feedback: active/pressed states for all interactive elements */
@layer utilities {
  /* Buttons and links with button-like appearance get press feedback */
  button:active:not(:disabled),
  [role="button"]:active:not(:disabled),
  a[class*="rounded-lg"]:active,
  a[class*="btn"]:active,
  input[type="submit"]:active:not(:disabled) {
    transform: scale(0.97);
    opacity: 0.85;
  }

  /* Smooth transition for press feedback — max 150ms ease-out */
  button,
  [role="button"],
  a[class*="rounded-lg"],
  a[class*="btn"],
  input[type="submit"] {
    transition: transform 0.1s ease-out, opacity 0.1s ease-out, background-color 0.15s ease-out, color 0.15s ease-out;
  }

  /* Sidebar nav items get subtle feedback */
  nav a:active {
    transform: scale(0.98);
    opacity: 0.9;
  }

  /*
   * Issue #130 (filed by @aiyogitar): table action buttons (Edit, Delete,
   * View icon-only buttons inside <td>) were "fluctuating" on hover and
   * becoming hard to click. Root cause: the global `transition: transform`
   * rule above combined with even a tiny layout shift from `hover:bg-gray-100`
   * adjacent siblings could cause the cursor to leave the button bounding
   * box mid-transition, triggering mouseout → mouseleave → button shrinks
   * back → mouseover → button moves → flicker loop.
   *
   * Fix: explicitly disable all transforms (not just press feedback) on
   * icon-only action buttons inside table cells, AND ensure they have
   * stable bounding boxes via min-width/min-height + flex-shrink:0. The
   * pattern matches the Tailwind class combo we use everywhere:
   *   p-1.5 ... rounded-lg ... transition-colors
   * inside a td.
   */
  td a[class*="p-1.5"][class*="rounded-lg"],
  td button[class*="p-1.5"][class*="rounded-lg"] {
    transform: none !important;
    transition: background-color 0.15s ease-out, color 0.15s ease-out !important;
    min-width: 28px;
    min-height: 28px;
    flex-shrink: 0;
  }

  /* Even on press, do not scale these — they're too small and the scale
     animation causes the click target to "miss" on mouse-down. */
  td a[class*="p-1.5"][class*="rounded-lg"]:active,
  td button[class*="p-1.5"][class*="rounded-lg"]:active {
    transform: none !important;
    opacity: 0.7;
  }
}

/* Accessibility: visible focus indicators for keyboard navigation */
@layer base {
  a:focus-visible,
  button:focus-visible,
  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible,
  [tabindex]:focus-visible {
    outline: 2px solid #c2410c;
    outline-offset: 2px;
  }
}

/* Global animation speed cap — all transitions max 200ms ease-out */
@layer base {
  *,
  *::before,
  *::after {
    transition-timing-function: ease-out;
  }

  /* Constrain all Tailwind transition-colors / transition-all to 150ms */
  .transition-colors,
  .transition-all,
  .transition-opacity,
  .transition-shadow,
  .transition {
    transition-duration: 150ms !important;
    transition-timing-function: ease-out !important;
  }

  /* Reduce card shadows — prefer subtle borders over heavy shadows */
  .shadow-sm {
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.04) !important;
  }

  /* Table sticky header needs background to prevent see-through */
  thead.sticky {
    box-shadow: 0 1px 0 0 rgb(0 0 0 / 0.06);
  }
}

/* Density: Compact mode */
@layer utilities {
  /* Cards */
  [data-density="compact"] .bg-white.rounded-xl {
    padding: 0.75rem;
  }
  [data-density="compact"] .bg-white.rounded-xl .p-5,
  [data-density="compact"] .bg-white.rounded-xl .p-6 {
    padding: 0.75rem;
  }
  [data-density="compact"] .bg-white.rounded-xl .p-4 {
    padding: 0.5rem 0.75rem;
  }

  /* Table rows */
  [data-density="compact"] table tbody td {
    padding-top: 0.375rem;
    padding-bottom: 0.375rem;
  }
  [data-density="compact"] table thead th {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }

  /* Text sizing */
  [data-density="compact"] .text-2xl {
    font-size: 1.25rem;
    line-height: 1.75rem;
  }
  [data-density="compact"] .text-3xl {
    font-size: 1.5rem;
    line-height: 2rem;
  }

  /* Grid gaps */
  [data-density="compact"] .gap-5 {
    gap: 0.75rem;
  }
  [data-density="compact"] .gap-6 {
    gap: 1rem;
  }

  /* Spacing */
  [data-density="compact"] .space-y-6 > * + * {
    margin-top: 1rem;
  }

  /* Main content padding */
  [data-density="compact"] main .p-6 {
    padding: 1rem;
  }
}
