@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --sidebar-width: 256px;
    --header-height: 80px;
    --primary-color: #3B82F6;
    --sidebar-bg: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    --loading-spinner-size: 24px;
}

*, *::before, *::after {
    box-sizing: border-box;
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

img, video, svg {
    max-width: 100%;
    height: auto;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
}

table {
    border-collapse: collapse;
    width: 100%;
}

.skip-to-content {
    position: absolute;
    left: -9999px;
    z-index: 9999;
    padding: 1rem;
    background: var(--primary-color);
    color: white;
    text-decoration: none;
    border-radius: 0 0 0.5rem 0;
}

.skip-to-content:focus {
    left: 0;
    top: 0;
    outline: 2px solid white;
    outline-offset: 2px;
}

.loading-spinner {
    display: inline-block;
    width: var(--loading-spinner-size);
    height: var(--loading-spinner-size);
    border: 3px solid rgba(59, 130, 246, 0.2);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(2px);
}

.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin: -8px 0 0 -8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.pull-to-refresh {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    background: var(--primary-color);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 0 0 1rem 1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    transition: transform 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.pull-to-refresh.active {
    transform: translateX(-50%) translateY(0);
}

.pull-to-refresh.pulling {
    transform: translateX(-50%) translateY(0);
}

.sidebar-close-btn {
    display: none;
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.sidebar-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.sidebar-gradient .sidebar-close-btn {
    display: flex;
}

.live-region {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 1024px) {
    :root {
        --sidebar-width: 0px;
    }

    .sidebar-gradient {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1000;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .sidebar-gradient.active {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(2px);
        z-index: 999;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .sidebar-overlay.active {
        display: block;
        opacity: 1;
    }

    .main-content {
        margin-left: 0 !important;
        padding-top: 64px !important;
    }

    .mobile-header {
        display: flex !important;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .stats-grid-3 {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .stats-grid-4 {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .grid-cols-2-responsive {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .mobile-full-width {
        width: 100% !important;
        margin-left: 0 !important;
    }
}

@media (max-width: 768px) {
    html {
        font-size: 14px;
    }

    .stats-grid,
    .stats-grid-3,
    .stats-grid-4 {
        grid-template-columns: 1fr !important;
    }

    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        position: relative;
    }

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

    .mobile-card-view {
        display: block;
    }

    .mobile-card-view tbody {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    .mobile-card-view tr {
        display: flex;
        flex-direction: column;
        background: white;
        border-radius: 0.75rem;
        padding: 1rem;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        margin-bottom: 0.5rem;
    }

    .mobile-card-view td {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem 0;
        border: none !important;
    }

    .mobile-card-view td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #6B7280;
    }

    .mobile-card-view thead {
        display: none;
    }

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

    .form-grid-2-cols {
        grid-template-columns: 1fr !important;
    }

    .mobile-nav-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        scrollbar-width: none;
    }

    .mobile-nav-tabs::-webkit-scrollbar {
        display: none;
    }

    .mobile-nav-tabs > * {
        scroll-snap-align: start;
    }
}

@media (max-width: 640px) {
    .glass-card {
        padding: 1.5rem !important;
    }

    .glass-card h1 {
        font-size: 1.5rem;
    }

    .login-container {
        padding: 1rem;
    }

    .btn-mobile-full {
        width: 100%;
    }

    .action-buttons {
        flex-direction: column;
        gap: 0.5rem;
    }

    .action-buttons button {
        width: 100%;
    }

    .header-actions {
        display: none;
    }

    .header-mobile-actions {
        display: flex !important;
    }

    .report-stats {
        grid-template-columns: 1fr !important;
    }

    .kpi-card {
        flex-direction: column;
        text-align: center;
    }

    .modal-fullscreen-mobile {
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 0 !important;
        min-height: 100vh !important;
    }

    .admin-actions {
        flex-direction: column;
        gap: 0.5rem;
    }

    .admin-actions a,
    .admin-actions button {
        width: 100%;
        justify-content: center;
    }
}

@media (min-width: 1025px) {
    .mobile-header,
    .sidebar-overlay,
    .sidebar-close-btn {
        display: none !important;
    }
}

@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;
    }
}

@media (hover: none) and (pointer: coarse) {
    button, a {
        min-height: 44px;
        min-width: 44px;
    }

    input, select, textarea {
        min-height: 44px;
    }
}

.focus-visible-ring:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

@container (max-width: 480px) {
    .card-adaptive {
        padding: 0.75rem;
    }

    .text-adaptive {
        font-size: 0.875rem;
    }
}

@media print {
    .sidebar-gradient,
    .mobile-header,
    .sidebar-overlay,
    .skip-to-content,
    .pull-to-refresh {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }
}

@supports (container-type: inline-size) {
    .adaptive-grid {
        display: grid;
        gap: 1rem;
    }

    @container (min-width: 600px) {
        .adaptive-grid {
            grid-template-columns: repeat(2, 1fr);
        }
    }

    @container (min-width: 900px) {
        .adaptive-grid {
            grid-template-columns: repeat(3, 1fr);
        }
    }
}

.aria-live-region {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.focus-trap {
    position: fixed;
    inset: 0;
    z-index: 9998;
}

.toast-notification {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    animation: slideInUp 0.3s ease;
    max-width: calc(100vw - 2rem);
}

.toast-notification.success {
    background: #10B981;
    color: white;
}

.toast-notification.error {
    background: #EF4444;
    color: white;
}

.toast-notification.info {
    background: #3B82F6;
    color: white;
}

@keyframes slideInUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

@keyframes progressShrink {
    from { width: 100%; }
    to { width: 0%; }
}

.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    pointer-events: none;
}

.toast-container > * {
    pointer-events: auto;
}

.toast-notification {
    position: relative;
    padding: 1rem 1rem 1.5rem;
    border-radius: 0.75rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    max-width: 380px;
    min-width: 300px;
    display: flex;
    align-items: flex-start;
    gap: 0.875rem;
    animation: slideInUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.toast-notification.hiding {
    animation: slideOutRight 0.3s ease forwards;
}

.toast-icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.2);
}

.toast-body {
    flex: 1;
    min-width: 0;
}

.toast-title {
    font-weight: 600;
    font-size: 0.9375rem;
    margin-bottom: 0.125rem;
}

.toast-message {
    font-size: 0.875rem;
    opacity: 0.95;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.95);
}

.toast-dismiss {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s, background 0.2s;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.375rem;
}

.toast-dismiss:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.1);
}

.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: rgba(255, 255, 255, 0.35);
    border-radius: 0 0 0.75rem 0.75rem;
    animation: progressShrink var(--toast-duration, 4000ms) linear forwards;
}

.toast-notification.success {
    background: linear-gradient(135deg, #10B981 0%, #059669 100%);
    color: white;
}

.toast-notification.error {
    background: linear-gradient(135deg, #EF4444 0%, #DC2626 100%);
    color: white;
}

.toast-notification.info {
    background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%);
    color: white;
}

.toast-notification.warning {
    background: linear-gradient(135deg, #F59E0B 0%, #D97706 100%);
    color: white;
}

@media (max-width: 640px) {
    .toast-container {
        left: 1rem;
        right: 1rem;
        bottom: 1rem;
    }

    .toast-notification {
        max-width: none;
        min-width: auto;
    }
}

.skeleton {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e8e8e8 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: 0.375rem;
}

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

.skeleton-text {
    height: 0.875rem;
    margin-bottom: 0.5rem;
}

.skeleton-text-sm {
    height: 0.75rem;
}

.skeleton-text-lg {
    height: 1.25rem;
}

.skeleton-text-xl {
    height: 1.5rem;
}

.skeleton-title {
    height: 1.75rem;
    width: 55%;
    margin-bottom: 0.75rem;
}

.skeleton-avatar {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    flex-shrink: 0;
}

.skeleton-avatar-sm {
    width: 2rem;
    height: 2rem;
}

.skeleton-avatar-lg {
    width: 3rem;
    height: 3rem;
}

.skeleton-button {
    height: 2.5rem;
    width: 7rem;
    border-radius: 0.5rem;
}

.skeleton-card {
    background: white;
    border-radius: 0.75rem;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.skeleton-card-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #f0f0f0;
}

.skeleton-card-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.skeleton-table {
    width: 100%;
}

.skeleton-table-row {
    display: flex;
    align-items: center;
    padding: 1rem 0.75rem;
    border-bottom: 1px solid #f5f5f5;
    gap: 1rem;
}

.skeleton-table-row > div {
    flex: 1;
}

.skeleton-line {
    height: 0.875rem;
    border-radius: 0.25rem;
}

.skeleton-line-sm {
    height: 0.75rem;
    width: 60%;
}

.skeleton-line-lg {
    height: 1rem;
}

.skeleton-badge {
    height: 1.5rem;
    width: 5rem;
    border-radius: 9999px;
}

.skeleton-chart {
    height: 280px;
    border-radius: 0.75rem;
}

.skeleton-stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

@media (max-width: 768px) {
    .skeleton-stat-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.skeleton-stat-card {
    padding: 1.25rem;
    background: white;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.skeleton-stat-icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
}

.skeleton-stat-value {
    height: 2rem;
    width: 50%;
    margin-bottom: 0.5rem;
}

.skeleton-stat-label {
    height: 0.875rem;
    width: 70%;
}

.loading-dots {
    display: inline-flex;
    gap: 3px;
    align-items: center;
}

.loading-dots span {
    width: 6px;
    height: 6px;
    background: currentColor;
    border-radius: 50%;
    animation: dot-bounce 1.4s ease-in-out infinite;
}

.loading-dots span:nth-child(1) { animation-delay: 0s; }
.loading-dots span:nth-child(2) { animation-delay: 0.15s; }
.loading-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes dot-bounce {
    0%, 80%, 100% { transform: scale(0.7); opacity: 0.6; }
    40% { transform: scale(1); opacity: 1; }
}

.skeleton-inline {
    display: inline-block;
    vertical-align: middle;
}

.skeleton-circle {
    border-radius: 50%;
}

.skeleton-rounded {
    border-radius: 0.5rem;
}

@media (prefers-reduced-motion: reduce) {
    .skeleton {
        animation: none;
        background: #e8e8e8;
    }

    .toast-notification {
        animation: none;
    }

    .toast-progress {
        animation: none;
        width: 0%;
    }

    .loading-dots span {
        animation: none;
        opacity: 0.6;
    }
}
