/**
 * Custom CSS Utilities
 * Additional styles for Ribeiro & Rodrigues Sistema de Gestao Juridica
 */

/* ==========================================================================
   Loading Animations
   ========================================================================== */

/* Spinner animation (fallback if Tailwind animate-spin is not available) */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.animate-spin {
    animation: spin 1s linear infinite;
}

/* Pulse animation for skeleton loaders */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.animate-pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Skeleton loader styles */
.skeleton {
    background: linear-gradient(
        90deg,
        rgba(0, 0, 0, 0.06) 25%,
        rgba(0, 0, 0, 0.12) 50%,
        rgba(0, 0, 0, 0.06) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

.dark .skeleton {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.06) 25%,
        rgba(255, 255, 255, 0.12) 50%,
        rgba(255, 255, 255, 0.06) 75%
    );
    background-size: 200% 100%;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ==========================================================================
   Transitions
   ========================================================================== */

/* Smooth page transitions */
.page-transition-enter {
    opacity: 0;
    transform: translateY(10px);
}

.page-transition-enter-active {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 200ms ease-out, transform 200ms ease-out;
}

.page-transition-leave {
    opacity: 1;
    transform: translateY(0);
}

.page-transition-leave-active {
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 150ms ease-in, transform 150ms ease-in;
}

/* Fade transitions */
.fade-enter {
    opacity: 0;
}

.fade-enter-active {
    opacity: 1;
    transition: opacity 200ms ease-out;
}

.fade-leave {
    opacity: 1;
}

.fade-leave-active {
    opacity: 0;
    transition: opacity 150ms ease-in;
}

/* Slide transitions */
.slide-up-enter {
    opacity: 0;
    transform: translateY(100%);
}

.slide-up-enter-active {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 300ms ease-out, transform 300ms ease-out;
}

.slide-down-leave-active {
    opacity: 0;
    transform: translateY(100%);
    transition: opacity 200ms ease-in, transform 200ms ease-in;
}

/* Scale transitions */
.scale-enter {
    opacity: 0;
    transform: scale(0.95);
}

.scale-enter-active {
    opacity: 1;
    transform: scale(1);
    transition: opacity 200ms ease-out, transform 200ms ease-out;
}

.scale-leave-active {
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 150ms ease-in, transform 150ms ease-in;
}

/* ==========================================================================
   HTMX Specific Styles
   ========================================================================== */

/* HTMX indicator - shown during requests */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-flex;
}

.htmx-request.htmx-indicator {
    display: inline-flex;
}

/* Disable element during HTMX request */
.htmx-request {
    pointer-events: none;
}

/* HTMX swapping transition */
.htmx-swapping {
    opacity: 0.5;
    transition: opacity 200ms ease-out;
}

/* HTMX settling transition */
.htmx-settling {
    opacity: 1;
    transition: opacity 200ms ease-in;
}

/* HTMX added element animation */
.htmx-added {
    animation: htmx-added 300ms ease-out;
}

@keyframes htmx-added {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================================================
   Responsive Tables
   ========================================================================== */

/* Responsive table wrapper */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

.dark .table-responsive {
    scrollbar-color: #475569 transparent;
}

.table-responsive::-webkit-scrollbar {
    height: 6px;
}

.table-responsive::-webkit-scrollbar-track {
    background: transparent;
}

.table-responsive::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 3px;
}

.dark .table-responsive::-webkit-scrollbar-thumb {
    background-color: #475569;
}

/* Stacked table on mobile */
@media (max-width: 640px) {
    .table-stack thead {
        display: none;
    }

    .table-stack tbody tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #e2e8f0;
        border-radius: 0.5rem;
        padding: 0.75rem;
    }

    .dark .table-stack tbody tr {
        border-color: #334155;
    }

    .table-stack tbody td {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem 0;
        border: none;
        border-bottom: 1px solid #f1f5f9;
    }

    .dark .table-stack tbody td {
        border-bottom-color: #1e293b;
    }

    .table-stack tbody td:last-child {
        border-bottom: none;
    }

    .table-stack tbody td::before {
        content: attr(data-label);
        font-weight: 500;
        color: #64748b;
    }

    .dark .table-stack tbody td::before {
        color: #94a3b8;
    }
}

/* ==========================================================================
   Form Enhancements
   ========================================================================== */

/* Input focus ring animation */
.input-focus-ring {
    position: relative;
}

.input-focus-ring::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: inherit;
    border: 2px solid transparent;
    transition: border-color 150ms ease-out;
    pointer-events: none;
}

.input-focus-ring:focus-within::after {
    border-color: #3b82f6;
}

/* Floating label */
.floating-label-group {
    position: relative;
}

.floating-label-group input,
.floating-label-group textarea {
    padding-top: 1.25rem;
}

.floating-label-group label {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: #64748b;
    pointer-events: none;
    transition: all 150ms ease-out;
}

.floating-label-group input:focus ~ label,
.floating-label-group input:not(:placeholder-shown) ~ label,
.floating-label-group textarea:focus ~ label,
.floating-label-group textarea:not(:placeholder-shown) ~ label {
    top: 0.5rem;
    transform: translateY(0);
    font-size: 0.75rem;
    color: #3b82f6;
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    /* Hide non-essential elements */
    .no-print,
    nav,
    aside,
    .sidebar,
    .navbar,
    button:not(.print-button),
    .htmx-indicator,
    #toast-container,
    .modal,
    footer {
        display: none !important;
    }

    /* Reset backgrounds and colors for printing */
    body {
        background: white !important;
        color: black !important;
        font-size: 12pt;
        line-height: 1.4;
    }

    /* Ensure content takes full width */
    main,
    .main-content,
    .content {
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Page break controls */
    .page-break-before {
        page-break-before: always;
    }

    .page-break-after {
        page-break-after: always;
    }

    .page-break-avoid {
        page-break-inside: avoid;
    }

    /* Table printing */
    table {
        border-collapse: collapse;
        width: 100%;
    }

    table th,
    table td {
        border: 1px solid #000;
        padding: 8px;
        text-align: left;
    }

    table thead {
        display: table-header-group;
    }

    table tr {
        page-break-inside: avoid;
    }

    /* Links */
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }

    a[href^="#"]:after,
    a[href^="javascript:"]:after {
        content: "";
    }

    /* Cards and containers */
    .card,
    .bg-white,
    .bg-slate-50 {
        background: white !important;
        border: 1px solid #ccc !important;
        box-shadow: none !important;
    }

    /* Ensure dark mode doesn't affect print */
    .dark body,
    .dark main,
    .dark .card {
        background: white !important;
        color: black !important;
    }
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */

/* Hide element but keep accessible to screen readers */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Show on focus for keyboard navigation */
.sr-only-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    padding: inherit;
    margin: inherit;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* Truncate text with ellipsis */
.truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.truncate-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Custom scrollbar */
.custom-scrollbar {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

.dark .custom-scrollbar {
    scrollbar-color: #475569 transparent;
}

.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 3px;
}

.dark .custom-scrollbar::-webkit-scrollbar-thumb {
    background-color: #475569;
}

/* Focus visible outline */
.focus-visible-ring:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Disabled state */
.disabled {
    opacity: 0.5;
    pointer-events: none;
    cursor: not-allowed;
}

/* ==========================================================================
   Dark Mode Transitions
   ========================================================================== */

/* Smooth transition when toggling dark mode */
html.dark-mode-transition,
html.dark-mode-transition *,
html.dark-mode-transition *::before,
html.dark-mode-transition *::after {
    transition: background-color 300ms ease-out,
                border-color 300ms ease-out,
                color 200ms ease-out !important;
}
