/* ===================================================================
   Week 3 Interactive Tools — styled to match lesson design language
   Matches: .example-box / .collapsible-section patterns in math-lessons.css
   =================================================================== */

.itm-tool {
    background-color: #fff;
    border: 2px solid #3b82f6;
    background: linear-gradient(135deg, #eff6ff 0%, #ffffff 100%);
    padding: 1.75rem;
    margin: 2em 0;
    border-radius: 1rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.06);
    transition: all 0.25s ease;
    color: #1e293b;
}

.itm-tool:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

.itm-tool h3 {
    margin-top: 0 !important;
    font-size: 1.25rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #1e40af;
}

.itm-tool h3::before {
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    content: '\f0e7';
    color: #3b82f6;
    margin-right: 0.5rem;
    font-size: 1.1rem;
}

.itm-tool > p:first-of-type {
    color: #6b7280;
    margin-bottom: 1.25rem;
}

.itm-tool fieldset {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    align-items: end;
    border: 0;
    padding: 0;
    margin: 0;
}

.itm-tool .itm-tool-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
}

.itm-tool label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: #374151;
    flex: 1;
    min-width: 0;
}

.itm-tool input[type="number"],
.itm-tool select {
    min-height: 42px;
    padding: 0.5rem 0.65rem;
    border-radius: 0.5rem;
    border: 1px solid #d1d5db;
    font: inherit;
    font-size: 0.95rem;
    background: #fff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.itm-tool input[type="number"]:focus,
.itm-tool select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.itm-tool input[type="number"]:focus-visible,
.itm-tool select:focus-visible,
.itm-tool button:focus-visible {
    outline: 3px solid #fbbf24;
    outline-offset: 2px;
}

.itm-tool button {
    min-height: 42px;
    padding: 0.5rem 1.5rem;
    border-radius: 0.5rem;
    border: 0;
    background: #3b82f6;
    color: #fff;
    font: inherit;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
    white-space: nowrap;
}

.itm-tool button:hover {
    background: #2563eb;
    transform: translateY(-1px);
}

.itm-tool button:active {
    transform: translateY(0);
}

.itm-tool button.itm-tool-secondary {
    background: #e5e7eb;
    color: #374151;
}

.itm-tool button.itm-tool-secondary:hover {
    background: #d1d5db;
}

.itm-tool button.itm-tool-danger {
    background: #fee2e2;
    color: #b91c1c;
}

.itm-tool button.itm-tool-danger:hover {
    background: #fecaca;
}

.itm-tool canvas {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 1.25rem auto 0;
    border: 1px solid #cbd5e1;
    border-radius: 0.5rem;
    background: #fff;
}

.itm-tool [role="status"] {
    margin-top: 1.25rem;
    padding: 0.85rem 1rem;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 0.5rem;
    color: #166534;
    font-size: 0.95rem;
    line-height: 1.5;
}

.itm-tool .itm-tool-lines {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.itm-tool .itm-tool-line-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.375rem;
    font-size: 0.85rem;
}

.itm-tool .itm-tool-line-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.15);
}

@media (max-width: 600px) {
    .itm-tool {
        padding: 1.25rem;
    }

    .itm-tool fieldset {
        grid-template-columns: 1fr;
    }

    .itm-tool .itm-tool-row {
        flex-direction: column;
        align-items: stretch;
    }

    .itm-tool button {
        width: 100%;
    }
}

@media (min-width: 768px) {
    .itm-tool fieldset.itm-tool-row-4 {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Tabs */
.itm-tool-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.itm-tool-tab {
    min-height: 38px;
    padding: 0.4rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid #d1d5db;
    background: #fff;
    color: #374151;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.itm-tool-tab:hover {
    border-color: #3b82f6;
}

.itm-tool-tab.active {
    background: #3b82f6;
    color: #fff;
    border-color: #3b82f6;
}

/* Graph Family Sorter display */
.itm-sorter-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    margin: 1rem 0;
}

.itm-sorter-equation {
    font-size: 1.15rem;
    text-align: center;
    min-height: 1.5rem;
}

.itm-sorter-score {
    font-weight: 600;
    color: #6b7280;
    margin-top: 0.5rem;
}

/* MathJax result containers */
.itm-tool [data-function-result],
.itm-tool [data-detect-result] {
    margin-top: 1.25rem;
    padding: 1rem;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 0.5rem;
    color: #166534;
    font-size: 0.95rem;
    line-height: 1.8;
    overflow-x: auto;
}

/* Function Explorer: aligned definitions and parameters. */
.itm-function-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.itm-function-card {
    min-width: 0;
    padding: 1rem;
    border: 1px solid #dbeafe;
    border-radius: 0.75rem;
    background: #f8fbff;
}

.itm-function-card legend {
    padding: 0 0.35rem;
    color: #1d4ed8;
    font-weight: 700;
}

.itm-function-card > label,
.itm-function-parameters label,
.itm-function-input-row label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #374151;
}

.itm-function-parameters {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.65rem;
    margin-top: 0.75rem;
}

.itm-function-parameters input,
.itm-function-card select,
.itm-function-input-row input {
    width: 100%;
    min-height: 2.5rem;
    box-sizing: border-box;
}

.itm-function-input-row {
    align-items: end;
}

.itm-sorter-status {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin: 0.75rem 0;
    color: #4b5563;
    font-weight: 600;
}

.itm-sorter-status p,
.itm-sorter-actions {
    margin: 0;
}

.itm-sorter-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

@media (max-width: 600px) {
    .itm-tool-tabs {
        flex-direction: column;
    }

    .itm-tool-tab {
        width: 100%;
    }

    .itm-function-grid,
    .itm-function-parameters {
        grid-template-columns: 1fr;
    }

    .itm-sorter-status {
        flex-direction: column;
        gap: 0.25rem;
    }
}
