/*------------------------------------*\
    Nginxy - Modernized Version
    by @lfelipe1501

    Theme name: Nginxy
    Theme author: @lfelipe1501
\*------------------------------------*/
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600&display=swap");
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap');

:root {
    color-scheme: dark;
    --primary-color: #6d8eff;
    --secondary-color: #adb5bd;
    --hover-color: #dc8867;
    --background-color: #282523;
    --text-color: #e0e0e0;
    --border-color: #2d2d2d;
    --header-color: #e0e0e0;
    --footer-color: #4e423b0a;
    --icon-size: 24px;
    --table-header-bg: #2d2d2d;
    --table-header-color: #e0e0e0;
    --table-shadow: rgba(0, 0, 0, 0.2);
    --icon-opacity: 0.9;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html {
    font-size: 16px;
    font-family: "Poppins", 'Andada Pro', 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.5;
}

body {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 1rem;
    background: var(--background-color);
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
    font-size: 16px;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--primary-color);
    opacity: 0.8;
}

/* Icon styles */
.icon-container {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 0.5rem;
}

.icon-container svg {
    width: var(--icon-size);
    height: var(--icon-size);
    opacity: var(--icon-opacity);
    transition: opacity 0.3s ease;
}

.colored-icon {
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2)) brightness(1.1);
}

.icon-text-container {
    display: flex;
    align-items: center;
}

/*------------------------------------*\
    Header
\*------------------------------------*/
h1 {
    font-weight: 500;
    text-align: center;
    font-size: 1.8rem;
    padding: 1.5rem 0;
    color: var(--header-color);
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

h1::before {
    content: "";
    display: inline-block;
    width: 30px;
    height: 30px;
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="%23ffc107" d="M10,4H4C2.89,4 2,4.89 2,6V18A2,2 0 0,0 4,20H20A2,2 0 0,0 22,18V8C22,6.89 21.1,6 20,6H12L10,4Z" /></svg>');
    background-size: contain;
    background-repeat: no-repeat;
}

/*------------------------------------*\
    Table (directory listing)
\*------------------------------------*/
table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
    box-shadow: 0 2px 5px var(--table-shadow);
    border-radius: 5px;
    overflow: hidden;
    table-layout: auto;
    font-size: 16px;
    opacity: 1;
    transition: opacity 0.2s ease-in;
}

/* Prevent flash of unstyled content */
table.loading {
    opacity: 0;
}

th {
    background-color: var(--table-header-bg);
    color: var(--table-header-color);
    padding: 0.75rem;
    text-align: left;
    font-weight: 500;
    position: relative;
    font-size: 16px !important;
}

th[data-sort] {
    position: relative;
    padding-right: 25px;
    /* Espacio para el icono de ordenamiento */
    user-select: none;
    /* Evitar selección de texto */
    cursor: pointer;
    transition: background-color 0.2s ease;
}

th[data-sort]::after {
    content: "⇕";
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.5;
    font-size: 0.8rem;
}

th[data-sort]:hover {
    background-color: var(--hover-color);
}

th[data-sort]:hover::after {
    opacity: 1;
}

/* Estilos para los iconos de ordenamiento */
.sort-icon {
    display: inline-block;
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.9rem;
    line-height: 1;
    opacity: 1;
    transition: all 0.2s ease;
}

/* 1st Column: Filename */
th:first-child {
    width: 60%;
}

/* 2nd Column: Last Modified */
th:nth-child(2) {
    width: 25%;
}

/* 3rd Column: Size */
th:nth-child(3) {
    width: 15%;
    text-align: right;
}

tr {
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s ease;
}

tr td {
    white-space: nowrap;
}

td {
    padding: 0.75rem;
    vertical-align: middle;
    min-width: 0;
    font-size: 16px !important;
    line-height: 1.5;
}

td {
    flex-grow: 1;
}

tr:hover {
    background-color: var(--hover-color);
}

tr:hover .colored-icon {
    opacity: 1;
    transform: scale(1.05);
}

td {
    padding: 0.75rem;
    vertical-align: middle;
    font-size: 16px !important;
}

td:last-child {
    text-align: right;
}

td a {
    display: flex;
    align-items: center;
    color: var(--text-color);
    min-height: 30px;
}

/* Prevent layout shift while icons load */
.icon-container {
    min-width: var(--icon-size);
    min-height: var(--icon-size);
    width: var(--icon-size);
    height: var(--icon-size);
    flex-shrink: 0;
    margin-right: 0.5rem;
}

/* Reserve space before icons are inserted */
td a::before {
    content: '';
    display: inline-block;
    width: var(--icon-size);
    height: var(--icon-size);
    flex-shrink: 0;
    margin-right: 0.5rem;
}

/* Hide the ::before pseudo-element once icon-container exists */
td a:has(.icon-container)::before {
    display: none;
}

td a:hover {
    color: var(--primary-color);
}

tr.parent a {
    color: var(--secondary-color);
}

/*------------------------------------*\
    File Grouping / Accordion
\*------------------------------------*/
tr.group-header {
    background-color: rgba(109, 142, 255, 0.1);
    cursor: pointer;
    user-select: none;
}

tr.group-header:hover {
    background-color: rgba(109, 142, 255, 0.2);
}

tr.group-header td {
    font-weight: 500;
    position: relative;
    padding-right: 5rem;
    white-space: normal;
    word-break: break-word;
}

tr.group-header .group-left {
    display: flex;
    align-items: center;
    width: 100%;
    max-width: calc(100% - 5rem);
    overflow: hidden;
}

tr.group-header .group-left span:not(.icon-container) {
    overflow: hidden;
    text-overflow: ellipsis;
}

tr.group-header .group-count {
    position: absolute;
    right: 2.5rem;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.6;
    font-size: 0.85em;
    white-space: nowrap;
}

tr.group-header .accordion-icon {
    display: inline-block;
    transition: transform 0.2s ease;
    font-size: 1rem;
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%) rotate(-90deg);
}

tr.group-header:not(.collapsed) .accordion-icon {
    transform: translateY(-50%) rotate(0deg);
}

tr.group-item {
    background-color: rgba(0, 0, 0, 0.05);
}

tr.group-item.hidden {
    display: none;
}

tr.group-item td:first-child {
    padding-left: 2.5rem;
}

tr.group-item a {
    font-size: 0.95em;
}

/*------------------------------------*\
    Footer
\*------------------------------------*/
#footer {
    padding: 1rem 0;
    text-align: center;
    color: var(--secondary-color);
    border-top: 1px solid var(--border-color);
    background-color: var(--footer-color);
    transition: background-color 0.3s ease, color 0.3s ease;
}

#footer .text-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.footer-logo {
    margin-top: 0.5rem;
    transition: filter 0.3s ease;
    display: block;
    margin: 10px auto;
}

/*------------------------------------*\
    Responsive Styles
\*------------------------------------*/
/* Wrapper for horizontal scroll on mobile */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Mobile View */
.mobile-view table {
    overflow-x: auto;
}

.mobile-view th:nth-child(2),
.mobile-view td:nth-child(2) {
    display: none;
}

.mobile-view th:nth-child(3),
.mobile-view td:nth-child(3) {
    display: none;
}

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

    body {
        padding: 0 0.5rem;
    }

    h1 {
        font-size: 1.5rem;
        padding: 1rem 0;
    }

    table {
        font-size: 14px !important;
        width: 100%;
        display: table;
    }

    th,
    td {
        padding: 0.5rem;
        font-size: 14px !important;
    }

    /* Hide size column on tablets/mobile */
    th:nth-child(3),
    td:nth-child(3) {
        display: none;
    }

    /* Make sure accordion takes full width */
    tr.group-header td {
        padding-right: 3rem;
        overflow: visible;
    }

    tr.group-header .group-left {
        max-width: calc(100% - 3rem);
    }

    tr.group-header .group-count {
        right: 1.8rem;
        font-size: 0.75em;
    }

    tr.group-header .accordion-icon {
        right: 0.5rem;
    }

    .icon-container svg {
        --icon-size: 20px;
    }

    /* Better spacing for touch targets */
    tr td a {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* Reduce indentation on mobile */
    tr.group-item td:first-child {
        padding-left: 1.5rem;
    }
}

@media (max-width: 480px) {
    html {
        font-size: 13px;
    }

    body {
        padding: 0 0.25rem;
    }

    h1 {
        font-size: 1.3rem;
    }

    table {
        font-size: 13px !important;
    }

    th,
    td {
        padding: 0.4rem;
        font-size: 13px !important;
    }

    /* Also hide date column on very small screens */
    th:nth-child(2),
    td:nth-child(2) {
        display: none;
    }

    /* Further optimize accordion on small screens */
    tr.group-header td {
        padding-right: 2.5rem;
    }

    tr.group-header .group-left {
        max-width: calc(100% - 2.5rem);
    }

    tr.group-header .group-count {
        display: none;
        /* Hide file count on very small screens */
    }

    tr.group-header .accordion-icon {
        right: 0.4rem;
    }

    .icon-container svg {
        --icon-size: 18px;
    }

    /* Adjust icon spacing */
    .icon-container {
        margin-right: 0.3rem;
    }

    /* Further reduce indentation on very small screens */
    tr.group-item td:first-child {
        padding-left: 1rem;
    }
}