/**
 * PostEx Express v2 - Custom Styles
 *
 * Supplements Tailwind CSS CDN with:
 *  - Custom animations
 *  - Scrollbar styling
 *  - Print styles
 *  - Utility transitions
 *  - Form enhancements
 */

/* ============================================
   CSS Custom Properties
   ============================================ */
:root {
    --postex-primary: #F97316;
    --postex-primary-dark: #EA580C;
    --postex-danger: #DC2626;
    --postex-warning: #F59E0B;
    --postex-success: #16A34A;
    --postex-bg: #F8FAFC;
    --sidebar-width: 280px;
    --header-height: 72px;
}


/* ============================================
   Base Resets & Enhancements
   ============================================ */
*,
*::before,
*::after {
    scrollbar-color: #d1d5db transparent;
    scrollbar-width: thin;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Focus ring utility */
:focus-visible {
    outline: 2px solid var(--postex-primary);
    outline-offset: 2px;
    border-radius: 0.25rem;
}


/* ============================================
   Custom Scrollbar
   ============================================ */
.scrollbar-thin::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

.scrollbar-thin::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 9999px;
}

.scrollbar-thin::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Hide scrollbar utility */
.scrollbar-hide::-webkit-scrollbar {
    display: none;
}
.scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
}


/* ============================================
   Custom Animations
   ============================================ */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideLeft {
    from {
        opacity: 0;
        transform: translateX(16px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideRight {
    from {
        opacity: 0;
        transform: translateX(-16px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

@keyframes pulse-ring {
    0% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    80%, 100% {
        transform: scale(2);
        opacity: 0;
    }
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
}

@keyframes spin-slow {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Animation utility classes */
.animate-fade-in       { animation: fadeIn 0.3s ease-out; }
.animate-fade-out      { animation: fadeOut 0.3s ease-in; }
.animate-slide-down    { animation: slideDown 0.3s ease-out; }
.animate-slide-up      { animation: slideUp 0.3s ease-out; }
.animate-slide-left    { animation: slideLeft 0.3s ease-out; }
.animate-slide-right   { animation: slideRight 0.3s ease-out; }
.animate-scale-in      { animation: scaleIn 0.3s ease-out; }
.animate-float         { animation: float 6s ease-in-out infinite; }
.animate-spin-slow     { animation: spin-slow 3s linear infinite; }

/* Skeleton loading shimmer */
.skeleton {
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 0.5rem;
}


/* ============================================
   Button Enhancements
   ============================================ */

/* Primary button shimmer on hover */
.btn-primary {
    position: relative;
    overflow: hidden;
}

.btn-primary::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        105deg,
        transparent 40%,
        rgba(255, 255, 255, 0.15) 45%,
        rgba(255, 255, 255, 0.25) 50%,
        rgba(255, 255, 255, 0.15) 55%,
        transparent 60%
    );
    background-size: 200% 100%;
    opacity: 0;
    transition: opacity 0.3s;
}

.btn-primary:hover::after {
    opacity: 1;
    animation: shimmer 0.8s ease-in-out;
}

.btn-primary:active {
    transform: scale(0.98);
}


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

/* Checkbox custom */
input[type="checkbox"] {
    cursor: pointer;
    accent-color: var(--postex-primary);
}

/* Select custom arrow */
select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20' fill='%236b7280'%3E%3Cpath fill-rule='evenodd' d='M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z' clip-rule='evenodd'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1.25rem;
    padding-right: 2.5rem;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Autofill override */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 30px white inset;
    -webkit-text-fill-color: #111827;
    transition: background-color 5000s ease-in-out 0s;
}

/* Number input: hide spinners */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type="number"] {
    -moz-appearance: textfield;
}


/* ============================================
   Table Enhancements
   ============================================ */
table {
    border-collapse: separate;
    border-spacing: 0;
}

/* Zebra striping */
tbody tr:nth-child(even) {
    background-color: rgba(248, 250, 252, 0.5);
}

/* Sticky table header */
.table-sticky-header thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: white;
}


/* ============================================
   Card Hover Effects
   ============================================ */
.card-hover {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.card-hover:hover {
    transform: translateY(-2px);
    box-shadow:
        0 10px 25px -5px rgba(0, 0, 0, 0.08),
        0 4px 10px -6px rgba(0, 0, 0, 0.04);
}


/* ============================================
   Transition Utilities
   ============================================ */
.transition-fast    { transition: all 0.15s ease; }
.transition-normal  { transition: all 0.3s ease; }
.transition-slow    { transition: all 0.5s ease; }

.transition-spring {
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}


/* ============================================
   Line Clamp (older browser fallback)
   ============================================ */
.line-clamp-1 {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

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

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


/* ============================================
   Backdrop Blur (Safari support)
   ============================================ */
.backdrop-blur-safe {
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
}


/* ============================================
   Print Styles
   ============================================ */
@media print {
    /* Hide non-essential elements */
    header,
    footer,
    aside,
    nav,
    .no-print,
    #toast-container,
    [x-data],
    button,
    .print\\:hidden {
        display: none !important;
    }

    /* Reset backgrounds and shadows */
    body {
        background: white !important;
        color: black !important;
        font-size: 12pt;
        line-height: 1.5;
    }

    /* Remove layout offset */
    .lg\\:ml-\\[280px\\] {
        margin-left: 0 !important;
    }

    main {
        padding: 0 !important;
    }

    /* Table improvements */
    table {
        width: 100% !important;
        border-collapse: collapse !important;
    }

    table th,
    table td {
        border: 1px solid #d1d5db !important;
        padding: 8px 12px !important;
    }

    table th {
        background: #f3f4f6 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Status badges in print */
    .bg-emerald-50,
    .bg-red-50,
    .bg-amber-50,
    .bg-blue-50 {
        border: 1px solid currentColor !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Page breaks */
    .page-break-before { page-break-before: always; }
    .page-break-after  { page-break-after: always; }
    .avoid-break       { page-break-inside: avoid; }

    /* Show URLs for links */
    a[href^="http"]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #6b7280;
    }

    /* Cards: remove shadows */
    [class*="shadow"] {
        box-shadow: none !important;
        border: 1px solid #e5e7eb !important;
    }

    /* Remove rounded corners for cleaner print */
    [class*="rounded"] {
        border-radius: 0 !important;
    }
}


/* ============================================
   Responsive Utilities
   ============================================ */

/* Touch target minimum size (accessibility) */
@media (pointer: coarse) {
    button,
    a,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 44px;
        min-width: 44px;
    }

    /* Exception for inline text links */
    p a,
    span a,
    li a {
        min-height: auto;
        min-width: auto;
    }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}


/* ============================================
   Loading State Utilities
   ============================================ */
.loading-overlay {
    position: relative;
    pointer-events: none;
    opacity: 0.6;
}

.loading-overlay::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}


/* ============================================
   Tooltip (CSS only, simple)
   ============================================ */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    padding: 6px 10px;
    background: #1f2937;
    color: white;
    font-size: 0.75rem;
    line-height: 1.4;
    border-radius: 0.5rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s ease;
    z-index: 50;
}

[data-tooltip]:hover::before {
    opacity: 1;
    transform: translateX(-50%) translateY(-4px);
}
