@layer utilities {

    html,
    body {
        overflow-x: hidden;
    }

    .glass-card {
        background: rgba(255, 255, 255, 0.03);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.05);
        transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        position: relative;
    }

    /* Top Gradient Line via Pseudo-element */
    .glass-header {
        background: rgba(255, 255, 255, 0.03);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.05);
        position: relative;
    }

    /* Enhanced Navbar Links */
    .nav-link {
        @apply relative py-1 text-gray-400 hover:text-white transition-colors duration-300;
        display: inline-block;
    }

    .nav-link::after {
        content: '';
        position: absolute;
        bottom: -2px;
        left: 0;
        width: 0;
        height: 2px;
        background: linear-gradient(90deg, #FF8C42 0%, #FF2E2E 100%);
        transition: width 0.3s ease;
        border-radius: 2px;
    }

    .nav-link:hover::after,
    .nav-link-active::after {
        width: 100% !important;
    }

    .nav-link-active {
        @apply text-white font-semibold !important;
    }

    .table-row-static {
        transition: background-color 0.2s ease;
    }

    .table-row-static:hover {
        background: rgba(255, 255, 255, 0.05);
    }

    /* Top Gradient Line via Pseudo-element (Featured Only) */
    .glass-card.featured::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 4px;
        background: linear-gradient(90deg, #FF8C42 0%, #FF2E2E 100%);
        opacity: 0;
        transition: opacity 0.4s ease;
        z-index: 10;
    }

    .glass-card:hover {
        transform: translateY(-10px) scale(1.02);
        background: rgba(255, 255, 255, 0.08);
        border-color: rgba(255, 140, 66, 0.5);
        /* Brand Orange */
        box-shadow: 0 20px 50px -10px rgba(255, 140, 66, 0.15);
        /* Orange Glow */
    }

    .glass-card.featured:hover::before {
        opacity: 1;
    }

    /* Animate button on card hover */
    .glass-card:hover button {
        background: linear-gradient(90deg, #FF8C42 0%, #FF2E2E 100%);
        border-color: transparent;
        box-shadow: 0 10px 20px -5px rgba(255, 140, 66, 0.4);
        transform: translateY(-2px);
    }

    /* Featured Card State (Always active) */
    .glass-card.featured {
        border-color: rgba(255, 140, 66, 0.5);
        box-shadow: 0 20px 50px -10px rgba(255, 140, 66, 0.15);
        transform: translateY(-10px) scale(1.02);
    }

    .glass-card.featured::before {
        opacity: 1;
    }

    .text-glow {
        text-shadow: 0 0 20px rgba(249, 115, 22, 0.5);
    }

    .orange-glow {
        box-shadow: 0 0 30px -5px rgba(249, 115, 22, 0.3);
    }

    .orange-gradient-text {
        background: linear-gradient(135deg, #FF8C42 0%, #FF2E2E 100%);
        -webkit-background-clip: text;
        background-clip: text;
        -webkit-text-fill-color: transparent;
    }

    .grid-bento {
        display: grid;
        grid-template-columns: repeat(12, 1fr);
        grid-template-rows: repeat(2, minmax(200px, auto));
        gap: 1.5rem;
    }

    /* Animations */
    @keyframes fadeInUp {
        from {
            opacity: 0;
            transform: translateY(20px);
        }

        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    @keyframes float {

        0%,
        100% {
            transform: translateY(0px) rotate(-6deg);
        }

        50% {
            transform: translateY(-10px) rotate(-6deg);
        }
    }

    @keyframes float-reverse {

        0%,
        100% {
            transform: translateY(0px) rotate(6deg);
        }

        50% {
            transform: translateY(10px) rotate(6deg);
        }
    }

    .animate-fade-in-up {
        animation: fadeInUp 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
        opacity: 0;
        /* Hidden by default */
    }

    .animate-float-slow {
        animation: float 6s ease-in-out infinite;
    }

    .animate-float-reverse-slow {
        animation: float-reverse 7s ease-in-out infinite;
    }

    @keyframes pulse-scale {

        0%,
        100% {
            transform: scale(1);
            opacity: 1;
        }

        50% {
            transform: scale(1.1);
            opacity: 0.8;
        }
    }

    .animate-pulse-scale {
        animation: pulse-scale 3s ease-in-out infinite;
    }

    .delay-100 {
        animation-delay: 0.1s;
    }

    .delay-200 {
        animation-delay: 0.2s;
    }

    .delay-300 {
        animation-delay: 0.3s;
    }

    .delay-400 {
        animation-delay: 0.4s;
    }

    .delay-500 {
        animation-delay: 0.5s;
    }

    /* Scroll Reveal */
    .reveal {
        opacity: 0;
        transform: translateY(30px);
        transition: all 0.8s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .reveal.visible {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #0f0f11;
}

::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

@media (max-width: 768px) {
    .hide-on-mobile {
        display: none !important;
    }

    #documents-table thead {
        display: none;
    }

    #documents-table,
    #documents-table tbody,
    #documents-table tr,
    #documents-table td {
        display: block;
        width: 100%;
    }

    #documents-table tr {
        margin-bottom: 1rem;
        border: 1px solid rgba(255, 255, 255, 0.05);
        border-radius: 1rem;
        background: rgba(255, 255, 255, 0.02);
        padding: 1rem;
        position: relative;
        overflow: hidden;
        /* Prevent inner content overflow */
    }

    #documents-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: right;
        padding: 0.75rem 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    }

    #documents-table td:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }

    #documents-table td::before {
        content: attr(data-label);
        font-weight: 600;
        text-transform: uppercase;
        font-size: 0.75rem;
        color: #9CA3AF;
        margin-right: 1rem;
    }

    /* Document Name Styling - Headline Style */
    #documents-table td[data-label="Документ"] {
        display: block;
        text-align: left;
        padding-top: 0;
        margin-bottom: 0.5rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        word-break: break-all;
        /* Fix for long filenames */
        white-space: normal;
        line-height: 1.4;
    }

    #documents-table td[data-label="Документ"]::before {
        display: none;
    }

    /* Action Buttons Alignment */
    #documents-table td[data-label="Действие"] {
        justify-content: flex-end;
    }
}

@media (max-width: 480px) {

    /* Global Container Padding */
    main {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    /* Navbar Adjustments for 320px - ONLY FOR STICKY NAVBAR */
    .glass-header.sticky {
        padding: 0.75rem 0.5rem !important;
        /* Tighter padding */
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.25rem;
        /* Ensure minimal gap */
        flex-wrap: nowrap !important;
        /* FORBID WRAPPING */
    }

    /* Ensure dashboard glass-card and glass-header (wrappers) are NOT flex */
    .glass-card,
    div.glass-header:not(.sticky) {
        display: block !important;
    }

    /* Logo Size */
    .glass-header .font-display {
        font-size: 1.1rem !important;
        /* Smaller logo */
    }

    /* Nav Button Mobile */
    nav a[href="login.html"],
    nav a[href="dashboard.html"],
    .glass-header button,
    .glass-header a.bg-white\/5 {
        padding: 0.4rem 0.75rem !important;
        font-size: 0.75rem !important;
        /* Smaller button text */
    }

    /* Header Adjustments */
    .glass-header h1 {
        font-size: 1.75rem !important;
        /* Smaller title */
        line-height: 1.2;
    }

    .glass-header h2 {
        font-size: 1.5rem !important;
    }

    /* Card Padding Reduction */
    .glass-card {
        padding: 1rem !important;
        /* Reduce from p-6/p-8 */
    }

    /* Stats Grid Gap */
    .grid-cols-1 {
        gap: 1rem !important;
    }

    /* Table Card Adjustments */
    #documents-table tr {
        padding: 0.75rem;
    }

    #documents-table td {
        padding: 0.5rem 0;
        font-size: 0.8125rem;
        /* Smaller text 13px */
    }

    #documents-table td::before {
        font-size: 0.65rem;
        /* Smaller label */
    }

    /* Upload Zone on Mobile */
    #drop-zone {
        height: 10rem !important;
        /* Matches h-40 */
    }

    /* Dashboard Header Fix */
    .glass-header .p-6.border-b {
        flex-wrap: wrap !important;
        gap: 0.5rem;
    }

    .glass-header h3 {
        font-size: 1.1rem !important;
    }

    /* Score Bar width fix for very small screens */
    #documents-table .w-32 {
        width: 5rem !important;
        /* Smaller bar on mobile */
    }

    /* Fix for 320px screens */
    @media (max-width: 340px) {
        .glass-card {
            padding: 1.25rem 0.75rem !important;
        }

        #analysis-visual-container {
            min-height: 19rem !important;
            padding-bottom: 3rem !important;
        }

        #loading-text {
            font-size: 0.875rem !important;
            line-height: 1.25;
        }

        .animate-pulse-scale {
            transform: scale(0.9);
        }

        #loading-state .relative.w-16 {
            width: 64px !important;
            height: 64px !important;
            flex-basis: 64px !important;
            flex-grow: 0 !important;
            flex-shrink: 0 !important;
        }
    }
}

/* Custom Modal System */
.custom-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.custom-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.custom-modal-card {
    position: relative;
    width: 90%;
    max-width: 450px;
    background: rgba(10, 10, 11, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 1.5rem;
    padding: 2.5rem 2rem 2rem;
    transform: scale(0.9);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

.custom-modal-overlay.active .custom-modal-card {
    transform: scale(1);
}

.custom-modal-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #FF8C42 0%, #FF2E2E 100%);
}

.custom-modal-title {
    font-family: 'Unbounded', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.custom-modal-body {
    font-size: 1rem;
    color: rgba(226, 226, 226, 0.7);
    line-height: 1.6;
    margin-bottom: 2rem;
}

.custom-modal-footer {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

.custom-modal-btn {
    padding: 0.75rem 1.5rem;
    border-radius: 0.75rem;
    font-weight: 600;
    font-size: 0.875rem;
    transition: all 0.2s ease;
    cursor: pointer;
}

.custom-modal-btn-primary {
    background: linear-gradient(90deg, #FF8C42 0%, #FF2E2E 100%);
    color: #fff;
    border: none;
    flex: 1;
}

.custom-modal-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px -5px rgba(255, 140, 66, 0.4);
}

.custom-modal-btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.1);
    flex: 1;
}

.custom-modal-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

@media (max-width: 480px) {
    .custom-modal-card {
        padding: 2rem 1.5rem 1.5rem;
    }

    .custom-modal-title {
        font-size: 1.1rem;
    }

    .custom-modal-body {
        font-size: 0.9rem;
    }
}