/* ===================================================================
   MARGIN ANALYSIS — Premium SaaS Upgrade Layer
   Applied ON TOP of marginAnalysis.css (editorial base)
   Elevates from editorial to Linear/Mercury/Carta quality
   =================================================================== */

/* ===================================================================
   1. KPI METRIC CARDS — Spatial Luxury & Visual Hierarchy
   =================================================================== */

/* More generous padding + breathing room */
.margin-metrics-grid {
    gap: 1.125rem;
    margin-bottom: 1.75rem;
    margin-top: 1.25rem;
}

.margin-metric-card {
    padding: 1.5rem 1.375rem 1.375rem;
    border-radius: 14px;
    border-left-width: 3px;
    box-shadow:
        0 1px 3px rgba(0, 0, 0, 0.03),
        0 1px 2px rgba(0, 0, 0, 0.015),
        0 0 0 1px rgba(0, 0, 0, 0.02);
}

.margin-metric-card:hover {
    transform: translateY(-1px);
    box-shadow:
        0 8px 24px rgba(0, 0, 0, 0.06),
        0 2px 8px rgba(0, 0, 0, 0.03),
        0 0 0 1px rgba(0, 0, 0, 0.03);
}

/* Larger, more commanding metric values */
.margin-metric-card .metric-value,
.metric-value {
    font-size: 1.875rem;
    letter-spacing: -0.03em;
    margin-bottom: 0.35rem;
    line-height: 1.15;
}

/* Tighter metric header spacing */
.metric-header {
    margin-bottom: 1rem;
}

/* Refined label with slightly more space */
.metric-label {
    font-size: 0.625rem;
    letter-spacing: 0.1em;
    gap: 0.4rem;
    margin-bottom: 0;
}

/* Subtitle — a touch more muted */
.metric-subtitle {
    font-size: 0.8125rem;
    color: var(--liq-text-secondary);
    line-height: 1.5;
    letter-spacing: 0.005em;
}

/* ===================================================================
   2. SPARKLINE CONTAINERS — Refined Background Strip
   =================================================================== */

.metric-sparkline {
    height: 40px;
    margin-top: 1.125rem;
    padding: 0.5rem 1.375rem;
    background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.008) 0%,
        rgba(0, 0, 0, 0.022) 100%
    );
    border-top: 1px solid rgba(0, 0, 0, 0.04);
    margin-left: -1.375rem;
    margin-right: -1.375rem;
    margin-bottom: -1.375rem;
    border-radius: 0 0 11px 11px;
}

/* ===================================================================
   3. BADGES — Frosted Glass Refinement
   =================================================================== */

/* Already frosted-glass in base; refine the subtlety */
.metric-badge {
    padding: 0.15rem 0.45rem;
    font-size: 0.5rem;
    letter-spacing: 0.07em;
    border-color: rgba(74, 144, 128, 0.1);
    background: rgba(74, 144, 128, 0.06);
}

/* Advanced badge variant */
.metric-badge[data-type="advanced"],
.metric-badge.badge-advanced {
    background: rgba(124, 58, 237, 0.06);
    color: #7C3AED;
    border-color: rgba(124, 58, 237, 0.1);
}

/* Fixed badge variant */
.metric-badge[data-type="fixed"],
.metric-badge.badge-fixed {
    background: rgba(30, 64, 175, 0.06);
    color: #1E40AF;
    border-color: rgba(30, 64, 175, 0.1);
}

/* ===================================================================
   4. TREND INDICATORS — Refined Pill Backgrounds
   =================================================================== */

.metric-trend {
    padding: 0.1875rem 0.5625rem;
    font-size: 0.625rem;
    letter-spacing: 0.01em;
}

.trend-positive {
    background: rgba(4, 120, 87, 0.06);
}

.trend-negative {
    background: rgba(190, 18, 60, 0.06);
}

.trend-neutral {
    background: rgba(168, 162, 158, 0.06);
}

/* ===================================================================
   5. TAB NAVIGATION — Polish
   =================================================================== */

.margin-view-tabs {
    padding: 0 1.25rem;
    gap: 0;
}

.view-tab {
    padding: 0.8125rem 1.125rem;
    font-size: 0.8125rem;
    letter-spacing: 0.015em;
}

.view-tab::after {
    left: 0.75rem;
    right: 0.75rem;
    height: 2px;
}

.view-tab.active {
    font-weight: 600;
}

/* ===================================================================
   6. CHART CARDS — Better Framing & Section Headings
   =================================================================== */

.margin-chart-wrapper {
    border-radius: 12px;
    padding: 1.25rem;
    border-color: var(--liq-border-lighter);
    box-shadow:
        0 1px 3px rgba(0, 0, 0, 0.03),
        0 0 0 1px rgba(0, 0, 0, 0.02);
}

.chart-header {
    margin-bottom: 0.875rem;
    padding-bottom: 0.625rem;
    border-bottom: 1px solid var(--liq-border-lighter);
}

.chart-title {
    font-family: var(--liq-font-body);
    font-size: 0.9375rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.chart-action-btn {
    padding: 0.3125rem 0.5rem;
    border-radius: 6px;
    font-size: 0.6875rem;
    font-weight: 500;
    border-color: var(--liq-border-lighter);
    background: transparent;
}

.chart-action-btn:hover {
    background: rgba(74, 144, 128, 0.06);
    border-color: rgba(74, 144, 128, 0.2);
    color: var(--liq-accent);
}

/* ===================================================================
   7. SECTION TITLES — Editorial Hierarchy
   =================================================================== */

.section-title {
    font-family: var(--liq-font-body);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--liq-text);
}

.section-subtitle {
    font-size: 0.8125rem;
    letter-spacing: 0.005em;
}

/* ===================================================================
   8. CONTENT AREA — Subtle Refinement
   =================================================================== */

.margin-content-area {
    padding: 1.5rem;
    margin: 1.25rem 1.25rem;
    border-color: var(--liq-border-lighter);
    box-shadow:
        0 1px 3px rgba(0, 0, 0, 0.025),
        0 0 0 1px rgba(0, 0, 0, 0.015);
}

/* ===================================================================
   9. ALERTS — Refined Left Accent + Subtle Background
   =================================================================== */

.margin-alerts-container {
    margin: 0 1.5rem 1rem;
    display: grid;
    gap: 0.5rem;
}

.margin-alert-banner {
    padding: 0.625rem 1rem;
    border-radius: 10px;
    border-left-width: 3px;
    background: var(--liq-surface);
    border: 1px solid var(--liq-border-lighter);
    border-left: 3px solid var(--liq-border-light);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.margin-alert-banner.alert-critical {
    background: rgba(190, 18, 60, 0.03);
    border-color: rgba(190, 18, 60, 0.08);
    border-left-color: var(--liq-loss);
    color: var(--liq-text);
}

.margin-alert-banner.alert-critical .alert-icon {
    color: var(--liq-loss);
}

.margin-alert-banner.alert-warning {
    background: rgba(202, 138, 4, 0.03);
    border-color: rgba(202, 138, 4, 0.08);
    border-left-color: var(--liq-warning);
    color: var(--liq-text);
}

.margin-alert-banner.alert-warning .alert-icon {
    color: var(--liq-warning);
}

.margin-alert-banner.alert-success {
    background: rgba(4, 120, 87, 0.03);
    border-color: rgba(4, 120, 87, 0.08);
    border-left-color: var(--liq-profit);
    color: var(--liq-text);
}

.margin-alert-banner.alert-success .alert-icon {
    color: var(--liq-profit);
}

.margin-alert-banner .alert-message {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--liq-text-secondary);
    line-height: 1.5;
}

.margin-alert-banner .alert-message strong {
    color: var(--liq-text);
    font-weight: 600;
}

.margin-alert-banner .alert-dismiss {
    opacity: 0.3;
    transition: opacity 0.15s ease;
}

.margin-alert-banner .alert-dismiss:hover {
    opacity: 0.7;
}

/* ===================================================================
   10. INSIGHTS PANEL — Mercury-Level Refinement
   =================================================================== */

.margin-insights-panel {
    background: var(--liq-surface);
    border: 1px solid var(--liq-border-lighter);
    border-radius: 12px;
    padding: 0;
    margin-top: 1.75rem;
    overflow: hidden;
}

.insights-header {
    padding: 0.875rem 1.25rem;
    margin-bottom: 0;
    border-bottom: 1px solid var(--liq-border-lighter);
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.008), transparent);
}

.insights-header h4 {
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: -0.005em;
}

.insight-items {
    padding: 0;
    gap: 0;
}

.margin-insight-item {
    border-radius: 0;
    border: none;
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
    border-left: none;
    padding: 0.875rem 1.25rem;
    margin: 0;
}

.margin-insight-item:last-child {
    border-bottom: none;
}

.margin-insight-item:hover {
    transform: none;
    background: rgba(0, 0, 0, 0.012);
    box-shadow: none;
}

.insight-icon-wrapper {
    width: 30px;
    height: 30px;
    border-radius: 8px;
}

.insight-title {
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: -0.005em;
}

.insight-description {
    font-size: 0.8125rem;
    line-height: 1.55;
}

/* ===================================================================
   11. CELEBRATION BANNER — Softer & More Refined
   =================================================================== */

.margin-celebration-banner {
    border-left-width: 3px;
    background: linear-gradient(135deg, rgba(4, 120, 87, 0.04) 0%, rgba(4, 120, 87, 0.02) 100%);
    border: 1px solid rgba(4, 120, 87, 0.08);
    border-left: 3px solid var(--liq-profit);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
    padding: 1rem 1.25rem;
}

.margin-celebration-banner h4,
.margin-celebration-banner .celebration-title {
    font-family: var(--liq-font-body);
    font-size: 0.9375rem;
    font-weight: 700;
}

/* ===================================================================
   12. CONTROLS — Refined Inputs
   =================================================================== */

.margin-controls {
    background: transparent;
    border-color: var(--liq-border-lighter);
    padding: 0.5rem 0;
    border: none;
    border-bottom: 1px solid var(--liq-border-lighter);
    border-radius: 0;
    margin-bottom: 1.125rem;
}

.control-select {
    padding: 0.4375rem 0.625rem;
    border-radius: 6px;
    font-size: 0.8125rem;
    border-color: var(--liq-border-lighter);
}

.control-select:hover {
    border-color: var(--liq-border);
}

.control-select:focus {
    box-shadow: 0 0 0 2px rgba(74, 144, 128, 0.1);
    border-color: var(--liq-accent);
}

.toggle-option {
    padding: 0.4375rem 0.75rem;
    font-size: 0.8125rem;
    border-radius: 6px;
}

.control-toggle {
    border-radius: 8px;
    background: var(--liq-bg);
    padding: 0.1875rem;
    gap: 0.125rem;
}

.toggle-option.active {
    background: var(--liq-text);
    border-radius: 6px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* ===================================================================
   13. DECOMPOSITION VIEW — Tighter Factor Cards
   =================================================================== */

.decomposition-factors {
    background: transparent;
    border: none;
    padding: 0;
}

.factor-item {
    border-radius: 10px;
    border-left-width: 3px;
    padding: 0.875rem;
    margin-bottom: 0.625rem;
    border-color: var(--liq-border-lighter);
    border-left-color: var(--liq-accent);
}

.factor-item:hover {
    transform: translateX(2px);
}

.factor-item.active {
    background: rgba(74, 144, 128, 0.04);
}

/* ===================================================================
   14. BENCHMARK CARDS — Cleaner Borders
   =================================================================== */

.benchmark-card {
    border-radius: 12px;
    border-left-width: 3px;
    padding: 1rem;
    border-color: var(--liq-border-lighter);
}

.benchmark-card:hover {
    transform: translateY(-1px);
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.04),
        0 0 0 1px rgba(0, 0, 0, 0.02);
}

.benchmark-badge {
    padding: 0.15rem 0.5rem;
    border-radius: 100px;
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-above {
    background: rgba(4, 120, 87, 0.08);
    color: var(--liq-profit);
}

.badge-below {
    background: rgba(190, 18, 60, 0.08);
    color: var(--liq-loss);
}

.badge-inline {
    background: rgba(202, 138, 4, 0.08);
    color: var(--liq-warning);
}

/* ===================================================================
   15. SENSITIVITY PANEL — Cleaner Containers
   =================================================================== */

.sensitivity-panel {
    background: transparent;
    border: none;
    padding: 0;
    margin-top: 0.875rem;
}

/* ===================================================================
   16. FORECAST SECTION — Consistent With Main Metrics
   =================================================================== */

.forecast-metric-card {
    padding: 1rem;
    border-radius: 12px;
    border-left-width: 3px;
    border-color: var(--liq-border-lighter);
}

.forecast-metric-card .metric-value {
    font-size: 1.375rem;
}

.forecast-metric-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
}

.period-btn-group {
    border-color: var(--liq-border-lighter);
    padding: 0.1875rem;
}

.period-btn {
    padding: 0.4375rem 0.875rem;
    font-size: 0.8125rem;
    border-radius: 6px;
}

.period-btn.active {
    background: var(--liq-text);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* ===================================================================
   17. EXPORT BUTTONS — More Ghost-Like
   =================================================================== */

.export-btn {
    padding: 0.3125rem 0.5rem;
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    border-color: transparent;
    color: var(--liq-text-muted);
    border-radius: 6px;
}

.export-btn:hover {
    background: rgba(74, 144, 128, 0.06);
    border-color: rgba(74, 144, 128, 0.15);
    color: var(--liq-accent);
}

/* ===================================================================
   18. HERO HEADER — Slightly More Breathing Room
   =================================================================== */

.margin-analysis-header {
    padding: 1.125rem 1.5rem;
    margin: 1rem 1.25rem 0;
    box-shadow:
        var(--liq-shadow-md),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.margin-analysis-header h3 {
    font-size: 1.375rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.margin-analysis-header p {
    font-size: 0.8125rem;
    letter-spacing: 0.01em;
}

/* ===================================================================
   19. PRINT — Inherit Premium Spacing
   =================================================================== */

@media print {
    .margin-metric-card,
    .margin-chart-wrapper,
    .benchmark-card,
    .forecast-metric-card {
        box-shadow: none;
        border: 1px solid var(--liq-border);
    }

    .margin-alert-banner {
        box-shadow: none;
    }

    .margin-insights-panel {
        border: 1px solid var(--liq-border);
    }
}
