:root {
    --primary: #6d9cff;
    --primary-hover: #5a85e0;
    --primary-light: rgba(109, 156, 255, 0.1);
    --success: #34d399;
    --warning: #f0b752;
    --warning-hover: #d9a03e;
    --danger: #f06060;
    --danger-hover: #d94a4a;
    --bg-page: #111318;
    --bg-card: #1a1d25;
    --bg-elevated: #22262f;
    --bg-input: #1e2129;
    --text-main: #d4d7de;
    --text-heading: #ebedf2;
    --text-muted: #7c8295;
    --border: #2a2e38;
    --border-hover: #3a3f4c;
    --radius: 10px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
    background-color: var(--bg-page);
    color: var(--text-main);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Navbar */
.navbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0.85rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}

.brand-icon {
    width: 32px;
    height: 32px;
    background: var(--primary);
    color: #111318;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.user-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--primary-light);
    color: var(--primary);
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 600;
}

.btn-logout {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.4rem 0.85rem;
    border-radius: 6px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-logout:hover {
    background: rgba(240, 96, 96, 0.12);
    color: var(--danger);
    border-color: rgba(240, 96, 96, 0.35);
}

/* Container */
.container {
    width: 100%;
    max-width: 1050px;
    margin: 2rem auto;
    padding: 0 1rem;
    flex: 1;
}

/* Alerts */
.alert {
    padding: 0.85rem 1.2rem;
    border-radius: var(--radius);
    margin-bottom: 1.2rem;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    overflow-wrap: anywhere;
}

.alert-success {
    background-color: rgba(52, 211, 153, 0.1);
    color: #6ee7b7;
    border: 1px solid rgba(52, 211, 153, 0.25);
}

.alert-danger {
    background-color: rgba(240, 96, 96, 0.1);
    color: #fca5a5;
    border: 1px solid rgba(240, 96, 96, 0.25);
}

.alert-info {
    background-color: rgba(109, 156, 255, 0.1);
    color: #93b4ff;
    border: 1px solid rgba(109, 156, 255, 0.2);
}

/* Tabs */
.tabs-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    overflow: hidden;
}

.tabs-header {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
}

.tab-btn {
    flex: 1;
    padding: 1rem 1.5rem;
    border: none;
    background: transparent;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s;
    border-bottom: 3px solid transparent;
}

.tab-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.03);
}

.tab-btn.active {
    color: var(--primary);
    background: var(--bg-card);
    border-bottom: 3px solid var(--primary);
}

.counter-badge {
    background: var(--bg-page);
    color: var(--text-muted);
    padding: 0.15rem 0.55rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 700;
}

.tab-btn.active .counter-badge {
    background: var(--primary-light);
    color: var(--primary);
}

.tab-content {
    display: none;
    padding: 2rem;
}

.tab-content.active {
    display: block;
}

/* Search bar */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.search-input {
    flex: 1;
    min-width: 240px;
    padding: 0.65rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    outline: none;
    background: var(--bg-input);
    color: var(--text-main);
    transition: border 0.2s;
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(109, 156, 255, 0.12);
}

.files-info-text {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Table */
.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.files-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.files-table th {
    background: var(--bg-elevated);
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
}

.files-table td {
    padding: 0.95rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.925rem;
    vertical-align: middle;
    color: var(--text-main);
}

.files-table tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

.file-name-cell {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    font-weight: 500;
    word-break: break-all;
    color: var(--text-heading);
}

.file-icon {
    font-size: 1.25rem;
}

.badge-size {
    display: inline-block;
    background: var(--bg-elevated);
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    font-size: 0.825rem;
    font-weight: 600;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.9rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease-in-out;
}

.btn-primary {
    background-color: var(--primary);
    color: #111318;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-warning {
    background-color: var(--warning);
    color: #111318;
}

.btn-warning:hover {
    background-color: var(--warning-hover);
}

.btn-danger-outline {
    background: transparent;
    border: 1px solid rgba(240, 96, 96, 0.3);
    color: var(--danger);
    padding: 0.5rem 0.7rem;
}

.btn-danger-outline:hover {
    background: rgba(240, 96, 96, 0.12);
    border-color: var(--danger);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3.5rem 1rem;
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 0.8rem;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 1.25rem;
    margin-bottom: 0.4rem;
    color: var(--text-heading);
}

.empty-state p {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 1.25rem;
}

/* Upload Tab Styles */
.upload-card {
    max-width: 650px;
    margin: 0 auto;
}

.dropzone {
    border: 2px dashed var(--border-hover);
    background: var(--bg-elevated);
    border-radius: var(--radius);
    padding: 3rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.dropzone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.dropzone-icon {
    font-size: 3rem;
    color: var(--primary);
    margin-bottom: 0.75rem;
}

.dropzone h3 {
    font-size: 1.15rem;
    margin-bottom: 0.35rem;
    color: var(--text-heading);
}

.dropzone p {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.file-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.selected-file-card {
    display: none;
    margin-top: 1.5rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
}

.selected-file-details {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    color: var(--text-main);
}

.selected-file-details > div {
    min-width: 0;
    overflow-wrap: anywhere;
}

.selected-file-details > span {
    flex-shrink: 0;
}

.upload-actions {
    margin-top: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 1.25rem;
    flex-wrap: wrap;
}

.upload-progress-container {
    flex: 1;
    min-width: 220px;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.progress-info .progress-status {
    color: var(--text-main);
}

.progress-info .progress-percent {
    font-weight: 700;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
}

.progress-bar-track {
    width: 100%;
    height: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary) 0%, #8bb2ff 100%);
    border-radius: 999px;
    width: 0%;
    transition: width 0.15s ease-out;
}

.notice-box {
    margin-top: 2rem;
    background: var(--bg-elevated);
    border-left: 4px solid var(--primary);
    padding: 0.9rem 1.1rem;
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Login Page Styles */
.login-body {
    background: linear-gradient(135deg, #0d0f14 0%, #171b26 50%, #111520 100%);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.login-card {
    background: var(--bg-card);
    width: 100%;
    max-width: 420px;
    padding: 2.5rem;
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h1 {
    font-size: 1.75rem;
    color: var(--text-heading);
    margin-top: 0.5rem;
}

.login-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-main);
}

.form-control {
    width: 100%;
    padding: 0.75rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    outline: none;
    background: var(--bg-input);
    color: var(--text-main);
    transition: all 0.2s;
}

.form-control::placeholder {
    color: var(--text-muted);
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(109, 156, 255, 0.12);
}

.btn-block {
    width: 100%;
    padding: 0.8rem;
    font-size: 1rem;
    justify-content: center;
}

.login-hint {
    margin-top: 1.5rem;
    background: var(--bg-elevated);
    border-radius: 8px;
    padding: 0.85rem;
    font-size: 0.825rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.login-hint strong {
    color: var(--text-main);
}

.login-hint code {
    background: var(--bg-page);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.825rem;
    color: var(--primary);
}

/* Footer */
footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.825rem;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
}

/* Role tags */
.role-tag {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-left: 0.25rem;
}

.role-tag.admin {
    background: rgba(109, 156, 255, 0.15);
    color: var(--primary);
}

/* Admin page */
.admin-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
}

.admin-section-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-heading);
    margin-bottom: 1rem;
}

.form-row {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    flex-wrap: wrap;
}

.form-row .form-group {
    flex: 1;
    min-width: 140px;
}

.form-control-sm {
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text-main);
    outline: none;
}

.form-control-sm:focus {
    border-color: var(--primary);
}

.form-control-sm option {
    background: var(--bg-card);
    color: var(--text-main);
}

.btn-sm {
    padding: 0.35rem 0.6rem;
    font-size: 0.8rem;
}

.role-form,
.password-form {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.password-input {
    width: 130px;
}

/* Textos alternativos: por defecto se muestra la versión de escritorio */
.text-touch,
.nav-label-short {
    display: none;
}

/* Móviles y pantallas táctiles: controles cómodos de pulsar.
   Con 16px en los campos, iOS no hace zoom al enfocarlos. */
@media (max-width: 760px), (pointer: coarse) {
    .text-pointer {
        display: none;
    }

    .text-touch {
        display: inline;
    }

    .btn,
    .btn-logout {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 44px;
    }

    .btn-danger-outline,
    .btn-sm {
        min-width: 44px;
    }

    .form-control,
    .form-control-sm,
    .search-input {
        min-height: 44px;
        font-size: 16px;
    }
}

/* Maquetación para móvil */
@media (max-width: 760px) {
    /* Barra superior en una sola fila */
    .navbar {
        padding: 0.5rem 0.75rem;
        gap: 0.75rem;
    }

    .brand {
        flex-shrink: 0;
        font-size: 1.1rem;
    }

    .user-nav {
        min-width: 0;
        gap: 0.4rem;
    }

    .user-nav form {
        flex-shrink: 0;
    }

    .user-badge {
        min-width: 0;
        padding: 0.35rem 0.6rem;
    }

    .user-name {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .user-badge .role-tag,
    .nav-label {
        display: none;
    }

    .nav-label-short {
        display: inline;
    }

    .btn-logout {
        flex-shrink: 0;
        min-width: 44px;
        padding: 0.4rem 0.7rem;
        white-space: nowrap;
    }

    /* Contenedores */
    .container {
        margin: 0.75rem auto;
        padding: 0 0.75rem;
    }

    .tab-content {
        padding: 1rem;
    }

    .tab-btn {
        min-height: 48px;
        padding: 0.75rem 0.5rem;
        font-size: 0.95rem;
        white-space: nowrap;
    }

    .toolbar {
        gap: 0.5rem;
        margin-bottom: 1rem;
    }

    .search-input {
        flex-basis: 100%;
        min-width: 0;
    }

    /* Las tablas pasan a ser una lista de tarjetas */
    .files-table,
    .files-table tbody {
        display: block;
    }

    .files-table thead {
        display: none;
    }

    .files-table tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 0.75rem;
        padding: 0.9rem;
        margin-bottom: 0.75rem;
        background: var(--bg-elevated);
        border: 1px solid var(--border);
        border-radius: var(--radius);
    }

    .files-table tr:last-child {
        margin-bottom: 0;
    }

    .files-table td {
        display: block;
        min-width: 0;
        padding: 0;
        border-bottom: none;
        font-size: 0.875rem;
    }

    .files-table tr:hover td {
        background: transparent;
    }

    .files-table td:first-child,
    .files-table td:last-child {
        grid-column: 1 / -1;
    }

    .file-name-cell {
        word-break: normal;
        overflow-wrap: anywhere;
    }

    .badge-size {
        background: var(--bg-card);
    }

    /* Descargar ocupa toda la fila; debajo, descargar y borrar + papelera */
    .file-actions {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 0.5rem;
    }

    .file-actions > a {
        grid-column: 1 / -1;
    }

    .file-actions .btn {
        width: 100%;
    }

    /* Usuarios: nombre y rol arriba, cambio de clave y borrado debajo */
    .users-table td:first-child {
        grid-column: auto;
    }

    .users-table .form-control-sm {
        width: auto;
    }

    .users-table .action-buttons {
        flex-wrap: nowrap;
    }

    .users-table .password-form {
        flex: 1;
        min-width: 0;
    }

    .users-table .password-input {
        flex: 1;
        min-width: 0;
    }

    /* Subida */
    .dropzone {
        padding: 2rem 1rem;
    }

    .upload-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        margin-top: 1rem;
    }

    .upload-progress-container {
        flex: none;
        min-width: 0;
        max-width: none;
    }

    .notice-box {
        margin-top: 1.25rem;
    }

    /* Formularios */
    .admin-card {
        padding: 1rem;
    }

    .admin-card .form-row {
        gap: 0;
    }

    .admin-card .form-group {
        flex-basis: 100%;
    }

    .admin-card .form-group:last-child {
        margin-bottom: 0;
    }

    .admin-card .btn {
        width: 100%;
    }

    /* Login */
    .login-body {
        padding: 1rem;
    }

    .login-card {
        padding: 1.75rem 1.25rem;
    }

    footer {
        padding: 1rem;
    }
}

/* Móviles muy estrechos */
@media (max-width: 360px) {
    .brand-name {
        display: none;
    }

    .tab-btn {
        gap: 0.3rem;
        padding: 0.75rem 0.25rem;
        font-size: 0.875rem;
    }
}
