/**
 * Progress Matrix Styles
 * Created: 2025-12-23
 * Updated: 2025-12-23 - Added CSS Variables for admin display settings
 */

/* CSS Variables for Admin Display Settings */
:root {
    --pm-row-height: 32px;
    --pm-column-width: 60px;
    --pm-group-header-height: 40px;
    --pm-leaf-header-height: 28px;
    --pm-corner-cell-width: 100px;
    --pm-font-group-header: 13px;
    --pm-font-leaf-header: 12px;
    --pm-font-cell-value: 11px;
    --pm-font-floor-label: 12px;
}

/* Container */
#progress-matrix-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: #fff;
}

/* Header - Compact like Risk Management */
.progress-matrix-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 15px;
    border-bottom: 1px solid #e0e0e0;
    background: #fafafa;
}

.progress-matrix-title {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #333;
}

.progress-matrix-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Action buttons - Minimal text style, all IDENTICAL */
/* Using specific selectors with !important to override any global styles */
.progress-matrix-header .export-btn,
.progress-matrix-header .save-filter-btn,
.progress-matrix-header .delete-filter-btn {
    padding: 6px 12px !important;
    background: transparent !important;
    color: #666 !important;
    border: 1px solid #d9d9d9 !important;
    border-radius: 4px !important;
    cursor: pointer !important;
    font-size: 12px !important;
    font-weight: 400 !important;
    font-family: inherit !important;
    line-height: 1 !important;
    height: 28px !important;
    min-width: 80px !important;
    box-sizing: border-box !important;
    transition: all 0.2s !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.progress-matrix-header .export-btn:hover,
.progress-matrix-header .save-filter-btn:hover {
    background: #f5f5f5 !important;
    border-color: #1890ff !important;
    color: #1890ff !important;
}

/* ============================================
   View Toggle (Phase 7)
   Table/Visual view switcher
   ============================================ */
.progress-matrix-header .view-toggle {
    display: flex;
    background: #f1f5f9;
    border-radius: 6px;
    padding: 2px;
    gap: 2px;
}

.progress-matrix-header .view-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border: none;
    background: transparent;
    border-radius: 4px;
    font-size: 12px;
    color: #64748b;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.progress-matrix-header .view-toggle-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.progress-matrix-header .view-toggle-btn:hover {
    color: #334155;
    background: rgba(255, 255, 255, 0.5);
}

.progress-matrix-header .view-toggle-btn.active {
    background: #ffffff;
    color: #1e293b;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.progress-matrix-header .header-divider {
    width: 1px;
    height: 24px;
    background: #e2e8f0;
    margin: 0 4px;
}

/* Filter dropdown */
.filter-select-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-select-wrapper label {
    font-size: 12px;
    color: #666;
}

#saved-filters-select {
    padding: 6px 10px;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    font-size: 12px;
    min-width: 150px;
    cursor: pointer;
}

#saved-filters-select:focus {
    border-color: #1890ff;
    outline: none;
}

.progress-matrix-header .delete-filter-btn:hover {
    background: #fff1f0 !important;
    border-color: #ff4d4f !important;
    color: #ff4d4f !important;
}

.progress-matrix-header .delete-filter-btn:disabled {
    background: transparent !important;
    color: #d9d9d9 !important;
    border-color: #e8e8e8 !important;
    cursor: not-allowed !important;
}

/* Save filter modal */
.save-filter-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.save-filter-modal-content {
    background: white;
    padding: 20px;
    border-radius: 8px;
    width: 400px;
    max-width: 90%;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.save-filter-modal h3 {
    margin: 0 0 15px 0;
    font-size: 16px;
    color: #333;
}

.save-filter-modal .form-group {
    margin-bottom: 15px;
}

.save-filter-modal label {
    display: block;
    margin-bottom: 5px;
    font-size: 13px;
    color: #666;
}

.save-filter-modal input,
.save-filter-modal textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    font-size: 13px;
    box-sizing: border-box;
}

.save-filter-modal input:focus,
.save-filter-modal textarea:focus {
    border-color: #1890ff;
    outline: none;
}

.save-filter-modal .modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.save-filter-modal .cancel-btn {
    padding: 8px 16px;
    background: #f5f5f5;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}

.save-filter-modal .confirm-btn {
    padding: 8px 16px;
    background: #1890ff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}

.save-filter-modal .confirm-btn:hover {
    background: #40a9ff;
}

/* ============================================
   Filter Section - Accordion Style (Option A)
   ============================================ */
.progress-matrix-filter {
    border-bottom: 1px solid #e0e0e0;
}

/* Accordion Toggle Header */
.filter-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: #f8f9fa;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.filter-toggle:hover {
    background: #f0f0f0;
}

.filter-toggle-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.filter-toggle-icon {
    font-size: 10px;
    color: #4a90d9;
    transition: transform 0.2s;
    width: 16px;
}

.filter-toggle.collapsed .filter-toggle-icon {
    transform: rotate(-90deg);
}

.filter-toggle-label {
    font-weight: 600;
    font-size: 13px;
    color: #333;
}

.filter-toggle-summary {
    font-size: 12px;
    color: #888;
}

.filter-toggle-hint {
    font-size: 12px;
    color: #4a90d9;
}

/* Accordion Content */
.filter-content {
    padding: 15px 20px;
    background: #f8f9fa;
    border-top: 1px solid #e8e8e8;
}

.filter-content.hidden {
    display: none;
}

/* Filter Header Row (inside accordion) */
.filter-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.filter-label {
    font-weight: 600;
    color: #333;
    font-size: 13px;
    white-space: nowrap;
}

/* Root-level filter chips in header row */
.filter-chips {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    padding: 5px 12px;
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid #d9d9d9;
    background: white;
    user-select: none;
}

.filter-chip.active {
    background: #1890ff;
    color: white;
    border-color: #1890ff;
}

.filter-chip:hover {
    border-color: #1890ff;
}

.filter-chip input {
    display: none;
}

/* Toolbar divider between chips and actions */
.toolbar-divider {
    width: 1px;
    height: 24px;
    background: #d9d9d9;
    margin: 0 4px;
}

.filter-actions {
    display: flex;
    gap: 8px;
}

.filter-actions button {
    padding: 6px 12px;
    border: 1px solid #d9d9d9;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.filter-actions button:hover {
    background: #f0f0f0;
    border-color: #1890ff;
}

/* WBS Tree Container - increased height by 20% (220px -> 265px) */
.wbs-tree-container {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    max-height: 265px;
    overflow-y: auto;
    padding: 10px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
}

/* Level-0 Group (Expandable Category) */
.wbs-group {
    min-width: 200px;
    max-width: 280px;
    flex: 0 0 auto;
}

.wbs-group-header {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 4px 4px 0 0;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

/* Light green highlight when group has selected items */
.wbs-group-header.has-selection {
    background: #f6ffed;
    border-color: #b7eb8f;
}

.wbs-group-header:hover {
    background: #f0f0f0;
}

.wbs-group-header.has-selection:hover {
    background: #d9f7be;
}

.wbs-group-header.collapsed {
    border-radius: 4px;
}

.wbs-group-chevron {
    margin-right: 8px;
    font-size: 10px;
    color: #666;
    transition: transform 0.2s;
}

.wbs-group-header.collapsed .wbs-group-chevron {
    transform: rotate(-90deg);
}

.wbs-group-name {
    font-weight: 600;
    color: #333;
    font-size: 13px;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wbs-group-checkbox {
    margin-left: 8px;
    cursor: pointer;
}

/* Selection count badge - minimal design */
.selected-count {
    background: #52c41a;
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 8px;
    white-space: nowrap;
}

.selected-count.none {
    background: #d9d9d9;
    color: #999;
}

.selected-count.partial {
    background: #95de64;
}

/* Level-1 Items (Selectable Children) */
.wbs-items {
    border: 1px solid #e0e0e0;
    border-top: none;
    border-radius: 0 0 4px 4px;
    background: #fafafa;
    max-height: 150px;
    overflow-y: auto;
}

.wbs-items.hidden {
    display: none;
}

.wbs-item {
    display: flex;
    align-items: center;
    padding: 6px 10px 6px 24px;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid #f0f0f0;
}

.wbs-item:last-child {
    border-bottom: none;
}

.wbs-item:hover {
    background: #e6f7ff;
}

.wbs-item input {
    margin-right: 8px;
    cursor: pointer;
}

.wbs-item-name {
    font-size: 12px;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Selected items - no special highlighting, just standard look */
.wbs-item.checked {
    background: transparent;
}

.wbs-item.checked .wbs-item-name {
    color: #333;
    font-weight: 400;
}

/* No roots selected message */
.no-roots-message {
    padding: 20px;
    text-align: center;
    color: #888;
    font-size: 13px;
    background: #f9f9f9;
    border: 1px dashed #d9d9d9;
    border-radius: 4px;
    margin-bottom: 10px;
}

/* Table Container - horizontal scroll with mouse wheel */
/* No padding/margin to prevent header gaps when scrolling */
.progress-matrix-table-container {
    flex: 1;
    overflow: auto;
    padding: 0;
    margin: 0;
    background: #fff;
    position: relative;
    /* Enable horizontal scroll with shift+wheel or trackpad */
}

/* Table - EXPLICIT display properties to override any global CSS conflicts */
/* Fixed column widths - table will NOT auto-expand to fill screen */
/* DESIGN: Option B - Modern Blue Header */
.progress-matrix-table {
    display: table !important;
    border-collapse: collapse;
    width: auto !important;        /* Don't auto-expand */
    table-layout: fixed !important; /* Fixed column widths */
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    font-size: 15px;
}

.progress-matrix-table thead {
    display: table-header-group !important;
}

.progress-matrix-table tbody {
    display: table-row-group !important;
}

.progress-matrix-table tr {
    display: table-row !important;
}

/* Alternating row colors - white and light blue-gray */
.progress-matrix-table tbody tr:nth-child(odd) {
    background-color: #fff;
}

.progress-matrix-table tbody tr:nth-child(even) {
    background-color: #f8fafc;
}

.progress-matrix-table th,
.progress-matrix-table td {
    display: table-cell !important;
    border: 1px solid #e0e0e0;
    padding: 10px 12px;
    text-align: center;
}

/* Header cells - Modern Blue */
.progress-matrix-table thead th {
    background: #4a90d9;
    color: white;
    font-weight: 500;
    border-color: #3a7bc8;
    position: sticky;
    top: 0;
    z-index: 10;
}

/* Corner cell (Floor header) - MUST stick both horizontally AND vertically */
.corner-cell {
    background: #4a90d9 !important;
    color: white !important;
    font-weight: 600;
    font-size: 16px;
    position: sticky !important;
    left: 0 !important;
    top: 0 !important;
    z-index: 30 !important;  /* Higher than both row headers (5) and column headers (10) */
    border: 1px solid white !important;
    width: 100px !important;
    min-width: 100px !important;
    max-width: 100px !important;
    vertical-align: middle;
    /* Needed for ::after pseudo-element positioning */
    overflow: visible;
}

/* Persistent right border for corner cell using pseudo-element - ALWAYS visible */
.corner-cell::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 1px;
    height: 100%;
    background: white;
    z-index: 31;
    transform: translateX(100%);
}

/* Level-0 Group Headers - Blue (Row 1 of header) */
.group-header {
    background: #4a90d9 !important;
    color: white !important;
    font-size: var(--pm-font-group-header, 13px);
    font-weight: 600;
    border: 1px solid white !important;
    height: var(--pm-group-header-height, 40px);
    position: sticky !important;
    top: 0 !important;
    z-index: 15 !important;
    line-height: 1.2;
    vertical-align: middle;
}

/* Small font class for long text group headers - applied via JS */
.group-header.small-text {
    font-size: 12px;
}

/* Leaf Column Headers - Lighter Blue (Row 2 of header) */
/* Font size controlled by CSS variable, will be reduced via JS for long text */
.leaf-header {
    font-size: var(--pm-font-leaf-header, 12px);
    background: #5a9de9 !important;
    color: white !important;
    font-weight: 400;
    width: var(--pm-column-width, 60px) !important;
    min-width: var(--pm-column-width, 60px) !important;
    max-width: var(--pm-column-width, 60px) !important;
    height: var(--pm-leaf-header-height, 28px);
    white-space: normal !important;  /* Allow text wrapping */
    word-wrap: break-word;
    word-break: break-word;
    line-height: 1.25;
    vertical-align: middle;
    border: 1px solid white !important;
    position: sticky !important;
    z-index: 14 !important;
    padding: 4px 6px !important;
}

/* Small font class for long text headers - applied via JS */
.leaf-header.small-text {
    font-size: 10px;
    line-height: 1.2;
}

/* Row Headers (Floor names) - Width controlled by CSS variable */
/* Background colors are set via tr:nth-child selectors below to match row striping */
/* Font size uses cell value for consistency with data cells */
.row-header {
    font-weight: 600;
    font-size: var(--pm-font-cell-value, 11px);
    text-align: left !important;
    position: sticky;
    left: 0;
    z-index: 5;
    width: var(--pm-corner-cell-width, 100px) !important;
    min-width: var(--pm-corner-cell-width, 100px) !important;
    max-width: var(--pm-corner-cell-width, 100px) !important;
    height: var(--pm-row-height, 32px);
    color: #333;
    border: 1px solid #e0e0e0 !important;
    /* Needed for ::after pseudo-element positioning */
    overflow: visible;
}

/* Persistent right border for row header using pseudo-element - ALWAYS visible */
.row-header::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 1px;
    height: 100%;
    background: #e0e0e0;
    z-index: 6;
    transform: translateX(100%);
}

/* Row header alternating colors - must match tbody row colors */
.progress-matrix-table tbody tr:nth-child(odd) .row-header {
    background-color: #fff !important;
}

.progress-matrix-table tbody tr:nth-child(even) .row-header {
    background-color: #f8fafc !important;
}

/* Progress cell base - Width controlled by CSS variable */
/* Gradient fill is applied via inline style in JS */
.progress-cell {
    font-weight: 500;
    font-size: var(--pm-font-cell-value, 11px);
    width: var(--pm-column-width, 60px) !important;
    min-width: var(--pm-column-width, 60px) !important;
    max-width: var(--pm-column-width, 60px) !important;
    height: var(--pm-row-height, 32px);
    color: #333;
    /* Default white background - gradient overrides this via inline style */
    background: white;
}

/* N/A and 0% cells inherit zebra pattern from row */
/* Odd rows = white, Even rows = #f8fafc */
.progress-matrix-table tbody tr:nth-child(odd) .progress-cell.na,
.progress-matrix-table tbody tr:nth-child(odd) .progress-cell.progress-0 {
    background: #ffffff !important;
}

.progress-matrix-table tbody tr:nth-child(even) .progress-cell.na,
.progress-matrix-table tbody tr:nth-child(even) .progress-cell.progress-0 {
    background: #f8fafc !important;
}

/* N/A cells - gray text */
.progress-cell.na {
    color: #ccc;
    font-style: italic;
}

/* 0% cells - darker gray text */
.progress-cell.progress-0 {
    color: #999;
}

/* Loading and error states */
.loading, .no-data, .error {
    padding: 40px;
    text-align: center;
    color: #666;
    font-size: 14px;
}

.loading {
    color: #1890ff;
}

.error {
    color: #cf1322;
    background: #fff1f0;
    border: 1px solid #ffa39e;
    border-radius: 4px;
    margin: 20px;
}

.no-data {
    color: #888;
    background: #fafafa;
    border: 1px dashed #d9d9d9;
    border-radius: 4px;
    margin: 20px;
}

/* Scrollbar styling - DOUBLED thickness for better visibility */
.progress-matrix-table-container::-webkit-scrollbar {
    width: 16px; /* DOUBLED from 8px */
    height: 16px; /* DOUBLED from 8px */
}

.progress-matrix-table-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.progress-matrix-table-container::-webkit-scrollbar-thumb {
    background: #888888; /* Darker for better visibility */
    border-radius: 4px;
    border: 2px solid #f1f1f1;
}

.progress-matrix-table-container::-webkit-scrollbar-thumb:hover {
    background: #555555;
}

.progress-matrix-table-container::-webkit-scrollbar-thumb:active {
    background: #333333;
}

.progress-matrix-table-container::-webkit-scrollbar-corner {
    background: #f1f1f1;
}

/* Firefox scrollbar styling */
.progress-matrix-table-container {
    scrollbar-width: auto; /* Thicker scrollbar in Firefox */
    scrollbar-color: #888888 #f1f1f1;
}

/* Hover effects on table - border highlight (Option D) */
/* Row hover: highlight floor column + border outline around entire row */
.progress-matrix-table tbody tr:hover {
    outline: 2px solid #3b82f6;
    outline-offset: -1px;
}

.progress-matrix-table tbody tr:hover .row-header {
    background-color: #bae6fd !important;
}

/* Individual cell hover - subtle border */
.progress-matrix-table tbody td:hover {
    outline: 2px solid #3b82f6;
    outline-offset: -1px;
}

/* ============================================
   PHASE 4: Yellow Triangle Note Indicator
   Reference: tests/progress-matrix-notes-designs.html Section 1 Option 1
   ============================================ */

.progress-matrix-cell.has-note {
    position: relative;
}

.progress-matrix-cell.has-note::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 14px 14px 0;
    border-color: transparent #f59e0b transparent transparent;
    pointer-events: none;
}
