/**
 * Spreadsheet Styles
 * Table, cells, editing, and row states
 */

.spreadsheet {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    background-color: var(--bg);
}

/* Selected cells */
.selected-cell {
    background-color: rgba(0, 123, 255, 0.2) !important;
    outline: 1px solid var(--primary);
}

/* Auto-populated cells (gray text to indicate matches filename) */
.cell-editable.auto-populated {
    color: var(--text-muted);
}

/* Changed fields (blue text to indicate value differs from original filename) */
.cell-editable.field-changed {
    color: var(--primary);
    font-weight: 500;
}

.spreadsheet thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: var(--bg-secondary);
}

.spreadsheet th {
    padding: 0.75rem 0.5rem;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid var(--border);
    background-color: var(--bg-secondary);
    position: relative;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.spreadsheet th:hover:not(.col-row-num) {
    background-color: var(--border);
}

/* Sort indicator */
.sort-indicator {
    display: inline-block;
    font-size: 0.75rem;
    color: var(--primary);
    margin-left: 0.25rem;
    margin-right: 0.25rem;
    font-weight: bold;
    vertical-align: middle;
}

.spreadsheet td {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    white-space: nowrap;
}

/* Column resizer */
.column-resizer {
    position: absolute;
    top: 0;
    right: 0;
    width: 5px;
    height: 100%;
    cursor: col-resize;
    user-select: none;
    z-index: 1;
}

.column-resizer:hover {
    background-color: var(--primary);
}

/* Column Widths */
.col-row-num {
    width: 50px;
    text-align: center;
    background-color: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-muted);
    user-select: none;
    -webkit-user-select: none;
}

.col-original {
    min-width: 250px;
}

.col-extension {
    width: 60px;
    text-align: center;
}

.col-new {
    min-width: 250px;
}

.col-trackingNumber {
    min-width: 200px;
    width: 200px;
}

.col-revision {
    width: 80px;
}

.col-status {
    width: 100px;
}

.col-title {
    min-width: 200px;
}

.col-sha256 {
    min-width: 150px;
    font-family: var(--font-mono);
    font-size: 11px;
}

.col-actions {
    width: 100px;
    text-align: center;
}

/* Row States */
.spreadsheet tbody tr {
    transition: background-color 0.15s;
}

.spreadsheet tbody tr:hover {
    background-color: var(--bg-hover);
}

.spreadsheet tbody tr.modified {
    border-left: 3px solid var(--warning);
}

.spreadsheet tbody tr.error {
    border-left: 3px solid var(--danger);
    background-color: rgba(220, 53, 69, 0.08);
}

.spreadsheet tbody tr.saving {
    opacity: 0.6;
    pointer-events: none;
}

/* Cell Content */
.cell-content {
    display: block;
    width: 100%;
}

.cell-link {
    color: var(--primary);
    text-decoration: none;
}

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

.cell-extension {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
}

.cell-computed {
    font-style: italic;
    color: var(--text-muted);
}

/* Editable Cells */
.cell-editable {
    cursor: text;
    position: relative;
}

.cell-editable:hover {
    background-color: var(--bg-hover);
}

.cell-content[contenteditable="true"] {
    outline: 2px solid var(--primary);
    outline-offset: 0;
    background-color: var(--bg);
    min-height: 1.5em;
}

.cell-content[contenteditable="true"]:focus {
    outline: 2px solid var(--primary);
    outline-offset: 0;
}

.cell-content.editing {
    white-space: pre-wrap;
    word-break: break-word;
}

/* Computed cells */
.cell-editable.computed {
    font-style: italic;
    color: var(--text-muted);
}

.cell-editable.computed:hover {
    font-style: normal;
    color: var(--text);
}

/* Validation states */
.validation-error {
    background-color: rgba(220, 53, 69, 0.1);
    border-left: 3px solid var(--danger);
}

.validation-warning {
    background-color: rgba(255, 193, 7, 0.1);
    border-left: 3px solid #ffc107;
}

/* Inline Actions */
.inline-actions {
    position: absolute;
    right: 0.25rem;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 0.25rem;
    background-color: var(--bg);
    padding: 0.125rem;
    border-radius: 3px;
}

.cell-editable {
    position: relative;
    padding-right: 3.5rem; /* Space for buttons */
}

.btn-inline {
    border: none;
    background: rgba(255, 255, 255, 0.9);
    cursor: pointer;
    font-size: 14px;
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
    transition: all 0.15s;
    font-weight: bold;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.btn-save {
    color: var(--success);
}

.btn-save:hover {
    background-color: var(--success);
    color: white;
}

.btn-cancel {
    color: var(--danger);
}

.btn-cancel:hover {
    background-color: var(--danger);
    color: white;
}

/* Formula Preview */
.formula-preview {
    position: absolute;
    bottom: 100%;
    left: 0;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.5rem;
    font-size: 12px;
    min-width: 200px;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.formula-preview-label {
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.formula-preview-value {
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.formula-preview-value.valid {
    color: var(--success);
}

.formula-preview-value.invalid {
    color: var(--danger);
}

.preview-check {
    color: var(--success);
    font-size: 16px;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 3px;
    transition: background-color 0.15s;
}

.preview-check:hover {
    background-color: rgba(40, 167, 69, 0.1);
}

.preview-error {
    color: var(--danger);
    font-size: 16px;
}

.formula-preview-errors {
    margin-top: 0.25rem;
    font-size: 11px;
    color: var(--danger);
    white-space: normal;
}

/* Validation States */
.cell-warning {
    background-color: rgba(255, 193, 7, 0.08);
    border-left: 3px solid var(--warning);
}

.cell-error {
    background-color: rgba(220, 53, 69, 0.08);
    border-left: 3px solid var(--danger);
}

.validation-icon {
    display: inline-block;
    margin-left: 0.25rem;
    cursor: help;
}

/* SHA256 Column */
.sha256-hash {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
}

.sha256-calculating {
    font-style: italic;
    color: var(--text-muted);
}

/* Action Buttons */
.row-actions {
    display: flex;
    gap: 0.25rem;
    justify-content: center;
}

.btn-icon {
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 4px;
    background-color: var(--bg);
    cursor: pointer;
    transition: all 0.15s;
}

.btn-icon:hover:not(:disabled) {
    background-color: var(--bg-hover);
    transform: scale(1.1);
}

.btn-icon:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.btn-save {
    color: var(--success);
}

.btn-cancel {
    color: var(--danger);
}

/* Inline tree-empty placeholder — shown by tree.js when the folder
   list is empty. Distinct from the top-level .empty-state overlay
   (shared/base.css) which is the welcome screen. */
.tree-empty {
    padding: 3rem;
    text-align: center;
    color: var(--text-muted);
}

.tree-empty h3 {
    margin-bottom: 0.5rem;
}

/* Spreadsheet Empty State */
.spreadsheet-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 1.5rem;
}

/* Selection Highlight */
.cell-selected {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
    z-index: 1;
}

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

.spreadsheet-container::-webkit-scrollbar-track {
    background-color: var(--bg-secondary);
}

.spreadsheet-container::-webkit-scrollbar-thumb {
    background-color: var(--border-dark);
    border-radius: 6px;
}

.spreadsheet-container::-webkit-scrollbar-thumb:hover {
    background-color: var(--text-muted);
}

/* Preview button active state */
#togglePreviewBtn.preview-active {
    background-color: var(--primary);
    color: white;
    border-color: var(--primary);
}
