/* ============================================================
   style-14-cost-analytics.css — Cost & Inventory Analytics (FEAT-026)
   Prefix: cost-*
   Supports both light and dark themes.
   ============================================================ */

/* ── Page layout ──────────────────────────────────────────── */
.cost-page {
    padding: 24px;
    min-height: 100vh;
    background: var(--bg-primary, #0e1117);
    color: var(--text-primary, #e8eaf0);
    font-family: 'Inter', 'Segoe UI', sans-serif;
}

.cost-header {
    margin-bottom: 20px;
}

.cost-page-title {
    font-size: 1.6rem;
    font-weight: 700;
    color: #e8eaf0;
    margin: 0;
}

/* ── Tabs ─────────────────────────────────────────────────── */
.cost-tabs-desktop {
    display: block;
    margin-bottom: 0;
}

.cost-tabs-mobile {
    display: none;
    margin-bottom: 16px;
}

.cost-tab-bar {
    border-bottom: 2px solid #2a2f45;
}

.cost-tab {
    background: transparent !important;
    border: none !important;
    color: #adb5bd !important;
    padding: 10px 20px !important;
    font-size: 0.95rem !important;
    cursor: pointer;
    border-bottom: 3px solid transparent !important;
    transition: color 0.2s, border-color 0.2s;
}

.cost-tab:hover {
    color: #e8eaf0 !important;
}

.cost-tab-selected {
    background: transparent !important;
    border: none !important;
    color: #f4a724 !important;
    border-bottom: 3px solid #f4a724 !important;
    font-weight: 600 !important;
}

/* Dash internal tab overrides */
.cost-tab-bar .tab.tab--selected {
    background: transparent !important;
    border-top: none !important;
    border-left: none !important;
    border-right: none !important;
    border-bottom: 3px solid #f4a724 !important;
    color: #f4a724 !important;
    font-weight: 600 !important;
}

.cost-tab-bar .tab {
    background: transparent !important;
    border: none !important;
    border-bottom: 3px solid transparent !important;
    color: #adb5bd !important;
}

.cost-tab-bar .tab:hover {
    color: #e8eaf0 !important;
}

.cost-tab-content {
    padding-top: 20px;
}

.cost-loading-placeholder {
    color: #adb5bd;
    padding: 40px;
    text-align: center;
}

/* ── Filter bar ───────────────────────────────────────────── */
.cost-filter-bar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 24px;
    padding: 16px;
    background: #1e2130;
    border-radius: 8px;
}

.cost-filter-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}

.cost-filter-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.cost-shortcut-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.cost-sh-btn {
    background: #2a2f45;
    color: #adb5bd;
    border: 1px solid #3a3f55;
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.cost-sh-btn:hover {
    background: #3a3f55;
    color: #e8eaf0;
}

.cost-sh-active {
    background: #e8734a;
    color: #fff;
    border-color: #e8734a;
}

.cost-period-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.cost-period-label {
    font-size: 0.88rem;
    color: #adb5bd;
    white-space: nowrap;
}

.cost-date-picker .DateRangePickerInput {
    background: #0e1117;
    border: 1px solid #2a2f45;
    border-radius: 6px;
}

/* ── Diesel rate label ────────────────────────────────────── */
.cost-diesel-rate-label {
    font-size: 0.82rem;
    color: #adb5bd;
}

.cost-rate-missing {
    font-weight: 600;
}

/* ── Export button ────────────────────────────────────────── */
.cost-export-btn {
    background: #2a2f45;
    color: #e8eaf0;
    border: 1px solid #3a3f55;
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 0.88rem;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.cost-export-btn:hover {
    background: #3a3f55;
}

/* ── KPI cards ────────────────────────────────────────────── */
.cost-kpi-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.cost-kpi-card {
    flex: 1;
    min-width: 160px;
    background: #1e2130;
    border-radius: 8px;
    padding: 18px 20px;
    border: 1px solid #2a2f45;
}

.cost-kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #e8734a;
    margin-bottom: 4px;
    font-variant-numeric: tabular-nums;
}

.cost-kpi-label {
    font-size: 0.80rem;
    color: #adb5bd;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.cost-kpi-sub {
    font-size: 0.78rem;
    color: #666e82;
    margin-top: 2px;
}

/* ── Chart ────────────────────────────────────────────────── */
.cost-chart-wrap {
    background: #1e2130;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 24px;
    border: 1px solid #2a2f45;
}

.cost-chart-title {
    font-size: 0.92rem;
    font-weight: 600;
    color: #e8eaf0;
    margin-bottom: 12px;
}

.cost-trend-chart {
    width: 100%;
}

/* ── Tables ───────────────────────────────────────────────── */
.cost-table-section {
    margin-bottom: 28px;
}

.cost-table-heading {
    font-size: 0.92rem;
    font-weight: 600;
    color: #e8eaf0;
    margin-bottom: 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid #2a2f45;
}

.cost-data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.cost-data-table thead tr {
    background: #2a2f45;
}

.cost-data-table th {
    padding: 10px 14px;
    text-align: left;
    color: #adb5bd;
    font-weight: 600;
    font-size: 0.80rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.cost-data-table td {
    padding: 9px 14px;
    color: #e8eaf0;
    border-bottom: 1px solid #1e2130;
    font-variant-numeric: tabular-nums;
}

.cost-data-table tbody tr:nth-child(odd) {
    background: #1e2130;
}

.cost-data-table tbody tr:nth-child(even) {
    background: #181c2c;
}

.cost-data-table tbody tr:hover {
    background: #2a2f45;
}

/* Parts catalog specific — fixed column widths */
.cost-parts-catalog-table th:first-child,
.cost-parts-catalog-table td:first-child {
    min-width: 100px;
    white-space: nowrap;
}

.cost-parts-catalog-table th:nth-child(2),
.cost-parts-catalog-table td:nth-child(2),
.cost-parts-catalog-table th:nth-child(3),
.cost-parts-catalog-table td:nth-child(3) {
    min-width: 160px;
}

.cost-parts-catalog-table th:last-child,
.cost-parts-catalog-table td:last-child {
    min-width: 80px;
    white-space: nowrap;
}

/* ── Tyre filters row ─────────────────────────────────────── */
.cost-tyre-filters-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.cost-bus-search-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #0e1117;
    border: 1px solid #2a2f45;
    border-radius: 6px;
    padding: 0 10px;
    min-width: 200px;
}

.cost-search-icon {
    font-size: 0.9rem;
    color: #adb5bd;
}

.cost-bus-search {
    background: transparent;
    border: none;
    outline: none;
    color: #e8eaf0;
    font-size: 0.88rem;
    padding: 7px 0;
    width: 100%;
}

.cost-bus-search::placeholder {
    color: #555e72;
}

.cost-branch-dropdown {
    min-width: 160px;
}

/* ── Parts catalog filter bar ─────────────────────────────── */
.cost-parts-filter-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    padding: 14px;
    background: #1e2130;
    border-radius: 8px;
}

.cost-parts-search-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    background: #0e1117;
    border: 1px solid #2a2f45;
    border-radius: 6px;
    padding: 0 12px;
    min-width: 240px;
}

.cost-parts-search {
    background: transparent;
    border: none;
    outline: none;
    color: #e8eaf0;
    font-size: 0.88rem;
    padding: 8px 0;
    width: 100%;
}

.cost-parts-search::placeholder {
    color: #555e72;
}

.cost-charge-code-dropdown {
    min-width: 180px;
}

/* ── Parts pagination ─────────────────────────────────────── */
.cost-parts-table-wrap {
    overflow-x: auto;
    margin-bottom: 12px;
}

.cost-parts-pagination-info {
    font-size: 0.82rem;
    color: #adb5bd;
    margin-bottom: 8px;
}

.cost-parts-pagination-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 12px 0;
}

.cost-page-btn {
    background: #2a2f45;
    color: #e8eaf0;
    border: 1px solid #3a3f55;
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 0.88rem;
    cursor: pointer;
    min-height: 44px;
    min-width: 80px;
    transition: background 0.2s;
}

.cost-page-btn:hover:not(:disabled) {
    background: #3a3f55;
}

.cost-page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.cost-page-info {
    font-size: 0.88rem;
    color: #adb5bd;
    min-width: 120px;
    text-align: center;
}

/* ── Empty / error states ─────────────────────────────────── */
.cost-empty-state {
    text-align: center;
    padding: 48px 20px;
    color: #adb5bd;
}

.cost-empty-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
    opacity: 0.6;
}

.cost-empty-msg {
    font-size: 1rem;
    margin-bottom: 6px;
    color: #adb5bd;
}

.cost-empty-sub {
    font-size: 0.82rem;
    color: #555e72;
}

.cost-error-banner {
    background: rgba(232, 115, 74, 0.12);
    border: 1px solid #e8734a;
    border-radius: 6px;
    padding: 12px 16px;
    color: #e8734a;
    font-size: 0.9rem;
    margin-bottom: 16px;
}

.cost-parts-empty {
    text-align: center;
    padding: 40px 20px;
}

/* ── Horizontal scroll for mobile tables ──────────────────── */
.cost-data-table-wrap {
    overflow-x: auto;
}

/* ── Light theme overrides ────────────────────────────────── */
body[data-theme="light"] .cost-page {
    background: #f8f9fa;
    color: #212529;
}

body[data-theme="light"] .cost-page-title {
    color: #212529;
}

body[data-theme="light"] .cost-filter-bar {
    background: #fff;
    border: 1px solid #dee2e6;
}

body[data-theme="light"] .cost-sh-btn {
    background: #e9ecef;
    color: #495057;
    border-color: #dee2e6;
}

body[data-theme="light"] .cost-sh-btn:hover {
    background: #dee2e6;
    color: #212529;
}

body[data-theme="light"] .cost-kpi-card {
    background: #fff;
    border-color: #dee2e6;
}

body[data-theme="light"] .cost-kpi-label {
    color: #6c757d;
}

body[data-theme="light"] .cost-kpi-sub {
    color: #868e96;
}

body[data-theme="light"] .cost-chart-wrap {
    background: #fff;
    border-color: #dee2e6;
}

body[data-theme="light"] .cost-chart-title {
    color: #212529;
}

body[data-theme="light"] .cost-table-heading {
    color: #212529;
    border-color: #dee2e6;
}

body[data-theme="light"] .cost-data-table th {
    color: #495057;
    background: #e9ecef;
}

body[data-theme="light"] .cost-data-table td {
    color: #212529;
    border-color: #dee2e6;
}

body[data-theme="light"] .cost-data-table tbody tr:nth-child(odd) {
    background: #f8f9fa;
}

body[data-theme="light"] .cost-data-table tbody tr:nth-child(even) {
    background: #fff;
}

body[data-theme="light"] .cost-data-table tbody tr:hover {
    background: #e9ecef;
}

body[data-theme="light"] .cost-parts-filter-bar {
    background: #fff;
    border: 1px solid #dee2e6;
}

body[data-theme="light"] .cost-parts-search-wrap {
    background: #f8f9fa;
    border-color: #dee2e6;
}

body[data-theme="light"] .cost-parts-search {
    color: #212529;
}

body[data-theme="light"] .cost-bus-search-wrap {
    background: #f8f9fa;
    border-color: #dee2e6;
}

body[data-theme="light"] .cost-bus-search {
    color: #212529;
}

body[data-theme="light"] .cost-export-btn {
    background: #e9ecef;
    color: #212529;
    border-color: #dee2e6;
}

body[data-theme="light"] .cost-export-btn:hover {
    background: #dee2e6;
}

body[data-theme="light"] .cost-page-btn {
    background: #e9ecef;
    color: #212529;
    border-color: #dee2e6;
}

body[data-theme="light"] .cost-page-btn:hover:not(:disabled) {
    background: #dee2e6;
}

body[data-theme="light"] .cost-diesel-rate-label {
    color: #495057;
}

body[data-theme="light"] .cost-period-label {
    color: #495057;
}

body[data-theme="light"] .cost-empty-state {
    color: #6c757d;
}

body[data-theme="light"] .cost-empty-msg {
    color: #6c757d;
}

body[data-theme="light"] .cost-error-banner {
    background: rgba(232, 115, 74, 0.08);
}

body[data-theme="light"] .cost-tyre-detail-panel-inner {
    background: #fff;
    border-color: #dee2e6;
}
body[data-theme="light"] .cost-detail-title {
    color: #212529;
}
body[data-theme="light"] .cost-detail-table th {
    color: #495057;
    border-bottom-color: #dee2e6;
}
body[data-theme="light"] .cost-detail-table td {
    color: #212529;
    border-bottom-color: #dee2e6;
}
body[data-theme="light"] .cost-detail-total-row td {
    border-top-color: #dee2e6;
}
body[data-theme="light"] .cost-detail-close-btn {
    color: #6c757d;
}
body[data-theme="light"] .cost-detail-close-btn:hover {
    background: #e9ecef;
    color: #212529;
}

/* ── Mobile responsive ────────────────────────────────────── */
@media (max-width: 768px) {
    .cost-tabs-desktop {
        display: none;
    }

    .cost-tabs-mobile {
        display: block;
    }

    .cost-kpi-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .cost-kpi-card {
        min-width: 0;
    }

    .cost-filter-bar {
        flex-direction: column;
        gap: 12px;
    }

    .cost-filter-right {
        align-items: stretch;
        width: 100%;
    }

    .cost-export-btn {
        width: 100%;
    }

    .cost-tyre-filters-row {
        flex-direction: column;
    }

    .cost-bus-search-wrap {
        width: 100%;
        min-width: 0;
    }

    .cost-branch-dropdown {
        min-width: 0;
        width: 100%;
    }

    .cost-parts-filter-bar {
        flex-direction: column;
    }

    .cost-charge-code-dropdown {
        min-width: 0;
        width: 100%;
    }

    .cost-data-table {
        min-width: 480px;
    }

    .cost-parts-catalog-table {
        min-width: 560px;
    }
}

/* ─── FEAT-027: Tyre Cost Transaction Detail Panel ───────────────────────── */

.cost-tyre-tx-link {
    cursor: pointer;
    color: var(--accent-blue, #4a9eff);
    text-decoration: underline;
    font-weight: 500;
}
.cost-tyre-tx-link:hover {
    color: #2d7dd6;
}

.cost-tyre-detail-panel {
    margin-top: 12px;
}

.cost-tyre-detail-panel-inner {
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 16px;
    background: var(--card-bg, rgba(255, 255, 255, 0.04));
}

.cost-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.cost-detail-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary, #e8eaf0);
}
.cost-detail-close-btn {
    background: none;
    border: none;
    color: var(--text-secondary, #9ea3b0);
    cursor: pointer;
    font-size: 1rem;
    padding: 2px 6px;
    border-radius: 4px;
    line-height: 1;
}
.cost-detail-close-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary, #e8eaf0);
}

.cost-detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}
.cost-detail-table th {
    text-align: left;
    padding: 6px 10px;
    color: var(--text-secondary, #9ea3b0);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-weight: 500;
}
.cost-detail-table td {
    padding: 5px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.cost-detail-amount {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.cost-detail-total-row td {
    font-weight: 600;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    border-bottom: none;
    padding-top: 8px;
}
.cost-detail-total-label {
    text-align: right;
    color: var(--text-secondary, #9ea3b0);
}
.cost-detail-total {
    color: var(--accent-blue, #4a9eff);
}
.cost-detail-empty {
    color: var(--text-secondary, #9ea3b0);
    font-size: 0.85rem;
    padding: 12px 0;
}

/* ── BUG-050 v2: Inline tyre expansion row ───────────────────────────────── */
.cost-tyre-expansion-row td.cost-tyre-inline-expansion {
    padding: 0 12px 12px 12px;
    background: var(--card-bg, rgba(255,255,255,0.04));
}
