/**
 * Muhuga Agricultural Marketplace
 * Custom styles to complement Tailwind CSS
 *
 * @package Muhuga
 * @version 1.0.0
 */

/* ============================================================
   CUSTOM SCROLLBAR
   ============================================================ */

/* Webkit browsers (Chrome, Safari, Edge) */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f1f5f9;
}

/* Hide scrollbar for category bar */
.scrollbar-hide::-webkit-scrollbar {
    display: none;
}

.scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
}


/* ============================================================
   PRODUCT CARD EFFECTS
   ============================================================ */

.muhuga-product-card {
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
    will-change: transform;
}

.muhuga-product-card:hover {
    transform: translateY(-4px);
}

.muhuga-product-card .line-clamp-1 {
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
}

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


/* ============================================================
   CATEGORY CARD STYLING
   ============================================================ */

.muhuga-category-card {
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
    will-change: transform;
}

.muhuga-category-card:hover {
    transform: translateY(-2px);
}

.muhuga-category-scroll {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}


/* ============================================================
   SEARCH BAR FOCUS EFFECTS
   ============================================================ */

.muhuga-search-input:focus {
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15);
    border-color: #059669;
}

.muhuga-search-category:focus {
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15);
    border-color: #059669;
}


/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */

.muhuga-toast {
    pointer-events: auto;
    min-width: 320px;
    max-width: 420px;
    padding: 14px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    animation: muhuga-toast-enter 0.35s ease forwards;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.muhuga-toast.removing {
    animation: muhuga-toast-exit 0.3s ease forwards;
}

.muhuga-toast-success {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
}

.muhuga-toast-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.muhuga-toast-warning {
    background: #fffbeb;
    border: 1px solid #fde68a;
    color: #92400e;
}

.muhuga-toast-info {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
}

.muhuga-toast-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    margin-top: 1px;
}

.muhuga-toast-message {
    flex: 1;
}

.muhuga-toast-close {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    opacity: 0.5;
    transition: opacity 0.2s;
    color: inherit;
}

.muhuga-toast-close:hover {
    opacity: 1;
}

@keyframes muhuga-toast-enter {
    from {
        opacity: 0;
        transform: translateX(100%) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

@keyframes muhuga-toast-exit {
    from {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateX(100%) scale(0.95);
    }
}


/* ============================================================
   MODAL BACKDROP
   ============================================================ */

.muhuga-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: muhuga-fade-in 0.2s ease;
}

.muhuga-modal-backdrop.closing {
    animation: muhuga-fade-out 0.2s ease forwards;
}

.muhuga-modal-content {
    background: white;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    animation: muhuga-modal-enter 0.3s ease;
}

.muhuga-modal-backdrop.closing .muhuga-modal-content {
    animation: muhuga-modal-exit 0.2s ease forwards;
}

@keyframes muhuga-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes muhuga-fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes muhuga-modal-enter {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes muhuga-modal-exit {
    from {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
    to {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }
}


/* ============================================================
   LOADING SPINNER
   ============================================================ */

.muhuga-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2.5px solid transparent;
    border-top-color: currentColor;
    border-right-color: currentColor;
    border-radius: 50%;
    animation: muhuga-spin 0.6s linear infinite;
}

.muhuga-spinner-lg {
    width: 36px;
    height: 36px;
    border-width: 3px;
}

.muhuga-spinner-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: inherit;
    z-index: 10;
}

@keyframes muhuga-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Full page loader */
.muhuga-page-loader {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 200;
    gap: 16px;
}

.muhuga-page-loader .muhuga-spinner {
    width: 48px;
    height: 48px;
    border-width: 4px;
    color: #059669;
}


/* ============================================================
   RESPONSIVE TABLES
   ============================================================ */

.muhuga-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
}

.muhuga-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.muhuga-table thead {
    background: #f8fafc;
}

.muhuga-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #64748b;
    border-bottom: 1px solid #e2e8f0;
    white-space: nowrap;
}

.muhuga-table td {
    padding: 12px 16px;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
    vertical-align: middle;
}

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

.muhuga-table tbody tr:hover {
    background: #f8fafc;
}

/* Responsive: Stack on mobile */
@media (max-width: 639px) {
    .muhuga-table-responsive thead {
        display: none;
    }

    .muhuga-table-responsive tr {
        display: block;
        padding: 12px 16px;
        border-bottom: 1px solid #e2e8f0;
    }

    .muhuga-table-responsive td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 6px 0;
        border-bottom: none;
        font-size: 13px;
    }

    .muhuga-table-responsive td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 12px;
        color: #64748b;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin-right: 16px;
    }
}


/* ============================================================
   SIDEBAR ACTIVE LINK
   ============================================================ */

.muhuga-sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    color: #475569;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.muhuga-sidebar-link:hover {
    background: #f0fdf4;
    color: #059669;
}

.muhuga-sidebar-link.active {
    background: #ecfdf5;
    color: #059669;
    font-weight: 600;
    box-shadow: inset 3px 0 0 #059669;
}

.muhuga-sidebar-link.active svg {
    color: #059669;
}


/* ============================================================
   NOTIFICATION BADGE ANIMATION
   ============================================================ */

.muhuga-badge-pulse {
    animation: muhuga-badge-pulse 2s ease-in-out infinite;
}

@keyframes muhuga-badge-pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
    }
}


/* ============================================================
   FORM INPUT FOCUS STYLES
   ============================================================ */

.muhuga-input {
    width: 100%;
    padding: 10px 14px;
    font-size: 14px;
    color: #1e293b;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    transition: all 0.2s ease;
    outline: none;
}

.muhuga-input:hover {
    border-color: #cbd5e1;
}

.muhuga-input:focus {
    border-color: #059669;
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.12);
}

.muhuga-input::placeholder {
    color: #94a3b8;
}

.muhuga-input-error {
    border-color: #ef4444;
}

.muhuga-input-error:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

.muhuga-field-error {
    font-size: 12px;
    color: #dc2626;
    margin-top: 4px;
    display: none;
}

.muhuga-field-error.visible {
    display: block;
}

.muhuga-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
}

.muhuga-label-required::after {
    content: " *";
    color: #ef4444;
}

textarea.muhuga-input {
    resize: vertical;
    min-height: 100px;
}

select.muhuga-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 40px;
}


/* ============================================================
   PAGINATION
   ============================================================ */

.muhuga-pagination {
    display: flex;
    align-items: center;
    gap: 4px;
}

.muhuga-pagination a,
.muhuga-pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    font-size: 13px;
    font-weight: 500;
    color: #475569;
    border-radius: 8px;
    transition: all 0.2s ease;
    text-decoration: none;
}

.muhuga-pagination a:hover {
    background: #f0fdf4;
    color: #059669;
}

.muhuga-pagination .active {
    background: #059669;
    color: white;
    font-weight: 600;
}

.muhuga-pagination .disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}


/* ============================================================
   DASHBOARD STAT CARD GRADIENTS
   ============================================================ */

.muhuga-stat-card {
    border-radius: 12px;
    padding: 20px 24px;
    color: white;
    position: relative;
    overflow: hidden;
}

.muhuga-stat-card::after {
    content: "";
    position: absolute;
    top: -50%;
    right: -30%;
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
}

.muhuga-stat-green {
    background: linear-gradient(135deg, #059669, #047857);
}

.muhuga-stat-blue {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
}

.muhuga-stat-orange {
    background: linear-gradient(135deg, #ea580c, #c2410c);
}

.muhuga-stat-purple {
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
}

.muhuga-stat-teal {
    background: linear-gradient(135deg, #0d9488, #0f766e);
}

.muhuga-stat-rose {
    background: linear-gradient(135deg, #e11d48, #be123c);
}

.muhuga-stat-card .stat-value {
    font-size: 28px;
    font-weight: 800;
    line-height: 1.2;
}

.muhuga-stat-card .stat-label {
    font-size: 13px;
    opacity: 0.85;
    margin-top: 4px;
}

.muhuga-stat-card .stat-icon {
    position: absolute;
    top: 16px;
    right: 16px;
    opacity: 0.3;
}


/* ============================================================
   PRINT STYLES FOR INVOICES
   ============================================================ */

@media print {
    /* Hide non-essential elements */
    header,
    footer,
    nav,
    .muhuga-sidebar,
    .muhuga-toast,
    #muhuga-toast-container,
    .muhuga-modal-backdrop,
    .no-print,
    [x-data] button[x-show] {
        display: none !important;
    }

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

    /* Invoice specific */
    .muhuga-invoice {
        padding: 0;
        margin: 0;
        max-width: 100%;
    }

    .muhuga-invoice-header {
        border-bottom: 2px solid #000;
        padding-bottom: 16px;
        margin-bottom: 16px;
    }

    .muhuga-table {
        font-size: 11pt;
    }

    .muhuga-table th,
    .muhuga-table td {
        padding: 8px 12px;
        border: 1px solid #ccc;
    }

    /* No page breaks inside cards */
    .muhuga-product-card,
    .muhuga-stat-card {
        break-inside: avoid;
    }

    /* Links: show URL */
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 10pt;
        color: #666;
    }

    /* No shadows */
    * {
        box-shadow: none !important;
        text-shadow: none !important;
    }
}


/* ============================================================
   DROPDOWN MENU LINKS
   ============================================================ */

.muhuga-dropdown-link {
    text-decoration: none;
}


/* ============================================================
   BUTTON STATES
   ============================================================ */

.muhuga-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    transition: all 0.2s ease;
    cursor: pointer;
    border: none;
    outline: none;
    text-decoration: none;
    line-height: 1.4;
}

.muhuga-btn:disabled,
.muhuga-btn.loading {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

.muhuga-btn-primary {
    background: #059669;
    color: white;
}

.muhuga-btn-primary:hover {
    background: #047857;
}

.muhuga-btn-accent {
    background: #ea580c;
    color: white;
}

.muhuga-btn-accent:hover {
    background: #c2410c;
}

.muhuga-btn-outline {
    background: white;
    color: #059669;
    border: 1.5px solid #059669;
}

.muhuga-btn-outline:hover {
    background: #ecfdf5;
}

.muhuga-btn-danger {
    background: #dc2626;
    color: white;
}

.muhuga-btn-danger:hover {
    background: #b91c1c;
}

.muhuga-btn-ghost {
    background: transparent;
    color: #475569;
}

.muhuga-btn-ghost:hover {
    background: #f1f5f9;
}


/* ============================================================
   FILTER SIDEBAR (MOBILE)
   ============================================================ */

.muhuga-filter-sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    width: 300px;
    height: 100vh;
    background: white;
    z-index: 80;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.1);
    transition: left 0.3s ease;
    overflow-y: auto;
    padding: 24px;
}

.muhuga-filter-sidebar.open {
    left: 0;
}

.muhuga-filter-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 79;
    display: none;
}

.muhuga-filter-overlay.open {
    display: block;
}

@media (min-width: 768px) {
    .muhuga-filter-sidebar {
        position: static;
        width: 100%;
        height: auto;
        box-shadow: none;
        padding: 0;
    }
}


/* ============================================================
   IMAGE PREVIEW
   ============================================================ */

.muhuga-image-preview {
    position: relative;
    display: inline-block;
    border-radius: 8px;
    overflow: hidden;
    border: 2px dashed #e2e8f0;
    background: #f8fafc;
}

.muhuga-image-preview img {
    display: block;
    max-width: 200px;
    max-height: 200px;
    object-fit: cover;
}

.muhuga-image-preview .remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: background 0.2s;
}

.muhuga-image-preview .remove-btn:hover {
    background: rgba(220, 38, 38, 0.8);
}


/* ============================================================
   STATUS BADGES
   ============================================================ */

.muhuga-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 9999px;
    text-transform: capitalize;
    letter-spacing: 0.01em;
}

.muhuga-badge-green {
    background: #dcfce7;
    color: #166534;
}

.muhuga-badge-yellow {
    background: #fef9c3;
    color: #854d0e;
}

.muhuga-badge-red {
    background: #fee2e2;
    color: #991b1b;
}

.muhuga-badge-blue {
    background: #dbeafe;
    color: #1e40af;
}

.muhuga-badge-gray {
    background: #f1f5f9;
    color: #475569;
}

.muhuga-badge-orange {
    background: #ffedd5;
    color: #9a3412;
}


/* ============================================================
   CONFIRMATION DIALOG
   ============================================================ */

.muhuga-confirm-dialog {
    text-align: center;
    padding: 32px 24px;
}

.muhuga-confirm-dialog .icon-wrapper {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.muhuga-confirm-dialog .icon-danger {
    background: #fee2e2;
    color: #dc2626;
}

.muhuga-confirm-dialog .icon-warning {
    background: #fef3c7;
    color: #d97706;
}

.muhuga-confirm-dialog h3 {
    font-size: 18px;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 8px;
}

.muhuga-confirm-dialog p {
    font-size: 14px;
    color: #64748b;
    margin-bottom: 24px;
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
}

.muhuga-confirm-dialog .actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}


/* ============================================================
   SKELETON LOADING
   ============================================================ */

.muhuga-skeleton {
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
    background-size: 200% 100%;
    animation: muhuga-skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: 6px;
}

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


/* ============================================================
   FILE UPLOAD AREA
   ============================================================ */

.muhuga-upload-area {
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    padding: 32px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #fafafa;
}

.muhuga-upload-area:hover {
    border-color: #059669;
    background: #f0fdf4;
}

.muhuga-upload-area.dragover {
    border-color: #059669;
    background: #ecfdf5;
    box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.1);
}


/* ============================================================
   M-PESA PAYMENT MODAL
   ============================================================ */

.muhuga-mpesa-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 32px 24px;
    text-align: center;
}

.muhuga-mpesa-status .phone-icon {
    width: 64px;
    height: 64px;
    background: #ecfdf5;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.muhuga-mpesa-status .phone-icon svg {
    width: 32px;
    height: 32px;
    color: #059669;
}

.muhuga-mpesa-waiting .waiting-text::after {
    content: '';
    display: inline-block;
    animation: muhuga-dots 1.5s steps(4, end) infinite;
}

@keyframes muhuga-dots {
    0%  { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}


/* ============================================================
   UTILITY OVERRIDES
   ============================================================ */

/* Ensure Alpine.js hidden elements don't flash */
[x-cloak] {
    display: none !important;
}

/* WordPress admin bar offset */
.admin-bar header.sticky {
    top: 32px;
}

@media (max-width: 782px) {
    .admin-bar header.sticky {
        top: 46px;
    }
}
