:root {
    --primary-green: #0f4d3a;
    --primary-green-light: #1a7f4e;
    --primary-green-accent: #d3efe2;
    --yellow-accent: #f2a83b;

    --white: #ffffff;
    --white-soft: #fbfdfc;
    --white-faint: #e8ecea;
    --white-muted: #6a7f74;

    --text: #163a2b;
    --text-muted: #6a7f74;
    --border: #e8ecea;

    --bg: #fbfdfc;
    
    /* New variables for enhanced design */
    --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.2);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
    overflow-x: hidden;
    max-width: 100vw;
}

/* Layout structure matching dashboard */
.layout {
    display: flex;
    min-height: 100vh;
}

.page-content {
    flex: 1;
    margin-left: 280px;
    padding: 28px;
    max-width: calc(100% - 280px);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    overflow-x: hidden;
}

.card {
    background-color: var(--white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 24px;
    margin-bottom: 24px;
    border: 1px solid var(--border);
}

.card-header {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
}

.card-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--primary-green);
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 20px;
}

.filter-group {
    flex: 1;
    min-width: 200px;
}

label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--text-muted);
    font-size: 14px;
}

.search-container {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

input, select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background-color: var(--white-soft);
    color: var(--text);
    font-size: 14px;
    transition: all 0.2s ease;
}

input.search-field {
    padding-left: 40px;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary-green-light);
    box-shadow: 0 0 0 3px rgba(26, 127, 78, 0.1);
}

.button-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.btn {
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    border: 1px solid var(--border);
    background-color: var(--white);
    color: var(--text);
    text-decoration: none;
}

.btn:hover {
    background-color: var(--white-faint);
    transform: translateY(-1px);
}

.btn-outline {
    border: 1px solid var(--primary-green);
    color: var(--primary-green);
}

.btn-outline:hover {
    background-color: var(--primary-green-accent);
}

.btn-success {
    background-color: var(--primary-green);
    color: var(--white);
    border: 1px solid var(--primary-green);
}

.btn-success:hover {
    background-color: var(--primary-green-light);
    transform: translateY(-1px);
}

.btn-danger {
    background-color: #dc2626;
    color: var(--white);
    border: 1px solid #dc2626;
}

.btn-danger:hover {
    background-color: #b91c1c;
    transform: translateY(-1px);
}

/* Loading states */
.loading-spinner {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.btn:disabled:hover {
    background-color: var(--white);
    color: var(--text);
}

/* Table Styles */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
}

th {
    background-color: var(--primary-green-accent);
    color: var(--primary-green);
    font-weight: 600;
    text-align: left;
    padding: 14px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

tr:hover {
    background-color: var(--white-soft);
}

.table-container {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

/* Action buttons */
.action-buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.action-btn {
    background: none;
    border: none;
    padding: 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.action-btn.edit {
    color: var(--primary-green);
}

.action-btn.delete {
    color: #dc2626;
}

.action-btn:hover {
    background-color: var(--white-faint);
    transform: scale(1.1);
}

.action-btn.edit:hover {
    background-color: var(--primary-green-accent);
}

.action-btn.delete:hover {
    background-color: #fef2f2;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.pagination-info {
    color: var(--text-muted);
    font-size: 14px;
}

.pagination-controls {
    display: flex;
    gap: 8px;
}

.pagination-btn {
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background-color: var(--white);
    color: var(--text);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
}

.pagination-btn.active {
    background-color: var(--primary-green);
    color: var(--white);
    border-color: var(--primary-green);
}

.pagination-btn:hover:not(.active) {
    background-color: var(--white-faint);
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination-btn:disabled:hover {
    background-color: var(--white);
}

/* Enhanced Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.3s ease-out;
    overflow-y: auto; /* Enable scrolling for the entire modal backdrop */
}

.modal-content {
    background-color: var(--white);
    margin: 2% auto; /* Reduced from 5% to 2% to position higher */
    padding: 0;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    max-height: 96vh; /* Limit maximum height to ensure buttons are visible */
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    transform: scale(0.9);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

.modal-content.modal-open {
    transform: scale(1);
    opacity: 1;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, var(--primary-green-accent) 0%, var(--white) 100%);
    flex-shrink: 0; /* Prevent header from shrinking */
}

.modal-body {
    padding: 24px;
    flex: 1; /* Take available space */
    overflow-y: auto; /* Enable scrolling only for the body */
    max-height: calc(70vh - 140px); /* Calculate height considering header and actions */
}

/* Modal Actions - Ensure they stay at bottom */
.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding: 20px 24px;
    border-top: 1px solid var(--border);
    background-color: var(--white-soft);
    flex-shrink: 0; /* Prevent actions from shrinking */
    margin-top: auto; /* Push to bottom */
}

/* Responsive adjustments for better button visibility */
@media (max-width: 768px) {
    .modal-content {
        margin: 1% auto; /* Even closer to top on mobile */
        max-height: 98vh; /* Use more vertical space on mobile */
    }
    
    .modal-body {
        max-height: calc(75vh - 140px); /* Adjust for mobile */
        padding: 20px;
    }
    
    .modal-actions {
        padding: 16px 20px;
    }
}

@media (max-width: 480px) {
    .modal-content {
        margin: 0.5% auto; /* Very close to top on small screens */
        width: 98%;
        max-height: 99vh;
    }
    
    .modal-body {
        max-height: calc(80vh - 140px); /* More space for content on small screens */
        padding: 16px;
    }
    
    .modal-header {
        padding: 16px 20px;
    }
    
    .modal-actions {
        padding: 16px 20px;
        flex-direction: column;
    }
}

/* Ensure the modal is always properly positioned */
@media (max-height: 600px) {
    /* For very short screens, ensure buttons are still visible */
    .modal-content {
        margin: 1% auto;
        max-height: 98vh;
    }
    
    .modal-body {
        max-height: calc(65vh - 140px); /* Reduce body height on short screens */
    }
}

/* Custom scrollbar for modal body */
.modal-body::-webkit-scrollbar {
    width: 6px;
}

.modal-body::-webkit-scrollbar-track {
    background: var(--white-soft);
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Form Grid Layout */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-muted);
    font-size: 14px;
}

.form-group input, 
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background-color: var(--white-soft);
    color: var(--text);
    font-size: 14px;
    transition: all 0.2s ease;
}

.form-group input:focus, 
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-green-light);
    box-shadow: 0 0 0 3px rgba(26, 127, 78, 0.1);
    background-color: var(--white);
}

.form-group input:invalid:not(:focus):not(:placeholder-shown) {
    border-color: #dc2626;
}

.form-group .input-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
    line-height: 1.4;
}

/* Required field indicator */
.form-group.required label:after {
    content: " *";
    color: #dc2626;
}

.form-section-title {
    grid-column: 1 / -1;
    font-size: 16px;
    font-weight: 600;
    color: var(--primary-green);
    margin-top: 10px;
    margin-bottom: 15px;
    border-bottom: 2px solid var(--primary-green-accent);
    padding-bottom: 5px;
}

.form-group textarea {
    min-height: 80px;
    resize: vertical;
    font-family: inherit;
}

input[readonly] {
    cursor: not-allowed;
    opacity: 0.8;
}

/* Modal Actions */
.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding: 24px;
    border-top: 1px solid var(--border);
    background-color: var(--white-soft);
}

/* Delete Modal Specific Styles */
.text-warning {
    color: #dc2626;
    font-size: 14px;
    margin-top: 8px;
}

/* Notification animations */
@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Responsive Design */
@media (max-width: 1200px) {
    .page-content {
        margin-left: 0;
        max-width: 100%;
        padding: 20px;
    }
}

@media (max-width: 768px) {
    .layout {
        flex-direction: column;
    }
    
    .page-content {
        margin-left: 0;
        max-width: 100%;
        padding: 15px;
    }
    
    .filter-row {
        flex-direction: column;
        gap: 12px;
    }
    
    .filter-group {
        min-width: 100%;
    }
    
    .button-row {
        justify-content: stretch;
        gap: 8px;
    }

    .btn {
        flex: 1;
        min-width: 120px;
        justify-content: center;
        font-size: 13px;
        padding: 10px 12px;
    }

    /* Modal responsive */
    .modal-content {
        margin: 10% auto;
        width: 95%;
        max-width: 95%;
    }
    
    .form-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .modal-actions {
        flex-direction: column;
    }
    
    .modal-body {
        padding: 20px;
    }
    
    .modal-header {
        padding: 20px;
    }

    /* Vertical table layout for mobile */
    .table-container {
        overflow-x: visible;
        margin: 0;
        padding: 0;
        width: 100%;
    }
    
    table {
        display: block;
        width: 100%;
    }

    thead {
        display: none;
    }

    tbody {
        display: block;
        width: 100%;
    }

    tr {
        display: block;
        width: 100%;
        margin-bottom: 16px;
        padding: 16px;
        background: var(--white);
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-sm);
    }

    td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 12px 8px;
        border-bottom: 1px solid var(--white-faint);
        border-right: none;
        width: 100%;
        text-align: right;
        white-space: normal;
        overflow: visible;
        max-width: none;
    }

    /* Add labels for each cell */
    td:before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--primary-green);
        text-align: left;
        font-size: 13px;
        flex: 1;
        margin-right: 16px;
    }

    /* Remove border from last cell in each row */
    td:last-child {
        border-bottom: none;
    }
    
    .pagination {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }

    .pagination-controls {
        flex-wrap: wrap;
        justify-content: center;
    }

    .pagination-btn {
        padding: 6px 10px;
        font-size: 13px;
    }

    .card {
        padding: 16px;
        margin-bottom: 16px;
    }

    .card-title {
        font-size: 18px;
    }
}


@media (min-width: 769px) {
    #membersTable th:nth-child(7),
    #membersTable td:nth-child(7) {
        width: 140px; /* Increased from 120px to 140px */
    }
    
    #membersTable th:nth-child(8),
    #membersTable td:nth-child(8) {
        width: 80px;
    }
    
    #membersTable th:nth-child(9),
    #membersTable td:nth-child(9) {
        width: 100px;
    }
}

@media (max-width: 480px) {
    .page-content {
        padding: 10px;
    }
    
    .button-row {
        flex-direction: column;
    }
    
    .btn {
        min-width: 100%;
    }
    
    .modal-content {
        margin: 5% auto;
        width: 98%;
    }
    
    .modal-header {
        padding: 16px 20px;
    }
    
    .modal-body {
        padding: 16px;
    }
    
    .modal-actions {
        padding: 16px 20px;
    }
    
    tr {
        padding: 12px;
        margin-bottom: 12px;
    }
    
    td {
        padding: 10px 6px;
        font-size: 14px;
    }
    
    td:before {
        font-size: 12px;
    }
}
