/**
 * table-popover.css
 * Styles for table row detail popovers
 */

:root {
    --popover-bg: rgba(40, 40, 40, 0.97);
    --popover-text: #ffffff;
    --popover-border: rgba(255, 255, 255, 0.15);
    --popover-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    --popover-label-color: rgba(255, 255, 255, 0.7);
    --popover-max-width: 400px;
    --popover-border-radius: 8px;
}

/* Popover container */
.table-popover {
    position: absolute;
    background: var(--popover-bg);
    color: var(--popover-text);
    border: 1px solid var(--popover-border);
    border-radius: var(--popover-border-radius);
    box-shadow: var(--popover-shadow);
    max-width: var(--popover-max-width);
    min-width: 280px;
    padding: 0;
    transition: opacity 0.2s ease-in-out;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.table-popover:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Close button */
.table-popover .popover-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: var(--popover-text);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s ease;
    z-index: 1;
}

.table-popover .popover-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.table-popover .popover-close:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Content area */
.table-popover .popover-content {
    padding: 16px;
    padding-top: 12px;
    max-height: 400px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) rgba(255, 255, 255, 0.1);
}

.table-popover .popover-content::-webkit-scrollbar {
    width: 8px;
}

.table-popover .popover-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.table-popover .popover-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

.table-popover .popover-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.4);
}

/* Field layout */
.table-popover .popover-field {
    margin-bottom: 12px;
}

.table-popover .popover-field:last-child {
    margin-bottom: 0;
}

.table-popover .popover-label {
    font-size: calc(var(--base-font-size) * 0.85);
    color: var(--popover-label-color);
    font-weight: 600;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.table-popover .popover-value {
    font-size: var(--base-font-size);
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Title gets special emphasis */
.table-popover .popover-title {
    font-weight: 500;
    font-size: calc(var(--base-font-size) * 1.05);
    padding-bottom: 8px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--popover-border);
}

/* Info button in table cells */
.title-info-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    background: rgba(33, 150, 243, 0.1);
    color: var(--accent-color);
    border: 1px solid rgba(33, 150, 243, 0.3);
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
    font-family: Georgia, serif;
    cursor: pointer;
    transition: all 0.15s ease;
    outline: none;
    padding: 0;
    line-height: 1;
    margin-right: 6px;
}

.title-info-btn:hover {
    background: rgba(33, 150, 243, 0.2);
    border-color: rgba(33, 150, 243, 0.5);
    transform: scale(1.1);
}

.title-info-btn:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.title-info-btn:active {
    transform: scale(0.95);
}

/* Chevron button in table rows */
.row-chevron {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 18px;
    flex-shrink: 0;
    background: rgba(33, 150, 243, 0.08);
    color: var(--accent-color);
    border: 1px solid rgba(33, 150, 243, 0.3);
    border-radius: 4px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.15s ease;
    outline: none;
    padding: 0;
    line-height: 1;
    margin-left: auto;
}

.row-chevron:hover {
    background: rgba(33, 150, 243, 0.2);
    border-color: rgba(33, 150, 243, 0.5);
    transform: translateX(2px);
}

.row-chevron:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.row-chevron:active {
    transform: translateX(0);
}

/* Chevron cell styling */
.tabulator-cell.cell-chevron {
    padding: 0 6px !important; /* Minimize padding so chevron height does not bump row height */
    text-align: right;
    vertical-align: middle;
}

/* Update title cell to accommodate info button */
.tabulator-cell.cell-title .title-cell {
    display: flex;
    align-items: center;
    gap: 0;
    min-width: 0;
    width: 100%;
}

.tabulator-cell.cell-title .title-action {
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    outline: none;
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .table-popover {
        /* Force popover to fit within viewport with safe margins */
        max-width: calc(100vw - 24px) !important;
        min-width: min(280px, calc(100vw - 24px)) !important;
        width: calc(100vw - 24px); /* Explicit width for better control */
        /* Use box-sizing to include padding in width calculation */
        box-sizing: border-box;
    }
    
    .table-popover .popover-content {
        max-height: 300px;
        /* Ensure content doesn't overflow */
        box-sizing: border-box;
        overflow-x: hidden;
    }
    
    .table-popover .popover-value {
        /* Ensure long words break properly on mobile */
        word-break: break-word;
        overflow-wrap: anywhere;
    }
    
    .title-info-btn {
        width: 24px;
        height: 24px;
        font-size: 13px;
    }
    
    .row-chevron {
        width: 22px;
        height: 18px;
        font-size: 16px;
    }
}

/* Dark theme support (already using dark colors, but ensure consistency) */
@media (prefers-color-scheme: dark) {
    :root {
        --popover-bg: rgba(30, 30, 30, 0.97);
        --popover-text: #ffffff;
        --popover-border: rgba(255, 255, 255, 0.2);
        --popover-label-color: rgba(255, 255, 255, 0.7);
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .table-popover {
        border: 2px solid var(--popover-border);
    }
    
    .title-info-btn,
    .row-chevron {
        border-width: 2px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .table-popover,
    .title-info-btn,
    .row-chevron {
        transition: none;
    }
    
    .title-info-btn:hover,
    .row-chevron:hover {
        transform: none;
    }
}
