@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600&display=swap');

/* DEFAULT THEME: PURE DARK */
.default-theme {
    --background-dark: #121212;
    --background-light: #1e1e1e;
    --text-light: #e0e0e0;
    --border-color: #333333;
    --input-background: #1e1e1e;
    --input-background-disabled: #2a2a2a;
    --label-color: #a0a0a0;
    --radio-checkbox-accent: #666666;
    --button-background: #252525;
    --button-background-hover: #383838;
    --edit-background: #444444;
    --delete-background: #884d4d;
    --text-contrast: #ffffff;
    --shadow-color: rgba(0, 0, 0, 0.5);
    --primary-color: #444444;
    --primary-color-rgb: 68, 68, 68;
    --secondary-color: #666666;
    --secondary-color-rgb: 102, 102, 102;
}

/* Light theme */
.light-theme {
    --background-dark: #ededeb;
    --background-light: #f9f9f9;
    --text-light: #333333;
    --border-color: #cccccc;
    --input-background: #ffffff;
    --input-background-disabled: #e0e0e0;
    --label-color: #5a2d81;
    --radio-checkbox-accent: #5a2d81;
    --button-background: #8a8787;
    --button-background-hover: #666;
    --edit-background: #e91e63;
    --delete-background: #dc3545;
    --text-contrast: #ffffff;
    --shadow-color: rgba(79, 77, 77, 0.1);
    --primary-color: #4f4d4d;
    --primary-color-rgb: 79, 77, 77;
    --secondary-color: #5a2d81;
    --secondary-color-rgb: 90, 45, 129;
}

/* Pink theme */
.pink-theme {
    --background-dark: #fce4ec;
    --background-light: #f8bbd0;
    --text-light: #880e4f;
    --border-color: #f48fb1;
    --input-background: #ffffff;
    --input-background-disabled: #f1f8e9;
    --label-color: #c2185b;
    --radio-checkbox-accent: #c2185b;
    --button-background: #c2185b;
    --button-background-hover: #ad1457;
    --edit-background: #ad1457;
    --delete-background: #d32f2f;
    --text-contrast: #ffffff;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --primary-color: #c2185b;
    --primary-color-rgb: 194, 24, 91;
    --secondary-color: #ad1457;
    --secondary-color-rgb: 173, 20, 87;
}

/* Indigo theme */
.indigo-theme {
    --background-dark: #2f3640;
    --background-light: #3b4151;
    --text-light: #f7f7f7;
    --border-color: #434a54;
    --input-background: #2f3640;
    --input-background-disabled: #3b4151;
    --label-color: #8b94b3;
    --radio-checkbox-accent: #8b94b3;
    --button-background: #452b8b;
    --button-background-hover: #3b2f6b;
    --edit-background: #452b8b;
    --delete-background: #e74c3c;
    --text-contrast: #ffffff;
    --shadow-color: rgba(0, 0, 0, 0.2);
    --primary-color: #452b8b;
    --primary-color-rgb: 69, 43, 139;
    --secondary-color: #3b2f6b;
    --secondary-color-rgb: 59, 47, 107;
}

/* Blue theme */
.blue-theme {
    --background-dark: #87ceeb;
    --background-light: #add8e6;
    --text-light: #1a237e;
    --border-color: #87ceeb;
    --input-background: #f7f7f7;
    --input-background-disabled: #e5e5e5;
    --label-color: #2196f3;
    --radio-checkbox-accent: #2196f3;
    --button-background: #03a9f4;
    --button-background-hover: #039be5;
    --edit-background: #03a9f4;
    --delete-background: #e74c3c;
    --text-contrast: #ffffff;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --primary-color: #03a9f4;
    --primary-color-rgb: 3, 169, 244;
    --secondary-color: #039be5;
    --secondary-color-rgb: 3, 155, 229;
}

/* Dark Orange theme */
.dark-orange-theme {
    --background-dark: #2f2f2f;
    --background-light: #3c3c3c;
    --text-light: #ffffff;
    --border-color: #666;
    --input-background: #3c3c3c;
    --input-background-disabled: #4c4c4c;
    --label-color: #ffa07a;
    --radio-checkbox-accent: #ffa07a;
    --button-background: #ff9900;
    --button-background-hover: #e68f00;
    --edit-background: #ff9900;
    --delete-background: #e74c3c;
    --text-contrast: #000000;
    --shadow-color: rgba(0, 0, 0, 0.2);
    --primary-color: #ff9900;
    --primary-color-rgb: 255, 153, 0;
    --secondary-color: #e68f00;
    --secondary-color-rgb: 230, 143, 0;
}

.green-theme {
    --background-dark: #f2f9f2;
    --background-light: #e5e5e5;
    --text-light: #2f4f2f;
    --border-color: #c6efce;
    --input-background: #f7fff7;
    --input-background-disabled: #e5e5e5;
    --label-color: #87b087;
    --radio-checkbox-accent: #87b087;
    --button-background: #004d00;
    --button-background-hover: #003300;
    --button-text-color: #ffffff;
    --edit-background: #004d00;
    --delete-background: #990000;
    --text-contrast: #ffffff;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --primary-color: #004d00;
    --primary-color-rgb: 0, 77, 0;
    --secondary-color: #003300;
    --secondary-color-rgb: 0, 51, 0;
}

/* General Data Grid Container Styling */
.anygrid-container {
    border-radius: 0.75rem;
    overflow: hidden;
    box-shadow: 0 4px 6px -1px var(--shadow-color), 0 2px 4px -2px var(--shadow-color);
    background-color: var(--background-dark);
    margin: 1rem auto;
    max-width: 95%;
}

/* Table Styling */
.anygrid-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.875rem;
    background-color: var(--background-dark);
    color: var(--text-light);
    border-radius: 0rem;
    overflow: hidden;
}

.anygrid-table th,
.anygrid-table td {
    border: none;
    text-align: left;
    padding: 0.75rem 1rem;
    vertical-align: middle;
}

.anygrid-table thead tr {
    background-color: var(--input-background);
    color: var(--text-light);
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 1px 3px var(--shadow-color);
}

.anygrid-table th {
    font-weight: 600;
    padding-top: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

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

.anygrid-table tbody tr:last-child {
    border-bottom: none;
}

.anygrid-table tbody tr:nth-child(even) {
    background-color: var(--background-light);
}

.anygrid-table tbody tr:hover {
    background-color: var(--button-background-hover);
    color: var(--text-contrast);
}

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

a:hover {
    color: var(--button-background-hover);
    text-decoration: underline;
}

/* TOP ACTIONS CSS SEARCH, ITEMS PER PAGE, CSV AND EXCEL EXPORT */

.search-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background-color: var(--background-dark);
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    border-top-left-radius: 0.75rem;
    border-top-right-radius: 0.75rem;
}

/* For mobile screens */
@media (max-width: 700px) {
    .search-container {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    input.anygrid-search-input,
    select.items-per-page,
    .anygrid-export-csv,
    .anygrid-export-excel {
        width: 100%;
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }

    input.anygrid-search-input,
    select.items-per-page {
        max-width: 100% !important;
    }
}

/* Standard input and select styles */
input.anygrid-search-input,
select.items-per-page {
    background-color: var(--input-background);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-light);
    font-size: 0.875rem;
    padding: 0.6rem 0.8rem;
    box-sizing: border-box;
    transition: border-color 0.3s, box-shadow 0.3s;
    height: 2.5rem;
    line-height: 1.5;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%239CA3AF'%3E%3Cpath fill-rule='evenodd' d='M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z' clip-rule='evenodd'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1.25rem;
}

input.anygrid-search-input {
    max-width: 18rem;
    color: var(--text-light);
}

input.anygrid-search-input:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--primary-color-rgb), 0.25);
}

input.anygrid-search-input::placeholder {
    color: var(--label-color);
    opacity: 0.7;
}

select.items-per-page {
    color: var(--text-light);
    max-width: 10rem;
}

select.items-per-page:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--primary-color-rgb), 0.25);
}

/* CSV & Excel Export Buttons */
.anygrid-export-csv,
.anygrid-export-excel {
    background-color: var(--button-background);
    color: var(--text-contrast);
    border: 1px solid var(--border-color);
    padding: 0.6rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 1px 2px 0 var(--shadow-color);
}

.anygrid-export-csv::before,
.anygrid-export-excel::before {
    content: "\2193";
    font-size: 1rem;
    line-height: 1;
}

.anygrid-export-csv:hover,
.anygrid-export-excel:hover {
    background-color: var(--button-background-hover);
    border-color: var(--button-background-hover);
    box-shadow: 0 2px 4px 0 var(--shadow-color);
}

.anygrid-export-csv:disabled,
.anygrid-export-excel:disabled {
    background-color: var(--input-background-disabled);
    color: var(--label-color);
    cursor: not-allowed;
    border-color: var(--border-color);
    box-shadow: none;
}

.anygrid-export-csv:focus,
.anygrid-export-excel:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--primary-color-rgb), 0.25);
}

/* END OF MOBILE SCREENS CSS */

/* Pagination Wrapper */
.pagination-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    background-color: var(--background-dark);
    border-top: 1px solid var(--border-color);
    border-bottom-left-radius: 0.75rem;
    border-bottom-right-radius: 0.75rem;
    flex-wrap: wrap;
    gap: 1rem;
}

/* Pagination Info */
.pagination-info {
    font-size: 0.875rem;
    color: var(--text-light);
    font-family: 'Montserrat', sans-serif;
}

/* Pagination Buttons */
.pagination-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.pagination-button {
    background-color: var(--button-background);
    border: none;
    border-radius: 50%;
    color: var(--text-contrast);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    width: 2.5rem;
    height: 2.5rem;
    text-decoration: none;
    transition: background-color 0.3s, color 0.3s, box-shadow 0.3s, transform 0.2s;
    box-shadow: 0 2px 4px 0 var(--shadow-color);
}

/* Active and Hover States for Pagination Buttons */
.pagination-button.active {
    background-color: var(--primary-color);
    color: var(--text-contrast);
    box-shadow: 0 4px 8px 0 rgba(var(--primary-color-rgb), 0.3);
    transform: translateY(-1px);
}

.pagination-button:hover:not(.active) {
    background-color: var(--button-background-hover);
    color: var(--text-contrast);
    box-shadow: 0 3px 6px 0 var(--shadow-color);
    transform: translateY(-1px);
}

.pagination-button:disabled {
    background-color: var(--input-background-disabled);
    color: var(--label-color);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

/* Focus State for Pagination Buttons */
.pagination-button:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--primary-color-rgb), 0.25);
}

/* Edit and Delete Buttons */
.edit,
.delete {
    border-radius: 0.375rem;
    padding: 0.4rem 0.75rem;
    color: var(--text-contrast);
    text-decoration: none;
    font-size: 0.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 1px 2px 0 var(--shadow-color);
}

.edit {
    background-color: var(--edit-background);
}

.delete {
    background-color: var(--delete-background);
}

.edit:hover {
    background-color: color-mix(in srgb, var(--edit-background) 80%, black);
    box-shadow: 0 2px 4px 0 var(--shadow-color);
}

.delete:hover {
    background-color: color-mix(in srgb, var(--delete-background) 80%, black);
    box-shadow: 0 2px 4px 0 var(--shadow-color);
}

.edit::before {
    content: '\270E';
}

.delete::before {
    content: '\1F5D1';
}

/* Column Sortable */
.anygrid-column-sortable {
    cursor: pointer;
    position: relative;
}

.anygrid-column-sortable:hover::after {
    opacity: 1;
}

.anygrid-column-sortable.asc::after {
    content: '\2191';
    opacity: 1;
}

.anygrid-column-sortable.desc::after {
    content: '\2193';
    opacity: 1;
}

/* Target all links inside AnyGrid containers */
#anygrid a,
.anygrid-table a,
.anygrid-modal a {
  text-decoration: none !important;
  color: inherit !important;
}

/* Optional: Add hover effect for better UX */
#anygrid a:hover,
.anygrid-table a:hover,
.anygrid-modal a:hover {
  text-decoration: underline !important;
}

/* MODAL CSS - FIXED WITH SOLID WHITE BACKGROUND */

/* Base Modal Styles */
.anygrid-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    z-index: 1000;
    font-family: 'Montserrat', sans-serif;
}

.modal-content {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #ffffff; /* Solid white background */
    color: #333333; /* Dark text for readability */
    width: 90%;
    max-width: 600px;
    border-radius: 0.75rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.25), 0 4px 6px -4px rgba(0, 0, 0, 0.2);
    padding: 2rem;
    z-index: 1001;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid #cccccc; /* Light border */
}

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
}

/* Modal Content Structure */
.modal-body {
    padding: 1.5rem 0;
}

.modal-footer {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid #cccccc; /* Light border */
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* Typography and Fields */
.record-field {
    display: flex;
    margin-bottom: 1.25rem;
    align-items: flex-start;
    flex-wrap: wrap;
}

.record-field strong,
.record-field label {
    flex: 0 0 150px;
    font-weight: 600;
    color: #5a2d81; /* Label color from theme */
    padding-right: 1rem;
}

.record-field span {
    flex: 1;
    word-break: break-word;
    color: #333333; /* Dark text for readability */
}

/* Styles for non-editable fields */
.record-field.non-editable {
    background-color: #f5f5f5; /* Light gray background */
    border-radius: 0.375rem;
    padding: 0.5rem 1rem;
    cursor: not-allowed;
    opacity: 0.9;
}

.record-field.non-editable strong,
.record-field.non-editable span {
    color: #8a8787; /* Muted text color */
    opacity: 0.8;
}

/* Styles for editable fields */
.record-field:not(.non-editable) {
    cursor: pointer;
}

/* Form Elements */
.record-field input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #cccccc; /* Light border */
    border-radius: 0.5rem;
    font-family: inherit;
    font-size: 0.9rem;
    background-color: #ffffff; /* White background */
    color: #333333; /* Dark text */
    transition: all 0.2s;
}

.record-field input:focus {
    border-color: #4f4d4d; /* Primary color from theme */
    outline: none;
    box-shadow: 0 0 0 3px rgba(79, 77, 77, 0.25); /* Primary color with opacity */
}

/* Buttons within Modal - FIXED */
.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.75rem;
    cursor: pointer;
    color: #5a2d81; /* Label color from theme */
    padding: 0.25rem;
    line-height: 1;
    transition: color 0.2s;
}

.modal-close:hover {
    color: #333333; /* Dark text on hover */
}

/* FIXED: Modal buttons with theme colors */
.anygrid-btn-delete,
.btn-save,
.retry-btn {
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s ease, box-shadow 0.2s ease;
    color: #ffffff; /* White text for contrast */
    box-shadow: 0 1px 2px 0 rgba(79, 77, 77, 0.1);
}

.anygrid-btn-delete,
.retry-btn {
    background-color: #dc3545; /* Delete background from theme */
}

.btn-save {
    background-color: #8a8787; /* Button background from theme */
}

.anygrid-btn-delete:hover,
.retry-btn:hover {
    background-color: #c82333; /* Darker red on hover */
    box-shadow: 0 2px 4px 0 rgba(79, 77, 77, 0.1);
}

.btn-save:hover {
    background-color: #666666; /* Button background hover from theme */
    box-shadow: 0 2px 4px 0 rgba(79, 77, 77, 0.1);
}

/* Animations */
.anygrid-modal.fade .modal-content {
    animation: fadeIn 0.3s ease-out;
}

.anygrid-modal.slide .modal-content {
    animation: slideIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -60%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

@keyframes slideIn {
    from {
        transform: translate(-50%, -40px);
        opacity: 0;
    }
    to {
        transform: translate(-50%, -50%);
        opacity: 1;
    }
}

/* Status Messages */
.modal-status {
    padding: 1rem;
    margin-top: 1.5rem;
    border-radius: 0.5rem;
    text-align: center;
    font-weight: 500;
    font-size: 0.9rem;
}

.modal-status.loading {
    background: rgba(79, 77, 77, 0.1); /* Primary color with opacity */
    color: #4f4d4d; /* Primary color from theme */
}

.modal-status.success {
    background: #e6f4ea; /* Light green */
    color: #137333; /* Dark green */
}

.modal-status.error {
    background: #fce8e6; /* Light red */
    color: #d93025; /* Dark red */
}

/* Delete Confirmation */
.delete-confirmation,
.delete-error {
    text-align: center;
    padding: 2.5rem;
    font-size: 1rem;
}

.delete-confirmation {
    color: #137333; /* Dark green */
}

.delete-error {
    color: #d93025; /* Dark red */
}

.checkmark,
.crossmark {
    width: 70px;
    height: 70px;
    margin: 0 auto 2rem;
    display: block;
}

.checkmark circle {
    stroke: #4CAF50;
    stroke-width: 2.5;
}

.checkmark path {
    stroke: #4CAF50;
    stroke-width: 2.5;
    stroke-linecap: round;
    animation: checkmark 0.6s ease-in-out forwards;
}

.crossmark circle {
    stroke: #F44336;
    stroke-width: 2.5;
}

.crossmark path {
    stroke: #F44336;
    stroke-width: 2.5;
    stroke-linecap: round;
    animation: crossmark 0.6s ease-in-out forwards;
}

@keyframes checkmark {
    0% {
        stroke-dashoffset: 100px;
        stroke-dasharray: 100px;
    }
    100% {
        stroke-dashoffset: 0;
        stroke-dasharray: 100px;
    }
}

@keyframes crossmark {
    0% {
        stroke-dashoffset: 100px;
        stroke-dasharray: 100px;
    }
    100% {
        stroke-dashoffset: 0;
        stroke-dasharray: 100px;
    }
}

/* Row States */
.row-deleting {
    animation: pulseWarning 0.8s infinite alternate;
}

.row-updated {
    animation: highlightUpdate 2s ease-out;
}

@keyframes pulseWarning {
    from {
        background-color: var(--background-dark);
    }
    to {
        background-color: color-mix(in srgb, var(--delete-background) 15%, var(--background-dark));
    }
}

@keyframes highlightUpdate {
    from {
        background-color: color-mix(in srgb, var(--primary-color) 15%, var(--background-dark));
    }
    to {
        background-color: transparent;
    }
}


/* Mobile-friendly block layout - CONTENT AGNOSTIC */
@media (max-width: 768px) {
    .anygrid-table, 
    .anygrid-table tbody, 
    .anygrid-table tr, 
    .anygrid-table td {
        display: block;
        width: 100%;
    }

    .anygrid-table thead {
        display: none; /* Hide real headers */
    }

    .anygrid-table tbody tr {
        margin-bottom: 1rem;
        padding: 1rem;
        border: 1px solid var(--border-color);
        border-radius: 0.5rem;
        background: var(--background-light);
    }

    .anygrid-table td {
        text-align: right;
        padding: 0.5rem 0;
        border-bottom: 1px solid rgba(0,0,0,0.05);
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    /* THE FIX: Pulls text from the 'data-label' attribute */
    .anygrid-table td::before {
        content: attr(data-label); 
        font-weight: 600;
        text-transform: uppercase;
        font-size: 0.75rem;
        color: var(--primary-color);
        text-align: left;
    }

    .anygrid-table td:last-child {
        border-bottom: none;
    }
}