/* ===================================
   ATS Pal - Applications View Styles (v2.2)
   Role: Dedicated CSS for /applications.html
   15-Column Table, Modals, Collapsible Filter, Score Coloring, Responsive
   =================================== */

/* --- 1. Filter Engine Panel (Collapsible) --- */
.filter-panel {
    background: var(--color-background);
    border-radius: var(--border-radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    border: 1px solid var(--color-border);
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    margin-bottom: 0;
    padding: 0 20px;
    transition: max-height 0.35s ease, opacity 0.25s ease, padding 0.35s ease, margin 0.35s ease;
}

.filter-panel.filter-panel--open {
    max-height: 1000px;
    /* Increased from 400px to avoid cutting off filter buttons on mobile */
    opacity: 1;
    padding: 20px;
    margin-bottom: 15px;
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    align-items: end;
}

.filter-group {
    display: flex;
    flex-direction: column;
}

.filter-group label {
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--color-text-light);
}

.filter-group input,
.filter-group select {
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 0.9rem;
    color: var(--color-text);
    background-color: var(--color-background-light);
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}

.filter-group input:focus,
.filter-group select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(26, 62, 111, 0.1);
}

.filter-actions {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    justify-content: flex-end;
    grid-column: 1 / -1;
    flex-direction: row;
}

.btn-filter-action {
    padding: 8px 20px !important;
    font-size: 0.85rem !important;
    min-width: auto !important;
    width: auto !important;
}

/* --- 2. Table Toolbar (Filter Toggle + Count + Column Toggle) --- */
.table-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    flex-wrap: wrap;
    gap: 10px;
}

.table-toolbar__info {
    font-size: 0.85rem;
    color: var(--color-text-light);
    font-weight: 500;
}

.toolbar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-background);
    color: var(--color-text);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s;
}

.toolbar-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.toolbar-btn.active {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.column-toggle-wrapper {
    position: relative;
}

.column-toggle-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 4px;
    background: var(--color-background);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    padding: 8px 0;
    min-width: 200px;
    z-index: 100;
}

.column-toggle-dropdown.open {
    display: block;
}

.column-toggle-dropdown label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s;
}

.column-toggle-dropdown label:hover {
    background: var(--color-background-accent);
}

/* --- 3. Table Layout --- */
.table-responsive-wrapper {
    position: relative;
}

/* Floating scroll hint OUTSIDE the table — right edge */
.table-scroll-hint {
    position: absolute;
    right: -18px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    background: var(--color-primary);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 700;
    box-shadow: 0 2px 10px rgba(26, 62, 111, 0.35);
    z-index: 15;
    cursor: pointer;
    animation: scrollBounce 1.5s ease-in-out infinite;
    transition: opacity 0.3s, transform 0.3s;
}

.table-scroll-hint:hover {
    transform: translateY(-50%) scale(1.15);
}

.table-scroll-hint.hidden {
    opacity: 0;
    pointer-events: none;
}

@keyframes scrollBounce {

    0%,
    100% {
        right: -18px;
    }

    50% {
        right: -12px;
    }
}

.table-responsive {
    overflow-x: auto;
    background: var(--color-background);
    border-radius: var(--border-radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    border: 1px solid var(--color-border);
    padding-bottom: 12px;
}

/* --- 3.1. Sticky Right Column (Status) --- */
.applications-table th:last-child,
.applications-table td:last-child {
    position: sticky;
    right: 0;
    z-index: 2;
    background-color: var(--color-background);
    border-left: 1px solid var(--color-border);
    box-shadow: -2px 0 5px rgba(0, 0, 0, 0.04);
}

/* Header corner */
.applications-table th:last-child {
    z-index: 12;
    background-color: var(--color-background-accent);
}

/* Background sync for sticky cells across states */
.applications-table tr.row--unread td:last-child {
    background-color: #ffffff;
}

.applications-table tr.row--has-status td:last-child {
    background-color: #a8c7fa !important;
}

.applications-table tbody tr:hover td:last-child {
    background-color: #f1f4f8; /* Slightly darker than row hover to ensure visibility */
}

/* Column widths with truncation */
.applications-table td.cell-truncate {
    max-width: 0;
    /* force overflow to apply */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Individual FIXED-widths per column */
/* Job Title */
.applications-table td:nth-child(2).cell-truncate {
    width: 250px;
    min-width: 250px;
    max-width: 250px;
}

/* Position */
.applications-table td:nth-child(3).cell-truncate {
    width: 200px;
    min-width: 200px;
    max-width: 200px;
}

/* Company */
.applications-table .cell-salary.cell-truncate {
    width: 200px;
    min-width: 200px;
    max-width: 200px;
}

/* Salary */
.applications-table td[data-label="Location"].cell-truncate {
    width: 200px;
    min-width: 200px;
    max-width: 200px;
}

/* --- New Row Blink: # cell flashes for 10s after real-time add --- */
@keyframes newRowBlink {

    0%,
    100% {
        background: transparent;
    }

    50% {
        background: var(--color-primary-light, rgba(26, 62, 111, 0.15));
    }
}

.cell-rownum.row-new-blink {
    animation: newRowBlink 0.8s ease-in-out infinite;
}

.applications-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1200px;
}

.applications-table th,
.applications-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.85rem;
    white-space: nowrap;
}

.applications-table th {
    background-color: var(--color-background-accent);
    color: var(--color-primary);
    font-weight: 700;
    position: sticky;
    top: 0;
    z-index: 10;
    user-select: none;
    text-align: center;
}

/* Sortable column header */
.applications-table th.sortable {
    cursor: pointer;
}

.applications-table th.sortable:hover {
    background-color: rgba(26, 62, 111, 0.08);
}

.sort-indicator {
    margin-left: 4px;
    font-size: 0.7rem;
    opacity: 0.4;
}

.sort-indicator.active {
    opacity: 1;
}

.applications-table tr {
    transition: background-color 0.2s;
}

.applications-table tbody tr:hover {
    background-color: rgba(237, 241, 247, 0.5);
}

/* --- 4. Row States --- */

/* Unread: no status selected → bold text, white bg */
.row--unread {
    font-weight: 700;
    background-color: #ffffff;
}

.row--unread td {
    color: #000;
}

/* Has status → highlight row */
.row--has-status {
    background-color: #a8c7fa !important;
}

/* --- 5. Status Dropdown --- */
.status-select {
    padding: 5px 8px;
    border-radius: 16px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--color-border);
    background-color: var(--color-background-light);
    outline: none;
    transition: all 0.2s;
    max-width: 180px;
}

.status-select:focus {
    border-color: var(--color-primary);
}

.status-time-stamp {
    font-size: 0.7rem;
    color: var(--color-text-light);
    display: block;
    margin-top: 3px;
    font-weight: 400;
    white-space: nowrap;
}

/* --- 6. Score Badges with Color Coding --- */
.score-cell {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.score-badge {
    display: inline-block;
    padding: 3px 7px;
    border-radius: 10px;
    font-size: 0.78rem;
    font-weight: 700;
}

.score-arrow {
    color: var(--color-text-light);
    font-size: 0.75rem;
}

/* Score color classes */
.score--excellent {
    background-color: #c3e6cb;
    color: #155724;
}

/* ≥90 */
.score--great {
    background-color: #d4edda;
    color: #155724;
}

/* 80-89 */
.score--good {
    background-color: #fff3cd;
    color: #856404;
}

/* 70-79 */
.score--fair {
    background-color: #ffeeba;
    color: #856404;
}

/* 60-69 */
.score--low {
    background-color: #f8d7da;
    color: #721c24;
}

/* ≤59 */

/* --- 7. Action Icons (Resume, Cover Letter) --- */
.action-icon-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    color: var(--color-primary);
    transition: all 0.2s;
    text-decoration: none;
}

.action-icon-link:hover {
    background: rgba(26, 62, 111, 0.1);
    color: #0d2e5c;
}

.action-icon-cover {
    color: #6c757d;
}

.action-icon-cover:hover {
    color: #495057;
    background: rgba(108, 117, 125, 0.1);
}

/* Apply link */
.action-link {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 600;
    font-size: 1rem;
    transition: color 0.2s;
}

.action-link:hover {
    color: #0d2e5c;
    text-decoration: underline;
}

/* View button for description */
.view-desc-btn {
    padding: 3px 10px;
    border: 1px solid var(--color-primary);
    border-radius: 12px;
    background: transparent;
    color: var(--color-primary);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.view-desc-btn:hover {
    background: var(--color-primary);
    color: #fff;
}

/* Center-align specific cells */
.cell-center,
.th-center {
    text-align: center !important;
}

.cell-center .score-cell {
    justify-content: center;
}

/* Row number cell */
.cell-rownum {
    font-weight: 700;
    color: var(--color-text-light);
    font-size: 0.8rem;
    text-align: center !important;
    min-width: 30px;
}

/* Salary display */
.cell-salary {
    min-width: 140px;
}

.salary-line {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.82rem;
    line-height: 1.6;
}

.salary-line svg {
    flex-shrink: 0;
    opacity: 0.6;
}

.salary-market {
    color: var(--color-text-light);
    font-size: 0.78rem;
}

.salary-specific {
    font-weight: 600;
    color: #155724;
}

/* --- 8. Modal --- */
/* Override global style.css modal defaults */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.modal-overlay.active {
    display: flex !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
}

.modal-box {
    background: #fff;
    border-radius: 12px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    animation: modalSlideIn 0.2s ease;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--color-primary);
}

.modal-close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--color-text-light);
    line-height: 1;
    padding: 0 4px;
}

.modal-close-btn:hover {
    color: var(--color-text);
}

.modal-body {
    padding: 20px;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--color-text);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 12px 20px;
    border-top: 1px solid var(--color-border);
}

.modal-footer .btn {
    padding: 8px 20px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.modal-footer .btn-cancel {
    background: #e9ecef;
    color: var(--color-text);
}

.modal-footer .btn-cancel:hover {
    background: #dee2e6;
}

.modal-footer .btn-confirm {
    background: var(--color-primary);
    color: #fff;
}

.modal-footer .btn-confirm:hover {
    background: #0d2e5c;
}

/* --- 9. Pagination Controls --- */
.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 25px;
    gap: 6px;
}

.page-btn {
    min-width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--color-border);
    background: var(--color-background);
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    color: var(--color-text);
    transition: all 0.2s;
    font-size: 0.85rem;
}

.page-btn:hover:not(:disabled) {
    background: var(--color-background-accent);
    color: var(--color-primary);
}

.page-btn.active {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: #f5f5f5;
}

.page-ellipsis {
    color: var(--color-text-light);
    font-weight: 600;
    padding: 0 4px;
}

/* Empty State */
.empty-state-container {
    padding: 60px 20px;
    text-align: center;
    color: var(--color-text-light);
}

.empty-state-icon {
    margin-bottom: 15px;
    opacity: 0.5;
}

/* Hidden column helper */
.col-hidden {
    display: none !important;
}

/* --- 10. Mobile Responsive View (Card Layout) --- */
@media (max-width: 768px) {
    .filter-panel {
        grid-template-columns: 1fr 1fr;
    }

    .filter-actions {
        justify-content: stretch;
    }

    .filter-actions .btn {
        flex: 1;
    }

    /* Transform Table to Cards */
    .applications-table,
    .applications-table tbody,
    .applications-table tr,
    .applications-table th {
        display: block;
        width: 100%;
    }

    .applications-table {
        min-width: unset;
    }

    /* Hide table headers */
    .applications-table thead {
        display: none;
    }

    .applications-table tbody tr {
        margin-bottom: 15px;
        border: 1px solid var(--color-border);
        border-radius: var(--border-radius);
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.03);
        background: var(--color-background);
        position: relative;
    }

    .applications-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: left;
        /* Changed from right to left */
        border-bottom: 1px solid var(--color-border);
        padding: 10px 14px;
        white-space: normal;
    }

    .applications-table td:last-child {
        border-bottom: none;
    }

    /* Hide non-mandatory columns on mobile (toggled cols stay hidden) */
    .applications-table td.col-hidden {
        display: none !important;
    }

    /* Use data-label attribute for mobile labels */
    .applications-table td::before {
        content: attr(data-label);
        font-weight: 700;
        text-transform: uppercase;
        font-size: 0.7rem;
        color: var(--color-text-light);
        margin-right: 12px;
        text-align: left;
        flex-shrink: 0;
    }

    /* Reset fixed widths and truncation for mobile */
    .applications-table td.cell-truncate,
    .applications-table td:nth-child(2).cell-truncate,
    .applications-table td:nth-child(3).cell-truncate,
    .applications-table .cell-salary.cell-truncate,
    .applications-table td[data-label="Location"].cell-truncate {
        width: 100% !important;
        min-width: unset !important;
        max-width: unset !important;
        white-space: normal !important;
        overflow: visible !important;
        text-align: left;
        /* Changed from right to left */
    }

    /* Adjust Unread mark for Card View */
    .row--unread {
        border-top: 3px solid var(--color-primary);
    }

    .row--has-status {
        border-left: 4px solid #a8c7fa;
    }

    /* Column toggle in mobile */
    .column-toggle-dropdown {
        right: 0;
        left: auto;
    }
}

@media (max-width: 480px) {
    .filter-panel {
        grid-template-columns: 1fr;
    }

    .table-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
}