/* ============================================
   IFM Functional Medicine Matrix - Styles
   Medical Professional Theme
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=Playfair+Display:wght@400;500;600;700&display=swap');

:root {
    --ifm-primary: #1B6B5A;
    --ifm-primary-light: #238C75;
    --ifm-primary-pale: #E8F5F1;
    --ifm-primary-dark: #134D41;
    --ifm-accent: #C8956C;
    --ifm-accent-light: #F5EDE5;
    --ifm-text: #2D3436;
    --ifm-text-light: #636E72;
    --ifm-border: #DFE6E9;
    --ifm-bg: #FFFFFF;
    --ifm-bg-soft: #F8FAFB;
    --ifm-shadow: 0 2px 12px rgba(27, 107, 90, 0.08);
    --ifm-shadow-lg: 0 8px 32px rgba(27, 107, 90, 0.12);
    --ifm-radius: 12px;
    --ifm-radius-sm: 8px;
    --ifm-font-body: 'DM Sans', sans-serif;
    --ifm-font-display: 'Playfair Display', serif;
    --ifm-energy: #E17055;
    --ifm-transport: #6C5CE7;
    --ifm-communication: #00B894;
    --ifm-defense: #FDCB6E;
    --ifm-assimilation: #74B9FF;
    --ifm-biotrans: #A29BFE;
    --ifm-structural: #FF7675;
}

/* Reset within plugin scope */
.ifm-matrix-wrap * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.ifm-matrix-wrap {
    font-family: var(--ifm-font-body);
    color: var(--ifm-text);
    max-width: 960px;
    margin: 40px auto;
    padding: 0 20px;
    -webkit-font-smoothing: antialiased;
}

/* ---- Header ---- */
.ifm-header {
    text-align: center;
    margin-bottom: 48px;
    padding: 40px 0;
    border-bottom: 2px solid var(--ifm-primary-pale);
}

.ifm-header__icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 16px;
    background: var(--ifm-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ifm-header__icon svg {
    width: 28px;
    height: 28px;
    fill: none;
    stroke: #fff;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.ifm-header h1 {
    font-family: var(--ifm-font-display);
    font-size: 32px;
    font-weight: 600;
    color: var(--ifm-primary-dark);
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.ifm-header p {
    font-size: 15px;
    color: var(--ifm-text-light);
    max-width: 520px;
    margin: 0 auto;
    line-height: 1.6;
}

/* ---- Progress Bar ---- */
.ifm-progress {
    margin-bottom: 40px;
    position: sticky;
    top: 0;
    background: var(--ifm-bg);
    padding: 16px 0;
    z-index: 100;
    border-bottom: 1px solid var(--ifm-border);
}

.ifm-progress__bar {
    width: 100%;
    height: 6px;
    background: var(--ifm-border);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 12px;
}

.ifm-progress__fill {
    height: 100%;
    background: linear-gradient(90deg, var(--ifm-primary), var(--ifm-primary-light));
    border-radius: 3px;
    transition: width 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    width: 0%;
}

.ifm-progress__steps {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--ifm-text-light);
    font-weight: 500;
}

.ifm-progress__step {
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.3s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
    text-align: center;
}

.ifm-progress__step:hover {
    background: var(--ifm-primary-pale);
    color: var(--ifm-primary);
}

.ifm-progress__step.active {
    color: var(--ifm-primary);
    font-weight: 600;
}

.ifm-progress__step.completed {
    color: var(--ifm-primary);
}

/* ---- Sections / Cards ---- */
.ifm-section {
    display: none;
    animation: ifmFadeIn 0.4s ease;
}

.ifm-section.active {
    display: block;
}

@keyframes ifmFadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.ifm-card {
    background: var(--ifm-bg);
    border: 1px solid var(--ifm-border);
    border-radius: var(--ifm-radius);
    padding: 32px;
    margin-bottom: 24px;
    box-shadow: var(--ifm-shadow);
    transition: box-shadow 0.3s;
}

.ifm-card:hover {
    box-shadow: var(--ifm-shadow-lg);
}

.ifm-card__header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--ifm-border);
}

.ifm-card__icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ifm-card__icon svg {
    width: 20px;
    height: 20px;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

.ifm-card__title {
    font-family: var(--ifm-font-display);
    font-size: 20px;
    font-weight: 600;
    color: var(--ifm-primary-dark);
}

.ifm-card__subtitle {
    font-size: 13px;
    color: var(--ifm-text-light);
    margin-top: 2px;
}

/* ---- Form Elements ---- */
.ifm-field {
    margin-bottom: 20px;
}

.ifm-field label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--ifm-text);
    margin-bottom: 6px;
    line-height: 1.5;
}

.ifm-field label .ifm-hint {
    font-weight: 400;
    color: var(--ifm-text-light);
    font-size: 12px;
    display: block;
    margin-top: 2px;
}

.ifm-field input[type="text"],
.ifm-field input[type="date"],
.ifm-field textarea,
.ifm-field select {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--ifm-border);
    border-radius: var(--ifm-radius-sm);
    font-family: var(--ifm-font-body);
    font-size: 14px;
    color: var(--ifm-text);
    background: var(--ifm-bg);
    transition: border-color 0.3s, box-shadow 0.3s;
    outline: none;
}

.ifm-field input:focus,
.ifm-field textarea:focus,
.ifm-field select:focus {
    border-color: var(--ifm-primary);
    box-shadow: 0 0 0 3px rgba(27, 107, 90, 0.1);
}

.ifm-field textarea {
    min-height: 80px;
    resize: vertical;
    line-height: 1.6;
}

.ifm-field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ---- Tag Selector ---- */
.ifm-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 6px;
}

.ifm-tag {
    padding: 8px 16px;
    border: 1.5px solid var(--ifm-border);
    border-radius: 24px;
    font-size: 13px;
    font-family: var(--ifm-font-body);
    cursor: pointer;
    transition: all 0.25s;
    background: var(--ifm-bg);
    color: var(--ifm-text-light);
    user-select: none;
}

.ifm-tag:hover {
    border-color: var(--ifm-primary);
    color: var(--ifm-primary);
    background: var(--ifm-primary-pale);
}

.ifm-tag.selected {
    background: var(--ifm-primary);
    color: #fff;
    border-color: var(--ifm-primary);
}

/* ---- Navigation Buttons ---- */
.ifm-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--ifm-border);
}

.ifm-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    border-radius: var(--ifm-radius-sm);
    font-family: var(--ifm-font-body);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    border: none;
    text-decoration: none;
}

.ifm-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.ifm-btn--primary {
    background: var(--ifm-primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(27, 107, 90, 0.3);
}

.ifm-btn--primary:hover {
    background: var(--ifm-primary-dark);
    box-shadow: 0 4px 16px rgba(27, 107, 90, 0.4);
    transform: translateY(-1px);
}

.ifm-btn--secondary {
    background: var(--ifm-bg);
    color: var(--ifm-text-light);
    border: 1.5px solid var(--ifm-border);
}

.ifm-btn--secondary:hover {
    border-color: var(--ifm-primary);
    color: var(--ifm-primary);
    background: var(--ifm-primary-pale);
}

.ifm-btn--accent {
    background: var(--ifm-accent);
    color: #fff;
}

.ifm-btn--accent:hover {
    background: #b88260;
}

.ifm-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ---- Section Titles ---- */
.ifm-section__title {
    font-family: var(--ifm-font-display);
    font-size: 24px;
    font-weight: 600;
    color: var(--ifm-primary-dark);
    margin-bottom: 8px;
}

.ifm-section__desc {
    font-size: 14px;
    color: var(--ifm-text-light);
    margin-bottom: 28px;
    line-height: 1.6;
}

/* ---- Color coded node icons ---- */
.ifm-node-assimilation { background: rgba(116, 185, 255, 0.15); }
.ifm-node-assimilation svg { stroke: #2e86de; }

.ifm-node-defense { background: rgba(253, 203, 110, 0.2); }
.ifm-node-defense svg { stroke: #d4a017; }

.ifm-node-energy { background: rgba(225, 112, 85, 0.15); }
.ifm-node-energy svg { stroke: var(--ifm-energy); }

.ifm-node-biotrans { background: rgba(162, 155, 254, 0.15); }
.ifm-node-biotrans svg { stroke: var(--ifm-biotrans); }

.ifm-node-transport { background: rgba(108, 92, 231, 0.15); }
.ifm-node-transport svg { stroke: var(--ifm-transport); }

.ifm-node-communication { background: rgba(0, 184, 148, 0.15); }
.ifm-node-communication svg { stroke: var(--ifm-communication); }

.ifm-node-structural { background: rgba(255, 118, 117, 0.15); }
.ifm-node-structural svg { stroke: var(--ifm-structural); }

/* ---- Export Section ---- */
.ifm-export-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 24px;
    justify-content: center;
}

/* ---- Final Matrix Render ---- */
.ifm-matrix-render {
    background: #fff;
    padding: 40px;
    border: 1px solid var(--ifm-border);
    border-radius: var(--ifm-radius);
}

.ifm-matrix-render__header {
    text-align: center;
    margin-bottom: 32px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--ifm-primary);
}

.ifm-matrix-render__header h2 {
    font-family: var(--ifm-font-display);
    font-size: 24px;
    color: var(--ifm-primary-dark);
    margin-bottom: 4px;
}

.ifm-matrix-render__header p {
    font-size: 13px;
    color: var(--ifm-text-light);
}

.ifm-matrix-render__patient {
    display: flex;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--ifm-primary-pale);
    border-radius: var(--ifm-radius-sm);
    margin-bottom: 24px;
    font-size: 14px;
}

.ifm-matrix-render__patient strong {
    color: var(--ifm-primary-dark);
}

/* History row */
.ifm-render-history {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.ifm-render-box {
    border: 1px solid var(--ifm-border);
    border-radius: var(--ifm-radius-sm);
    padding: 16px;
    background: var(--ifm-bg-soft);
}

.ifm-render-box h4 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--ifm-primary);
    margin-bottom: 8px;
    font-weight: 600;
}

.ifm-render-box p, .ifm-render-box ul {
    font-size: 13px;
    color: var(--ifm-text);
    line-height: 1.6;
}

.ifm-render-box ul {
    list-style: none;
    padding: 0;
}

.ifm-render-box li {
    padding: 2px 0;
}

.ifm-render-box li::before {
    content: "• ";
    color: var(--ifm-primary);
    font-weight: 700;
}

/* Nodes grid */
.ifm-render-nodes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.ifm-render-node {
    border: 1px solid var(--ifm-border);
    border-radius: var(--ifm-radius-sm);
    padding: 16px;
    border-left: 4px solid var(--ifm-primary);
}

.ifm-render-node h4 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ifm-render-node p {
    font-size: 12px;
    color: var(--ifm-text);
    line-height: 1.5;
}

.ifm-render-node--assimilation { border-left-color: #74B9FF; }
.ifm-render-node--defense { border-left-color: #FDCB6E; }
.ifm-render-node--energy { border-left-color: #E17055; }
.ifm-render-node--biotrans { border-left-color: #A29BFE; }
.ifm-render-node--transport { border-left-color: #6C5CE7; }
.ifm-render-node--communication { border-left-color: #00B894; }
.ifm-render-node--structural { border-left-color: #FF7675; }

/* Lifestyle row */
.ifm-render-lifestyle {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.ifm-render-lifestyle-item {
    text-align: center;
    padding: 14px 10px;
    border: 1px solid var(--ifm-border);
    border-radius: var(--ifm-radius-sm);
    background: var(--ifm-bg-soft);
}

.ifm-render-lifestyle-item h5 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--ifm-primary);
    margin-bottom: 6px;
}

.ifm-render-lifestyle-item p {
    font-size: 12px;
    color: var(--ifm-text);
    line-height: 1.4;
}

.ifm-render-mental {
    text-align: center;
    padding: 16px;
    background: var(--ifm-primary-pale);
    border-radius: var(--ifm-radius-sm);
    margin-bottom: 16px;
}

.ifm-render-mental h4 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--ifm-primary-dark);
    margin-bottom: 6px;
}

.ifm-render-mental p {
    font-size: 13px;
    color: var(--ifm-text);
}

/* CC */
.ifm-render-cc {
    text-align: center;
    padding: 14px;
    border: 2px solid var(--ifm-primary);
    border-radius: var(--ifm-radius-sm);
    margin-bottom: 24px;
}

.ifm-render-cc h4 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--ifm-primary);
    margin-bottom: 4px;
}

.ifm-render-cc p {
    font-size: 14px;
    font-weight: 500;
    color: var(--ifm-text);
}

.ifm-render-footer {
    text-align: center;
    padding-top: 16px;
    border-top: 1px solid var(--ifm-border);
    font-size: 11px;
    color: var(--ifm-text-light);
}

/* ---- Loading overlay ---- */
.ifm-loading {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.92);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 16px;
}

.ifm-loading.active {
    display: flex;
}

.ifm-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--ifm-border);
    border-top-color: var(--ifm-primary);
    border-radius: 50%;
    animation: ifmSpin 0.8s linear infinite;
}

@keyframes ifmSpin {
    to { transform: rotate(360deg); }
}

.ifm-loading p {
    font-size: 14px;
    color: var(--ifm-text-light);
    font-weight: 500;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .ifm-matrix-wrap {
        padding: 0 12px;
    }
    .ifm-header h1 {
        font-size: 24px;
    }
    .ifm-card {
        padding: 20px;
    }
    .ifm-field-row {
        grid-template-columns: 1fr;
    }
    .ifm-render-history {
        grid-template-columns: 1fr;
    }
    .ifm-render-nodes {
        grid-template-columns: 1fr;
    }
    .ifm-render-lifestyle {
        grid-template-columns: 1fr 1fr;
    }
    .ifm-progress__steps {
        display: none;
    }
    .ifm-export-actions {
        flex-direction: column;
    }
    .ifm-matrix-render {
        padding: 20px;
    }
}

@media print {
    .ifm-progress,
    .ifm-nav,
    .ifm-export-actions,
    .ifm-header,
    .ifm-btn {
        display: none !important;
    }
    .ifm-matrix-render {
        border: none;
        box-shadow: none;
        padding: 20px;
    }
    .ifm-matrix-wrap {
        max-width: 100%;
    }
    @page {
        size: letter;
        margin: 1cm;
    }
}
