/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --color-bg: #f1f5f9;
    --color-white: #ffffff;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-border: #e2e8f0;
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-green: #16a34a;
    --color-green-bg: #f0fdf4;
    --color-amber: #d97706;
    --color-amber-bg: #fffbeb;
    --color-red: #dc2626;
    --color-red-bg: #fef2f2;
    --color-navy: #1e293b;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    min-height: 100vh;
}

/* ===== Top Bar ===== */
.top-bar {
    background: var(--color-navy);
    color: white;
    padding: 0 24px;
    height: 60px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-md);
}

.top-bar-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: white;
}

.logo-img {
    height: 44px;
    width: auto;
    object-fit: contain;
    display: block;
}

.header-title {
    font-size: 22px;
    font-weight: 700;
    color: white;
    margin-left: 16px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 4px;
}

.nav-user {
    color: rgba(255,255,255,0.6);
    font-size: 13px;
    margin-left: 12px;
    padding-right: 4px;
}

.nav-logout {
    font-size: 13px;
}

.nav-link {
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s;
}

.nav-link:hover {
    color: white;
    background: rgba(255,255,255,0.1);
}

.nav-link.active {
    color: white;
    background: rgba(255,255,255,0.15);
}

/* ===== Main Content ===== */
.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

/* ===== Summary Cards ===== */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.card {
    background: var(--color-white);
    border-radius: var(--radius);
    padding: 20px 24px;
    box-shadow: var(--shadow);
    border-left: 4px solid transparent;
}

.card-label {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
    margin-bottom: 8px;
}

.card-value {
    font-size: 32px;
    font-weight: 700;
    line-height: 1.1;
    margin-bottom: 4px;
}

.card-sub {
    font-size: 13px;
    color: var(--color-text-muted);
}

.card-remaining {
    font-size: 20px;
    font-weight: 700;
    color: var(--color-text);
    margin-top: 6px;
    margin-bottom: 2px;
}

.card-alert {
    border-left-color: var(--color-red);
}

.card-alert .card-value {
    color: var(--color-red);
}

.card-alert.card-ok {
    border-left-color: var(--color-green);
}

.card-alert.card-ok .card-value {
    color: var(--color-green);
}

.card-margin {
    border-left-color: var(--color-green);
}

.card-margin .card-value {
    color: var(--color-green);
}

.card-margin.margin-amber {
    border-left-color: var(--color-amber);
}

.card-margin.margin-amber .card-value {
    color: var(--color-amber);
}

.card-margin.margin-red {
    border-left-color: var(--color-red);
}

.card-margin.margin-red .card-value {
    color: var(--color-red);
}

.card-quoted {
    border-left-color: #8b5cf6;
}

.card-quoted .card-value {
    color: #8b5cf6;
}

.card-neutral {
    border-left-color: var(--color-primary);
}

.card-neutral .card-value {
    color: var(--color-primary);
}

/* ===== Portfolio Overview ===== */
.portfolio-section {
    margin-bottom: 24px;
}

.portfolio-panel {
    background: var(--color-white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    border-left: 4px solid var(--color-primary);
}

.portfolio-header {
    font-size: 16px;
    font-weight: 700;
    color: var(--color-text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 16px;
}

/* ===== Filters ===== */
.filters-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.search-input {
    flex: 1;
    min-width: 200px;
    padding: 8px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 14px;
    background: var(--color-white);
    outline: none;
    transition: border-color 0.15s;
}

.search-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.filter-buttons {
    display: flex;
    gap: 4px;
}

.filter-btn {
    padding: 6px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-white);
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

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

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

/* ===== Job Table ===== */
.job-table-section {
    background: var(--color-white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.table-wrapper {
    overflow-x: auto;
}

.job-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.job-table thead {
    background: #f8fafc;
    border-bottom: 2px solid var(--color-border);
}

.job-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}

.job-table th.sortable:hover {
    color: var(--color-primary);
}

.job-table th .sort-arrow {
    margin-left: 4px;
    opacity: 0.4;
}

.job-table th.sort-active .sort-arrow {
    opacity: 1;
    color: var(--color-primary);
}

.job-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

.job-table tbody tr {
    cursor: pointer;
    transition: background 0.1s;
}

.job-table tbody tr:hover {
    background: #f8fafc;
}

.job-table tbody tr.expanded {
    background: #f1f5f9;
}

.job-number {
    font-weight: 600;
    color: var(--color-primary);
    font-size: 13px;
}

.job-name {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Budget Gauge (mini progress bar) */
.gauge-mini {
    display: flex;
    align-items: center;
    gap: 8px;
}

.gauge-bar {
    width: 80px;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.gauge-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s;
}

.gauge-fill.green { background: var(--color-green); }
.gauge-fill.amber { background: var(--color-amber); }
.gauge-fill.red { background: var(--color-red); }

.gauge-text {
    font-size: 12px;
    font-weight: 600;
    min-width: 44px;
}

/* Variance & Margin cells */
.positive { color: var(--color-green); }
.negative { color: var(--color-red); }
.neutral { color: var(--color-text-muted); }

.no-data {
    color: var(--color-text-muted);
    font-style: italic;
    font-size: 12px;
}

.empty-state {
    text-align: center;
    padding: 48px 16px !important;
    color: var(--color-text-muted);
    font-size: 14px;
}

/* ===== Expanded Job Detail ===== */
.job-detail-row td {
    padding: 0 !important;
    border-bottom: 2px solid var(--color-primary);
}

.job-detail {
    padding: 20px 24px;
    background: #f8fafc;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.detail-table th {
    padding: 8px 12px;
    text-align: right;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border);
}

.detail-table th:first-child {
    text-align: left;
}

.detail-table td {
    padding: 8px 12px;
    text-align: right;
    border-bottom: 1px solid #f1f5f9;
}

.detail-table td:first-child {
    text-align: left;
    font-weight: 600;
}

.detail-table tr.total-row {
    border-top: 2px solid var(--color-border);
    font-weight: 700;
}

.detail-table tr.total-row td {
    padding-top: 12px;
    border-bottom: none;
}

.detail-chart-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 220px;
}

/* Large budget gauge */
.gauge-large {
    margin-top: 16px;
}

.gauge-bar-large {
    width: 100%;
    height: 24px;
    background: #e2e8f0;
    border-radius: 12px;
    overflow: visible;
    position: relative;
}

.gauge-fill-large {
    height: 100%;
    border-radius: 12px;
    transition: width 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 12px;
    font-weight: 700;
    min-width: 48px;
}

.gauge-label-large {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    font-size: 12px;
    color: var(--color-text-muted);
}

/* ===== Upload Page ===== */
.upload-page {
    max-width: 900px;
    margin: 0 auto;
}

.page-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}

.page-desc {
    color: var(--color-text-muted);
    margin-bottom: 24px;
}

.upload-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.upload-card {
    background: var(--color-white);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

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

.upload-card-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.upload-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    background: #f1f5f9;
    border-radius: 4px;
    color: var(--color-text-muted);
}

.badge-link {
    text-decoration: none;
    background: #eff6ff;
    color: var(--color-primary);
    cursor: pointer;
    transition: background 0.15s;
}

.badge-link:hover {
    background: #dbeafe;
}

.upload-desc {
    font-size: 13px;
    color: var(--color-text-muted);
    margin-bottom: 16px;
    line-height: 1.6;
}

.file-drop-zone {
    border: 2px dashed var(--color-border);
    border-radius: var(--radius);
    padding: 32px 24px;
    text-align: center;
    transition: all 0.15s;
    position: relative;
    margin-bottom: 12px;
}

.file-drop-zone.drag-over {
    border-color: var(--color-primary);
    background: #eff6ff;
}

.file-drop-zone.has-file {
    border-color: var(--color-green);
    background: var(--color-green-bg);
}

.file-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.drop-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.drop-text {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
}

.drop-or {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-bottom: 8px;
}

.file-name {
    display: none;
    margin-top: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-green);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 18px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    border: none;
    text-decoration: none;
}

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

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

.btn-primary:disabled {
    background: #94a3b8;
    cursor: not-allowed;
}

.btn-outline {
    background: white;
    border: 1px solid var(--color-border);
    color: var(--color-text);
}

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

.btn-upload {
    width: 100%;
    padding: 10px;
}

/* Upload status messages */
.upload-status {
    margin-top: 8px;
}

.status-success {
    padding: 10px 14px;
    background: var(--color-green-bg);
    border: 1px solid #bbf7d0;
    border-radius: var(--radius);
    color: var(--color-green);
    font-size: 13px;
    font-weight: 500;
}

.status-error {
    padding: 10px 14px;
    background: var(--color-red-bg);
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    color: var(--color-red);
    font-size: 13px;
    font-weight: 500;
}

/* ===== Empty Banner ===== */
.empty-banner {
    margin-top: 32px;
}

.empty-banner-inner {
    text-align: center;
    padding: 48px 24px;
    background: var(--color-white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.empty-banner h2 {
    font-size: 20px;
    margin-bottom: 8px;
}

.empty-banner p {
    color: var(--color-text-muted);
    margin-bottom: 16px;
}

/* ===== Responsive ===== */
@media (max-width: 1100px) {
    .summary-cards {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 900px) {
    .summary-cards {
        grid-template-columns: 1fr;
    }

    .upload-grid {
        grid-template-columns: 1fr;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    .job-name {
        max-width: 160px;
    }
}

@media (max-width: 640px) {
    .main-content {
        padding: 16px;
    }

    .top-bar {
        padding: 0 16px;
    }

    .logo-text {
        display: none;
    }

    .card-value {
        font-size: 28px;
    }

    .filters-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .search-input {
        min-width: 0;
    }
}
