/* ============================================================
   SPM Tool — Dashboard (Fase 1.5)
   Scopeado con `body.dashboard-v2`. Depende de design-system + components.
   ============================================================ */

body.dashboard-v2 {
    background: var(--color-gray-50);
    color: var(--color-navy-900);
    font-family: var(--font-ui);
    font-size: var(--fs-base);
}

body.dashboard-v2 .main-content {
    background: var(--color-gray-50);
    padding: 24px 32px 80px;
    overflow-y: auto;
}

/* ------------------------------------------------------------
   Page header
   ------------------------------------------------------------ */
body.dashboard-v2 .main-content > .header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    padding: 0 0 20px;
    background: transparent;
    border-bottom: none;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

body.dashboard-v2 .header-title h2 {
    font-size: var(--fs-3xl);
    font-weight: var(--fw-semibold);
    color: var(--color-navy-900);
    letter-spacing: var(--letter-tight);
    margin: 0;
}

body.dashboard-v2 .header-title h2::before {
    content: "OVERVIEW";
    display: block;
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    color: var(--color-gray-700);
    text-transform: uppercase;
    letter-spacing: var(--letter-caps);
    margin-bottom: 4px;
}

body.dashboard-v2 .header-subtitle {
    font-size: var(--fs-base);
    color: var(--color-gray-800);
    margin-top: 4px;
}

body.dashboard-v2 .header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

body.dashboard-v2 .user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-gray-300);
    background: #fff;
    transition: background var(--transition-fast);
}

body.dashboard-v2 .user-profile:hover { background: var(--color-gray-100); }

body.dashboard-v2 .user-profile img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

body.dashboard-v2 .user-profile .name {
    font-size: var(--fs-md);
    font-weight: var(--fw-medium);
    color: var(--color-navy-900);
    display: block;
    line-height: 1.2;
}

body.dashboard-v2 .user-profile .role {
    font-size: var(--fs-xs);
    color: var(--color-gray-800);
    display: block;
    line-height: 1.2;
    margin-top: 2px;
}

/* ------------------------------------------------------------
   Toolbar de filtros
   ------------------------------------------------------------ */
body.dashboard-v2 .toolbar.form-view {
    display: flex;
    gap: 14px;
    align-items: flex-end;
    flex-wrap: wrap;
    padding: 14px 16px;
    background: #fff;
    border: 1px solid var(--color-gray-300);
    border-radius: var(--radius-xl);
    margin-bottom: 16px;
}

body.dashboard-v2 .toolbar .form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1 1 160px;
    min-width: 0;
}

body.dashboard-v2 .toolbar label {
    font-size: var(--fs-caps);
    color: var(--color-gray-700);
    text-transform: uppercase;
    letter-spacing: var(--letter-caps);
    font-weight: var(--fw-medium);
}

body.dashboard-v2 .toolbar .cost-input,
body.dashboard-v2 .toolbar select,
body.dashboard-v2 .toolbar input[type="date"] {
    padding: 7px 10px;
    background: #fff;
    border: 1px solid var(--color-gray-350);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: var(--fs-md);
    color: var(--color-navy-900);
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    width: 100% !important;
    min-width: 0;
}

body.dashboard-v2 .toolbar select {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg width='10' height='6' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238a90a2' stroke-width='1.4' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}

body.dashboard-v2 .toolbar .cost-input:focus,
body.dashboard-v2 .toolbar select:focus,
body.dashboard-v2 .toolbar input[type="date"]:focus {
    border-color: var(--color-navy-700);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-navy-700) 15%, transparent);
}

body.dashboard-v2 .toolbar .btn-secondary,
body.dashboard-v2 .toolbar #clear-date-filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    background: #fff;
    color: var(--color-navy-900);
    border: 1px solid var(--color-gray-350);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: var(--fs-md);
    font-weight: var(--fw-medium);
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast);
}

body.dashboard-v2 .toolbar .btn-secondary:hover,
body.dashboard-v2 .toolbar #clear-date-filter-btn:hover {
    background: var(--color-gray-100);
    border-color: var(--color-gray-400);
}

/* ------------------------------------------------------------
   KPIs (grid de 6)
   ------------------------------------------------------------ */
body.dashboard-v2 .summary-cards {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

body.dashboard-v2 .summary-cards .ds-kpi {
    margin: 0;
}

/* ------------------------------------------------------------
   Rows del dashboard (timeline + cost dist, insights + recent + pending)
   ------------------------------------------------------------ */
body.dashboard-v2 .dashboard-row {
    display: grid;
    gap: 12px;
    margin-bottom: 16px;
}

body.dashboard-v2 .dashboard-row--timeline { grid-template-columns: 2fr 1fr; }
body.dashboard-v2 .dashboard-row--triple   { grid-template-columns: 1fr 1fr 1fr; }

/* ------------------------------------------------------------
   Plans Timeline (SVG)
   ------------------------------------------------------------ */
body.dashboard-v2 .plans-timeline {
    padding: 14px 18px 18px;
}

body.dashboard-v2 .plans-timeline svg {
    width: 100%;
    height: auto;
    display: block;
    font-family: var(--font-ui);
}

body.dashboard-v2 .plans-timeline__axis-label {
    font-size: 9.5px;
    fill: var(--color-gray-700);
}

body.dashboard-v2 .plans-timeline__axis-tick {
    font-size: 9.5px;
    fill: var(--color-gray-700);
    font-family: var(--font-mono);
}

body.dashboard-v2 .plans-timeline__grid { stroke: var(--color-gray-200); }

body.dashboard-v2 .plans-timeline__axis { stroke: var(--color-gray-400); }

body.dashboard-v2 .plans-timeline__legend {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin-top: 8px;
    padding: 0 4px;
}

body.dashboard-v2 .plans-timeline__legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: var(--fs-caps);
    color: var(--color-gray-800);
}

body.dashboard-v2 .plans-timeline__legend-swatch {
    width: 14px;
    height: 2px;
    border-radius: 1px;
}

body.dashboard-v2 .plans-timeline__empty {
    display: grid;
    place-items: center;
    height: 260px;
    color: var(--color-gray-700);
    font-size: var(--fs-md);
}

body.dashboard-v2 .plans-timeline__tooltip {
    position: absolute;
    background: var(--color-navy-900);
    color: #fff;
    padding: 6px 10px;
    border-radius: var(--radius-md);
    font-size: var(--fs-xs);
    pointer-events: none;
    transform: translate(-50%, -110%);
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(13, 18, 32, 0.2);
    z-index: 5;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

body.dashboard-v2 .plans-timeline__tooltip--visible { opacity: 1; }

body.dashboard-v2 .plans-timeline__tooltip-id {
    font-family: var(--font-mono);
    font-weight: var(--fw-semibold);
}

body.dashboard-v2 .plans-timeline__tooltip-meta {
    color: var(--color-gray-500);
    margin-top: 2px;
}

/* ------------------------------------------------------------
   Cost Distribution (lista con barras)
   ------------------------------------------------------------ */
body.dashboard-v2 .cost-distribution__row {
    padding: 10px 0;
    border-bottom: 1px solid var(--color-gray-150);
}

body.dashboard-v2 .cost-distribution__row:last-child { border-bottom: none; }

body.dashboard-v2 .cost-distribution__head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

body.dashboard-v2 .cost-distribution__dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}

body.dashboard-v2 .cost-distribution__label {
    font-size: var(--fs-md);
    font-weight: var(--fw-medium);
    color: var(--color-navy-900);
}

body.dashboard-v2 .cost-distribution__amount {
    margin-left: auto;
    font-family: var(--font-mono);
    font-size: var(--fs-base);
    font-weight: var(--fw-semibold);
    color: var(--color-navy-900);
}

body.dashboard-v2 .cost-distribution__bar {
    height: 6px;
    background: var(--color-gray-200);
    border-radius: 3px;
    overflow: hidden;
}

body.dashboard-v2 .cost-distribution__bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width var(--transition-base);
}

body.dashboard-v2 .cost-distribution__pct {
    font-size: var(--fs-caps);
    color: var(--color-gray-700);
    margin-top: 4px;
}

/* ------------------------------------------------------------
   Compact list (Recent plans, Pending review)
   ------------------------------------------------------------ */
body.dashboard-v2 .compact-list__item {
    display: block;
    padding: 10px 0;
    border-bottom: 1px solid var(--color-gray-150);
    text-decoration: none;
    color: inherit;
    transition: background var(--transition-fast);
}

body.dashboard-v2 .compact-list__item:last-child { border-bottom: none; }

body.dashboard-v2 .compact-list__item:hover {
    background: var(--color-gray-100);
    margin: 0 -8px;
    padding-left: 8px;
    padding-right: 8px;
    border-radius: var(--radius-md);
}

body.dashboard-v2 .compact-list__row {
    display: flex;
    align-items: center;
    gap: 10px;
}

body.dashboard-v2 .compact-list__id {
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    color: var(--color-navy-900);
    font-weight: var(--fw-medium);
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

body.dashboard-v2 .compact-list__amount {
    font-family: var(--font-mono);
    font-size: var(--fs-base);
    font-weight: var(--fw-semibold);
    color: var(--color-navy-900);
    white-space: nowrap;
}

body.dashboard-v2 .compact-list__meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

body.dashboard-v2 .compact-list__meta-right {
    margin-left: auto;
    font-size: var(--fs-caps);
    color: var(--color-gray-700);
}

body.dashboard-v2 .compact-list__empty {
    padding: 30px;
    text-align: center;
    color: var(--color-gray-700);
    font-size: var(--fs-md);
}

/* ------------------------------------------------------------
   Insights
   ------------------------------------------------------------ */
body.dashboard-v2 .insights .ds-alert {
    margin-bottom: 8px;
}

body.dashboard-v2 .insights .ds-alert:last-child { margin-bottom: 0; }

body.dashboard-v2 .insights__empty {
    padding: 30px;
    text-align: center;
    color: var(--color-gray-700);
    font-size: var(--fs-md);
}

/* ------------------------------------------------------------
   List headers (titulos internos)
   ------------------------------------------------------------ */
body.dashboard-v2 .list-header {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
}

body.dashboard-v2 .list-header h3 {
    font-size: var(--fs-base);
    font-weight: var(--fw-semibold);
    color: var(--color-navy-900);
    margin: 0;
}

/* ------------------------------------------------------------
   Tabla Teams breakdown
   ------------------------------------------------------------ */
body.dashboard-v2 .table-wrapper {
    overflow-x: clip;
    border-radius: var(--radius-md);
}

body.dashboard-v2 .history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--fs-md);
}

body.dashboard-v2 .history-table thead th {
    background: var(--color-gray-100);
    font-size: var(--fs-caps);
    color: var(--color-gray-700);
    text-transform: uppercase;
    letter-spacing: var(--letter-caps);
    font-weight: var(--fw-medium);
    text-align: left;
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-gray-300);
    white-space: nowrap;
}

body.dashboard-v2 .history-table thead th.col-cost,
body.dashboard-v2 .history-table thead th.col-numeric { text-align: right; }

body.dashboard-v2 .history-table tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--color-gray-200);
    color: var(--color-navy-900);
    vertical-align: middle;
}

body.dashboard-v2 .history-table tbody tr:last-child td { border-bottom: none; }

body.dashboard-v2 .history-table tbody tr:hover td { background: var(--color-gray-100); }

body.dashboard-v2 .history-table .col-cost,
body.dashboard-v2 .history-table .col-numeric {
    font-family: var(--font-mono);
    text-align: right;
    white-space: nowrap;
}

body.dashboard-v2 .history-table tbody tr.row-total td {
    background: var(--color-navy-800);
    color: #fff;
    font-weight: var(--fw-semibold);
}

body.dashboard-v2 .history-table tbody tr.row-total td:first-child {
    text-transform: uppercase;
    letter-spacing: var(--letter-caps);
    font-size: var(--fs-sm);
}

body.dashboard-v2 .history-table tbody tr.row-total:hover td { background: var(--color-navy-800); }

body.dashboard-v2 .history-table tbody tr.row-total td.col-cost { color: var(--color-gray-500); }
body.dashboard-v2 .history-table tbody tr.row-total td.col-cost:nth-child(3) { color: #fff; }

/* Progress bar debajo del total por equipo */
body.dashboard-v2 .teams-breakdown-table .team-total-cell {
    min-width: 150px;
}

body.dashboard-v2 .teams-breakdown-table .team-total-amount {
    font-family: var(--font-mono);
    font-size: var(--fs-base);
    font-weight: var(--fw-semibold);
    color: var(--color-navy-900);
}

body.dashboard-v2 .teams-breakdown-table .team-total-bar {
    height: 4px;
    background: var(--color-gray-200);
    border-radius: 2px;
    margin-top: 4px;
    overflow: hidden;
}

body.dashboard-v2 .teams-breakdown-table .team-total-bar-fill {
    height: 100%;
    border-radius: 2px;
}

body.dashboard-v2 .teams-breakdown-table .team-total-pct {
    font-size: var(--fs-caps);
    color: var(--color-gray-700);
    margin-top: 3px;
}

/* Celdas en cero, mas sutiles */
body.dashboard-v2 .history-table .col-cost.is-zero { color: var(--color-gray-500); }

/* ------------------------------------------------------------
   Responsivo
   ------------------------------------------------------------ */
@media (max-width: 1280px) {
    body.dashboard-v2 .summary-cards { grid-template-columns: repeat(3, 1fr); }
    body.dashboard-v2 .dashboard-row--timeline { grid-template-columns: 1fr; }
    body.dashboard-v2 .dashboard-row--triple   { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
    body.dashboard-v2 .main-content { padding: 16px; }
    body.dashboard-v2 .summary-cards { grid-template-columns: repeat(2, 1fr); }
    body.dashboard-v2 .dashboard-row--triple { grid-template-columns: 1fr; }
    body.dashboard-v2 .main-content > .header { flex-direction: column; align-items: flex-start; }
    body.dashboard-v2 .header-actions {
        width: 100%;
        align-items: flex-start;
    }

    body.dashboard-v2 .ds-segmented {
        max-width: 100%;
        overflow-x: auto;
    }

    body.dashboard-v2 .table-wrapper {
        overflow: visible;
    }

    body.dashboard-v2 .history-table,
    body.dashboard-v2 .history-table thead,
    body.dashboard-v2 .history-table tbody,
    body.dashboard-v2 .history-table tr,
    body.dashboard-v2 .history-table th,
    body.dashboard-v2 .history-table td {
        display: block;
        width: 100%;
    }

    body.dashboard-v2 .history-table thead {
        display: none;
    }

    body.dashboard-v2 .history-table tbody tr {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px 12px;
        padding: 12px;
        border-bottom: 1px solid var(--color-gray-300);
    }

    body.dashboard-v2 .history-table tbody td {
        padding: 0;
        border-bottom: none;
        min-width: 0;
    }

    body.dashboard-v2 .history-table tbody td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 2px;
        color: var(--color-gray-700);
        font-size: var(--fs-caps);
        font-weight: var(--fw-medium);
        letter-spacing: var(--letter-caps);
        text-transform: uppercase;
    }

    body.dashboard-v2 .history-table .col-cost,
    body.dashboard-v2 .history-table .col-numeric {
        text-align: left;
        white-space: normal;
    }

    body.dashboard-v2 .history-table tbody tr.row-total {
        background: var(--color-navy-800);
    }

    body.dashboard-v2 .history-table tbody tr.row-total td {
        background: transparent;
    }
}

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