/* ==========================================================================
   ITI DesignSpec — Design System
   Single source of truth for typography, colors, spacing, and shared components.
   Loaded after Bootstrap 5.3 so custom properties take precedence.
   ========================================================================== */

/* ---------- 1. CSS Custom Properties (Design Tokens) -------------------- */

:root {
    /* ---- Typography ---------------------------------------------------- */
    --font-primary: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --font-mono: 'Consolas', 'Courier New', monospace;

    --font-size-base: 1rem;       /* 16px */
    --font-size-sm: 0.875rem;     /* 14px */
    --font-size-xs: 0.75rem;      /* 12px */
    --font-size-2xs: 0.6875rem;   /* 11px — dense chips / legends only */

    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;

    /* ---- Modular type scale (Major Third ≈ 1.25) ----------------------- */
    --h1-size: 2.441rem;   /* ~39px */
    --h2-size: 1.953rem;   /* ~31px */
    --h3-size: 1.563rem;   /* ~25px */
    --h4-size: 1.25rem;    /* ~20px */
    --h5-size: 1rem;        /* 16px */
    --h6-size: 0.875rem;   /* ~14px */

    /* ---- Brand green ramp (ITI forest green) --------------------------- */
    /* Official ITI Australia brand primary is forest green #084830 (anchored
       on --green-700). Primitives below match docs/plan_theme_brand_alignment.md
       §3.1 so the full theme migration builds on this ramp without forking it.
       Contrast ratios in that doc are vs white. Phase 0 establishes the ramp and
       points the --iti-* semantic family at it; per-surface/Bootstrap-utility
       clean-ups remain that separate migration plan. */
    --green-50: #F0F4F3;
    --green-100: #E1E9E6;
    --green-200: #BFCFC9;
    --green-300: #97B2A8;
    --green-400: #668E7F;
    --green-500: #396D59;
    --green-600: #1C5741;
    --green-700: #084830;   /* THE ITI BRAND PRIMARY (anchor) */
    --green-800: #004030;
    --green-900: #04281A;

    /* ---- Color palette ------------------------------------------------- */
    /* Semantic brand tokens now resolve through the forest-green ramp above
       (was off-brand blue #2c5282 / #1a365d). --iti-accent stays as-is until
       the timber ramp lands in the theme migration. */
    --iti-primary: var(--green-700);        /* #084830 */
    --focus-ring: var(--green-700);         /* keyboard focus outline (brand) */
    --focus-ring-on-dark: #ffffff;          /* focus on green chrome (sidebar / optional dark navbar) */
    --iti-primary-dark: var(--green-800);   /* #004030 */
    --iti-secondary: var(--green-500);      /* #396D59 */
    --iti-accent: #ed8936;

    /* Status */
    --color-success: #198754;
    --color-danger: #dc3545;
    --color-warning: #ffc107;
    --color-info: #0dcaf0;
    /* Text on the muted status surfaces below (Bootstrap emphasis set) */
    --color-success-emphasis: #0f5132;
    --color-danger-emphasis: #842029;
    --color-warning-emphasis: #664d03;

    /* Neutrals */
    --gray-50: #f8f9fa;
    --gray-100: #e9ecef;
    --gray-200: #dee2e6;
    --gray-300: #ced4da;
    --gray-400: #adb5bd;
    --gray-500: #6c757d;
    --gray-600: #6c757d;
    --gray-700: #495057;
    --gray-800: #343a40;
    --gray-900: #212529;

    /* ---- Semantic text colors (single source for body / muted text) ---- */
    --text-heading: var(--iti-primary);
    --text-body: var(--gray-800);     /* #343a40 default copy */
    --text-muted: var(--gray-500);    /* #6c757d secondary / hints */
    --text-subtle: var(--gray-400);   /* #adb5bd faint / placeholders */

    /* Surfaces */
    --surface-white: #ffffff;
    --surface-bg: var(--gray-50);
    --surface-chrome: var(--green-800); /* #004030 — navbar + members rail */
    --surface-warning-muted: #fff3cd;
    --surface-success-muted: #d1e7dd;
    --surface-danger-muted: #f8d7da;
    --iti-primary-soft: var(--green-100);  /* #E1E9E6 active-row / selection tint (was blue #e7f1ff) */

    /* Published span-table load-case bands (non-status presentation tones) */
    --span-matrix-band-green-bg: #2E5E46;
    --span-matrix-band-blue-bg: #1D4E66;
    --span-matrix-band-orange-bg: #9B441C;
    --span-matrix-band-text: var(--surface-white);

    /* Visualizer / diagram semantic colors */
    --color-beam: #8B4513;
    --color-udl: #4169E1;

    /* ---- Spacing scale ------------------------------------------------- */
    --space-1: 0.25rem;   /* 4px  */
    --space-2: 0.5rem;    /* 8px  */
    --space-3: 0.75rem;   /* 12px */
    --space-4: 1rem;      /* 16px */
    --space-5: 1.5rem;    /* 24px */
    --space-6: 2rem;      /* 32px */
    --space-8: 3rem;      /* 48px */

    /* ---- Shadows ------------------------------------------------------- */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 25px rgba(0, 0, 0, 0.15);

    /* ---- Borders & radii ----------------------------------------------- */
    --border-radius: 8px;
    --border-color: var(--gray-200);

    /* ---- Bootstrap 5.3 brand override (forest green) ------------------- */
    /* Redefining --iti-primary does NOT reach Bootstrap utilities on its own
       (they read their own --bs-* set). Anchor Bootstrap's primary + link
       colours on #084830 so btn-primary / links / focus pick up the brand. */
    --bs-primary: #084830;
    --bs-primary-rgb: 8, 72, 48;
    --bs-link-color: #084830;
    --bs-link-color-rgb: 8, 72, 48;
    --bs-link-hover-color: #004030;
    --bs-link-hover-color-rgb: 0, 64, 48;
    --bs-focus-ring-color: rgba(8, 72, 48, 0.25);
}

/* Bootstrap .btn-primary / .btn-outline-primary read their own --bs-btn-*
   set, so the :root --bs-primary override above is not enough — pin the
   button component variables (and the .text-primary utility used by
   spinners/placeholders) to the green ramp. */
.btn-primary {
    --bs-btn-bg: var(--green-700);
    --bs-btn-border-color: var(--green-700);
    --bs-btn-hover-bg: var(--green-800);
    --bs-btn-hover-border-color: var(--green-800);
    --bs-btn-active-bg: var(--green-800);
    --bs-btn-active-border-color: var(--green-800);
}

.btn-outline-primary {
    --bs-btn-color: var(--green-700);
    --bs-btn-border-color: var(--green-700);
    --bs-btn-hover-bg: var(--green-700);
    --bs-btn-hover-border-color: var(--green-700);
    --bs-btn-active-bg: var(--green-700);
    --bs-btn-active-border-color: var(--green-700);
}

.text-primary {
    color: var(--green-700) !important;
}

/* ---------- 2. Base elements -------------------------------------------- */

body {
    font-family: var(--font-primary);
    background-color: var(--surface-bg);
    color: var(--gray-900);
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-primary);
    font-weight: var(--font-weight-bold);
    color: var(--iti-primary);
    line-height: 1.2;
    margin-bottom: 0.5em;
}

h1 { font-size: var(--h1-size); }
h2 { font-size: var(--h2-size); }
h3 { font-size: var(--h3-size); }
h4 { font-size: var(--h4-size); }
h5 { font-size: var(--h5-size); }
h6 { font-size: var(--h6-size); }

/* ---------- 3. Navigation ---------------------------------------------- */

.navbar-brand {
    font-weight: var(--font-weight-bold);
    color: var(--iti-primary) !important;
}

/* ---------- 4. Cards --------------------------------------------------- */

.card-member {
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
    border: 2px solid transparent;
}

.card-member:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
    border-color: var(--iti-primary);
}

.card-member.planned {
    opacity: 0.6;
    cursor: not-allowed;
}

.card-member.planned:hover {
    transform: none;
    border-color: transparent;
}

.badge-planned {
    background-color: var(--gray-500);
}

.badge-active {
    background-color: var(--iti-secondary);
}

/* ---------- 5. Form sections ------------------------------------------- */

.form-section,
.param-section {
    background: var(--surface-white);
    border-radius: var(--border-radius);
    padding: var(--space-5);
    margin-bottom: var(--space-5);
    box-shadow: var(--shadow-sm);
}

.form-section h5,
.param-section h5 {
    color: var(--iti-primary);
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-2);
    border-bottom: 2px solid var(--gray-100);
}

.section-checkbox {
    margin-right: var(--space-4);
    margin-bottom: var(--space-2);
}

/* ---------- 6. Buttons ------------------------------------------------- */

.btn-generate {
    background-color: var(--iti-primary);
    border-color: var(--iti-primary);
    padding: var(--space-3) var(--space-6);
    font-size: 1.1rem;
}

.btn-generate:hover {
    background-color: var(--iti-primary-dark);
}

/* ---------- 7. Results tables ------------------------------------------ */

.results-table th {
    background-color: var(--iti-primary);
    color: var(--surface-white);
}

.results-table .pass {
    color: var(--color-success);
    font-weight: var(--font-weight-semibold);
}

.results-table .fail {
    color: var(--color-danger);
    font-weight: var(--font-weight-semibold);
}

/* ---------- 8. Loading overlay ----------------------------------------- */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loading-overlay.hidden {
    display: none;
}

.progress-info {
    margin-top: var(--space-4);
    font-size: 1.1rem;
    color: var(--iti-primary);
}

.overlay-spinner {
    width: 4rem;
    height: 4rem;
}

/* ---------- 9. Footer -------------------------------------------------- */

footer {
    background-color: var(--gray-800);
    color: var(--gray-400);
    padding: var(--space-5) 0;
    margin-top: var(--space-8);
}

/* ---------- 10. Span table form components ----------------------------- */

/* Section group (collapsible section list in span table forms) */
.section-group-content {
    max-height: 300px;
    overflow-y: auto;
}

.section-group-header {
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

.section-group-header:hover {
    background-color: var(--gray-100) !important;
}

.section-group.collapsed .section-group-content {
    display: none !important;
}

.section-group.collapsed .bi-chevron-down {
    transform: rotate(-90deg);
}

.bi-chevron-down {
    transition: transform 0.2s ease;
}

.section-group-content.collapsed {
    display: none;
}

.section-scroll-body {
    max-height: 1000px;
    overflow-y: auto;
}

.hidden-block {
    display: none;
}

/* Progress bars (span table generation) */
.progress-thin {
    height: 8px;
}

.progress-zero {
    width: 0%;
}

.progress-container {
    display: none;
}

.progress-container.active {
    display: block;
}

.progress-track {
    height: 24px;
}

.progress-initial {
    width: 0%;
}

/* Parameter column toggle */
.param-col.hidden {
    display: none;
}

/* Cambered badge (replaces inline font-size:0.7em) */
.badge-cambered {
    font-size: 0.7em;
}

/* ---------- 11. Design form components --------------------------------- */

/* Input groups */
.input-group-text {
    min-width: 50px;
}

.span-input {
    max-width: 100px;
}

.results-hidden {
    display: none;
}

.spinner-xl {
    width: 3rem;
    height: 3rem;
}

.clickable-header {
    cursor: pointer;
}

/* Result cards with pass/fail indicators */
.result-card {
    transition: all 0.3s;
}

.result-card.pass {
    border-left: 4px solid var(--color-success);
}

.result-card.fail {
    border-left: 4px solid var(--color-danger);
}

.utilization-bar {
    height: 8px;
    border-radius: 4px;
}

.combo-badge {
    font-size: var(--font-size-xs);
}

/* Log / calculation output */
.log-output,
.calc-log-output {
    overflow-y: auto;
    white-space: pre-wrap;
    font-family: var(--font-mono);
}

.log-output {
    max-height: 1600px;
    font-size: 0.8rem;
    background: var(--gray-50);
}

.calc-log-output {
    max-height: 500px;
    font-size: var(--font-size-xs);
}

.log-output-large {
    max-height: 960px;
    overflow: auto;
}

/* Section selector items (design forms) */
.section-select-item {
    cursor: pointer;
    padding: var(--space-2) var(--space-3);
    border-radius: 4px;
}

.section-select-item:hover {
    background: var(--gray-100);
}

.section-select-item.selected {
    background: var(--iti-primary);
    color: var(--surface-white);
}

/* Pass / fail text (wall framing & general) */
.result-pass {
    color: var(--color-success);
    font-weight: var(--font-weight-semibold);
}

.result-fail {
    color: var(--color-danger);
    font-weight: var(--font-weight-semibold);
}

/* Stress ratio (wall framing) */
.stress-ratio {
    font-family: var(--font-mono);
}

/* ---------- 12. Wall framing / Excel-backed components ----------------- */

.excel-warning {
    background: var(--surface-warning-muted);
    border: 1px solid var(--color-warning);
    border-radius: var(--border-radius);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
}

.excel-ok {
    background: var(--surface-success-muted);
    border: 1px solid var(--color-success);
    border-radius: var(--border-radius);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
}

.grade-column {
    min-width: 200px;
}

.grade-card {
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    padding: var(--space-3);
    margin-bottom: var(--space-2);
}

.grade-card .section-list {
    max-height: 200px;
    overflow-y: auto;
}

/* Inline spinner (product loading etc.) */
.loading-spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--gray-200);
    border-top-color: var(--iti-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---------- 13. Index page --------------------------------------------- */

.section-card {
    border: none;
    box-shadow: var(--shadow-md);
}

.nav-pills .nav-link {
    font-weight: var(--font-weight-semibold);
    border-radius: 999px;
}

.nav-pills .nav-link.active {
    background-color: var(--iti-primary);
}

.home-category-title {
    color: var(--iti-primary);
    font-size: var(--h4-size);
    font-weight: var(--font-weight-bold);
}

/* Optional one-liner under a Home card title (same voice as .page-header__sub). */
.home-category-sub {
    margin: -0.5rem 0 1rem;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.home-launcher-btn {
    min-width: 10rem;
}

.home-page .home-tab-nav {
    margin-bottom: var(--space-4);
}

.about-page .breadcrumb {
    margin-bottom: var(--space-4);
}

/* ---------- 14. Responsive breakpoints --------------------------------- */

/* Tablet: reduce heading sizes, adjust layout */
@media (max-width: 991.98px) {
    h1 { font-size: calc(var(--h1-size) * 0.85); }
    h2 { font-size: calc(var(--h2-size) * 0.85); }
    h3 { font-size: calc(var(--h3-size) * 0.9); }
}

/* Small devices: further scale, single-column */
@media (max-width: 767.98px) {
    h1 { font-size: calc(var(--h1-size) * 0.7); }
    h2 { font-size: calc(var(--h2-size) * 0.75); }
    h3 { font-size: calc(var(--h3-size) * 0.8); }

    .form-section,
    .param-section {
        padding: var(--space-4);
        margin-bottom: var(--space-4);
    }

    .btn-generate {
        width: 100%;
        padding: var(--space-3) var(--space-4);
    }
}

/* Extra small: compact spacing */
@media (max-width: 575.98px) {
    body {
        font-size: 0.9375rem;
    }

    .form-section,
    .param-section {
        padding: var(--space-3);
    }

    footer {
        padding: var(--space-4) 0;
        margin-top: var(--space-6);
    }
}
