@import "tailwindcss";
@plugin "@tailwindcss/forms";

/* 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;
  }
}

/* Issue #321: Pagy pagination styling */
nav.pagy {
  display: flex;
  justify-content: center;
  padding: 1rem 0;
  gap: 0.25rem;
}
nav.pagy a, nav.pagy span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.5rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #374151;
  transition: background-color 0.15s;
}
nav.pagy a:hover {
  background-color: #f3f4f6;
}
nav.pagy a[aria-current="page"],
nav.pagy span.current {
  background-color: #1B5E20;
  color: white;
}
nav.pagy span.gap {
  color: #9ca3af;
}

/* ─── Help prose: typography for rendered Markdown help pages ─── */
.help-prose {
  color: #1f2937;
  font-size: 0.9375rem;
  line-height: 1.65;
  max-width: 72ch;
}
.help-prose h1 {
  font-size: 1.875rem;
  font-weight: 700;
  margin: 0 0 1rem;
  color: #111827;
  letter-spacing: -0.01em;
}
.help-prose h2 {
  font-size: 1.4rem;
  font-weight: 600;
  margin: 2rem 0 0.75rem;
  color: #111827;
  border-top: 1px solid #e5e7eb;
  padding-top: 1.25rem;
}
.help-prose h2:first-child { border-top: 0; padding-top: 0; }
.help-prose h3 {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 1.5rem 0 0.5rem;
  color: #1f2937;
}
.help-prose h4 {
  font-size: 1rem;
  font-weight: 600;
  margin: 1.25rem 0 0.5rem;
  color: #374151;
}
.help-prose p { margin: 0.75rem 0; }
.help-prose ul, .help-prose ol {
  margin: 0.75rem 0;
  padding-left: 1.5rem;
}
.help-prose ul { list-style: disc; }
.help-prose ol { list-style: decimal; }
.help-prose li { margin: 0.25rem 0; }
.help-prose li > p { margin: 0.25rem 0; }
.help-prose a {
  color: #1B5E20;
  text-decoration: underline;
  text-decoration-color: rgba(27, 94, 32, 0.35);
  text-underline-offset: 2px;
}
.help-prose a:hover {
  text-decoration-color: #1B5E20;
}
.help-prose strong { font-weight: 600; color: #111827; }
.help-prose em { font-style: italic; }
.help-prose blockquote {
  border-left: 4px solid #d1d5db;
  background: #f9fafb;
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  border-radius: 0 0.375rem 0.375rem 0;
  color: #4b5563;
}
.help-prose blockquote > p:first-child { margin-top: 0; }
.help-prose blockquote > p:last-child { margin-bottom: 0; }
.help-prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, "Liberation Mono", monospace;
  font-size: 0.875em;
  padding: 0.125rem 0.375rem;
  background: #f3f4f6;
  border-radius: 0.25rem;
  color: #b91c1c;
}
.help-prose pre {
  background: #1f2937;
  color: #f3f4f6;
  padding: 1rem 1.125rem;
  border-radius: 0.5rem;
  overflow-x: auto;
  margin: 1rem 0;
  font-size: 0.85rem;
  line-height: 1.55;
}
.help-prose pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}
.help-prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.875rem;
}
.help-prose th {
  background: #f9fafb;
  font-weight: 600;
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 2px solid #e5e7eb;
  color: #374151;
}
.help-prose td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: top;
}
.help-prose img { max-width: 100%; height: auto; border-radius: 0.5rem; }
.help-prose hr { border: 0; border-top: 1px solid #e5e7eb; margin: 2rem 0; }
.help-prose pre.mermaid {
  background: #ffffff;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  text-align: center;
  padding: 1.25rem;
  overflow-x: auto;
}
.help-prose pre.mermaid > svg {
  max-width: 100%;
  height: auto;
  display: inline-block;
}

/* Help sidebar (TOC) */
.help-toc-section {
  margin-bottom: 1.25rem;
}
.help-toc-section > h3 {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
  margin: 0 0 0.375rem;
  padding: 0 0.5rem;
}
.help-toc-section a {
  display: block;
  padding: 0.375rem 0.5rem;
  color: #374151;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  line-height: 1.4;
}
.help-toc-section a:hover {
  background: #f3f4f6;
  color: #111827;
}
.help-toc-section a.help-toc-active {
  background: #ecfdf5;
  color: #1B5E20;
  font-weight: 600;
}
