/**
 * QScrap Shared CSS Utilities
 * 
 * Common utility classes and component styles used across all modules
 * Include this file before module-specific CSS
 */

/* ===== CSS VARIABLES (Shared Theme) ===== */
:root {
    /* Primary Colors */
    --primary: #8D1B3D;
    --primary-dark: #6B1530;
    --primary-light: #818cf8;
    --accent: #8D1B3D;

    /* Status Colors */
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;

    /* Light Theme Backgrounds */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;

    /* Light Theme Text */
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;

    /* Borders & Shadows */
    --border: #e2e8f0;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);

    /* Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Input */
    --input-bg: #ffffff;
}

/* ===== DARK THEME ===== */
[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: rgba(255, 255, 255, 0.1);
    --border-color: rgba(255, 255, 255, 0.1);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --input-bg: #334155;
}

/* ===== UTILITY CLASSES ===== */

/* Background Utilities */
.bg-primary {
    background-color: var(--bg-primary) !important;
}

.bg-secondary {
    background-color: var(--bg-secondary) !important;
}

.bg-card {
    background-color: var(--bg-card) !important;
}

.bg-accent {
    background-color: var(--accent) !important;
}

.bg-success {
    background-color: var(--success) !important;
}

.bg-warning {
    background-color: var(--warning) !important;
}

.bg-danger {
    background-color: var(--danger) !important;
}

/* Text Utilities */
.text-primary {
    color: var(--text-primary) !important;
}

.text-secondary {
    color: var(--text-secondary) !important;
}

.text-muted {
    color: var(--text-muted) !important;
}

.text-accent {
    color: var(--accent) !important;
}

.text-success {
    color: var(--success) !important;
}

.text-warning {
    color: var(--warning) !important;
}

.text-danger {
    color: var(--danger) !important;
}

.text-white {
    color: white !important;
}

/* Font Weight */
.fw-normal {
    font-weight: 400 !important;
}

.fw-medium {
    font-weight: 500 !important;
}

.fw-semibold {
    font-weight: 600 !important;
}

.fw-bold {
    font-weight: 700 !important;
}

/* Spacing Utilities */
.m-0 {
    margin: 0 !important;
}

.mt-1 {
    margin-top: 4px !important;
}

.mt-2 {
    margin-top: 8px !important;
}

.mt-3 {
    margin-top: 12px !important;
}

.mt-4 {
    margin-top: 16px !important;
}

.mb-1 {
    margin-bottom: 4px !important;
}

.mb-2 {
    margin-bottom: 8px !important;
}

.mb-3 {
    margin-bottom: 12px !important;
}

.mb-4 {
    margin-bottom: 16px !important;
}

.p-0 {
    padding: 0 !important;
}

.p-2 {
    padding: 8px !important;
}

.p-3 {
    padding: 12px !important;
}

.p-4 {
    padding: 16px !important;
}

/* Display Utilities */
.d-none {
    display: none !important;
}

.d-block {
    display: block !important;
}

.d-flex {
    display: flex !important;
}

.d-grid {
    display: grid !important;
}

.flex-column {
    flex-direction: column !important;
}

.align-center {
    align-items: center !important;
}

.justify-center {
    justify-content: center !important;
}

.justify-between {
    justify-content: space-between !important;
}

.gap-1 {
    gap: 4px !important;
}

.gap-2 {
    gap: 8px !important;
}

.gap-3 {
    gap: 12px !important;
}

.gap-4 {
    gap: 16px !important;
}

.gap-5 {
    gap: 24px !important;
}

.gap-6 {
    gap: 32px !important;
}

/* Responsive Grid Utilities */
.grid-responsive {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-md);
}

@media (min-width: 640px) {
    .grid-responsive {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .grid-responsive {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1280px) {
    .grid-responsive {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* App Shell Layout */
.app-shell {
    display: flex;
    min-height: 100vh;
    background: var(--bg-page);
}

.app-sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: var(--z-fixed);
    transition: transform var(--transition-normal);
}

.app-main {
    flex: 1;
    margin-left: 280px;
    padding: var(--space-lg);
    transition: margin-left var(--transition-normal);
    width: 100%;
}

/* Premium Transitions */
:root {
    --transition-normal: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Mobile Utilities */
@media (max-width: 768px) {
    .hide-on-mobile {
        display: none !important;
    }
}

/* Mobile App Shell */
@media (max-width: 1024px) {
    .app-sidebar {
        transform: translateX(-100%);
    }

    .app-sidebar.is-open {
        transform: translateX(0);
        box-shadow: var(--shadow-xl);
    }

    .app-main {
        margin-left: 0;
        padding: var(--space-md);
    }

    .app-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: var(--z-modal-backdrop);
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--transition-normal);
    }

    .app-overlay.is-visible {
        opacity: 1;
        pointer-events: auto;
    }
}

/* Border Utilities */
.rounded-sm {
    border-radius: var(--radius-sm) !important;
}

.rounded-md {
    border-radius: var(--radius-md) !important;
}

.rounded-lg {
    border-radius: var(--radius-lg) !important;
}

.rounded-xl {
    border-radius: var(--radius-xl) !important;
}

.border {
    border: 1px solid var(--border) !important;
}

.border-0 {
    border: none !important;
}

/* ===== TOAST COMPONENT ===== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 400px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--info);
    transform: translateX(120%);
    opacity: 0;
    transition: all 0.3s ease;
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast.hide {
    transform: translateX(120%);
    opacity: 0;
}

.toast-success {
    border-left-color: var(--success);
}

.toast-success i {
    color: var(--success);
}

.toast-error {
    border-left-color: var(--danger);
}

.toast-error i {
    color: var(--danger);
}

.toast-warning {
    border-left-color: var(--warning);
}

.toast-warning i {
    color: var(--warning);
}

.toast-info {
    border-left-color: var(--info);
}

.toast-info i {
    color: var(--info);
}

.toast i {
    font-size: 20px;
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.4;
}

.toast-close {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.toast-close:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

/* ===== MODAL COMPONENT ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal-container,
.modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: modal-enter 0.3s ease;
}

@keyframes modal-enter {
    from {
        transform: scale(0.95) translateY(-20px);
        opacity: 0;
    }

    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.modal-header h3,
.modal-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-close {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 24px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--border);
    color: var(--text-primary);
}

.modal-close:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-shrink: 0;
}

/* Modal Sizes */
.modal-sm {
    max-width: 400px;
}

.modal-md {
    max-width: 500px;
}

.modal-lg {
    max-width: 600px;
}

.modal-xl {
    max-width: 800px;
}

/* ===== RESPONSIVE TABLE WRAPPER ===== */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
    background: var(--bg-card);
}

.table-responsive table {
    min-width: 600px;
}

/* ===== STATUS BADGES ===== */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: capitalize;
}

.status-badge.confirmed {
    background: #dbeafe;
    color: #6B1530;
}

.status-badge.preparing {
    background: #fef3c7;
    color: #b45309;
}

.status-badge.ready,
.status-badge.ready_for_pickup {
    background: #fed7aa;
    color: #c2410c;
}

.status-badge.collected {
    background: #e0e7ff;
    color: #4338ca;
}

.status-badge.pending {
    background: #fef3c7;
    color: #b45309;
}

.status-badge.in-transit,
.status-badge.in_transit {
    background: #dbeafe;
    color: #6B1530;
}

.status-badge.delivered {
    background: #d1fae5;
    color: #059669;
}

.status-badge.completed {
    background: #d1fae5;
    color: #059669;
}

.status-badge.cancelled {
    background: #fee2e2;
    color: #dc2626;
}

.status-badge.disputed {
    background: #fee2e2;
    color: #dc2626;
}

.status-badge.refunded {
    background: #f3e8ff;
    color: #7c3aed;
}

.status-badge.available {
    background: #d1fae5;
    color: #059669;
}

.status-badge.busy {
    background: #fef3c7;
    color: #b45309;
}

.status-badge.offline {
    background: #f1f5f9;
    color: #64748b;
}

.status-badge.open {
    background: #dbeafe;
    color: #6B1530;
}

.status-badge.resolved {
    background: #d1fae5;
    color: #059669;
}

.status-badge.contested {
    background: #fee2e2;
    color: #dc2626;
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(141, 27, 61, 0.4);
}

.btn-success {
    background: linear-gradient(135deg, var(--success) 0%, #059669 100%);
    color: white;
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger) 0%, #dc2626 100%);
    color: white;
}

.btn-warning {
    background: linear-gradient(135deg, var(--warning) 0%, #d97706 100%);
    color: white;
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--bg-primary);
    border-color: var(--text-muted);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--border);
    color: var(--text-primary);
}

.btn-outline:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
}

/* ===== ACCESSIBLE FOCUS STATES ===== */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ===== RESPONSIVE BREAKPOINTS ===== */

/* Mobile: < 600px */
@media (max-width: 599px) {
    .toast-container {
        left: 10px;
        right: 10px;
        max-width: none;
    }

    .modal-container,
    .modal {
        max-width: none;
        margin: 10px;
        max-height: calc(100vh - 40px);
    }

    .hide-mobile {
        display: none !important;
    }
}

/* Tablet: 600px - 1024px */
@media (min-width: 600px) and (max-width: 1024px) {
    .hide-tablet {
        display: none !important;
    }
}

/* Desktop: > 1024px */
@media (min-width: 1025px) {
    .hide-desktop {
        display: none !important;
    }
}

/* ===== SKIP LINK (Accessibility) ===== */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary);
    color: white;
    padding: 8px 16px;
    z-index: 10000;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 var(--radius-sm) 0;
    transition: top 0.3s;
}

.skip-link:focus {
    top: 0;
}

/* ===== GLASS MORPHISM CARDS ===== */
.glass-card {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-lg);
}

[data-theme="dark"] .glass-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ===== LOADING SPINNER ===== */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

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

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state i,
.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    display: block;
}

.empty-state h4 {
    margin: 0 0 8px;
    color: var(--text-secondary);
}

.empty-state p {
    margin: 0;
    font-size: 14px;
}

/* ===== PAGINATION COMPONENT ===== */
.pagination {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 20px 0;
    justify-content: center;
    flex-wrap: wrap;
}

.page-btn {
    min-width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.page-btn:hover:not(:disabled) {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    transform: translateY(-1px);
}

.page-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.page-ellipsis {
    padding: 0 8px;
    color: var(--text-muted);
    font-size: 14px;
}

.page-info {
    margin-left: 12px;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ===== EXPANDABLE ROWS ===== */
.expandable-row {
    cursor: pointer;
    transition: background 0.2s;
}

.expandable-row:hover {
    background: var(--bg-hover, rgba(141, 27, 61, 0.05));
}

.expand-icon {
    transition: transform 0.3s ease;
    color: var(--text-secondary);
    font-size: 16px;
}

.expand-icon.expanded {
    transform: rotate(180deg);
}

.details-row {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
}

.expanded-content {
    padding: 20px;
    animation: slideDown 0.3s ease;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.expandable-row td:last-child {
    text-align: center;
    width: 40px;
}

/* Mobile pagination adjustments */
@media (max-width: 599px) {
    .pagination {
        gap: 4px;
        padding: 15px 0;
    }

    .page-btn {
        min-width: 32px;
        height: 32px;
        font-size: 13px;
    }

    .page-info {
        width: 100%;
        text-align: center;
        margin: 8px 0 0 0;
        font-size: 12px;
    }
}