/* Table wrapper with responsive scrolling */
.tm-table-wrapper {
    background: #f9fafb;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    margin: 20px 0;
    padding: 10px;
    border-radius: 8px;
    overflow-x: auto; /* Horizontal scroll for wide tables */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on mobile */
    width: 100%; /* Ensure wrapper takes full width */
}

/* Table base styles */
.tm-table {
    width: 100%; /* Strictly 100% width on all devices */
    border-collapse: collapse;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
}

.tm-table th {
    background: #fff; /* No gradient */
    color: #000;
    padding: 12px 15px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid #d1d5db; /* Subtle separator */
}

.tm-table th.asc:after {
    content: ' ?';
    margin-left: 5px;
}

.tm-table th.desc:after {
    content: ' ?';
    margin-left: 5px;
}

.tm-table td {
    padding: 12px 15px;
    border-bottom: 1px solid #d1d5db;
    text-align: left; /* Align text to the left */
    word-wrap: break-word; /* Ensure text wraps */
    overflow-wrap: break-word; /* Modern alternative for wrapping */
    max-width: 0; /* Allow wrapping by limiting width implicitly */
    background: #ffffff; /* Clean background for readability */
    color: #2d3748; /* Darker text for contrast */
    font-size: 0.95em; /* Slightly smaller for balance */
    line-height: 1.4; /* Improved readability */
}

/* Table row hover and striping */
.tm-table tr {
    transition: background 0.3s ease;
}

.tm-table tr:nth-child(even) {
    background: #f9fafb;
}

.tm-table tr:hover {
    background: #eef2f7;
}

/* Table controls */
.tm-table-controls {
    margin-bottom: 15px;
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap; /* Wrap on small screens */
}

.tm-search-input,
.tm-filter-select {
    padding: 10px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1em;
    background: #fff;
    transition: all 0.3s ease;
}

.tm-search-input:focus,
.tm-filter-select:focus {
    border-color: #4a5568;
    box-shadow: 0 0 0 3px rgba(74, 85, 104, 0.2);
    outline: none;
}

/* Edit button */
.tm-edit-button {
    background: #2d3748;
    color: #fff;
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    text-decoration: none;
    transition: all 0.3s ease;
    font-weight: 500;
}

.tm-edit-button:hover {
    background: #4a5568;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Modal styles */
.tm-edit-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.tm-edit-modal-content {
    background: #ffffff;
    margin: 5% auto;
    padding: 25px;
    border-radius: 12px;
    width: 90%;
    max-width: 550px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.tm-edit-modal-close {
    float: right;
    font-size: 1.6em;
    cursor: pointer;
    color: #4a5568;
    transition: color 0.3s ease;
}

.tm-edit-modal-close:hover {
    color: #2d3748;
}

.tm-edit-form input {
    width: 100%;
    padding: 10px;
    margin: 12px 0;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1em;
    background: #f7fafc;
    transition: border-color 0.3s ease;
}

.tm-edit-form input:focus {
    border-color: #4a5568;
    box-shadow: 0 0 0 3px rgba(74, 85, 104, 0.1);
}

.tm-edit-form button {
    background: #2d3748;
    color: #fff;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
}

.tm-edit-form button:hover {
    background: #4a5568;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Responsive breakpoints */
@media (max-width: 1024px) {
    .tm-table {
        width: 100%; /* Ensure 100% width */
    }
    .tm-table-controls {
        flex-direction: column;
        align-items: flex-start;
    }
    .tm-search-input,
    .tm-filter-select {
        width: 100%;
        margin-bottom: 10px;
    }
}

@media (max-width: 768px) {
    .tm-table {
        width: 100%; /* Ensure 100% width */
    }
}

@media (max-width: 480px) {
    .tm-table-wrapper {
        padding: 5px;
        width: 100%; /* Ensure full width */
    }
    .tm-table {
        width: auto; /* Allow natural width based on content */
        min-width: 100%; /* Ensure it fills the wrapper initially */
        display: table; /* Revert to standard table layout */
        overflow-x: auto; /* Enable horizontal scrolling */
    }
    .tm-table th,
    .tm-table td {
        padding: 10px; /* Consistent padding */
        min-width: 100px; /* Minimum width to prevent overlap */
        max-width: 200px; /* Cap width to control overlap */
        word-wrap: break-word; /* Allow wrapping as fallback */
        overflow-wrap: break-word; /* Modern wrapping */
        white-space: normal; /* Remove nowrap to allow wrapping if needed */
        text-overflow: ellipsis; /* Add ellipsis if text overflows */
        overflow: hidden; /* Hide overflow beyond cell */
    }
    .tm-table-controls {
        gap: 5px;
        flex-direction: column;
        align-items: stretch;
    }
    .tm-search-input,
    .tm-filter-select {
        width: 100%;
        margin-bottom: 5px;
    }
    .tm-edit-button {
        width: 100%;
        text-align: center;
        margin-top: 10px;
    }
}

/* Front-end form styling */
.tm-form-label {
    white-space: nowrap;
    display: inline-block;
    vertical-align: middle;
    padding-right: 10px;
    font-weight: 500;
    color: #2d3748;
}

.tm-form-field {
    min-width: 300px;
    margin-left: 15px;
    vertical-align: middle;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px;
    font-size: 1em;
    transition: border-color 0.3s ease;
}

.tm-form-field:focus {
    border-color: #4a5568;
    box-shadow: 0 0 0 3px rgba(74, 85, 104, 0.1);
}

@media (max-width: 600px) {
    .tm-form-label {
        max-width: 150px;
    }
    .tm-form-field {
        min-width: 150px;
    }
}