/* ==========================================================================
   Design System & Variables
   ========================================================================== */
:root {
    /* Color Palette - Slate & Indigo (Premium Dark UI) */
    --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Transition speeds */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);

    --border-radius-sm: 6px;
    --border-radius-md: 12px;
    --border-radius-lg: 20px;
    --border-radius-full: 9999px;
}

/* Dark Theme (Default) */
.dark-theme {
    --bg-app: #090d16;
    --bg-card: #111827;
    --bg-header: #1f2937;
    --bg-table-header: #1e293b;
    --bg-table-row-odd: #111827;
    --bg-table-row-even: #151e2e;
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-inverse: #090d16;

    --border-color: #334155;
    --border-color-light: #1e293b;

    --accent-color: #6366f1; /* Indigo */
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --accent-glow: rgba(99, 102, 241, 0.15);

    --highlight-bg-row: rgba(99, 102, 241, 0.08);
    --highlight-bg-col: rgba(99, 102, 241, 0.08);
    --highlight-bg-intersection: rgba(99, 102, 241, 0.18);
    
    --highlight-bg-cell: #6366f1;
    --search-match-bg: rgba(245, 158, 11, 0.15);
    --search-match-border: #f59e0b;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -2px rgba(0, 0, 0, 0.4);
    
    --scrollbar-track: #0f172a;
    --scrollbar-thumb: #334155;
    --scrollbar-thumb-hover: #475569;
}

/* Light Theme */
.light-theme {
    --bg-app: #f8fafc;
    --bg-card: #ffffff;
    --bg-header: #ffffff;
    --bg-table-header: #f1f5f9;
    --bg-table-row-odd: #ffffff;
    --bg-table-row-even: #f8fafc;
    
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-inverse: #ffffff;

    --border-color: #e2e8f0;
    --border-color-light: #f1f5f9;

    --accent-color: #4f46e5;
    --accent-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    --accent-glow: rgba(79, 70, 229, 0.08);

    --highlight-bg-row: rgba(79, 70, 229, 0.04);
    --highlight-bg-col: rgba(79, 70, 229, 0.04);
    --highlight-bg-intersection: rgba(79, 70, 229, 0.1);
    
    --highlight-bg-cell: #4f46e5;
    --search-match-bg: rgba(217, 119, 6, 0.1);
    --search-match-border: #d97706;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

    --scrollbar-track: #f1f5f9;
    --scrollbar-thumb: #cbd5e1;
    --scrollbar-thumb-hover: #94a3b8;
}

/* ==========================================================================
   Base Elements & Global Styles
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-app);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    transition: background-color var(--transition-normal), color var(--transition-normal);
    line-height: 1.5;
}

/* ==========================================================================
   Layout Structure
   ========================================================================== */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* Header Styles */
.app-header {
    height: 72px;
    background-color: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    box-shadow: var(--shadow-sm);
    z-index: 50;
    flex-shrink: 0;
    transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 42px;
    height: 42px;
    background: var(--accent-gradient);
    border-radius: var(--border-radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.logo-icon i {
    width: 22px;
    height: 22px;
}

.logo-text h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.logo-text .sub-title {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Search Box styling */
.search-box {
    position: relative;
    display: flex;
    align-items: center;
    background-color: var(--bg-app);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    padding: 2px 8px 2px 14px;
    width: 320px;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.search-box:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-icon {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    pointer-events: none;
    margin-right: 8px;
}

.search-box input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-main);
    font-family: var(--font-sans);
    font-size: 14px;
    padding: 8px 0;
    width: 100%;
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.icon-btn {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--border-radius-sm);
    display: none; /* JS will toggle this */
    align-items: center;
    justify-content: center;
    transition: color var(--transition-fast), background var(--transition-fast);
}

.icon-btn:hover {
    color: var(--text-main);
    background-color: rgba(148, 163, 184, 0.1);
}

.icon-btn i {
    width: 16px;
    height: 16px;
}

/* Theme Toggle Button */
.theme-toggle-btn {
    width: 42px;
    height: 42px;
    background-color: var(--bg-app);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-main);
    transition: border-color var(--transition-fast), color var(--transition-fast);
}

.theme-toggle-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.theme-toggle-btn i {
    width: 18px;
    height: 18px;
}

.dark-theme .sun-icon { display: block; }
.dark-theme .moon-icon { display: none; }
.light-theme .sun-icon { display: none; }
.light-theme .moon-icon { display: block; }

/* Main Section */
.app-main {
    display: flex;
    flex: 1;
    overflow: hidden;
    padding: 20px;
    gap: 20px;
    flex-direction: row;
}

/* ==========================================================================
   Left Section: Table Design
   ========================================================================== */
.table-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.table-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

.table-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.card-title-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-title-group i {
    width: 20px;
    height: 20px;
    color: var(--accent-color);
}

.card-title-group h2 {
    font-size: 16px;
    font-weight: 600;
}

.table-legend {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--text-muted);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-color {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    display: inline-block;
}

.legend-color.hover-row { background-color: rgba(99, 102, 241, 0.12); border: 1px solid rgba(99, 102, 241, 0.2); }
.legend-color.hover-col { background-color: rgba(99, 102, 241, 0.12); border: 1px solid rgba(99, 102, 241, 0.2); }
.legend-color.hover-cell { background-color: var(--accent-color); }

/* Table scroll wrapper */
.matrix-table-wrapper {
    overflow: auto;
    flex: 1;
    position: relative;
}

/* Custom Scrollbar Styles */
.matrix-table-wrapper::-webkit-scrollbar,
.sidebar-section::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.matrix-table-wrapper::-webkit-scrollbar-track,
.sidebar-section::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

.matrix-table-wrapper::-webkit-scrollbar-thumb,
.sidebar-section::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: var(--border-radius-full);
}

.matrix-table-wrapper::-webkit-scrollbar-thumb:hover,
.sidebar-section::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

/* ==========================================================================
   Table Styles & Highlight Logic
   ========================================================================== */
.matrix-table-wrapper table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    font-family: var(--font-sans);
}

.matrix-table-wrapper table tr {
    transition: background-color var(--transition-fast);
}

.matrix-table-wrapper table th,
.matrix-table-wrapper table td {
    padding: 10px 14px;
    text-align: center;
    font-size: 13px;
    border-bottom: 1px solid var(--border-color-light);
    border-right: 1px solid var(--border-color-light);
    white-space: nowrap;
    transition: background-color var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
}

.matrix-table-wrapper table th {
    background-color: var(--bg-table-header);
    color: var(--text-muted);
    font-weight: 600;
}

/* Stage index column (first column) */
.matrix-table-wrapper table td:first-child,
.matrix-table-wrapper table th:first-child {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--text-main);
    background-color: var(--bg-table-header);
    position: sticky;
    left: 0;
    z-index: 5;
    border-right: 2px solid var(--border-color);
}

/* Highlight Stage header */
.matrix-table-wrapper table tr:nth-child(2) th:first-child {
    font-family: var(--font-sans);
}

/* Row shading */
.matrix-table-wrapper table tbody tr:nth-child(odd) td:not(:first-child) {
    background-color: var(--bg-table-row-odd);
}

.matrix-table-wrapper table tbody tr:nth-child(even) td:not(:first-child) {
    background-color: var(--bg-table-row-even);
}

/* Numeric alignment for salary cells */
.matrix-table-wrapper table tbody td:not(:first-child) {
    font-family: var(--font-mono);
    cursor: pointer;
    font-weight: 500;
}

.matrix-table-wrapper table tbody td:empty {
    cursor: default;
    background-color: transparent !important;
}

/* Sticky Headers setup */
.matrix-table-wrapper table tr:nth-child(1) th {
    position: sticky;
    top: 0;
    z-index: 10;
    height: 42px;
}

.matrix-table-wrapper table tr:nth-child(2) th {
    position: sticky;
    top: 42px;
    z-index: 10;
    height: 42px;
}

.matrix-table-wrapper table tr:nth-child(3) th {
    position: sticky;
    top: 84px;
    z-index: 10;
    height: 42px;
    border-bottom: 2px solid var(--border-color);
}

/* Sticky headers intersection cells (first cell of row 1, 2, 3) */
.matrix-table-wrapper table tr:nth-child(1) th:first-child {
    top: 0;
    left: 0;
    z-index: 20;
    border-right: 2px solid var(--border-color);
}

.matrix-table-wrapper table tr:nth-child(2) th:first-child {
    top: 42px;
    left: 0;
    z-index: 20;
    border-right: 2px solid var(--border-color);
}

.matrix-table-wrapper table tr:nth-child(3) th:first-child {
    top: 84px;
    left: 0;
    z-index: 20;
    border-right: 2px solid var(--border-color);
    border-bottom: 2px solid var(--border-color);
}

/* Sub headers (pay bands) styles */
.sub-header {
    background-color: var(--bg-header) !important;
    color: var(--text-main) !important;
    border-bottom: 2px solid var(--border-color) !important;
}

.pay-band {
    background-color: var(--bg-table-header) !important;
}

/* --- CROSSHAIR HIGHLIGHTING CLASSES (JS-triggered) --- */

/* Highlight active row */
.matrix-table-wrapper table tr.active-row td:not(:first-child) {
    background-color: var(--highlight-bg-row) !important;
}

/* Highlight active column */
.matrix-table-wrapper table td.active-col {
    background-color: var(--highlight-bg-col) !important;
}

/* Highlight column header cells (levels and grade pay) */
.matrix-table-wrapper table th.active-col-header {
    background-color: var(--highlight-bg-intersection) !important;
    color: var(--accent-color) !important;
}

/* Intersection cell of active row & active col */
.matrix-table-wrapper table tr.active-row td.active-col {
    background-color: var(--highlight-bg-intersection) !important;
}

/* Active hovered cell */
.matrix-table-wrapper table td.active-cell {
    background: var(--accent-gradient) !important;
    color: white !important;
    font-weight: 700 !important;
    transform: scale(1.06);
    box-shadow: 0 4px 14px var(--accent-glow);
    z-index: 4;
    position: relative;
    border-radius: var(--border-radius-sm);
}

/* Search results match class */
.matrix-table-wrapper table td.search-match {
    background-color: var(--search-match-bg) !important;
    outline: 2px solid var(--search-match-border);
    outline-offset: -2px;
    z-index: 3;
    font-weight: 700;
}

/* Selected locked cell */
.matrix-table-wrapper table td.selected-cell {
    background: var(--accent-gradient) !important;
    color: white !important;
    font-weight: 700 !important;
    outline: 2px solid #ffffff;
    outline-offset: -2px;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
    z-index: 4;
}

/* ==========================================================================
   Right Section: Sidebar Panel
   ========================================================================== */
.sidebar-section {
    width: 380px;
    flex-shrink: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.sidebar-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md);
    transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

/* Welcome Card style */
.welcome-card {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.card-icon-header {
    width: 56px;
    height: 56px;
    background-color: var(--accent-glow);
    border-radius: var(--border-radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-color);
    margin-bottom: 20px;
}

.card-icon-header i {
    width: 26px;
    height: 26px;
}

.welcome-card h3 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 12px;
}

.welcome-card p {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 24px;
    line-height: 1.5;
}

.guide-list {
    list-style: none;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
}

.guide-list li {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    font-size: 13px;
    color: var(--text-main);
}

.guide-list li i {
    color: var(--accent-color);
    width: 16px;
    height: 16px;
    margin-top: 2px;
    flex-shrink: 0;
}

.guide-list li span {
    line-height: 1.4;
}

/* Calculator Card style */
.calculator-card {
    display: flex;
    flex-direction: column;
    animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card-header-accent {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.badge {
    background-color: var(--accent-glow);
    color: var(--accent-color);
    padding: 4px 10px;
    border-radius: var(--border-radius-full);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.close-btn {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--border-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    transition: color var(--transition-fast), background var(--transition-fast);
}

.close-btn:hover {
    color: var(--text-main);
    background-color: rgba(148, 163, 184, 0.1);
}

.close-btn i {
    width: 18px;
    height: 18px;
}

.calculator-hero {
    text-align: center;
    padding: 10px 0 24px 0;
    border-bottom: 1px solid var(--border-color);
}

.hero-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    display: block;
}

.hero-val-group {
    display: inline-flex;
    align-items: flex-start;
    gap: 4px;
    color: var(--text-main);
}

.hero-val-group .currency {
    font-size: 20px;
    font-weight: 500;
    margin-top: 4px;
    color: var(--text-muted);
}

.hero-val-group .hero-value {
    font-size: 38px;
    font-weight: 800;
    font-family: var(--font-mono);
    line-height: 1;
}

.hero-subtext {
    font-size: 13px;
    color: var(--accent-color);
    font-weight: 600;
    margin-top: 8px;
    display: block;
}

/* Calculator Breakdown details */
.calculator-details {
    padding-top: 20px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    font-size: 13px;
}

.detail-row.header-detail {
    padding-bottom: 12px;
}

.detail-info {
    display: flex;
    flex-direction: column;
}

.detail-label {
    font-weight: 500;
    color: var(--text-main);
}

.detail-sublabel {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.detail-value {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text-main);
}

.calc-select {
    background-color: var(--bg-app);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 4px 8px;
    font-family: var(--font-sans);
    font-size: 11px;
    outline: none;
    cursor: pointer;
    margin-top: 4px;
    width: fit-content;
    transition: border-color var(--transition-fast);
}

.calc-select:hover,
.calc-select:focus {
    border-color: var(--accent-color);
}

.divider {
    height: 1px;
    background-color: var(--border-color-light);
    margin: 8px 0;
}

.section-header-row {
    padding: 8px 0 4px 0;
}

.section-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Highlight totals rows */
.gross-row, .net-row {
    padding: 14px 0;
}

.gross-row .detail-label,
.net-row .detail-label {
    font-weight: 700;
    font-size: 14px;
}

.gross-row .detail-value {
    color: #10b981; /* Emerald Green */
    font-size: 16px;
    font-weight: 700;
}

.net-row .detail-value {
    font-size: 18px;
    font-weight: 800;
    color: #10b981; /* Emerald Green */
}

/* Dark mode adjustment for green values */
.dark-theme .gross-row .detail-value,
.dark-theme .net-row .detail-value {
    color: #34d399;
}

/* Utilities */
.hidden {
    display: none !important;
}

/* ==========================================================================
   Footer
   ========================================================================== */
.app-footer {
    height: 52px;
    background-color: var(--bg-header);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 24px;
    flex-shrink: 0;
    font-size: 11px;
    color: var(--text-muted);
    transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

.footer-info {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.disclaimer {
    max-width: 60%;
    text-align: right;
    font-style: italic;
}

/* Custom Input Fields for Allowances and Deductions */
.detail-val-input {
    background-color: var(--bg-app);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 6px 8px;
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 600;
    width: 75px;
    text-align: right;
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.detail-val-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.detail-input-container {
    display: flex;
    align-items: center;
    gap: 4px;
    position: relative;
}

.currency-prefix {
    font-family: var(--font-sans);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
}

.percent-container {
    display: flex;
    align-items: center;
    gap: 2px;
}

.percent-suffix {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
}

.select-and-pct {
    display: flex;
    align-items: center;
    gap: 8px;
}

.calc-select-small {
    background-color: var(--bg-app);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 5px 6px;
    font-family: var(--font-sans);
    font-size: 12px;
    outline: none;
    cursor: pointer;
}

.calc-select-small:hover,
.calc-select-small:focus {
    border-color: var(--accent-color);
}

/* Hide spinner arrows for inputs */
.detail-val-input[type=number] {
    -moz-appearance: textfield;
}

.detail-val-input::-webkit-outer-spin-button,
.detail-val-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* ==========================================================================
   Responsive Breakpoints & Adjustments
   ========================================================================== */
@media (max-width: 1024px) {
    .app-main {
        flex-direction: column;
        overflow-y: auto;
    }
    
    body {
        overflow: auto;
    }

    .app-container {
        height: auto;
        min-height: 100vh;
    }

    .table-section {
        height: 600px;
        flex: none;
    }

    .sidebar-section {
        width: 100%;
        flex: none;
    }
}

@media (max-width: 768px) {
    .app-header {
        height: auto;
        flex-direction: column;
        padding: 16px 20px;
        gap: 16px;
    }
    
    .app-main {
        padding: 12px;
        gap: 12px;
    }

    .search-box {
        width: 260px;
    }
    
    .footer-info {
        flex-direction: column;
        gap: 6px;
        text-align: center;
    }
    
    .disclaimer {
        max-width: 100%;
        text-align: center;
    }
    
    .app-footer {
        height: auto;
        padding: 16px;
    }
}
