/* ==========================================================
   AI Math Solver — exact pixel values from Figma
   ========================================================== */

/* Page wrapper — overrides the two-col flex from main-content */
.ams-page {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

/* ── Title section ── */
.ams-header {
    display: flex;
    flex-direction: column;
    gap: 14px;
    text-align: center;
    max-width: 800px;
    width: 100%;
}

.ams-title {
    font-size: 36px;
    font-weight: 700;
    line-height: 48px;
    color: #263842;
    margin: 0;
}

.ams-subtitle {
    font-size: 16px;
    font-weight: 400;
    line-height: 24px;
    color: #000;
    margin: 0;
}

/* ── Inner container (max 800 px) ── */
.ams-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
    max-width: 800px;
    width: 100%;
}

/* ── Input box ── */
.ams-input-box {
    background: #f6f8f9;
    border: 1px solid #cedae0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    align-content: stretch;
    overflow: hidden;
    width: 100%;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ams-input-box:focus-within {
    border-color: #065a8d;
}

.ams-textarea-area {
    height: 180px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    flex-shrink: 0;
    width: 100%;
    box-sizing: border-box;
}

/* ── MathQuill wrapper & placeholder ── */
.ams-mathquill-wrap {
    position: relative;
    width: 100%;
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
}

#MathInput {
    display: block;
    width: 100%;
    min-height: 100%;
    cursor: text;
}

/* Remove MathQuill's default border — only touch decoration, never layout/font props */
#MathInput,
#MathInput.mq-editable-field,
#MathInput.mq-math-mode {
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    background: transparent !important;
}

/* Let the root block follow the input height (overrides MathQuill's fixed 148px) */
#MathInput .mq-root-block {
    min-height: 0 !important;
}

/* Σ / ∏ lower limit: give it a little top spacing so it clears the operator and
   reads cleanly, without touching MathQuill's default float/layout. */
#MathInput .mq-large-operator .mq-from {
    margin-top: 10px;
}

/* nth-root with a FRACTION index (e.g. the 13/4-th root, or a mixed number 3¼):
   both renderers tuck the index into the radical notch with a big negative margin
   (KaTeX -.555em on .root, MathQuill -.6em on sup.mq-nthroot) — fine for a
   single-glyph index, but a wide fraction collides with the √ stroke. Reduce the
   overlap for fraction indices only; integer indices keep each lib's default. */
.katex .sqrt > .root:has(.mfrac),
#MathInput sup.mq-nthroot:has(.mq-fraction) {
    margin-right: -0.05em;
}

/* Show the caret only while the field is focused — no stray cursor on page load / blur */
#MathInput:not(.mq-focused) .mq-cursor {
    display: none !important;
}

#mathPlaceholder {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    color: #7a9aab;
    font-size: 16px;
    font-weight: 400;
    line-height: 24px;
}

/* ── Toolbar ── */
.ams-toolbar {
    background: #ffffff;
    border-top: 1px solid #cedae0;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    align-content: stretch;
    flex-shrink: 0;
    width: 100%;
    box-sizing: border-box;
}

.ams-toolbar-left {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

.ams-tool-btn {
    background: #ffffff;
    border: 1px solid #cedae0;
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
    color: #47677a;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.15s;
}

.ams-tool-btn:hover {
    background: #edf1f3;
}

.ams-tool-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.ams-delete-btn {
    background: #ffffff;
    border: none;
    width: 32px;
    height: 32px;
    display: none;
    /* hidden until there is something to clear */
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    transition: background 0.15s;
}

.ams-delete-btn.is-visible {
    display: flex;
}

.ams-delete-btn:hover {
    background: #edf1f3;
}

.ams-delete-btn svg {
    width: 18px;
    height: 18px;
}

/* ── Solve button ── */
.ams-solve-row {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ams-solve-btn {
    background: #065a8d;
    border: none;
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 500;
    line-height: 24px;
    color: #ffffff;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
    transition: background 0.15s;
}

.ams-solve-btn:hover {
    background: #054d78;
}

.ams-solve-btn svg {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

/* Solve button loader — replaces the arrow while waiting for a response */
.ams-solve-loader {
    display: none;
    width: 20px;
    height: 20px;
    box-sizing: border-box;
    flex-shrink: 0;
    border: 2.5px solid rgba(255, 255, 255, 0.4);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: ams-spin 0.6s linear infinite;
}

.ams-solve-btn.is-loading svg {
    display: none;
}

.ams-solve-btn.is-loading .ams-solve-loader {
    display: block;
}

@keyframes ams-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── Result box ── */
.ams-result-box {
    background: #f6f8f9;
    border: 1px solid #cedae0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 300px;
    width: 100%;
}

.ams-result-box.d-none {
    display: none !important;
}

/* Result header */
.ams-result-header {
    background: #ffffff;
    border-bottom: 1px solid #cedae0;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0;
}

.ams-result-title {
    font-size: 24px;
    font-weight: 700;
    line-height: 32px;
    color: #263842;
    flex: 1 0 0;
    min-width: 0;
}

.ams-result-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
}

.ams-action-item {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 5px 18px;
    font-size: 16px;
    font-weight: 400;
    line-height: 24px;
    color: #263842;
    cursor: pointer;
    white-space: nowrap;
    border-right: 1px solid #edf1f3;
    transition: background 0.15s;
}

.ams-action-item:hover {
    background: #f0f4f6;
}

.ams-action-item svg {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
}

/* Result body */
.ams-result-body {
    padding: 24px;
}

/* ── Question box (user's input echoed at the top of the result) ── */
.ams-question-box {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    margin-bottom: 24px;
    background: #ffffff;
    border: 1px solid #edf1f3;
}

.ams-question-label {
    flex-shrink: 0;
    align-self: flex-start;
    padding: 6px 10px;
    background: rgba(6, 90, 141, 0.04);
    color: #065a8d;
    font-size: 16px;
    font-weight: 700;
    line-height: 24px;
    white-space: nowrap;
}

.ams-question-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    min-width: 0;
    flex: 1;
}

.ams-question-text {
    font-size: 18px;
    font-weight: 400;
    line-height: 24px;
    color: #263842;
    word-break: break-word;
}

.ams-question-img {
    display: block;
    height: 80px;
    width: auto;
    max-width: 100%;
    border: 1px solid #065a8d;
    border-radius: 10px;
    object-fit: cover;
}

/* Feedback widget — pixel-match Figma (node 1856-7612). All rules scoped to
   .ams-page so the shared widget on other tools is unaffected. */
.ams-page .feedback_sections {
    width: 100%;
    max-width: 800px;
    margin-inline: auto;
}

/* Title group: centered, "We love Feedback" 18/26 w700 + subtitle 16/24 w400 */
.ams-page .feedback {
    text-align: center;
}

.ams-page .feedback-title {
    margin: 0 0 4px;
    font: 700 18px/26px "Noto Serif";
    color: #263842;
}

.ams-page .fb_section_1 > p {
    margin: 0;
    font: 400 16px/24px "Noto Serif";
    color: #263842;
}

/* Rating boxes: #f6f8f9 frame, 10px pad, fit-content centered, gap 20 above */
.ams-page .feedback_boxes {
    width: fit-content;
    margin: 20px auto 0;
    padding: 10px;
    gap: 0;
    justify-content: center;
    background-color: #f6f8f9;
}

/* Each box 88px wide, icon 24, label 14/20 w400 */
.ams-page .rating_box {
    width: 88px;
    gap: 8px;
}

.ams-page .rating_box img {
    height: 24px;
    width: 24px;
}

.ams-page .rating_box span {
    font: 400 14px/20px "Noto Serif";
    color: #263842;
}

/* Detail state after a rating click (Figma node 1856-7708): subtitle + input row.
   Back arrow is absent from the design, so hide it on this page. */
.ams-page .feedback_detail > div:first-child > p {
    margin: 0;
    font: 400 16px/24px "Noto Serif";
    color: #263842;
    text-align: center;
}

.ams-page .feedback-back-btn {
    display: none;
}

.ams-page .feedback_input {
    width: fit-content;
    max-width: 100%;
    margin: 20px auto 0;
    padding-top: 0;
    gap: 16px;
    justify-content: center;
}

.ams-page #feedback_msg {
    width: 349px;
    max-width: 100%;
    height: 40px;
    padding: 10px 16px;
    border: 1px solid #767676;
    background: #fff;
    font: 400 14px/20px "Noto Serif";
    color: #263842;
}

.ams-page .feedback_input button.fb_button {
    width: auto;
    height: 40px;
    padding: 8px 15px;
    gap: 2px;
    background: #065a8d;
    color: #fff;
    font: 500 16px/24px "Noto Serif";
}

/* Answer section */
.ams-answer-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.ams-answer-value {
    font-size: 16px;
    font-weight: 400;
    line-height: 1.8;
    color: #263842;
    margin: 0;
    word-break: break-word;
}

/* Step spacing — the global `* { margin: 0 }` reset strips the default block
   margins, so we space the step headings and centered equation blocks here
   (instead of relying on stray <br> the model emits inconsistently). A larger
   gap before each step heading, a tighter gap around its equations. */
.ams-answer-value > p {
    margin: 18px 0 6px;
}

.ams-answer-value > div {
    margin: 6px 0;
}

.ams-answer-value > :first-child {
    margin-top: 0;
}

.ams-answer-value .katex {
    font-size: 1.05em;
    line-height: normal;
    vertical-align: middle;
}

/* Inline fractions: keep numerator/denominator clear of the container line-height */
.ams-answer-value .katex .mfrac {
    line-height: normal;
}

/* Powers / subscripts a touch smaller */
.ams-answer-value .katex .mtight {
    font-size: 0.85em !important;
}

.ams-answer-value .katex-display {
    margin: 0.6em 0;
    overflow-x: auto;
    overflow-y: hidden;
}

/* Final answer box: size to the matrix and never show a scrollbar — the
   final result should always be displayed in full. */
.ams-answer-value .final-answer .katex-display {
    width: max-content;
    max-width: 100%;
    margin: 0.4em auto;
    overflow-x: visible;
    overflow-y: visible;
}

/* Steps section */
.ams-steps-section {
    display: flex;
    flex-direction: column;
    gap: 36px;
    padding-top: 36px;
}

/* ── Ask More row ── */
.ams-ask-more-row {
    display: flex;
    align-items: center;
    justify-content: center;
    padding-bottom: 16px;
}

.ams-ask-more-btn {
    background: #263842;
    border: none;
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 500;
    line-height: 24px;
    color: #ffffff;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
    transition: background 0.15s;
}

.ams-ask-more-btn:hover {
    background: #1a2830;
}

.ams-ask-more-btn svg {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

/* ==========================================================
   Math Keyboard  (exact values from Figma node 1515:2014)
   ========================================================== */
.ams-keyboard {
    background: #ffffff;
    border: 1px solid #edf1f3;
    box-shadow: 0px 0px 48px -8px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    width: 100%;
    overflow: hidden;
}

.ams-keyboard.d-none {
    display: none;
}

/* ── Reset global p,span overrides inside keyboard ── */
#mathKeyboard span {
    /* font-size: inherit !important; */
    line-height: 1 !important;
}

/* ── Tab row ── */
.ams-kb-tabs {
    background: #f6f8f9;
    border-bottom: 1px solid #edf1f3;
    padding: 12px;
    display: flex;
    gap: 10px;
    align-items: center;
    overflow-x: auto;
    flex-shrink: 0;
    scrollbar-width: none;
}

.ams-kb-tabs::-webkit-scrollbar {
    display: none;
}

.ams-kb-tab {
    background: #ffffff;
    border: 1px solid #edf1f3;
    padding: 8px 12px;
    font-size: 16px;
    font-weight: 500;
    line-height: 24px;
    color: #000000;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.ams-kb-tab:hover {
    background: #edf1f3;
}

.ams-kb-tab--active {
    background: #000000;
    border-color: #000000;
    color: #ffffff;
}

.ams-kb-tab--active:hover {
    background: #1a1a1a;
}

/* ── Key panels ── */
.ams-kb-panel {
    display: none;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px;
    align-items: flex-start;
    align-content: flex-start;
}

.ams-kb-panel--active {
    display: flex;
}

/* ── Individual keys ── */
#mathKeyboard .ams-kb-key {
    background: #f6f8f9;
    border: none;
    flex: 1 0 0;
    min-width: 68px;
    max-width: 76px;
    height: 48px;
    padding: 12px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px !important;
    font-weight: 600 !important;
    line-height: 1 !important;
    color: #000000 !important;
    cursor: pointer;
    font-family: inherit;
    text-align: center;
    white-space: nowrap;
    box-sizing: border-box;
    transition: background 0.15s;
    user-select: none;
}

#mathKeyboard .ams-kb-key:hover {
    background: #e4e9ec;
}

#mathKeyboard .ams-kb-key:active {
    background: #d0d8de;
}

#mathKeyboard .ams-kb-key--del {
    color: #47677a !important;
}

/* ── Fraction label inside key ── */
#mathKeyboard .kb-frac {
    display: inline-flex !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 2px !important;
    font-size: 12px !important;
    line-height: 1 !important;
}

#mathKeyboard .kb-frac-bar {
    width: 14px !important;
    height: 1px !important;
    background: currentColor !important;
    display: block !important;
}

/* ── Integral / Sigma with limits ── */
#mathKeyboard .kb-intlim {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    line-height: 1 !important;
    gap: 1px !important;
}

#mathKeyboard .kb-intlim span:nth-child(1),
#mathKeyboard .kb-intlim span:nth-child(3) {
    font-size: 9px !important;
    font-weight: 600 !important;
    opacity: 0.7 !important;
    line-height: 1 !important;
}

#mathKeyboard .kb-intlim span:nth-child(2) {
    font-size: 18px !important;
    line-height: 18px !important;
}

/* ── Matrix mini-grid (tab icon + size keys) ── */
#mathKeyboard .kb-mat {
    display: inline-grid !important;
    grid-template-columns: repeat(var(--c, 2), 1fr) !important;
    grid-template-rows: repeat(var(--r, 2), 1fr) !important;
    gap: 2px !important;
    width: 26px;
    height: 24px;
    padding: 3px 5px !important;
    position: relative;
    box-sizing: border-box;
    vertical-align: middle;
}

#mathKeyboard .kb-mat::before,
#mathKeyboard .kb-mat::after {
    content: '' !important;
    position: absolute;
    top: 0;
    bottom: 0;
    width: 3px;
    border: 1.4px solid currentColor;
}

#mathKeyboard .kb-mat::before {
    left: 0;
    border-right: 0;
    border-radius: 2px 0 0 2px;
}

#mathKeyboard .kb-mat::after {
    right: 0;
    border-left: 0;
    border-radius: 0 2px 2px 0;
}

#mathKeyboard .kb-mat i {
    display: block;
    background: currentColor;
    border-radius: 1px;
    min-width: 2px;
    min-height: 2px;
}

#mathKeyboard .kb-mat--1x1 { --r: 1; --c: 1; }
#mathKeyboard .kb-mat--1x2 { --r: 1; --c: 2; }
#mathKeyboard .kb-mat--1x3 { --r: 1; --c: 3; }
#mathKeyboard .kb-mat--1x4 { --r: 1; --c: 4; }
#mathKeyboard .kb-mat--2x1 { --r: 2; --c: 1; }
#mathKeyboard .kb-mat--2x2 { --r: 2; --c: 2; }
#mathKeyboard .kb-mat--2x3 { --r: 2; --c: 3; }
#mathKeyboard .kb-mat--2x4 { --r: 2; --c: 4; }
#mathKeyboard .kb-mat--3x1 { --r: 3; --c: 1; }
#mathKeyboard .kb-mat--3x2 { --r: 3; --c: 2; }
#mathKeyboard .kb-mat--3x3 { --r: 3; --c: 3; }
#mathKeyboard .kb-mat--3x4 { --r: 3; --c: 4; }
#mathKeyboard .kb-mat--4x1 { --r: 4; --c: 1; }
#mathKeyboard .kb-mat--4x2 { --r: 4; --c: 2; }
#mathKeyboard .kb-mat--4x3 { --r: 4; --c: 3; }
#mathKeyboard .kb-mat--4x4 { --r: 4; --c: 4; }

/* ── Matrix inserted into the Math Input (editable bracket-grid) ── */
.ams-mx {
    display: inline-grid;
    gap: 5px 5px;
    padding: 4px 10px;
    margin: 0 4px;
    /* gap so the caret isn't glued to the bracket */
    position: relative;
    vertical-align: middle;
    line-height: 1;
    align-items: center;
    justify-items: center;
    color: #263842;
}

.ams-mx::before,
.ams-mx::after {
    content: '';
    position: absolute;
    top: 1px;
    bottom: 1px;
    width: 6px;
    border: 1.6px solid currentColor;
}

.ams-mx::before {
    left: 0;
    border-right: 0;
}

.ams-mx::after {
    right: 0;
    border-left: 0;
}

.ams-mx .ams-mcell {
    min-width: 16px;
    height: 24px;
    padding: 0 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #c2ccd6;
    border-radius: 5px;
    background: #fff;
    font-size: 15px;
    color: #263842;
    outline: none;
    line-height: 1;
    white-space: nowrap;
    cursor: text;
}

.ams-mx .ams-mcell:focus {
    border-color: #065a8d;
    box-shadow: 0 0 0 1px #065a8d;
}

/* ── Active state for Math Input toolbar button ── */
.ams-tool-btn--active {
    border-color: #263842 !important;
    color: #263842 !important;
    background: #edf1f3 !important;
}

/* ==========================================================
   Responsive
   ========================================================== */

/* ── Validation shake ── */
.ams-input-box.ai-validate {
    border-color: #e53935;
    animation: ams-shake 0.3s;
}

@keyframes ams-shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-4px);
    }

    75% {
        transform: translateX(4px);
    }
}

/* ── Crop modal ── */
.ams-crop-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(38, 56, 66, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
    animation: ams-fade-in 0.2s ease-out;
}

@keyframes ams-fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.ams-crop-modal-inner {
    background: #ffffff;
    border: 1px solid #dddddd;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    width: 640px;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: ams-slide-up 0.25s ease-out;
}

@keyframes ams-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Modal header */
.ams-crop-header {
    background: #f9f9f9;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-shrink: 0;
}

.ams-crop-title {
    font-size: 18px;
    font-weight: 700;
    line-height: 28px;
    color: #263842;
    margin: 0;
}

.ams-crop-close {
    background: transparent;
    border: none;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    color: #263842;
    transition: background 0.15s;
}

.ams-crop-close:hover {
    background: #edf1f3;
}

/* Modal body — edge-to-edge cropper canvas */
.ams-crop-body {
    padding: 0;
    background: #263842;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ams-crop-image-wrap {
    width: 100%;
    height: 370px;
    background: #263842;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.ams-crop-modal-inner img#cropImage {
    display: block;
    max-width: 100%;
    max-height: 370px;
}

/* Modal actions */
.ams-crop-actions {
    background: #f9f9f9;
    padding: 16px 24px;
    display: flex;
    gap: 10px;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.ams-crop-tools {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ams-crop-tool-btn {
    background: #ffffff;
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    color: #263842;
    transition: background 0.15s, border-color 0.15s;
}

.ams-crop-tool-btn:hover {
    background: #f3f5f7;
    border-color: #d8dde2;
}

.ams-crop-tool-btn svg {
    flex-shrink: 0;
}

.ams-crop-confirm-btn {
    background: #263842;
    border: none;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 15px;
    font-size: 16px;
    font-weight: 500;
    line-height: 24px;
    color: #ffffff;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}

.ams-crop-confirm-btn:hover {
    background: #1c2b35;
}

.ams-crop-confirm-btn svg {
    flex-shrink: 0;
}

/* Cropper.js — themed handles & box */
.ams-crop-image-wrap .cropper-view-box,
.ams-crop-image-wrap .cropper-face {
    border-radius: 2px;
}

.ams-crop-image-wrap .cropper-view-box {
    outline: 2px solid #3399ff;
    outline-color: #3399ff;
}

.ams-crop-image-wrap .cropper-line,
.ams-crop-image-wrap .cropper-point {
    background-color: #3399ff;
}

.ams-crop-image-wrap .cropper-point.point-se,
.ams-crop-image-wrap .cropper-point.point-sw,
.ams-crop-image-wrap .cropper-point.point-ne,
.ams-crop-image-wrap .cropper-point.point-nw {
    width: 10px;
    height: 10px;
    opacity: 1;
}

.ams-crop-image-wrap .cropper-dashed {
    border-color: rgba(255, 255, 255, 0.6);
}

/* Replace default checkered transparency pattern with themed solid color */
.ams-crop-image-wrap .cropper-bg {
    background-image: none !important;
    background-color: #263842 !important;
}

.ams-crop-image-wrap .cropper-modal {
    background-color: #263842;
    opacity: 0.65;
}

.ams-crop-image-wrap .cropper-container {
    background-color: #263842;
}

.ams-crop-image-wrap .cropper-wrap-box,
.ams-crop-image-wrap .cropper-canvas {
    background-color: #263842;
}

/* Uploaded image preview (bottom of the input) */
.ams-image-preview {
    position: relative;
    flex-shrink: 0;
    margin-top: 8px;
}

.ams-image-preview img {
    display: block;
    height: 80px;
    width: auto;
    max-width: 100%;
    border: 1px solid #cedae0;
    border-radius: 4px;
    cursor: pointer;
    transition: border-color 0.15s, filter 0.15s;
}

.ams-image-preview img:hover {
    border-color: #065a8d;
    filter: brightness(0.88);
}

/* Locked while a request is in flight — blocks re-crop and the remove (cross) button */
.ams-image-preview.is-locked {
    pointer-events: none;
    opacity: 0.6;
}

/* "Click to re-crop" hint shown over the preview on hover */
.ams-image-preview::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 4px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
}

.ams-image-preview:hover::after {
    opacity: 1;
}

.ams-image-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: #263842;
    cursor: pointer;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.ams-image-remove:hover {
    background: #1a2832;
}

/* Drag-over highlight */
.ams-input-box.drag-over {
    border-color: #4caf50;
    border-style: dashed;
}

/* ==========================================================
   How It Works — full-width section below the in-content ad
   (exact values from Figma node 1776-6860)
   ========================================================== */
.ams-how {
    width: 100%;
    padding: 80px 0;
}

.ams-how-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 64px;
}

/* ── Header ── */
.ams-how-head {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    max-width: 600px;
    text-align: center;
}

.ams-how-eyebrow {
    font-size: 14px;
    font-weight: 700;
    line-height: 20px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: #bd7836;
}

.ams-how-headings {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ams-how-title {
    font-size: 32px;
    font-weight: 700;
    line-height: 44px;
    color: #263842;
    margin: 0;
}

.ams-how-subtitle {
    font-size: 16px;
    font-weight: 400;
    line-height: 24px;
    color: #47677A;
    margin: 0;
}

/* ── Step cards ── */
.ams-how-grid {
    display: flex;
    align-items: stretch;
    gap: 24px;
    width: 100%;
}

.ams-how-card {
    position: relative;
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 48px 32px 32px;
    background: #ffffff;
    border: 1px solid #e2e7ec;
    border-radius: 16px;
}

.ams-how-num {
    position: absolute;
    top: -16px;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #0d5b8e;
    color: #ffffff;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
}

.ams-how-icon {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    background: rgba(6, 90, 141, 0.07);
    flex-shrink: 0;
}

.ams-how-text {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
}

.ams-how-card-title {
    font-size: 18px;
    font-weight: 700;
    line-height: 30px;
    color: #065a8d;
    margin: 0;
}

.ams-how-card-desc {
    font-size: 16px;
    font-weight: 400;
    line-height: 24px;
    color: #000;
    margin: 0;
}

/* ==========================================================
   Intro header — full-width centered section (Figma node 1776-6861)
   ========================================================== */
.ams-intro {
    width: 100%;
    padding: 80px 0;
}

.ams-intro-head {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    max-width: 900px;
    margin: 0 auto;
    text-align: center;
}

/* ==========================================================
   Features grid — light-grey full-width section (Figma node 1774-11570)
   ========================================================== */
.ams-features {
    width: 100%;
    padding: 80px 0;
    background: #f6f8f9;
}

.ams-features-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 48px;
}

.ams-features-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    width: 100%;
}

.ams-feature-card {
    flex: 1 1 calc((100% - 48px) / 3);
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
    padding: 24px;
    background: #ffffff;
    border: 1px solid #e2e7ec;
    border-radius: 16px;
}

.ams-feature-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: rgba(6, 90, 141, 0.07);
    flex-shrink: 0;
}

.ams-feature-text {
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
}

.ams-feature-title {
    font-size: 18px;
    font-weight: 700;
    line-height: 30px;
    color: #065a8d;
    margin: 0;
}

.ams-feature-desc {
    font-size: 16px;
    font-weight: 400;
    line-height: 24px;
    color: #000;
    margin: 0;
}

/* ==========================================================
   FAQ accordion — two-column section (Figma node 1776-6863)
   ========================================================== */
.ams-faq {
    width: 100%;
    padding: 80px 0;
}

.ams-faq-inner {
    display: flex;
    align-items: flex-start;
    gap: 48px;
}

/* ── Left column ── */
.ams-faq-side {
    width: 440px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.ams-faq-side-head {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ams-faq-btn {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 12px 24px;
    background: #065a8d;
    color: #ffffff;
    font-size: 16px;
    font-weight: 500;
    line-height: 24px;
    text-decoration: none;
    transition: background 0.15s ease;
}

.ams-faq-btn:hover {
    background: #054b76;
    color: #ffffff;
}

/* ── Right column (accordion) ── */
.ams-faq-list {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.ams-faq-item {
    background: #ffffff;
    border: 1px solid #edf1f3;
    border-radius: 10px;
    overflow: hidden;
    transition: border-color 0.2s ease;
}

.ams-faq-item--open {
    border-color: #939393;
}

.ams-faq-q {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px 14px 22px;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
}

.ams-faq-question {
    font-size: 18px;
    font-weight: 700;
    line-height: 28px;
    color: #0d5b8e;
}

.ams-faq-icon {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Plus → minus: hide the vertical stroke when the item is open */
.ams-faq-item--open .ams-faq-icon-v {
    display: none;
}

.ams-faq-a-wrap {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.25s ease;
}

.ams-faq-item--open .ams-faq-a-wrap {
    grid-template-rows: 1fr;
}

.ams-faq-a-inner {
    overflow: hidden;
}

.ams-faq-answer {
    margin: 0;
    padding: 0 22px 22px;
    font-size: 16px;
    font-weight: 400;
    line-height: 24px;
    color: #000;
}

/* ============ Responsive: media queries (largest → smallest) ============ */

@media (max-width: 991px) {
    .ams-feature-card {
        flex-basis: calc((100% - 24px) / 2);
    }

    .ams-faq-inner {
        flex-direction: column;
        gap: 36px;
    }

    .ams-faq-side {
        width: 100%;
        gap: 28px;
    }

    .ams-faq-list {
        width: 100%;
    }
}

@media (max-width: 768px) {
    .ams-how {
        padding: 48px 0;
    }

    .ams-how-inner {
        gap: 40px;
    }

    .ams-how-grid {
        flex-direction: column;
        gap: 36px;
    }

    .ams-how-title {
        font-size: 26px;
        line-height: 36px;
    }

    .ams-intro {
        padding: 48px 0;
    }

    .ams-features {
        padding: 48px 0;
    }

    .ams-features-inner {
        gap: 36px;
    }

    .ams-feature-card {
        flex-basis: 100%;
    }

    .ams-faq {
        padding: 48px 0;
    }

    .ams-title {
        font-size: 26px;
        line-height: 36px;
    }

    .ams-subtitle {
        font-size: 14px;
    }

    .ams-result-header {
        gap: 8px;
    }

    .ams-result-actions {
        width: 100%;
    }

    .ams-action-item {
        padding: 5px 12px;
        font-size: 14px;
    }

    .ams-solve-btn,
    .ams-ask-more-btn {
        padding: 10px 18px;
        font-size: 14px;
    }
}

@media (max-width: 600px) {
    .ams-crop-modal {
        padding: 12px;
    }

    .ams-crop-modal-inner {
        width: 100%;
    }

    .ams-crop-image-wrap {
        height: 300px;
    }

    .ams-crop-modal-inner img#cropImage {
        max-height: 300px;
    }

    .ams-crop-header {
        padding: 14px 16px;
    }

    .ams-crop-actions {
        padding: 12px 16px;
    }

    .ams-crop-confirm-btn {
        font-size: 15px;
    }

    /* Feedback (Figma node 1856-7861): boxes go full-width and shrink to fill
       the row; the input row spans full width with the field flexing. */
    .ams-page .feedback_boxes {
        box-sizing: border-box;
        width: 100%;
        margin: 20px 0 0;
        justify-content: space-between;
    }

    .ams-page .rating_box {
        flex: 1;
        width: auto;
        min-width: 0;
    }

    .ams-page .feedback_input {
        width: 100%;
        gap: 12px;
    }

    .ams-page #feedback_msg {
        width: auto;
        flex: 1;
    }
}

@media (max-width: 425px) {
    .ams-toolbar-left {
        flex-wrap: wrap;
    }

    .ams-tool-btn {
        padding: 5px 10px;
        font-size: 13px;
    }

    .ams-action-item {
        padding: 4px 8px;
        font-size: 13px;
    }

    .ams-answer-value {
        font-size: 26px;
    }
}
