/* ==========================================================================
   Itqan Tools — AI Math & Science Solver
   Matches the site's calc-tool design system (black/white + blue accent)
   ========================================================================== */

/* Guide button — identical to the other tools */
.merge-sidebar-help-btn {
    width: 100%;
    margin: 0 0 0.85rem;
    padding: 0.55rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 600;
    border: 1px dashed #dee2e6;
    border-radius: 8px;
    background: #fff;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.merge-sidebar-help-btn:hover {
    background: #f8f9fa;
    border-color: #adb5bd;
    color: #111;
}

.ms-container .ms-label,
.ms-container label {
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 0.4rem;
    display: block;
}

/* Subject select — same look as calc form-select */
.ms-subject { cursor: pointer; }

/* keep the two columns the same height */
.ms-col { display: flex; flex-direction: column; }

/* Equation input box */
.ms-textarea-wrap {
    position: relative;
    border: 2px solid #dee2e6;
    border-radius: 12px;
    background: #fff;
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
    flex: 1 1 auto;
    display: flex;
}
.ms-textarea-wrap:focus-within {
    border-color: #000;
    box-shadow: 0 0 0 0.2rem rgba(0, 0, 0, 0.08);
}
.ms-textarea {
    width: 100%;
    border: 0;
    background: transparent;
    resize: vertical;
    padding: 0.8rem 1rem 2.8rem;
    font-size: 1.05rem;
    color: #1a1d23;
    min-height: 150px;
    font-family: 'Cairo', system-ui, sans-serif;
    line-height: 1.7;
    /* keep pasted equations on one visual line where possible */
    white-space: pre-wrap;
    word-break: break-word;
}
.ms-textarea:focus { outline: none; }
.ms-keypad-toggle {
    position: absolute;
    inset-inline-end: 0.65rem;
    bottom: 0.55rem;
    width: 36px;
    height: 32px;
    border: 1px solid #dfe3e7;
    border-radius: 8px;
    background: #f8f9fa;
    color: #1a1d23;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
}
.ms-keypad-toggle::after {
    content: attr(data-tooltip);
    position: absolute;
    inset-inline-end: 0;
    bottom: calc(100% + 8px);
    min-width: 220px;
    max-width: 260px;
    padding: 0.45rem 0.65rem;
    border-radius: 8px;
    background: #111;
    color: #fff;
    font-size: 0.74rem;
    font-weight: 600;
    line-height: 1.45;
    text-align: center;
    white-space: normal;
    opacity: 0;
    visibility: hidden;
    transform: translateY(4px);
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
    pointer-events: none;
    z-index: 5;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}
.ms-keypad-toggle::before {
    content: "";
    position: absolute;
    inset-inline-end: 10px;
    bottom: calc(100% + 2px);
    border: 6px solid transparent;
    border-top-color: #111;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
    pointer-events: none;
    z-index: 6;
}
.ms-keypad-toggle:hover::after,
.ms-keypad-toggle:focus-visible::after,
.ms-keypad-toggle:hover::before,
.ms-keypad-toggle:focus-visible::before {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.ms-keypad-toggle:hover,
.ms-keypad-toggle[aria-expanded="true"] {
    background: #000;
    color: #fff;
    border-color: #000;
}

/* ==========================================================================
   Expandable equation editor
   ========================================================================== */
.ms-keypad {
    margin-top: 1.1rem;
    border: 1px solid #dfe3e7;
    border-radius: 16px;
    background: #fff;
    overflow: hidden;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.08);
    position: sticky;
    bottom: 0;
    z-index: 4;
    animation: none;
}
.ms-keypad[hidden] { display: none !important; }
.ms-keypad.is-opening {
    animation: ms-keypad-open 0.2s ease both;
}
@keyframes ms-keypad-open {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
.ms-keypad-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 0.95rem;
    background: linear-gradient(145deg, #2a2a2a 0%, #000 100%);
    color: #fff;
    font-weight: 700;
    font-size: 0.9rem;
}
.ms-keypad-head > div { display: flex; align-items: center; gap: 0.5rem; }
.ms-keypad-head i { opacity: 0.9; }
.ms-keypad-close {
    width: 30px;
    height: 30px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}
.ms-keypad-close:hover { background: #fff; color: #000; }
.ms-keypad-hint {
    margin: 0;
    padding: 0.65rem 0.85rem;
    color: #6c757d;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    font-size: 0.78rem;
    text-align: center;
}
.ms-editor-layout {
    display: grid;
    grid-template-columns: minmax(260px, 0.85fr) minmax(330px, 1.15fr);
    gap: 0.85rem;
    padding: 0.85rem;
}
.ms-basic-pad {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.45rem;
    align-content: start;
}
.ms-special-pad {
    min-width: 0;
    border: 1px solid #e6e8eb;
    border-radius: 12px;
    overflow: hidden;
}
.ms-keypad-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: #f8f9fa;
    border-bottom: 1px solid #e6e8eb;
}
.ms-keypad-tab {
    position: relative;
    border: 0;
    background: transparent;
    color: #495057;
    padding: 0.75rem 0.35rem;
    font-size: 0.82rem;
    font-weight: 800;
}
.ms-keypad-tab::after {
    content: "";
    position: absolute;
    inset-inline: 18%;
    bottom: 0;
    height: 3px;
    border-radius: 3px 3px 0 0;
    background: transparent;
}
.ms-keypad-tab:hover,
.ms-keypad-tab.is-active { color: #000; }
.ms-keypad-tab.is-active::after { background: #000; }
.ms-special-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.45rem;
    padding: 0.65rem;
}
.ms-special-grid[hidden] { display: none !important; }
.ms-special-grid.is-active { animation: none; }
.ms-special-grid.is-active.ms-anim { animation: ms-key-group 0.16s ease both; }
@keyframes ms-key-group {
    from { opacity: 0; transform: translateX(5px); }
    to { opacity: 1; transform: translateX(0); }
}
.ms-key {
    min-width: 0;
    height: 42px;
    border: 1px solid #dee2e6;
    background: #fff;
    border-radius: 9px;
    color: #1a1d23;
    font-weight: 700;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transform: none !important;
}
.ms-key:hover { background: #000; color: #fff; border-color: #000; }
.ms-key:active { background: #111; color: #fff; border-color: #111; transform: none !important; }
.ms-key:focus { outline: none; }
.ms-key--op { background: #f0f1f3; }
.ms-key--fn { background: #f0f1f3; font-size: 0.8rem; font-weight: 800; }
.ms-key--var { color: #444; font-style: italic; }
.ms-key--act { background: #1a1d23; color: #fff; border-color: #1a1d23; }
.ms-key--act:hover { background: #000; }

@media (max-width: 767.98px) {
    .ms-editor-layout { grid-template-columns: 1fr; }
}
@media (max-width: 575.98px) {
    .ms-editor-layout { gap: 0.65rem; padding: 0.6rem; }
    .ms-basic-pad,
    .ms-special-grid { gap: 0.35rem; }
    .ms-key { height: 40px; font-size: 0.9rem; }
    .ms-keypad-tab { font-size: 0.76rem; padding-inline: 0.15rem; }
}

/* Upload area — same dashed style as PDF tools */
.ms-dropzone {
    position: relative;
    border: 2px dashed #dee2e6;
    border-radius: 12px;
    background: #fff;
    min-height: 220px;
    height: 100%;
    padding: 1.5rem 1rem;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s ease;
    cursor: pointer;
}
.ms-dropzone:hover,
.ms-dropzone:focus,
.ms-dropzone.dragover {
    background: #f8f9fa;
    border-color: #000;
    outline: none;
}
.ms-drop-ic {
    width: 58px;
    height: 58px;
    margin: 0 auto 0.7rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    color: #0d6efd;
    background: #eef4ff;
    border: 2px solid #0d6efd;
}
.ms-drop-title { font-weight: 800; color: #1a1d23; margin-bottom: 0.3rem; }
.ms-drop-hint { color: #6c757d; font-size: 0.85rem; }
.ms-drop-max { color: #adb5bd; font-size: 0.78rem; margin-top: 0.35rem; }

.ms-file-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 10px;
    padding: 0.6rem 0.8rem;
    color: #1a1d23;
}
.ms-file-chip i.fa-file-lines { color: #0d6efd; }
.ms-file-name { flex: 1; font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-file-remove { border: 0; background: #eef0f2; color: #b3261e; width: 28px; height: 28px; border-radius: 8px; }
.ms-file-remove:hover { background: #ffe1e1; }

/* Solve button — full-width block, clearly separated from the inputs above */
.ms-solve-btn { display: block; width: 100%; }

/* Solve button spinner */
.ms-spinner {
    width: 18px; height: 18px; margin-inline-start: 0.5rem;
    border: 2.5px solid rgba(255, 255, 255, 0.5); border-top-color: #fff;
    border-radius: 50%; display: inline-block; vertical-align: middle;
    animation: ms-spin 0.7s linear infinite;
}
@keyframes ms-spin { to { transform: rotate(360deg); } }

/* Inline ad below the selection interface */
.ms-inline-ad {
    margin: 1.25rem auto 0;
    min-height: 90px;
    display: flex; align-items: center; justify-content: center;
    background: #fff; border: 1px solid #e9ecef; border-radius: 12px; overflow: hidden;
}
.ms-inline-ad ins { width: 100%; }

.ms-alert {
    margin-top: 1.1rem;
    background: #fff4f4; border: 1px solid #ffd4d4; color: #b3261e;
    border-radius: 12px; padding: 0.85rem 1.05rem; font-weight: 600; text-align: center;
}

.ms-subject-hint {
    margin-top: 0.55rem;
    padding: 0.6rem 0.8rem;
    border-radius: 10px;
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1.5;
    min-height: 2.6rem;
}
.ms-subject-hint.d-none {
    display: block !important;
    visibility: hidden;
    border-color: transparent !important;
    background: transparent !important;
    color: transparent !important;
    pointer-events: none;
}
.ms-subject-hint--info {
    background: #eef6ff;
    border: 1px solid #cfe2ff;
    color: #084298;
}
.ms-subject-hint--warn {
    background: #fff8e6;
    border: 1px solid #ffe08a;
    color: #7a5b00;
}

/* ==========================================================================
   Result page ("الجواب")
   ========================================================================== */
.ms-problem-box {
    background: #f8f9fa; border: 2px dashed #dee2e6; border-radius: 12px;
    padding: 0.9rem 1.1rem; margin-bottom: 1.25rem;
}
.ms-problem-label { font-size: 0.78rem; font-weight: 700; color: #6c757d; margin-bottom: 0.3rem; }
.ms-problem-text { font-size: 1.05rem; color: #1a1d23; font-weight: 600; word-break: break-word; }

.ms-answer-card {
    background: linear-gradient(145deg, #2a2a2a 0%, #000 100%);
    border: 2px solid #000; border-radius: 14px;
    padding: 1.25rem 1.4rem; margin-bottom: 1.4rem; color: #fff; text-align: center;
}
.ms-answer-label {
    font-size: 0.8rem; font-weight: 700; color: rgba(255, 255, 255, 0.75);
    text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 0.4rem;
}
.ms-answer-value { font-size: 1.5rem; font-weight: 800; color: #fff; overflow-x: auto; }

.ms-sub-title {
    font-weight: 800; color: #1a1d23; font-size: 1.05rem;
    margin: 0 0 0.85rem; padding-bottom: 0.45rem; border-bottom: 2px solid #000;
    display: flex; align-items: center; gap: 0.5rem;
}
.ms-sub-title i { color: #111; }

.ms-steps-box, .ms-explain-box {
    background: #fff; border: 2px solid #e9ecef; border-radius: 14px;
    padding: 1.2rem 1.4rem; margin-bottom: 1.3rem;
}
.ms-steps { list-style: none; counter-reset: ms-step; padding: 0; margin: 0; }
.ms-steps li {
    counter-increment: ms-step; position: relative; padding-inline-start: 2.4rem;
    padding-bottom: 1rem; margin-bottom: 1rem; border-bottom: 1px dashed #e9ecef;
}
.ms-steps li:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
.ms-steps li::before {
    content: counter(ms-step); position: absolute; inset-inline-start: 0; top: 0;
    width: 1.7rem; height: 1.7rem; border-radius: 50%; background: #000; color: #fff;
    font-size: 0.8rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}
.ms-step-title { font-weight: 700; color: #1a1d23; margin-bottom: 0.3rem; }
.ms-step-prose { color: #495057; font-size: 0.95rem; margin-bottom: 0.35rem; line-height: 1.6; }
.ms-step-math { overflow-x: auto; color: #2a2f52; }

/* Hide MathJax assistive / menu chrome that looks like stray symbols */
.ms-answer-value mjx-assistive-mml,
.ms-steps mjx-assistive-mml,
.ms-explain mjx-assistive-mml,
.MathJax_Menu,
mjx-container[jax="CHTML"] > .MJX-Assistive-MathML {
    display: none !important;
}
.ms-answer-value {
    direction: ltr;
    unicode-bidi: isolate;
}
.ms-answer-value mjx-container {
    margin: 0.2rem auto !important;
}

.ms-explain { color: #2a2f52; line-height: 1.9; font-size: 1.02rem; min-width: 0; }
.ms-explain h2 {
    font-size: 1.1rem; font-weight: 800; color: #fff; margin: 1.5rem 0 0.9rem;
    background: linear-gradient(145deg, #2a2a2a 0%, #000 100%);
    padding: 0.55rem 0.95rem; border-radius: 10px; display: inline-block;
}
.ms-explain h2:first-child { margin-top: 0; }
.ms-explain h3 { font-size: 1.02rem; font-weight: 700; color: #1a1d23; margin: 1rem 0 0.5rem; }
.ms-explain p { margin-bottom: 0.7rem; overflow-wrap: anywhere; }
.ms-explain ul { padding-inline-start: 1.4rem; margin-bottom: 0.8rem; }

/* Numbered solution steps as animated cards for students */
.ms-explain ol {
    list-style: none; counter-reset: ai-step; padding: 0; margin: 0.5rem 0 1rem;
}
.ms-explain ol > li {
    counter-increment: ai-step; position: relative;
    background: #f8f9fb; border: 1px solid #e9ecef; border-inline-start: 4px solid #000;
    border-radius: 12px; padding: 0.9rem 1rem 0.9rem 1rem; margin-bottom: 0.8rem;
    padding-inline-start: 3rem;
    overflow-x: auto; overflow-y: hidden;
    animation: ms-step-in 0.4s ease both;
}
.ms-explain ol > li::before {
    content: counter(ai-step); position: absolute; inset-inline-start: 0.7rem; top: 0.85rem;
    width: 1.7rem; height: 1.7rem; border-radius: 50%;
    background: linear-gradient(145deg, #2a2a2a, #000); color: #fff;
    font-size: 0.82rem; font-weight: 800;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
}
.ms-explain ol > li:nth-child(1) { animation-delay: 0.02s; }
.ms-explain ol > li:nth-child(2) { animation-delay: 0.08s; }
.ms-explain ol > li:nth-child(3) { animation-delay: 0.14s; }
.ms-explain ol > li:nth-child(4) { animation-delay: 0.20s; }
.ms-explain ol > li:nth-child(5) { animation-delay: 0.26s; }
.ms-explain ol > li:nth-child(n+6) { animation-delay: 0.30s; }
@keyframes ms-step-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.ms-explain li { margin-bottom: 0.35rem; overflow-wrap: anywhere; }
.ms-explain code { background: #f1f3f5; padding: 0.1rem 0.35rem; border-radius: 6px; font-size: 0.92em; word-break: break-all; }
.ms-explain strong { color: #1a1d23; }

/* Keep long equations inside their boxes (scroll instead of overflowing) */
.ms-explain mjx-container,
.ms-step-math mjx-container,
.ms-answer-value mjx-container {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 2px;
}
.ms-explain mjx-container[display="true"] { display: block; }

.ms-result-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 0.5rem; }

@media (max-width: 768px) {
    .ms-dropzone { min-height: 160px; }
}
