/* ==========================================================================
   DataGrid Component Styles
   Following CreditHaven StyleGuide.md design system
   ========================================================================== */

/* CSS Variables */
:root {
    --grid-bg: #FFFFFF;
    --grid-border: #E5E7EB;
    --grid-border-radius: 0;
    --grid-header-bg: #F9FAFB;
    --grid-row-hover: #F9FAFB;
    --grid-row-selected: #EEF2FF;

    /* Text colors */
    --grid-text-primary: #111827;
    --grid-text-secondary: #6B7280;
    --grid-text-muted: #9CA3AF;

    /* Primary colors */
    --grid-primary: #4F46E5;
    --grid-primary-hover: #4338CA;
    --grid-primary-light: #EEF2FF;

    /* Status colors */
    --grid-success: #10B981;
    --grid-success-light: #D1FAE5;
    --grid-error: #EF4444;
    --grid-error-light: #FEE2E2;
    --grid-warning: #F59E0B;
    --grid-warning-light: #FEF3C7;
    --grid-info: #3B82F6;
    --grid-info-light: #DBEAFE;
}

/* ==========================================================================
   Main Container
   ========================================================================== */

.data-grid {
    background: var(--grid-bg);
    border-radius: var(--grid-border-radius);
    border: 1px solid var(--grid-border);
    overflow: hidden;
    margin: 24px 24px 0 24px;
}

/* ==========================================================================
   Grid Header
   ========================================================================== */

.grid-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--grid-border);
}

.grid-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 24px;
    font-weight: 600;
    color: var(--grid-text-primary);
    margin: 0;
}

.grid-title-icon {
    font-size: 22px;
    color: var(--grid-primary);
}

.grid-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.btn i {
    font-size: 14px;
}

.btn-primary {
    background: #4F46E5;
    color: #FFFFFF;
    border: 1px solid #4F46E5;
}

.btn-primary:hover {
    background: #4338CA;
    border-color: #4338CA;
}

.btn-outline {
    background: var(--grid-bg);
    color: var(--grid-text-primary);
    border: 1px solid var(--grid-border);
}

.btn-outline:hover {
    background: var(--grid-header-bg);
    border-color: #9CA3AF;
}

.btn-danger {
    background: var(--grid-error);
    color: #FFFFFF;
    border: 1px solid var(--grid-error);
}

.btn-danger:hover {
    background: #DC2626;
    border-color: #DC2626;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 1px solid var(--grid-border);
    background: var(--grid-bg);
    color: var(--grid-text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background: var(--grid-header-bg);
    color: var(--grid-text-primary);
}

.btn-icon.active {
    background: var(--grid-primary-light);
    color: var(--grid-primary);
    border-color: var(--grid-primary);
}

/* ==========================================================================
   Tab Filters
   ========================================================================== */

.grid-tabs {
    display: flex;
    gap: 4px;
    padding: 12px 24px;
    border-bottom: 1px solid var(--grid-border);
    background: var(--grid-bg);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--grid-text-secondary);
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.tab-btn:hover {
    background: var(--grid-header-bg);
    color: var(--grid-text-primary);
}

.tab-btn.active {
    background: var(--grid-text-primary);
    color: #FFFFFF;
    border-color: var(--grid-text-primary);
}

.tab-btn.tab-add {
    padding: 8px 12px;
    color: var(--grid-text-muted);
}

.tab-btn.tab-add:hover {
    color: var(--grid-primary);
}

.tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--grid-primary);
    color: #FFFFFF;
    font-size: 11px;
    font-weight: 600;
}

.tab-btn.active .tab-badge {
    background: #FFFFFF;
    color: var(--grid-text-primary);
}

/* ==========================================================================
   Toolbar
   ========================================================================== */

.grid-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--grid-border);
    background: var(--grid-bg);
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Page Size Selector */
.page-size-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.page-size-label {
    font-size: 14px;
    color: var(--grid-text-secondary);
}

.page-size-select {
    padding: 8px 32px 8px 12px;
    border: 1px solid var(--grid-border);
    border-radius: 6px;
    font-size: 14px;
    color: var(--grid-text-primary);
    background: var(--grid-bg);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 8px center;
    background-repeat: no-repeat;
    background-size: 16px;
    appearance: none;
    cursor: pointer;
}

.page-size-select:focus {
    outline: none;
    border-color: var(--grid-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Search */
.grid-search {
    position: relative;
    width: 280px;
}

.grid-search .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--grid-text-muted);
    font-size: 14px;
    pointer-events: none;
}

.grid-search .search-input {
    width: 100%;
    padding: 10px 12px 10px 40px;
    border: 1px solid var(--grid-border);
    border-radius: 8px;
    font-size: 14px;
    color: var(--grid-text-primary);
    background: var(--grid-bg);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.grid-search .search-input::placeholder {
    color: var(--grid-text-muted);
}

.grid-search .search-input:focus {
    outline: none;
    border-color: var(--grid-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* View Toggle */
.view-toggle {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--grid-header-bg);
    border-radius: 8px;
}

.view-toggle .view-btn {
    border: none;
    background: transparent;
}

.view-toggle .view-btn.active {
    background: var(--grid-bg);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* ==========================================================================
   Data Table
   ========================================================================== */

.grid-table-container {
    overflow-x: auto;
}

.grid-table {
    width: 100%;
    border-collapse: collapse;
}

/* Table Header */
.grid-table thead {
    background: var(--grid-header-bg);
}

.grid-table th {
    padding: 12px 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--grid-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--grid-border);
    white-space: nowrap;
}

.grid-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.grid-table th.sortable:hover {
    color: var(--grid-text-primary);
}

.th-content {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sort-icon {
    font-size: 12px;
    color: var(--grid-text-muted);
    transition: color 0.2s;
}

.grid-table th.sorted-asc .sort-icon,
.grid-table th.sorted-desc .sort-icon {
    color: var(--grid-primary);
}

.grid-table th.sorted-asc .sort-icon::before {
    content: "\f0de"; /* fa-sort-up */
}

.grid-table th.sorted-desc .sort-icon::before {
    content: "\f0dd"; /* fa-sort-down */
}

.filter-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--grid-text-muted);
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.filter-btn:hover {
    background: var(--grid-border);
    color: var(--grid-text-primary);
}

/* Table Body */
.grid-table td {
    padding: 16px;
    font-size: 14px;
    color: var(--grid-text-primary);
    border-bottom: 1px solid #F3F4F6;
    vertical-align: middle;
}

.grid-table tbody tr:hover {
    background: var(--grid-row-hover);
}

.grid-table tbody tr.selected {
    background: var(--grid-row-selected);
}

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

/* Checkbox Column */
.col-checkbox {
    width: 48px;
    text-align: center;
}

.col-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--grid-primary);
}

/* ==========================================================================
   Cell Templates
   ========================================================================== */

/* Badge */
.cell-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.cell-badge.badge-success,
.cell-badge.badge-booked,
.cell-badge.badge-confirmed {
    background: var(--grid-success-light);
    color: #065F46;
}

.cell-badge.badge-warning,
.cell-badge.badge-on-hold,
.cell-badge.badge-pending {
    background: var(--grid-warning-light);
    color: #92400E;
}

.cell-badge.badge-error,
.cell-badge.badge-cancelled,
.cell-badge.badge-void {
    background: var(--grid-error-light);
    color: #991B1B;
}

.cell-badge.badge-info,
.cell-badge.badge-in-progress,
.cell-badge.badge-ticketed {
    background: var(--grid-info-light);
    color: #1E40AF;
}

.cell-badge.badge-default {
    background: #F3F4F6;
    color: var(--grid-text-secondary);
}

.cell-badge.badge-muted {
    background: #F3F4F6;
    color: #9CA3AF;
}

/* Link */
.cell-link {
    color: var(--grid-primary);
    text-decoration: none;
    font-weight: 500;
}

.cell-link:hover {
    text-decoration: underline;
}

/* Actions */
.cell-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.action-btn.btn-edit {
    background: var(--grid-primary-light);
    color: var(--grid-primary);
    width: 32px;
    height: 32px;
    padding: 0;
    justify-content: center;
}

.action-btn.btn-edit:hover {
    background: var(--grid-primary);
    color: #FFFFFF;
}

.action-btn.btn-delete {
    background: var(--grid-error-light);
    color: var(--grid-error);
}

.action-btn.btn-delete:hover {
    background: var(--grid-error);
    color: #FFFFFF;
}

/* Icon-only action buttons */
.action-btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.action-btn-icon.btn-edit {
    background: var(--grid-primary-light);
    color: var(--grid-primary);
}

.action-btn-icon.btn-edit:hover {
    background: var(--grid-primary);
    color: #FFFFFF;
}

.action-btn-icon.btn-delete {
    background: var(--grid-error-light);
    color: var(--grid-error);
}

.action-btn-icon.btn-delete:hover {
    background: var(--grid-error);
    color: #FFFFFF;
}

/* ==========================================================================
   Inline Edit
   ========================================================================== */

.inline-edit-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--grid-primary);
    border-radius: 6px;
    font-size: 14px;
    color: var(--grid-text-primary);
    background: var(--grid-bg);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.inline-edit-input:focus {
    outline: none;
}

.inline-edit-actions {
    display: flex;
    gap: 4px;
    margin-top: 8px;
}

.inline-edit-actions .btn {
    padding: 6px 12px;
    font-size: 12px;
}

/* ==========================================================================
   Empty State
   ========================================================================== */

.grid-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 24px;
    text-align: center;
}

.grid-empty i {
    font-size: 48px;
    color: var(--grid-text-muted);
    margin-bottom: 16px;
}

.grid-empty p {
    font-size: 16px;
    color: var(--grid-text-secondary);
    margin: 0;
}

/* Loading State */
.loading-row td {
    padding: 60px 24px;
    text-align: center;
}

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--grid-text-muted);
}

.loading-spinner i {
    font-size: 24px;
}

.loading-spinner span {
    font-size: 14px;
}

/* ==========================================================================
   Pagination
   ========================================================================== */

.grid-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-top: 1px solid var(--grid-border);
    background: var(--grid-bg);
}

.pagination-info {
    font-size: 14px;
    color: var(--grid-text-secondary);
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pagination-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--grid-border);
    border-radius: 6px;
    background: var(--grid-bg);
    font-size: 14px;
    font-weight: 500;
    color: var(--grid-text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.pagination-btn:hover:not(:disabled) {
    background: var(--grid-header-bg);
    border-color: #9CA3AF;
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-numbers {
    display: flex;
    align-items: center;
    gap: 4px;
}

.page-number {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--grid-text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    background: transparent;
}

.page-number:hover {
    background: var(--grid-header-bg);
    color: var(--grid-text-primary);
}

.page-number.active {
    background: var(--grid-text-primary);
    color: #FFFFFF;
}

.page-ellipsis {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: var(--grid-text-muted);
}

/* ==========================================================================
   Modal Styles
   ========================================================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 20px;
    z-index: 1000;
    overflow-y: auto;
}

.modal-container {
    background: var(--grid-bg);
    border-radius: var(--grid-border-radius);
    width: 100%;
    max-width: 500px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    animation: modalSlideIn 0.3s ease;
}

.modal-container.modal-sm {
    max-width: 400px;
}

.modal-container.modal-lg {
    max-width: 800px;
}

.modal-container.modal-xl {
    max-width: 1000px;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--grid-border);
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--grid-text-primary);
    margin: 0;
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--grid-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--grid-header-bg);
    color: var(--grid-text-primary);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--grid-border);
    background: var(--grid-header-bg);
    border-radius: 0 0 var(--grid-border-radius) var(--grid-border-radius);
}

/* ==========================================================================
   Form Elements (for modals)
   ========================================================================== */

.form-group {
    margin-bottom: 1px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--grid-text-primary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--grid-border);
    border-radius: 6px;
    font-size: 14px;
    color: var(--grid-text-primary);
    background: var(--grid-bg);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input::placeholder {
    color: var(--grid-text-muted);
}

.form-input:focus {
    outline: none;
    border-color: var(--grid-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-input.is-invalid {
    border-color: var(--grid-error);
}

.form-input.is-invalid:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.form-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--grid-border);
    border-radius: 6px;
    font-size: 14px;
    color: var(--grid-text-primary);
    background: var(--grid-bg);
    transition: border-color 0.2s, box-shadow 0.2s;
    resize: vertical;
    font-family: inherit;
}

.form-textarea::placeholder {
    color: var(--grid-text-muted);
}

.form-textarea:focus {
    outline: none;
    border-color: var(--grid-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-textarea.is-invalid {
    border-color: var(--grid-error);
}

.form-textarea.is-invalid:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.validation-error {
    display: block;
    font-size: 12px;
    color: var(--grid-error);
    margin-top: 4px;
}

.text-danger {
    color: var(--grid-error);
    font-weight: 500;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

@media (max-width: 768px) {
    .grid-header {
        flex-direction: column;
        gap: 16px;
        align-items: flex-start;
    }

    .grid-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .grid-toolbar {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .toolbar-left,
    .toolbar-right {
        width: 100%;
    }

    .grid-search {
        width: 100%;
    }

    .grid-pagination {
        flex-direction: column;
        gap: 16px;
    }

    .pagination-info {
        text-align: center;
    }

    .pagination-controls {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .grid-tabs {
        padding: 12px 16px;
    }

    .tab-btn {
        padding: 6px 12px;
        font-size: 13px;
    }

    .modal-container {
        margin: 20px;
        max-width: calc(100% - 40px);
    }
}

@media (max-width: 480px) {
    .grid-header,
    .grid-toolbar,
    .grid-pagination {
        padding: 12px 16px;
    }

    .grid-table th,
    .grid-table td {
        padding: 12px;
    }

    .page-size-wrapper {
        width: 100%;
    }

    .page-numbers {
        display: none;
    }
}
