/* =========================================================================
   ZYANTIK PORTFOLIO COST MANAGEMENT - STYLES
   Custom styles for portfolio application
   Extends base style.css with portfolio-specific components
   ========================================================================= */

/* Portfolio Upload Section */
.portfolio-upload-section {
    min-height: 60vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
}

.upload-card {
    background: white;
    border: 2px dashed var(--border-strong);
    border-radius: 12px;
    padding: 3rem;
    text-align: center;
    max-width: 600px;
    width: 100%;
    transition: all 0.3s ease;
}

.upload-card:hover {
    border-color: var(--brand);
    box-shadow: 0 4px 12px rgba(13, 148, 136, 0.1);
}

.upload-card h2 {
    margin: 0 0 0.5rem 0;
    color: var(--text-primary);
    font-size: 1.5rem;
}

.upload-card p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.btn-large {
    padding: 0.875rem 2rem;
    font-size: 1rem;
    font-weight: 600;
}

.upload-status {
    margin-top: 1.5rem;
    padding: 1rem;
    border-radius: 8px;
    display: none;
}

.upload-status.success {
    background-color: var(--success-bg);
    color: var(--success);
    border: 1px solid var(--success-border);
}

.upload-status.error {
    background-color: var(--danger-bg);
    color: var(--danger);
    border: 1px solid var(--danger-border);
    white-space: pre-wrap;
}

.upload-status.info {
    background-color: var(--info-bg);
    color: var(--info);
    border: 1px solid var(--info-border);
}

/* Portfolio Dashboard */
.portfolio-dashboard {
    padding: 0;
}

/* Summary Cards Grid */
.summary-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.summary-card {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.summary-card-icon {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.summary-card-content {
    flex: 1;
}

.summary-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.summary-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Dashboard Sections */
.dashboard-section {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.dashboard-section h3 {
    margin: 0 0 1.5rem 0;
    color: var(--text-primary);
    font-size: 1.125rem;
    font-weight: 600;
}

/* Chart Containers */
.chart-container {
    min-height: 300px;
}

/* Horizontal Bar Chart */
.horizontal-bar-chart {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.bar-row {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.bar-label {
    min-width: 200px;
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.bar-container {
    flex: 1;
    height: 32px;
    background-color: var(--bg-subtle);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 0.5rem;
    transition: width 0.3s ease;
}

.bar-value {
    color: white;
    font-weight: 600;
    font-size: 0.875rem;
    white-space: nowrap;
}

/* ==========================================================================
   Timeline Chart — stacked columns, one series per project

   The plot area and the x-axis are separate rows on purpose. They used to be
   one column per month containing both the bar and its label; because the
   labels are vertical text their height varies with the month name, and the
   columns were bottom-aligned, so every month's baseline sat at a slightly
   different height. Splitting them means the baseline is the bottom of a
   fixed-height plot and cannot move.

   Gridlines and their tick labels are positioned by value inside that same
   plot box, so "$0" is the baseline rather than an approximation of it.

   Series colours: validated for CVD separation and >= 3:1 contrast against
   the white card surface. Slot order is the safety mechanism — re-run the
   palette validator before changing it.
   ========================================================================== */
.timeline-chart {
    --tl-plot-height: 240px;
    --tl-gutter: 52px;
    --tl-col-gap: 0.5rem;
    --tl-bar-max: 24px;

    --series-1: #199e70;
    --series-2: #c98500;
    --series-3: #d55181;
    --series-4: #008300;
    --series-5: #4a3aa7;
    --series-6: #e34948;
    --series-7: #2a78d6;
    --series-8: #eb6834;
    --series-other: var(--zinc-500);
}

.tl-plot {
    position: relative;
    height: var(--tl-plot-height);
    margin-left: var(--tl-gutter);
}

/* Gridlines ------------------------------------------------------------- */
.tl-gridlines {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.tl-gridline {
    position: absolute;
    left: 0;
    right: 0;
    border-top: 1px solid var(--border);
}

/* The zero line is the baseline the bars sit on, so it reads a step stronger */
.tl-gridline:first-child {
    border-top-color: var(--border-strong);
}

.tl-tick {
    position: absolute;
    right: calc(100% + 8px);
    transform: translateY(-50%);
    font-size: var(--text-xs);
    color: var(--text-muted);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* Bars ------------------------------------------------------------------ */
.tl-bars {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: flex-end;
    gap: var(--tl-col-gap);
}

.tl-col {
    flex: 1 1 0;
    min-width: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
}

.tl-stack {
    width: 100%;
    max-width: var(--tl-bar-max);
    display: flex;
    flex-direction: column-reverse;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    overflow: hidden;
    cursor: pointer;
}

.tl-seg {
    width: 100%;
    flex-shrink: 0;
}

/* A 2px band of the card surface separates touching segments. It is drawn as
   a border so that box-sizing keeps each segment's height exactly proportional
   to its value — the gap insets the fill, it does not displace the stack. */
.tl-seg:not(:first-child) {
    border-bottom: 2px solid var(--bg-surface);
}

.tl-peak {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-1);
    white-space: nowrap;
}

/* X axis ---------------------------------------------------------------- */
.tl-xaxis {
    display: flex;
    gap: var(--tl-col-gap);
    margin-left: var(--tl-gutter);
    padding-top: var(--space-2);
}

.tl-xlabel {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    justify-content: center;
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.tl-xlabel span {
    white-space: nowrap;
}

/* Legend ---------------------------------------------------------------- */
.tl-legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-4);
    margin-top: var(--space-4);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border);
}

.tl-legend-item {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}

.tl-swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}

.tl-legend-label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

/* Projects List */
.projects-list {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.project-card {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: box-shadow 0.2s ease;
}

.project-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.project-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.project-name {
    margin: 0 0 0.25rem 0;
    color: var(--text-primary);
    font-size: 1.25rem;
    font-weight: 600;
}

.project-file-name {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.project-card-details {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.detail-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.detail-value {
    color: var(--text-primary);
    font-weight: 500;
}

.cost-value {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--success);
}

.project-card-breakdown {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.breakdown-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.breakdown-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.breakdown-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Timeline Table */
.timeline-container,
.comparison-container {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow-x: auto;
}

.timeline-table-scroll,
.comparison-table-scroll {
    overflow-x: auto;
    max-width: 100%;
}

.timeline-table,
.comparison-table {
    min-width: 800px;
}

.timeline-table th,
.comparison-table th {
    white-space: nowrap;
}

.project-list-cell {
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.total-row {
    background-color: var(--bg-subtle);
    font-weight: 600;
}

.total-row td {
    border-top: 2px solid var(--border-strong);
}

/* Comparison Controls */
.comparison-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.comparison-controls label {
    font-weight: 500;
    color: var(--text-primary);
}

.comparison-select {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    background: white;
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
}

.comparison-select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.1);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-muted);
}

.empty-state svg {
    margin-bottom: 1rem;
}

.empty-state p {
    margin: 0;
    font-size: 1rem;
}

/* Alert Container */
.alert-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 400px;
}

.alert {
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: slideIn 0.3s ease;
}

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

.alert-success {
    background-color: var(--success-bg);
    color: var(--success);
    border: 1px solid var(--success-border);
}

.alert-error {
    background-color: var(--danger-bg);
    color: var(--danger);
    border: 1px solid var(--danger-border);
}

.alert-info {
    background-color: var(--info-bg);
    color: var(--info);
    border: 1px solid var(--info-border);
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .summary-cards-grid {
        grid-template-columns: 1fr;
    }

    .bar-label {
        min-width: 120px;
        font-size: 0.75rem;
    }

    /* Narrower tick gutter and a shorter plot; the plot/x-axis split means the
       baseline stays put whatever the labels do */
    .timeline-chart {
        --tl-plot-height: 200px;
        --tl-gutter: 44px;
        --tl-col-gap: 0.25rem;
    }

    .project-card-breakdown {
        grid-template-columns: repeat(2, 1fr);
    }

    .comparison-controls {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 480px) {
    .upload-card {
        padding: 2rem 1.5rem;
    }

    .summary-value {
        font-size: 1.5rem;
    }

    /* Too narrow for a label per column — show every other one rather than let
       them overlap. The columns keep their positions, so bars and the labels
       that remain stay aligned. */
    .tl-xlabel:nth-child(even) span {
        display: none;
    }
}

/* Print Styles */
@media print {
    .portfolio-upload-section,
    .header-controls,
    .tab-navigation,
    .section-actions,
    .btn,
    button {
        display: none !important;
    }

    .portfolio-dashboard {
        display: block !important;
    }

    .project-card,
    .dashboard-section,
    .timeline-container,
    .comparison-container {
        box-shadow: none;
        border: 1px solid var(--border);
        page-break-inside: avoid;
    }
}
