/* ====================================
   DataGrid Styles - Office Professional
   ==================================== */

/* Container */
.datagrid-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 13px;
    border: 1px solid #E2E8F0;
    border-radius: 6px;
    overflow: hidden;
}

/* Header */
.datagrid-header {
    background: #F8FAFC;
    border-bottom: 2px solid #E2E8F0;
    overflow: hidden;
    flex-shrink: 0;
}

.datagrid-header-row {
    display: flex;
    width: fit-content;
    min-width: 100%;
    height: 100%;
}

.datagrid-header-cell {
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-weight: 600;
    color: #1E293B;
    border-right: 1px solid #E2E8F0;
    background: #F8FAFC;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
    user-select: none;
}

.datagrid-header-cell:last-child {
    border-right: none;
}

.datagrid-header-cell.sortable {
    cursor: pointer;
}

.datagrid-header-cell.sortable:hover {
    background: #E2E8F0;
}

.datagrid-header-cell.sorted {
    background: var(--theme-primary-light);
    color: var(--theme-primary);
}

.datagrid-header-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.datagrid-sort-icon {
    margin-left: 6px;
    font-size: 10px;
    color: #64748B;
}

.datagrid-header-cell.sorted .datagrid-sort-icon {
    color: var(--theme-primary);
}

/* Column Resize Handle */
.datagrid-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    cursor: col-resize;
    background: transparent;
    z-index: 10;
}

.datagrid-resize-handle:hover {
    background: var(--theme-primary-hover);
}

/* Body */
.datagrid-body {
    flex: 1;
    min-height: 0; /* Required for flex child to shrink and enable scrolling */
    overflow: auto;
    background: #ffffff;
}

.datagrid-row {
    display: flex;
    width: fit-content;
    min-width: 100%;
    border-bottom: 1px solid #E2E8F0;
    background: #ffffff;
    transition: background-color 0.12s ease;
}

.datagrid-row:last-child {
    border-bottom: none;
}

.datagrid-row.striped {
    background: #F8FAFC;
}

.datagrid-row.hoverable:hover {
    background: #F1F5F9;
}

.datagrid-row.selected {
    background: var(--theme-primary-light) !important;
}

.datagrid-row.selected:hover {
    background: var(--theme-primary-lighter) !important;
}

/* Cells */
.datagrid-cell {
    display: flex;
    align-items: center;
    padding: 0 12px;
    border-right: 1px solid #F1F5F9;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: #1E293B;
}

.datagrid-cell:last-child {
    border-right: none;
}

.datagrid-cell-content {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.datagrid-index-cell {
    font-weight: 500;
    color: #64748B;
    background: #F8FAFC;
    border-right: 1px solid #E2E8F0 !important;
}

.datagrid-row.selected .datagrid-index-cell {
    background: var(--theme-primary-lighter);
}

/* Scrollbar Styling */
.datagrid-body::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

.datagrid-body::-webkit-scrollbar-track {
    background: #F8FAFC;
    border-left: 1px solid #E2E8F0;
}

.datagrid-body::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 6px;
    border: 2px solid #F8FAFC;
}

.datagrid-body::-webkit-scrollbar-thumb:hover {
    background: #94A3B8;
}

.datagrid-body::-webkit-scrollbar-corner {
    background: #F8FAFC;
}

/* Compact Variant */
.datagrid-container.compact .datagrid-header-cell,
.datagrid-container.compact .datagrid-cell {
    padding: 0 8px;
    font-size: 12px;
}

/* Dense Variant */
.datagrid-container.dense .datagrid-row {
    height: 28px !important;
}

.datagrid-container.dense .datagrid-header {
    height: 32px !important;
}

/* Dark Theme */
.datagrid-container.dark {
    background: #1E293B;
    border-color: #334155;
}

.datagrid-container.dark .datagrid-header {
    background: #334155;
    border-bottom-color: #475569;
}

.datagrid-container.dark .datagrid-header-cell {
    background: #334155;
    color: #E2E8F0;
    border-right-color: #475569;
}

.datagrid-container.dark .datagrid-header-cell.sortable:hover {
    background: #475569;
}

.datagrid-container.dark .datagrid-header-cell.sorted {
    background: var(--theme-primary);
    color: #ffffff;
}

.datagrid-container.dark .datagrid-body {
    background: #1E293B;
}

.datagrid-container.dark .datagrid-row {
    background: #1E293B;
    border-bottom-color: #334155;
}

.datagrid-container.dark .datagrid-row.striped {
    background: #334155;
}

.datagrid-container.dark .datagrid-row.hoverable:hover {
    background: #475569;
}

.datagrid-container.dark .datagrid-row.selected {
    background: var(--theme-primary) !important;
}

.datagrid-container.dark .datagrid-cell {
    color: #E2E8F0;
    border-right-color: #334155;
}

.datagrid-container.dark .datagrid-index-cell {
    background: #334155;
    color: #94A3B8;
    border-right-color: #475569 !important;
}

.datagrid-container.dark .datagrid-row.selected .datagrid-index-cell {
    background: var(--theme-primary);
}

/* Loading State */
.datagrid-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.datagrid-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #E2E8F0;
    border-top-color: var(--theme-primary);
    border-radius: 50%;
    animation: datagrid-spin 0.8s linear infinite;
}

@keyframes datagrid-spin {
    to { transform: rotate(360deg); }
}

/* Empty State */
.datagrid-empty {
    padding: 60px 20px;
    text-align: center;
    color: #64748B;
}

.datagrid-empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.datagrid-empty-message {
    font-size: 14px;
    font-weight: 500;
}

/* Cell Type Variations */
.datagrid-cell.cell-number {
    font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
    justify-content: flex-end;
}

.datagrid-cell.cell-currency {
    font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
    justify-content: flex-end;
    color: var(--theme-accent);
}

.datagrid-cell.cell-status {
    font-weight: 500;
}

.datagrid-cell.cell-date {
    color: #64748B;
}

/* Status Badges */
.datagrid-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.datagrid-badge.badge-success {
    background: #DCFCE7;
    color: #166534;
}

.datagrid-badge.badge-warning {
    background: #FEF3C7;
    color: #92400E;
}

.datagrid-badge.badge-error {
    background: #FEE2E2;
    color: #DC2626;
}

.datagrid-badge.badge-info {
    background: var(--theme-primary-light);
    color: var(--theme-primary);
}

.datagrid-badge.badge-neutral {
    background: #F1F5F9;
    color: #64748B;
}

/* Action Buttons in Cells */
.datagrid-cell-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.datagrid-row:hover .datagrid-cell-actions {
    opacity: 1;
}

.datagrid-cell-action-btn {
    padding: 4px 8px;
    background: transparent;
    border: 1px solid #E2E8F0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    color: #64748B;
    transition: all 0.12s ease;
}

.datagrid-cell-action-btn:hover {
    background: #F1F5F9;
    border-color: var(--theme-primary-hover);
    color: var(--theme-primary);
}

/* Editable Cells */
.datagrid-container.edit-mode .datagrid-cell.editable {
    cursor: text;
}

.datagrid-container.edit-mode .datagrid-cell.editable .datagrid-cell-content:not(:has(.datagrid-cell-input)) {
    border: 1px solid var(--theme-primary-lighter);
    border-radius: 2px;
    padding: 4px 6px;
    margin: -3px -7px;
    min-height: 27px;
    vertical-align:bottom;
}

.datagrid-container.edit-mode .datagrid-cell.editable:hover .datagrid-cell-content:not(:has(.datagrid-cell-input)) {
    border-color: var(--theme-primary);
    border-style: solid;
    background: #FEFCE8;
}

.datagrid-cell.editable.editing {
    padding: 0 4px;
    background: #ffffff !important;
}

.datagrid-cell-input {
    width: 100%;
    height: 100%;
    padding: 4px 8px;
    border: 2px solid var(--theme-primary);
    border-radius: 2px;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    background: #ffffff;
    outline: none;
    box-sizing: border-box;
}

select.datagrid-cell-input {
    cursor: pointer;
}

input[type="checkbox"].datagrid-cell-input {
    width: auto;
    height: auto;
}

.datagrid-cell-input:focus {
    box-shadow: 0 0 0 2px var(--theme-primary-focus);
}

/* Dark theme editable cells */
.datagrid-container.dark.edit-mode .datagrid-cell.editable:hover {
    background: #854D0E;
}

.datagrid-container.dark .datagrid-cell.editable.editing {
    background: #1E293B !important;
}

.datagrid-container.dark .datagrid-cell-input {
    background: #1E293B;
    color: #E2E8F0;
    border-color: var(--theme-primary);
}

/* Flash animation for highlighted rows - 3 pulses over 3 seconds */
@keyframes datagrid-flash-anim {
    0%        { background-color: inherit; }
    5%        { background-color: #FEF08A; }
    28%       { background-color: inherit; }
    38%       { background-color: #FEF08A; }
    61%       { background-color: inherit; }
    71%       { background-color: #FEF08A; }
    95%       { background-color: inherit; }
    100%      { background-color: inherit; }
}

.datagrid-row.datagrid-flash {
    animation: datagrid-flash-anim 3s ease-in-out;
}

.datagrid-container.dark .datagrid-row.datagrid-flash {
    animation: datagrid-flash-anim-dark 3s ease-in-out;
}

@keyframes datagrid-flash-anim-dark {
    0%        { background-color: inherit; }
    5%        { background-color: #854D0E; }
    28%       { background-color: inherit; }
    38%       { background-color: #854D0E; }
    61%       { background-color: inherit; }
    71%       { background-color: #854D0E; }
    95%       { background-color: inherit; }
    100%      { background-color: inherit; }
}
