/* Quote Table UI Improvements */

/* 1. Table Layout & Column Widths */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    position: relative;
    border: 1px solid var(--medium-gray);
    border-radius: var(--radius-md);
    background: white;
}

/* Allow section tables to extend closer to the card edge */
.quote-block[data-section] .section-content {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
}

.quote-block[data-section] .table-responsive {
    width: calc(100% + 1.5rem);
    margin-left: -0.75rem;
    margin-right: -0.75rem;
}

@media (max-width: 768px) {
    .quote-block[data-section] .section-content {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .quote-block[data-section] .table-responsive {
        width: 100%;
        margin-left: 0;
        margin-right: 0;
    }
}

/* Disable problematic responsive behavior that breaks on Windows browsers */
/* @media (max-width: 1100px) {
    .table-responsive tbody {
        display: block;
        overflow-x: auto;
        width: 100%;
    }
} */

/* Fixed column width specifications using colgroup - no manual resize */
.quote-table {
    table-layout: fixed !important;
    width: 100%;
    border-collapse: collapse !important;
    display: table !important; /* Force table display for cross-browser compatibility */
}

/* Ensure table elements maintain proper display types */
.quote-table thead {
    display: table-header-group !important;
}

.quote-table tbody {
    display: table-row-group !important;
}

.quote-table tr {
    display: table-row !important;
}

.quote-table th,
.quote-table td {
    display: table-cell !important;
    box-sizing: border-box !important;
}

/* Ensure all cells handle text wrapping properly */
.quote-table th,
.quote-table td {
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Dedicated action column sizing */
.quote-table col.action-column {
    width: 140px !important;
}

.quote-table th.action-column,
.quote-table td.action-cell {
    width: 140px;
    min-width: 140px;
}

.quote-table td.action-cell {
    text-align: right;
}

/* Input sizing - removed conflicting styles, now handled by performer-quote-overrides.css */

/* 2. Financial Column Alignment */
.quote-table th.col-total,
.quote-table td.col-total,
.quote-table th.col-unit-price,
.quote-table td.col-unit-price,
.quote-table th.col-qty,
.quote-table td.col-qty,
.quote-table th.col-staff,
.quote-table td.col-staff,
.quote-table th.col-days,
.quote-table td.col-days {
    text-align: end;
}

/* Numeric input alignment */
.quote-table input[type="number"] {
    text-align: end;
}

/* Move total column to far right */
.quote-table {
    table-layout: fixed;
}

/* Remove flex display that was breaking table layout
.quote-table thead tr {
    display: flex;
}

.quote-table tbody tr {
    display: flex;
}
*/

/* Ensure total column is always at the end */
.quote-table th.col-total,
.quote-table td.col-total {
    /* margin-left: auto; This doesn't work well with tables */
    text-align: end !important;
}

/* Align TYPE and DESCRIPTION inputs vertically across rows */
.quote-table td:nth-child(2),
.quote-table td:nth-child(3) {
    vertical-align: top;
}

.drag-handle-cell {
    width: 72px;
    min-width: 72px;
    white-space: nowrap;
    position: relative;
    overflow: visible;
    padding-left: 0;
    padding-right: 0.05rem;
}

.row-handle-wrapper {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.35rem;
}

.row-handle-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
}

.row-handle-wrapper .drag-handle {
    margin-right: 0;
}

.row-lock-btn {
    width: 1.36rem;
    height: 1.36rem;
    border-radius: 999px;
    border: 1px solid #cbd5f5;
    background: #fff;
    color: #475569;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-size: 0.66rem;
    transition: all 0.2s ease;
}

.row-lock-btn:hover,
.row-lock-btn:focus-visible {
    border-color: #64748b;
    color: #0f172a;
    box-shadow: 0 0 0 1px rgba(100,116,139,0.25);
}

.row-lock-btn--locked {
    background: #e0f2fe;
    color: #0f172a;
    border-color: #0f172a;
}

.row-lock-btn--locked:hover,
.row-lock-btn--locked:focus-visible {
    box-shadow: 0 0 0 1px rgba(15,23,42,0.6);
}

.row-lock-btn--disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pf-row--manual {
    background-color: rgba(15, 23, 42, 0.03);
}

.pf-mode-col {
    width: 80px !important;
    min-width: 80px;
    text-align: center;
}

.pf-mode-cell {
    text-align: center;
}

.mode-chip {
    border-radius: 999px;
    font-size: 0.7rem;
    padding: 0.1rem 0.75rem;
    border: 1px solid #cbd5f5;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: #fff;
    color: #475569;
    transition: all 0.2s ease;
}

.mode-chip:hover,
.mode-chip:focus-visible {
    border-color: #64748b;
    color: #0f172a;
}

.mode-chip--manual {
    background: #fee2e2;
    color: #991b1b;
    border-color: #991b1b;
}

.mode-chip--manual:hover,
.mode-chip--manual:focus-visible {
    box-shadow: 0 0 0 1px rgba(15,23,42,0.5);
}

/* Crew Fees: let this table auto-size columns based on content */
.quote-block[data-section="crewFees"] .quote-table {
    table-layout: auto !important;
}

/* Crew Fees compact numeric columns */
.quote-block[data-section="crewFees"] th.col-staff,
.quote-block[data-section="crewFees"] td.col-staff,
.quote-block[data-section="crewFees"] th.col-days,
.quote-block[data-section="crewFees"] td.col-days {
    width: 3.5rem;
    max-width: 3.5rem;
    text-align: center;
}

/* Crew Fees: narrow first column (drag + info + lock) */
.quote-block[data-section="crewFees"] .quote-table thead th:first-child,
.quote-block[data-section="crewFees"] .quote-table tbody td:first-child {
    width: 4.5rem;
    max-width: 4.5rem;
    padding-left: 0.2rem;
    padding-right: 0.2rem;
}

/* Crew Fees: Super / PF / Line column */
.quote-block[data-section="crewFees"] col.pf-mode-col,
.quote-block[data-section="crewFees"] th.pf-mode-col,
.quote-block[data-section="crewFees"] td.pf-mode-cell {
    width: 7rem;
    min-width: 7rem;
}
.quote-block[data-section="crewFees"] .pf-mode-cell {
    display: flex;
    justify-content: center;
    gap: 0.25rem;
}
.quote-block[data-section="crewFees"] .pf-mode-cell .mode-chip {
    padding: 0.12rem 0.35rem;
    font-size: 0.7rem;
}

.code-info-dot {
    width: 1.36rem;
    height: 1.36rem;
    border-radius: 999px;
    border: 1px solid #9ca3af;
    background: #ffffff;
    color: #4b5563;
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: help;
    padding: 0;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.15);
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
    z-index: 50;
}

.code-info-dot:hover,
.code-info-dot:focus-visible {
    transform: translateY(-1px);
    border-color: #6b7280;
    box-shadow: 0 3px 8px rgba(15, 23, 42, 0.25);
}

.code-info-dot:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.code-info-dot--empty {
    border-color: #e5e7eb;
    background: #f9fafb;
    color: #9ca3af;
}

.code-tooltip-global {
    position: fixed;
    left: 0;
    top: 0;
    background: #111827;
    color: #fff;
    padding: 0.35rem 0.7rem;
    border-radius: 0.35rem;
    font-size: 0.72rem;
    line-height: 1.4;
    max-width: 24rem;
    box-shadow: 0 3px 12px rgba(15, 23, 42, 0.35);
    pointer-events: none;
    display: none;
    z-index: 999999;
    white-space: normal;
}

.rule-tooltip__code {
    font-weight: 600;
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #a5b4fc;
}

.rule-tooltip__line {
    padding-left: 0.75rem;
    position: relative;
    margin-bottom: 0.25rem;
}

.rule-tooltip__line::before {
    content: '•';
    position: absolute;
    left: 0;
    color: #94a3b8;
}

.rule-tooltip__line--suppressed {
    opacity: 0.6;
    text-decoration: line-through;
}

.rule-tooltip__line--super-on {
    color: #34d399;
}

.rule-tooltip__line--super-off {
    color: #f87171;
}

.rule-tooltip__line--empty {
    opacity: 0.75;
    font-style: italic;
}

/* 3. Consistent Component Structure */
.quote-block {
    margin-bottom: 2rem;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-md);
    overflow: visible;
}

.quote-block header {
    background: #f8f9fa;
    padding: 1rem;
    border-bottom: 1px solid #e2e8f0;
}

.quote-block header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #2d3748;
}

.quote-block .section-header {
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.quote-block .section-header h3 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.quote-block table {
    margin: 0;
    border: none;
}

.quote-block footer {
    background: #f8f9fa;
    padding: 1rem;
    border-top: 1px solid #e2e8f0;
}

.quote-block .subtotal {
    text-align: end;
    font-weight: 600;
    color: #2d3748;
    margin: 0;
}

/* Drag and drop styles */
.drag-handle {
    cursor: move;
    color: #9ca3af;
    padding: 4px 8px;
    margin-right: 8px;
    font-size: 14px;
}

.drag-handle:hover {
    color: #6b7280;
}

.sortable-ghost {
    opacity: 0.4;
    background: #f3f4f6;
}

.sortable-drag {
    opacity: 0.8;
    background: #fff;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* Empty field placeholder */
.empty-placeholder {
    color: #a0aec0;
    font-style: italic;
    text-align: center;
}

/* 4. Change Tracking & Collaboration */
.field-changed {
    background-color: #fef3c7 !important;
    position: relative;
}

.change-diff {
    display: block;
    font-size: 11px;
    font-family: Arial, sans-serif;
    margin-top: 2px;
}

.change-diff .old-value {
    color: #dc2626;
    text-decoration: line-through;
}

.change-diff .new-value {
    color: #059669;
    font-weight: 600;
}

.change-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #1a202c;
    color: white;
    padding: 0.5rem 0.75rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 100;
}

.field-changed:hover .change-tooltip {
    opacity: 1;
}

/* Badge component */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-notice {
    background-color: #fee2e2;
    color: #dc2626;
}

.badge-comment {
    background-color: #dbeafe;
    color: #2563eb;
}

.badge-count {
    margin-left: 0.25rem;
}

/* 5. Validation, Defaults & Accessibility */
.input-error {
    border-color: #dc2626 !important;
}

.validation-message {
    font-size: 0.75rem;
    color: #dc2626;
    margin-top: 0.25rem;
}

/* Focus rings */
.quote-table input:focus-visible,
.quote-table select:focus-visible,
.quote-table textarea:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Keyboard increment/decrement for number inputs */
.quote-table input[type="number"] {
    -moz-appearance: textfield;
}

.quote-table input[type="number"]::-webkit-inner-spin-button,
.quote-table input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Improved table structure */
.quote-table {
    width: 100%;
    border-collapse: collapse;
}

.quote-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #f8f9fa;
}

.quote-table thead th {
    font-weight: 600;
    color: #4a5568;
    padding: 0.75rem;
    border-bottom: 2px solid #e2e8f0;
}

.quote-table tbody tr {
    border-bottom: 1px solid #e2e8f0;
}

.quote-table tbody tr:hover {
    background-color: #f7fafc;
}

.quote-table tbody td {
    padding: 0.5rem;
}

/* Comment row styling */
.comment-row {
    background-color: #f8f9fa;
}

.comment-row td {
    padding: 1rem;
}

/* Sticky footer improvements */
.sticky-totals-footer {
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

/* Responsive improvements */
@media (max-width: 768px) {
    .quote-block {
        margin-bottom: 1rem;
    }
    
    .quote-table {
        font-size: 0.875rem;
    }
    
    .quote-table th,
    .quote-table td {
        padding: 0.5rem 0.25rem;
    }
}
