/* Maestros · histórico de precios y ahorro estimado */

.mph-panel,
.mph-chart-card,
.mph-ranking-card,
.mph-events-card {
    background: var(--pv-card-surface);
    border: 1px solid var(--pv-card-border);
    border-radius: var(--pv-card-radius);
    box-shadow: var(--pv-elevation);
    backdrop-filter: var(--pv-glass-blur);
    -webkit-backdrop-filter: var(--pv-glass-blur);
}

.mps-panel {
    margin-bottom: 20px;
    padding: 22px;
    font-family: var(--pv-font-ui);
}

.mph-panel-header,
.mph-modal-header,
.mph-card-title-row,
.mph-modal-heading {
    display: flex;
    align-items: center;
}

.mph-panel-header,
.mph-card-title-row {
    justify-content: space-between;
    gap: 18px;
}

.mph-panel-header h3,
.mph-card-title-row h4,
.mph-modal-header h2 {
    margin: 0;
    color: var(--pv-text-primary);
}

.mph-panel-header h3 {
    font-size: var(--pv-text-xl);
}

.mph-panel-header p,
.mph-card-title-row p,
.mph-modal-header p {
    margin: 4px 0 0;
    color: var(--pv-text-secondary);
    font-size: var(--pv-text-sm);
}

.mph-eyebrow {
    margin-bottom: 5px;
    color: var(--pv-accent-cyan);
    font-family: var(--pv-font-mono);
    font-size: var(--pv-text-xs);
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.mps-calculation-form {
    margin-top: 20px;
}

.mps-filter-section {
    min-width: 0;
    margin: 0;
    padding: 16px;
    border: 1px solid var(--pv-card-border);
    border-radius: var(--pv-input-radius);
    background: color-mix(in srgb, var(--pv-card-surface-solid) 84%, transparent);
}

.mps-filter-section--calculation {
    border-color: color-mix(in srgb, var(--pv-accent) 42%, var(--pv-card-border));
    background: color-mix(in srgb, var(--pv-accent) 5%, var(--pv-card-surface-solid));
}

.mps-filter-section--view {
    margin-top: 14px;
}

.mps-filter-legend {
    display: flex;
    max-width: 100%;
    align-items: center;
    gap: 10px;
    padding: 0 9px 0 0;
    color: var(--pv-text-primary);
}

.mps-filter-step {
    display: inline-grid;
    flex: 0 0 28px;
    width: 28px;
    height: 28px;
    place-items: center;
    border: 1px solid color-mix(in srgb, var(--pv-accent) 56%, var(--pv-card-border));
    border-radius: 50%;
    background: color-mix(in srgb, var(--pv-accent) 15%, transparent);
    color: var(--pv-accent-cyan);
    font-family: var(--pv-font-mono);
    font-size: var(--pv-text-xs);
    font-weight: 800;
}

.mps-filter-legend-copy {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 2px;
}

.mps-filter-legend-copy strong {
    color: var(--pv-text-primary);
    font-size: var(--pv-text-sm);
    line-height: 1.3;
}

.mps-filter-legend-copy small {
    color: var(--pv-text-secondary);
    font-size: var(--pv-text-xs);
    font-weight: 500;
    line-height: 1.4;
}

.mps-calculation-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
    align-items: end;
    gap: 12px;
    margin-top: 4px;
}

.mps-filter-description {
    margin: 12px 0 0;
    color: var(--pv-text-secondary);
    font-size: var(--pv-text-xs);
    line-height: 1.5;
}

#mps-baseline-description {
    padding: 9px 11px;
    border-left: 3px solid var(--pv-accent);
    border-radius: 0 var(--pv-input-radius) var(--pv-input-radius) 0;
    background: color-mix(in srgb, var(--pv-accent) 7%, transparent);
    color: var(--pv-text-primary);
}

.mps-view-filter-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin: 4px 0 12px;
}

.mps-view-filter-heading .mps-filter-description {
    margin: 0;
}

.mps-view-filter-status {
    flex: 0 0 auto;
    border-color: color-mix(in srgb, var(--pv-accent-cyan) 48%, var(--pv-card-border));
    color: var(--pv-accent-cyan);
}

.mps-view-filter-grid {
    display: grid;
    grid-template-columns: minmax(145px, .8fr) minmax(180px, 1fr) minmax(260px, 1.6fr) auto;
    align-items: end;
    gap: 12px;
}

.mps-filter-section--view[disabled] .mps-view-filter-grid {
    opacity: .58;
}

.mps-filter-section--view[disabled] .mph-field select,
.mps-filter-section--view[disabled] .mph-secondary-button {
    cursor: not-allowed;
}

.mph-status,
.mph-currency-pill {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    border: 1px solid var(--pv-card-border);
    border-radius: 999px;
    background: var(--pv-card-surface-solid);
    color: var(--pv-text-secondary);
    font-size: var(--pv-text-xs);
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
}

.mph-status { padding: 8px 11px; }
.mph-currency-pill { padding: 7px 10px; }

.mph-status.is-loading {
    border-color: var(--pv-accent);
    color: var(--pv-accent-cyan);
}

.mph-status.is-success {
    border-color: var(--pv-green);
    color: var(--pv-green-text);
}

.mph-status.is-dirty {
    border-color: var(--pv-amber);
    color: var(--pv-amber-text);
}

.mph-filter-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(130px, 1fr));
    gap: 12px;
    margin-top: 20px;
    padding: 16px;
    border: 1px solid var(--pv-card-border);
    border-radius: var(--pv-input-radius);
    background: color-mix(in srgb, var(--pv-card-surface-solid) 84%, transparent);
}

.mph-filter-grid--history {
    grid-template-columns: repeat(4, minmax(150px, 1fr)) auto;
    margin-top: 0;
}

.mph-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.mph-field--wide { grid-column: span 2; }

.mph-field > span {
    color: var(--pv-text-secondary);
    font-size: var(--pv-text-xs);
    font-weight: 700;
    letter-spacing: .02em;
}

.mph-field select,
.mph-field input {
    width: 100%;
    min-height: 40px;
    padding: 8px 10px;
    border: 1px solid var(--pv-card-border);
    border-radius: var(--pv-input-radius);
    outline: none;
    background: var(--pv-card-surface-solid);
    color: var(--pv-text-primary);
    font: 500 var(--pv-text-sm)/1.25 var(--pv-font-ui);
    transition: border-color var(--pv-duration-fast) ease, box-shadow var(--pv-duration-fast) ease;
}

.mph-field select:focus,
.mph-field input:focus {
    border-color: var(--pv-accent);
    box-shadow: var(--pv-glow-accent);
}

.mph-primary-button,
.mph-secondary-button,
.mph-icon-button,
.mph-history-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    cursor: pointer;
    font-family: var(--pv-font-ui);
    transition: transform var(--pv-duration-fast) var(--pv-ease-out),
        background var(--pv-duration-fast) ease,
        border-color var(--pv-duration-fast) ease;
}

.mph-primary-button {
    align-self: end;
    min-height: 40px;
    gap: 7px;
    padding: 9px 14px;
    border-radius: var(--pv-input-radius);
    background: var(--pv-accent-hover);
    color: #fff;
    font-size: var(--pv-text-sm);
    font-weight: 750;
}

.mph-primary-button:hover { background: #1d4ed8; transform: translateY(-1px); }
.mph-primary-button:disabled { cursor: wait; opacity: .65; transform: none; }
.mph-primary-button .material-symbols-outlined { font-size: 18px; }

.mph-secondary-button {
    min-height: 40px;
    gap: 7px;
    padding: 9px 14px;
    border: 1px solid var(--pv-card-border);
    border-radius: var(--pv-input-radius);
    background: var(--pv-card-surface-solid);
    color: var(--pv-text-secondary);
    font-size: var(--pv-text-sm);
    font-weight: 700;
}

.mph-secondary-button:hover,
.mph-secondary-button:focus-visible {
    border-color: var(--pv-accent);
    color: var(--pv-accent-cyan);
}

.mph-secondary-button:focus-visible {
    outline: none;
    box-shadow: var(--pv-glow-accent);
}

.mph-secondary-button:disabled {
    opacity: .65;
}

.mph-secondary-button .material-symbols-outlined {
    font-size: 18px;
}

.mph-kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.mph-kpi {
    position: relative;
    overflow: hidden;
    min-height: 118px;
    padding: 16px;
    border: 1px solid var(--pv-card-border);
    border-radius: var(--pv-input-radius);
    background: var(--pv-card-surface-solid);
}

.mph-kpi::before {
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    background: var(--pv-accent-cyan);
    content: '';
}

.mph-kpi--positive::before { background: var(--pv-green); }
.mph-kpi--negative::before { background: var(--pv-red); }
.mph-kpi--net::before { background: var(--pv-accent); }

.mph-kpi > span,
.mph-kpi > small {
    display: block;
    color: var(--pv-text-secondary);
    font-size: var(--pv-text-xs);
}

.mph-kpi > span { font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }

.mph-kpi > strong {
    display: block;
    margin: 8px 0 4px;
    color: var(--pv-text-primary);
    font-family: var(--pv-font-mono);
    font-size: var(--pv-text-xl);
}

.mph-kpi-currency-line {
    display: block;
    line-height: 1.35;
}

.mph-kpi-currency-line + .mph-kpi-currency-line {
    margin-top: 3px;
}

.mph-kpi--positive > strong { color: var(--pv-green-text); }
.mph-kpi--negative > strong { color: var(--pv-red-text); }

.mph-quality-note,
.mph-error,
.mph-as-of {
    margin-top: 14px;
    padding: 11px 13px;
    border-radius: var(--pv-input-radius);
    font-size: var(--pv-text-sm);
    line-height: 1.5;
}

.mph-quality-note {
    border: 1px solid var(--pv-amber);
    background: color-mix(in srgb, var(--pv-amber) 8%, transparent);
    color: var(--pv-amber-text);
}

.mph-error {
    border: 1px solid var(--pv-red);
    background: color-mix(in srgb, var(--pv-red) 9%, transparent);
    color: var(--pv-red-text);
}

.mph-as-of {
    border: 1px solid var(--pv-accent);
    background: color-mix(in srgb, var(--pv-accent) 9%, transparent);
    color: var(--pv-text-primary);
}

.mph-analysis-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.65fr) minmax(320px, .85fr);
    gap: 16px;
    margin-top: 16px;
}

.mph-chart-card,
.mph-ranking-card,
.mph-events-card {
    min-width: 0;
    padding: 17px;
}

.mph-chart-wrap {
    position: relative;
    min-height: 310px;
    margin-top: 14px;
}

.mph-currency-charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 14px;
}

.mph-currency-chart {
    min-width: 0;
    padding: 13px;
    border: 1px solid var(--pv-card-border);
    border-radius: var(--pv-input-radius);
    background: color-mix(in srgb, var(--pv-card-surface-solid) 80%, transparent);
}

.mph-currency-chart h5 {
    margin: 0;
    color: var(--pv-text-primary);
    font: 700 var(--pv-text-sm)/1.3 var(--pv-font-ui);
}

.mph-currency-chart > p {
    margin: 3px 0 10px;
    color: var(--pv-text-secondary);
    font-size: var(--pv-text-xs);
}

.mph-currency-chart__canvas {
    position: relative;
    height: 265px;
}

.mph-empty {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--pv-text-secondary);
    font-size: var(--pv-text-sm);
}

.mph-table-scroll {
    max-height: 330px;
    margin-top: 12px;
    overflow: auto;
    border: 1px solid var(--pv-card-border);
    border-radius: var(--pv-input-radius);
}

.mph-table {
    width: 100%;
    border-collapse: collapse;
    color: var(--pv-text-primary);
    font-size: var(--pv-text-sm);
}

.mph-table th {
    position: sticky;
    z-index: 1;
    top: 0;
    padding: 10px 11px;
    border-bottom: 1px solid var(--pv-card-border);
    background: var(--pv-card-surface-solid);
    color: var(--pv-text-secondary);
    font-size: var(--pv-text-xs);
    text-align: left;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.mph-table td {
    padding: 11px;
    border-bottom: 1px solid var(--pv-card-border);
    vertical-align: middle;
}

.mph-table tbody tr:last-child td { border-bottom: 0; }
.mph-table tbody tr:hover { background: color-mix(in srgb, var(--pv-accent) 5%, transparent); }
.mph-table .mph-number { text-align: right; font-family: var(--pv-font-mono); }
.mph-empty-cell { color: var(--pv-text-secondary); text-align: center; }

.mph-item-link {
    border: 0;
    background: transparent;
    color: var(--pv-text-primary);
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    text-align: left;
}

.mph-item-link:hover { color: var(--pv-accent-cyan); }
.mph-money-positive { color: var(--pv-green-text); }
.mph-money-negative { color: var(--pv-red-text); }

.mph-methodology {
    margin-top: 16px;
    border-top: 1px solid var(--pv-card-border);
    color: var(--pv-text-secondary);
    font-size: var(--pv-text-sm);
}

.mph-methodology summary {
    padding: 12px 0 4px;
    color: var(--pv-text-primary);
    cursor: pointer;
    font-weight: 700;
}

.mph-methodology > div { padding: 8px 0 2px; line-height: 1.6; }

.mph-action-col,
.mph-action-cell {
    width: 82px;
    text-align: center !important;
}

.mph-history-button {
    width: 34px;
    height: 34px;
    border: 1px solid var(--pv-card-border);
    border-radius: var(--pv-input-radius);
    background: var(--pv-card-surface-solid);
    color: var(--pv-text-secondary);
}

.mph-history-button:hover,
.mph-history-button:focus-visible {
    border-color: var(--pv-accent);
    color: var(--pv-accent-cyan);
    transform: translateY(-1px);
}

.mph-history-button.is-improvement { border-color: var(--pv-green); color: var(--pv-green-text); }
.mph-history-button.is-increase { border-color: var(--pv-red); color: var(--pv-red-text); }
.mph-history-button.is-unchanged { color: var(--pv-text-muted); }
.mph-history-button .material-symbols-outlined { font-size: 19px; }

.mph-drawer-history {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
}
.mph-drawer-history .material-symbols-outlined { font-size: 18px; }

#material-detail-drawer .m-drawer-footer { flex-wrap: wrap; }

.mph-cell-subtitle {
    display: block;
    margin-top: 3px;
    color: var(--pv-text-secondary);
    font-size: var(--pv-text-xs);
    font-weight: 500;
}

.mph-change {
    display: inline-flex;
    padding: 4px 7px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--pv-text-secondary) 10%, transparent);
    color: var(--pv-text-secondary);
    font-size: var(--pv-text-xs);
    font-weight: 700;
}

.mph-change--improvement {
    background: color-mix(in srgb, var(--pv-green) 11%, transparent);
    color: var(--pv-green-text);
}

.mph-change--increase {
    background: color-mix(in srgb, var(--pv-red) 11%, transparent);
    color: var(--pv-red-text);
}

.mph-sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.mph-modal[hidden],
.mph-field[hidden],
.mph-empty[hidden],
.mph-error[hidden],
.mph-quality-note[hidden],
.mph-as-of[hidden] { display: none !important; }

.mph-modal {
    position: fixed;
    z-index: 12000;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    font-family: var(--pv-font-ui);
}

.mph-modal-backdrop {
    position: absolute;
    inset: 0;
    background: color-mix(in srgb, var(--pv-bg-base) 84%, transparent);
    backdrop-filter: var(--pv-glass-blur-heavy);
    -webkit-backdrop-filter: var(--pv-glass-blur-heavy);
}

.mph-modal-dialog {
    position: relative;
    display: flex;
    flex-direction: column;
    width: min(1500px, 96vw);
    max-height: 94vh;
    overflow: hidden;
    border: 1px solid var(--pv-card-border);
    border-radius: var(--pv-card-radius);
    background: var(--pv-bg-base);
    box-shadow: var(--pv-elevation);
    animation: mph-modal-in var(--pv-duration-normal) var(--pv-ease-out);
}

@keyframes mph-modal-in {
    from { opacity: 0; transform: translateY(14px) scale(.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.mph-modal-header {
    flex-shrink: 0;
    justify-content: space-between;
    gap: 20px;
    padding: 18px 22px;
    border-bottom: 1px solid var(--pv-card-border);
    background: var(--pv-card-surface-solid);
}

.mph-modal-heading { gap: 13px; }
.mph-modal-header h2 { font-size: var(--pv-text-xl); }

.mph-modal-icon,
.mph-icon-button {
    width: 42px;
    height: 42px;
    border-radius: var(--pv-input-radius);
}

.mph-modal-icon {
    display: grid;
    place-items: center;
    background: color-mix(in srgb, var(--pv-accent) 16%, transparent);
    color: var(--pv-accent-cyan);
}

.mph-icon-button {
    border: 1px solid var(--pv-card-border);
    background: transparent;
    color: var(--pv-text-secondary);
}

.mph-icon-button:hover { border-color: var(--pv-red); color: var(--pv-red-text); }

.mph-modal-body {
    overflow-y: auto;
    padding: 20px 22px 26px;
}

.mph-kpi-grid--history { margin-bottom: 16px; }
.mph-chart-card--modal { margin-top: 0; }
.mph-chart-wrap--modal { min-height: 380px; }
.mph-events-card { margin-top: 16px; }
.mph-table-scroll--events { max-height: 360px; }
.mph-table-scroll--events .mph-table { min-width: 900px; }

.mph-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    color: var(--pv-text-secondary);
    font-size: var(--pv-text-xs);
}

.mph-legend span { display: inline-flex; align-items: center; gap: 5px; }
.mph-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--pv-text-secondary); }
.mph-dot--positive { background: var(--pv-green); }
.mph-dot--negative { background: var(--pv-red); }
.mph-dot--supplier { background: var(--pv-amber); }

body.mph-modal-open { overflow: hidden; }

@media (max-width: 1180px) {
    .mps-calculation-grid { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
    .mps-view-filter-grid { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
    .mps-view-filter-item { grid-column: span 2; }
    .mph-filter-grid { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
    .mph-filter-grid--history { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
    .mph-analysis-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    .mps-panel { padding: 16px; }
    .mps-calculation-grid,
    .mps-view-filter-grid { grid-template-columns: 1fr; }
    .mps-view-filter-item { grid-column: auto; }
    .mps-view-filter-heading {
        align-items: flex-start;
        flex-direction: column;
    }
    .mps-filter-legend { align-items: flex-start; }
    .mps-calculate-button,
    .mph-secondary-button { width: 100%; }
    .mph-panel-header,
    .mph-card-title-row { align-items: flex-start; flex-direction: column; }
    .mph-filter-grid,
    .mph-filter-grid--history { grid-template-columns: 1fr; }
    .mph-field--wide { grid-column: auto; }
    .mph-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .mph-modal { padding: 0; }
    .mph-modal-dialog { width: 100vw; max-height: 100vh; min-height: 100vh; border-radius: 0; }
    .mph-modal-header,
    .mph-modal-body { padding-right: 15px; padding-left: 15px; }
    .mph-chart-wrap--modal { min-height: 300px; }
    .mph-currency-charts { grid-template-columns: 1fr; }
    #material-detail-drawer > .drawer-content {
        width: min(600px, 100vw) !important;
        max-height: 100vh !important;
    }
}

@media (max-width: 440px) {
    .mph-kpi-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    .mph-modal-dialog { animation: none; }
    .mph-primary-button,
    .mph-secondary-button,
    .mph-icon-button,
    .mph-history-button { transition: none; }
}
