/* 2026-01-12 | diagrams-css | WHY: web-responsive-diagrams | FROM: design-system-extension */

/**
 * DIAGRAMS.CSS - Extension for Web-Responsive Diagrams
 *
 * Purpose: Standalone diagrams for articles/web (NOT carousel slides)
 *
 * Key differences from carousel system:
 * - Responsive (max-width) instead of fixed 320×400
 * - No branding elements (logo, handle, mascot)
 * - Inherits palette & typography from themes.css
 *
 * Usage:
 *   <link rel="stylesheet" href="themes.css">
 *   <link rel="stylesheet" href="diagrams.css">
 *
 *   <div class="diagram var-soft">
 *       <div class="diagram-title">...</div>
 *       <div class="diagram-content">...</div>
 *   </div>
 */

/* ==========================================================================
   BASE DIAGRAM CONTAINER
   ========================================================================== */

.diagram {
    /* Fluid sizing - adapts to container width */
    width: 100%;
    max-width: 100%;
    min-height: 200px;

    /* Structure */
    padding: 24px;
    border-radius: 8px;
    box-sizing: border-box;

    /* Layout */
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Size variants (use to LIMIT width when needed) */
.diagram.diagram-sm {
    max-width: 320px;
    padding: 20px;
    gap: 12px;
}

.diagram.diagram-md {
    max-width: 480px;
}

.diagram.diagram-lg {
    max-width: 600px;
    padding: 32px;
    gap: 20px;
}

.diagram.diagram-wide {
    max-width: 800px;
}

/* ==========================================================================
   DIAGRAM TITLE
   ========================================================================== */

.diagram-title {
    font-family: var(--font-h1);
    font-size: 1.3rem;
    line-height: 1;
    text-align: center;
}

.diagram-subtitle {
    font-family: var(--font-h2);
    font-size: 0.75rem;
    text-transform: lowercase;
    text-align: center;
    opacity: 0.8;
}

/* ==========================================================================
   DIAGRAM CONTENT LAYOUTS
   ========================================================================== */

.diagram-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Horizontal split (two columns) */
.diagram-content.split {
    flex-direction: row;
    justify-content: space-between;
    align-items: stretch;
}

/* Grid layout */
.diagram-content.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.diagram-content.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

/* ==========================================================================
   DIAGRAM BOXES (reusable containers)
   ========================================================================== */

.diagram-box {
    padding: 14px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.diagram-box.flex-1 {
    flex: 1;
}

/* Box header with icon */
.box-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.box-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.box-icon svg {
    width: 16px;
    height: 16px;
}

.box-label {
    font-family: var(--font-h2);
    font-size: 0.75rem;
    text-transform: lowercase;
}

/* ==========================================================================
   DIAGRAM ITEMS (lists, steps, etc.)
   ========================================================================== */

.diagram-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.diagram-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-body);
    font-size: 0.65rem;
}

.item-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.item-number {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-h2);
    font-size: 0.7rem;
    flex-shrink: 0;
}

/* ==========================================================================
   DIAGRAM ARROWS & CONNECTORS
   ========================================================================== */

.diagram-arrows {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
    width: 60px;
}

.arrow {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.arrow svg {
    width: 22px;
    height: 22px;
}

.arrow-label {
    font-family: var(--font-h2);
    font-size: 0.55rem;
    text-transform: lowercase;
    opacity: 0.7;
}

/* Horizontal flow */
.diagram-flow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
}

.flow-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex: 1;
}

.flow-box {
    padding: 6px 8px;
    border-radius: 4px;
    font-family: var(--font-body);
    font-size: 0.55rem;
    text-align: center;
    width: 100%;
    box-sizing: border-box;
}

.flow-arrow {
    font-size: 0.8rem;
    opacity: 0.5;
    flex-shrink: 0;
}

/* ==========================================================================
   DIAGRAM STAGES (funnel, timeline)
   ========================================================================== */

.diagram-stages {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.stage {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 6px;
    position: relative;
}

.stage-number {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-h2);
    font-size: 0.7rem;
    flex-shrink: 0;
}

.stage-content {
    flex: 1;
}

.stage-name {
    font-family: var(--font-h2);
    font-size: 0.7rem;
    text-transform: lowercase;
    margin-bottom: 2px;
}

.stage-desc {
    font-family: var(--font-body);
    font-size: 0.6rem;
    opacity: 0.75;
}

.stage-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stage-icon svg {
    width: 18px;
    height: 18px;
}

/* ==========================================================================
   DIAGRAM BALANCE (comparison layout)
   ========================================================================== */

.diagram-balance {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 40px;
    flex: 1;
}

.balance-side {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.balance-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.balance-icon svg {
    width: 24px;
    height: 24px;
}

.balance-label {
    font-family: var(--font-h2);
    font-size: 0.7rem;
    text-transform: lowercase;
    letter-spacing: 0.5px;
}

.balance-metrics {
    font-family: var(--font-body);
    font-size: 0.65rem;
    text-align: center;
    opacity: 0.8;
    line-height: 1.4;
}

.balance-fulcrum {
    position: relative;
    width: 100%;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.fulcrum-line {
    width: 100%;
    height: 3px;
    background: currentColor;
    opacity: 0.3;
}

.fulcrum-center {
    position: absolute;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fulcrum-center svg {
    width: 14px;
    height: 14px;
}

/* ==========================================================================
   DIAGRAM AMPLIFIER (bottom highlight)
   ========================================================================== */

.diagram-amplifier {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    border-radius: 6px;
    margin-top: auto;
}

.amplifier-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.amplifier-icon svg {
    width: 16px;
    height: 16px;
}

.amplifier-label {
    font-family: var(--font-h2);
    font-size: 0.7rem;
    text-transform: lowercase;
}

/* ==========================================================================
   THEME OVERRIDES FOR DIAGRAMS

   These extend themes.css with diagram-specific styling.
   Each theme defines colors for diagram components.
   ========================================================================== */

/* --- var-soft (light dragée background) --- */
.var-soft.diagram {
    background: var(--oi-dragee);
    color: var(--oi-marine);
}

.var-soft .diagram-box.primary {
    background: var(--oi-empire);
    color: var(--oi-albatre);
}

.var-soft .diagram-box.secondary {
    background: var(--oi-albatre);
    color: var(--oi-marine);
}

.var-soft .diagram-box.primary .box-icon {
    background: var(--oi-chartreuse);
}

.var-soft .diagram-box.primary .box-icon svg {
    stroke: var(--oi-marine);
}

.var-soft .diagram-box.primary .item-dot {
    background: var(--oi-chartreuse);
}

.var-soft .diagram-box.secondary .box-icon {
    background: var(--oi-marine);
}

.var-soft .diagram-box.secondary .box-icon svg {
    stroke: var(--oi-albatre);
}

.var-soft .diagram-box.secondary .item-dot {
    background: var(--oi-empire);
}

.var-soft .arrow svg {
    stroke: var(--oi-marine);
}

/* --- var-clear (light albâtre background) --- */
.var-clear.diagram {
    background: var(--oi-albatre);
    color: var(--oi-marine);
}

.var-clear .diagram-box {
    background: rgba(27, 34, 44, 0.05);
}

.var-clear .diagram-box.primary {
    background: var(--oi-empire);
    color: var(--oi-albatre);
}

.var-clear .diagram-box.secondary {
    background: var(--oi-dragee);
    color: var(--oi-marine);
}

.var-clear .diagram-box.primary .box-icon {
    background: var(--oi-chartreuse);
}

.var-clear .diagram-box.primary .box-icon svg {
    stroke: var(--oi-marine);
}

.var-clear .diagram-box.primary .item-dot {
    background: var(--oi-chartreuse);
}

.var-clear .diagram-box.secondary .box-icon {
    background: var(--oi-empire);
}

.var-clear .diagram-box.secondary .box-icon svg {
    stroke: var(--oi-albatre);
}

.var-clear .diagram-box.secondary .item-dot {
    background: var(--oi-empire);
}

.var-clear .stage {
    background: var(--oi-empire);
    color: var(--oi-albatre);
}

.var-clear .stage-name,
.var-clear .stage-desc {
    color: var(--oi-albatre);
}

.var-clear .stage-desc {
    opacity: 0.85;
}

.var-clear .stage-number,
.var-clear .item-number {
    background: var(--oi-chartreuse);
    color: var(--oi-marine);
}

.var-clear .stage-icon svg {
    stroke: var(--oi-chartreuse);
}

.var-clear .balance-icon {
    background: var(--oi-empire);
}

.var-clear .balance-icon svg {
    stroke: var(--oi-chartreuse);
}

.var-clear .fulcrum-center {
    background: var(--oi-chartreuse);
}

.var-clear .fulcrum-center svg {
    stroke: var(--oi-marine);
}

.var-clear .flow-box {
    background: rgba(27, 34, 44, 0.1);
}

/* --- var-deep (dark marine background) --- */
.var-deep.diagram {
    background: var(--oi-marine);
    color: var(--oi-albatre);
}

.var-deep .diagram-box {
    background: rgba(255, 255, 255, 0.05);
}

.var-deep .stage {
    background: rgba(255, 255, 255, 0.05);
}

.var-deep .stage-icon svg {
    stroke: var(--oi-chartreuse);
}

.var-deep .diagram-amplifier {
    background: var(--oi-chartreuse);
    color: var(--oi-marine);
}

.var-deep .amplifier-icon {
    background: var(--oi-marine);
}

.var-deep .amplifier-icon svg {
    stroke: var(--oi-chartreuse);
}

/* --- var-growth (dark empire background) --- */
.var-growth.diagram {
    background: var(--oi-empire);
    color: var(--oi-albatre);
}

.var-growth .diagram-box {
    background: rgba(255, 255, 255, 0.08);
}

.var-growth .stage {
    background: rgba(255, 255, 255, 0.08);
}

.var-growth .stage-number,
.var-growth .item-number {
    background: var(--oi-chartreuse);
    color: var(--oi-marine);
}

.var-growth .stage-icon svg {
    stroke: var(--oi-chartreuse);
}

/* --- var-impact (bright chartreuse background) --- */
.var-impact.diagram {
    background: var(--oi-chartreuse);
    color: var(--oi-marine);
}

.var-impact .diagram-box {
    background: rgba(27, 34, 44, 0.1);
}

.var-impact .stage-number,
.var-impact .item-number {
    background: var(--oi-marine);
    color: var(--oi-chartreuse);
}

/* ==========================================================================
   RESPONSIVE ADJUSTMENTS

   Mobile-first approach:
   - Grids collapse to single column
   - Wide diagrams constrained to viewport
   - Flow layouts stack vertically
   - Scroll wrapper for complex diagrams
   ========================================================================== */

/* --- Tablet breakpoint (640px) --- */
@media (max-width: 640px) {
    /* Wide diagrams: constrain to viewport */
    .diagram.diagram-wide {
        max-width: 100%;
    }

    .diagram.diagram-lg {
        max-width: 100%;
        padding: 24px;
    }

    /* 3-column grid → 2 columns on tablet */
    .diagram-content.grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* --- Mobile breakpoint (480px) --- */
@media (max-width: 480px) {
    .diagram {
        padding: 16px;
        gap: 12px;
    }

    .diagram-title {
        font-size: 1.1rem;
    }

    /* Split layout → stack vertically */
    .diagram-content.split {
        flex-direction: column;
    }

    /* 2-column grid → single column on mobile */
    .diagram-content.grid-2 {
        grid-template-columns: 1fr;
    }

    /* 3-column grid → single column on mobile */
    .diagram-content.grid-3 {
        grid-template-columns: 1fr;
    }

    /* Arrows: horizontal on mobile when split stacks */
    .diagram-arrows {
        flex-direction: row;
        width: 100%;
        height: auto;
        padding: 8px 0;
    }

    /* Balance layout: reduce gap */
    .diagram-balance {
        gap: 20px;
    }

    .balance-icon {
        width: 40px;
        height: 40px;
    }

    /* Flow layout: stack on very small screens */
    .diagram-flow {
        flex-wrap: wrap;
        gap: 8px;
    }

    .flow-step {
        flex: 1 1 100%;
    }

    .flow-arrow {
        transform: rotate(90deg);
        margin: 4px 0;
    }
}

/* ==========================================================================
   SCROLL WRAPPER (for complex diagrams that can't collapse)

   Usage: <div class="diagram-scroll"><div class="diagram diagram-wide">...</div></div>
   ========================================================================== */

.diagram-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
}

/* Visual hint that content scrolls */
.diagram-scroll::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 20px;
    background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.1));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

/* Show hint only when scrollable */
@media (max-width: 640px) {
    .diagram-scroll {
        position: relative;
    }

    .diagram-scroll::after {
        opacity: 1;
    }
}

/* ==========================================================================
   UTILITY CLASSES (for inline diagram layouts)

   These allow diagram-designer agent to use classes instead of inline styles
   ========================================================================== */

/* Responsive flex row → column */
.diagram-row {
    display: flex;
    gap: 12px;
    align-items: center;
}

@media (max-width: 480px) {
    .diagram-row {
        flex-direction: column;
    }
}

/* Flex container that wraps */
.diagram-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

/* Centered flex column */
.diagram-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

/* Auto-fit grid (no media query needed - responsive by nature) */
.diagram-auto-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}
