/* AI Writer */
.min-w-0 { min-width: 0 !important; } /* not in this Metronic build; needed for flex children that must shrink */
#ai-editor .ai-rail { width: 340px; }
@media (max-width: 1199.98px) { #ai-editor .ai-rail { width: auto; } }
#ai-quill { min-height: 520px; font-size: 1.25rem; line-height: 1.7; }
#ai-quill.ql-container, #ai-quill-toolbar.ql-toolbar { font-family: inherit; } /* Quill's stylesheet forces Helvetica; use the app font (Inter) */
#ai-quill .ql-editor { min-height: 520px; padding: 24px 28px; }
#ai-quill .ql-editor h1 { font-size: 1.9em; margin: .4em 0 .5em; }
/* the first block is the article title */
#ai-quill .ql-editor > h1:first-child { font-size: 2.2em; line-height: 1.25; margin: 0 0 .7em; color: var(--bs-gray-900); }
#ai-quill .ql-editor > h1:first-child, #ai-quill .ql-editor > h2:first-child, #ai-quill .ql-editor > h3:first-child { margin-top: 0; }
#ai-quill .ql-editor h2 { font-size: 1.45em; margin: 1.3em 0 .5em; }
#ai-quill .ql-editor h3 { font-size: 1.15em; margin: 1.1em 0 .4em; }
#ai-quill .ql-editor p { margin-bottom: .9em; }
#ai-quill .ql-editor ol, #ai-quill .ql-editor ul, #ai-quill .ql-editor blockquote, #ai-quill .ql-editor pre { margin-bottom: .9em; }
#ai-quill .ql-editor li { margin-bottom: .25em; }
.ai-preview ul, .ai-preview ol { margin-bottom: .9em; }
#ai-quill .ql-editor img { max-width: 100%; height: auto; }
/* borderless text area; the toolbar keeps its own bordered, light-grey strip */
#ai-quill-toolbar.ql-toolbar.ql-snow { border: 0; background: transparent; padding: 4px 0; flex: 1 1 auto; display: flex; flex-wrap: wrap; align-items: center; row-gap: 8px; }
.ai-toolbar-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding-bottom: .85rem; }
/* measured in JS (layoutToolbar): when the tools and the AI actions do not fit side by side, the actions take their own line above, right-aligned */
.ai-toolbar-row.is-stacked .ai-toolbar-actions { order: -1; width: 100%; justify-content: flex-end; }
/* the editor card shows a spinner until Quill has built the toolbar and the text is in place */
.ai-editor-card:not(.is-ready) .ai-toolbar-row, .ai-editor-card:not(.is-ready) #ai-quill { visibility: hidden; }
.ai-editor-card .ai-editor-loading { position: absolute; left: 0; right: 0; top: 0; height: 320px; display: flex; align-items: center; justify-content: center; }
.ai-editor-card.is-ready .ai-editor-loading { display: none; }
#ai-gen-state { height: 35px; display: inline-flex; align-items: center; padding-top: 0; padding-bottom: 0; }
#ai-quill-toolbar.ql-toolbar.ql-snow .ql-formats { margin-right: 4px; }
#ai-quill-toolbar.ql-snow .ql-picker.ql-header { width: 122px; }
#ai-quill-toolbar.ql-snow .ql-picker.ql-header .ql-picker-label { padding-right: 22px; }
/* hide Quill's toolbar until Quill has built it (it adds .ql-toolbar on init); avoids the unstyled flash */
#ai-quill-toolbar:not(.ql-toolbar) { visibility: hidden; }
.ai-toolbar-row { min-height: 42px; }
.ai-toolbar-actions { display: flex; align-items: center; gap: .5rem; flex-shrink: 0; white-space: nowrap; }
#ai-quill.ql-container.ql-snow { border: 0; }
#ai-quill .ql-editor { padding: 16px 40px 0 36px; line-height: 1.7; }
.ai-stream-spinner { display: inline-block; margin: .25rem 0 0 .25rem; vertical-align: middle; }
.ai-preview { min-height: 200px; line-height: 1.65; }
.ai-preview h1 { font-size: 1.7em; } .ai-preview h2 { font-size: 1.35em; margin-top: 1.4em; } .ai-preview h3 { font-size: 1.1em; margin-top: 1.1em; }
/* rail scroll boxes carry no bottom padding of their own: every panel's bottom space is the card body's
   normal padding, so scroll-box panels, the Images panel and empty states all end the same way */
.ai-scroll { max-height: 320px; overflow-y: auto; }
.ai-section-list { max-height: 360px; overflow-y: auto; min-width: 280px; max-width: 360px; }
/* section fold-out: theme menu links are no-wrap flex rows; long headings must wrap inside the panel */
.ai-section-list .menu-link { white-space: normal; display: block; line-height: 1.35; padding-top: .5rem; padding-bottom: .5rem; overflow-wrap: anywhere; }
#ai-keyword-chips .badge { cursor: default; font-weight: 500; font-size: .95rem; padding: .5rem .75rem; }
#ai-keyword-chips .badge.missing { background: var(--bs-gray-100); color: var(--bs-gray-700); cursor: pointer; }
#ai-keyword-chips .badge.missing:hover { background: var(--bs-gray-200); color: var(--bs-gray-900); }
#ai-image-results .ai-img { cursor: pointer; border-radius: .375rem; width: 100%; aspect-ratio: 4/3; object-fit: cover; }
#ai-image-results .ai-img:hover { outline: 3px solid var(--bs-primary); }
#ai-research-steps li { padding: .35rem 0; color: var(--bs-gray-600); }
#ai-research-steps li.done { color: var(--bs-gray-800); }
#ai-research-steps li .ki-duotone { margin-right: .5rem; }
#ai-title-options .ai-title-opt { text-align: left; }
.ai-section-highlight { background: #fff7d6; transition: background 1.2s; }

/* content score dial (RGraph meter, same component as the audit report) */
.ai-dial-wrap { position: relative; display: flex; justify-content: center; margin-top: -2.5rem; }
.ai-dial-wrap canvas { max-width: 100%; height: auto; }
.ai-dial-value { position: absolute; left: 0; right: 0; bottom: 34px; text-align: center; font-size: 2.1rem; font-weight: 700; line-height: 1; color: var(--bs-gray-900); pointer-events: none; }
.ai-dial-value small { font-size: .95rem; font-weight: 500; color: var(--bs-gray-500); margin-left: 2px; }

/* wizard: staged progress block and loaders */
#ai-research-steps .ai-stage-content { display: flex; flex-direction: column; justify-content: center; min-height: var(--bs-timeline-icon-size); margin-bottom: 1.25rem; }
#ai-research-steps .timeline-item:last-child .ai-stage-content { margin-bottom: 0; }
.ai-loader-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,.6); border-radius: .475rem; }
#ai-title-options .ai-title-opt { white-space: normal; }
.ai-preview-fixed { height: 520px; overflow-y: auto; }
.timeline-item.has-popover { cursor: help; }
#ai-research-steps .timeline-item.has-popover .ai-stage-content { flex-direction: row; align-items: flex-start; justify-content: space-between; gap: .75rem; }
.ai-stage-cue { margin-top: 2px; }
#ai-research-steps .timeline-item.has-popover .ai-stage-content > div { flex-grow: 1; }
.ai-stage-cue { display: inline-flex; align-items: center; flex-shrink: 0; }
.timeline-item.has-popover:hover .ai-stage-cue i { color: var(--bs-primary) !important; }
#ai-title-options .ai-title-opt.selected { box-shadow: none; }

/* "Pages Currently Ranking" popover, laid out like a Google result */
.ai-serp-popover { max-width: 440px; }
.ai-serp-popover .popover-body { max-height: min(56vh, 540px); overflow-y: auto; padding-top: .75rem; padding-bottom: .75rem; }
.ai-serp-item { padding: .85rem 0; border-bottom: 1px dashed var(--bs-gray-200); }
.ai-serp-item:first-child { padding-top: .35rem; }
.ai-serp-item:last-child { border-bottom: 0; }
.ai-serp-site { display: flex; align-items: center; gap: .4rem; font-size: 12px; line-height: 1.3; color: #4d5156; min-width: 0; margin-bottom: .55rem; }
.ai-serp-site img { width: 16px; height: 16px; border-radius: 50%; background: #f1f3f4; flex-shrink: 0; }
.ai-serp-domain { color: #202124; font-weight: 500; white-space: nowrap; }
.ai-serp-url { color: #4d5156; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1 1 auto; } /* min-width:0 lets the flex item shrink below its content */
.ai-serp-url::before { content: '› '; }
.ai-serp-title { display: block; color: #1a0dab; font-size: 15px; line-height: 1.3; margin: 0 0 .25rem; }
.ai-serp-title:hover { color: #1a0dab; text-decoration: underline !important; }
.ai-serp-desc { color: #4d5156; font-size: 12px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* internal links card: fixed table so the action column stays aligned and long phrases wrap */
#ai-internal-links { overflow-x: hidden; }
#ai-internal-links .ai-int-table { table-layout: fixed; width: 100%; }
#ai-internal-links .ai-int-table td { vertical-align: top; overflow-wrap: anywhere; }
#ai-internal-links .ai-int-table col.ai-int-action { width: 78px; }
#ai-internal-links .ai-int-table .btn, #ai-internal-links .ai-int-table .badge { white-space: nowrap; }

/* app-frame layout (xl and up, where the rail sits beside the editor): the page itself never
   scrolls; the editor text and the right rail each scroll inside their own box, so the title
   bar, AI actions and toolbar stay put (same structure GrowthBar uses: two viewport-sized boxes) */
@media (min-width: 1200px) {
    .ai-page { height: calc(100vh - 104px); display: flex; flex-direction: column; } /* 74px fixed header + 30px content padding top; runs to the bottom edge */
    .ai-page-bar { flex-shrink: 0; }
    #ai-editor { flex: 1 1 auto; min-height: 0; }
    /* the editor column is the scroll box: the card grows with the text, so its bottom edge only
       appears when you reach the end (GrowthBar's feel); the toolbar row sticks at the top */
    #ai-editor > .flex-grow-1 { overflow-y: auto; min-height: 0; }
    /* article text reads like a page, not a banner: the editor card caps at a reading width and
       centres itself in the space between the app menu and the rail; it still shrinks on narrow screens */
    #ai-editor > .flex-grow-1 > .card { max-width: 1200px; margin-left: auto !important; margin-right: auto !important; }
    #ai-editor > .flex-grow-1 > .ai-scroll-end { max-width: 1200px; margin: 0 auto; }
    #ai-editor .ai-scroll-end { height: 30px; flex-shrink: 0; } /* real spacer: grey space under the card at the very end (bottom padding of a scroll box is unreliable across browsers) */
    #ai-editor > .flex-grow-1 > .card { margin-bottom: 0 !important; }
    #ai-editor > .flex-grow-1 > .card > .card-body { padding-top: 0; }
    #ai-editor .ai-toolbar-row { position: sticky; top: 0; z-index: 5; background: #fff; padding-top: 1.5rem; }
    #ai-quill .ql-editor { min-height: 60vh; }
    #ai-editor .ai-rail { height: 100%; overflow-y: auto; padding-right: 4px; scrollbar-width: thin; scrollbar-color: transparent transparent; }
    #ai-editor .ai-rail:hover { scrollbar-color: var(--bs-gray-300) transparent; }
    #ai-editor .ai-rail::-webkit-scrollbar { width: 6px; }
    #ai-editor .ai-rail::-webkit-scrollbar-thumb { background: transparent; border-radius: 3px; }
    #ai-editor .ai-rail:hover::-webkit-scrollbar-thumb { background: var(--bs-gray-300); }
    #ai-editor .ai-rail > .card:last-child { margin-bottom: 0 !important; }
}

/* block tag labels in a left gutter (pure CSS, never part of the saved document): H1, H2, P, UL... */
#ai-quill .ql-editor > * { position: relative; }
#ai-quill .ql-editor > h1::before, #ai-quill .ql-editor > h2::before, #ai-quill .ql-editor > h3::before, #ai-quill .ql-editor > h4::before,
#ai-quill .ql-editor > p::before, #ai-quill .ql-editor > blockquote::before, #ai-quill .ql-editor > ol::before, #ai-quill .ql-editor > pre::before {
    position: absolute; left: -36px; width: 22px; white-space: nowrap; text-align: right; font-size: 12px; line-height: 1; font-weight: 600; letter-spacing: .02em;
    color: var(--bs-gray-500); pointer-events: none; user-select: none;
}
#ai-quill .ql-editor > h1::before { content: 'h1'; top: 10px; }
#ai-quill .ql-editor > h1:first-child::before { top: 11px; }
#ai-quill .ql-editor > h2::before { content: 'h2'; top: 7px; }
#ai-quill .ql-editor > h3::before { content: 'h3'; top: 5px; }
#ai-quill .ql-editor > h4::before { content: 'h4'; top: 4px; }
#ai-quill .ql-editor > p::before { content: 'p'; top: 7px; }
#ai-quill .ql-editor > blockquote::before { content: 'qu'; top: 7px; }
#ai-quill .ql-editor > pre::before { content: 'co'; top: 7px; }
#ai-quill .ql-editor > ol::before { content: 'ol'; top: 7px; }
#ai-quill .ql-editor > ol:has(> li[data-list="bullet"])::before { content: 'ul'; }
/* empty blocks carry no label (an empty Quill line is <p><br></p>); the empty title keeps its placeholder */
#ai-quill .ql-editor > p:has(> br:only-child)::before, #ai-quill .ql-editor > h2:has(> br:only-child)::before, #ai-quill .ql-editor > h3:has(> br:only-child)::before,
#ai-quill .ql-editor > h4:has(> br:only-child)::before, #ai-quill .ql-editor > h1:not(:first-child):has(> br:only-child)::before { content: none; }
#ai-quill .ql-editor > h1:first-child:has(> br:only-child)::before { content: var(--ai-title-placeholder, 'Untitled'); position: static; width: auto; font-size: inherit; line-height: inherit; font-weight: inherit; letter-spacing: 0; text-align: left; color: var(--bs-gray-400); }

/* version history: tall modal, list and preview scroll on their own, headers on both columns line up */
#ai-history-modal .ai-history-content { height: 88vh; }
#ai-history-modal .ai-history-body { overflow: hidden; min-height: 0; }
#ai-history-modal .ai-history-bar { height: 36px; display: flex; align-items: center; margin-bottom: .75rem; flex-shrink: 0; }
#ai-history-modal .ai-history-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
#ai-history-modal .ai-preview h1 { font-size: 1.7em; margin: 0 0 .6em; }
#ai-history-modal .ai-preview { overflow-x: hidden; overflow-wrap: anywhere; }
#ai-history-modal .ai-preview img, #ai-history-modal .ai-preview video, #ai-history-modal .ai-preview iframe { max-width: 100%; height: auto; }
#ai-history-modal .ai-preview table { max-width: 100%; display: block; overflow-x: auto; }
#ai-history-modal .ai-preview pre { white-space: pre-wrap; }
#ai-history-modal .ai-version-tile.ai-version-selected { background: var(--bs-gray-100); }

/* link tooltip (Quill): sized for the larger text, URL styled as a link, roomier edit field; the
   same width in view and edit mode so the bounds-based placement holds when switching */
#ai-quill.ql-snow .ql-tooltip { font-size: 14px; padding: 8px 14px; border-color: var(--bs-gray-300); box-shadow: 0 6px 24px rgba(0,0,0,.08); border-radius: .475rem; z-index: 4; } /* below the sticky toolbar row (5) */
#ai-quill.ql-snow .ql-tooltip::before { line-height: 34px; color: var(--bs-gray-600); }
#ai-quill.ql-snow .ql-tooltip a { line-height: 34px; }
#ai-quill.ql-snow .ql-tooltip a.ql-preview { max-width: 400px; color: var(--bs-primary); text-decoration: underline; }
#ai-quill.ql-snow .ql-tooltip a.ql-action, #ai-quill.ql-snow .ql-tooltip a.ql-remove { color: var(--bs-gray-700); }
#ai-quill.ql-snow .ql-tooltip a.ql-action:hover, #ai-quill.ql-snow .ql-tooltip a.ql-remove:hover { color: var(--bs-primary); }
#ai-quill.ql-snow .ql-tooltip input[type=text] { width: 400px; height: 34px; font-size: 14px; padding: 4px 10px; border: 1px solid var(--bs-gray-300); border-radius: .375rem; }
#ai-quill.ql-snow .ql-tooltip.ql-editing::before { content: 'Link:'; }

#ai-image-search .ki-duotone { color: var(--bs-gray-600); }

/* image search button: icon and spinner share one centred box */
#ai-image-search { display: inline-flex; align-items: center; justify-content: center; width: 46px; padding-left: 0; padding-right: 0; }
#ai-image-search .indicator-label, #ai-image-search .indicator-progress { display: inline-flex !important; align-items: center; line-height: 1; }
#ai-image-search .indicator-progress { display: none !important; }
#ai-image-search[data-kt-indicator=on] .indicator-label { display: none !important; }
#ai-image-search[data-kt-indicator=on] .indicator-progress { display: inline-flex !important; }
#ai-image-search .indicator-progress .spinner-border { vertical-align: 0; }

/* rail: roomier Top Rankings rows; grey space under the last card */
.ai-rail .ai-serp-item { padding: .7rem 0; }
.ai-rail .ai-serp-item:first-child { padding-top: 1rem; }
#ai-editor .ai-rail .ai-scroll-end { height: 8px; } /* plus the last card's own bottom margin */
/* Quill's icon picker (align) sits on the text baseline; centre it like the buttons */
#ai-quill-toolbar.ql-snow .ql-icon-picker .ql-picker-label { display: flex; align-items: center; height: 24px; padding-top: 0; padding-bottom: 0; }
#ai-quill-toolbar.ql-snow .ql-icon-picker .ql-picker-label svg { display: block; }

#ai-title-options .ai-title-opt { white-space: normal; }

/* Competitor Content: expandable heading lists, headings as grey tags indented by level */
#ai-competitor-content .ai-cc-toggle { width: 28px; height: 28px; margin-top: 2px; }
#ai-competitor-content .ai-cc-toggle i { transition: transform .15s; }
#ai-competitor-content .ai-cc-toggle[aria-expanded="true"] i { transform: rotate(180deg); }
#ai-competitor-content .ai-cc-headings { padding-top: .6rem; padding-left: calc(16px + .35rem); flex-direction: column; align-items: flex-start; gap: .35rem; } /* left edge lines up with the page title text (after the favicon) */
#ai-competitor-content .ai-cc-headings.show { display: flex; } /* .collapse stays display:none until shown */
#ai-competitor-content .ai-scroll { overflow-x: hidden; }
#ai-competitor-content .ai-cc-body { min-width: 0; flex: 1 1 auto; } /* flex items default to min-width:auto and would not shrink below the URL line */
#ai-competitor-content .ai-heading-tag { white-space: normal; text-align: left; font-weight: 500; font-size: .85rem; line-height: 1.35; padding: .35rem .6rem; color: var(--bs-gray-700); background: var(--bs-gray-100); cursor: pointer; max-width: 100%; overflow-wrap: anywhere; }
#ai-competitor-content .ai-heading-tag:hover { background: var(--bs-primary-light); color: var(--bs-primary); }
#ai-competitor-content .ai-cc-l1, #ai-competitor-content .ai-cc-l2 { margin-left: 0; }
#ai-competitor-content .ai-cc-l3 { margin-left: 1.1rem; max-width: calc(100% - 1.1rem); }
#ai-competitor-content .ai-cc-l4, #ai-competitor-content .ai-cc-l5, #ai-competitor-content .ai-cc-l6 { margin-left: 2.2rem; max-width: calc(100% - 2.2rem); }
#ai-competitor-content .ai-cc-favicon { width: 16px; height: 16px; border-radius: 50%; background: #f1f3f4; margin-top: 3px; margin-right: .35rem; }
#ai-competitor-content .ai-serp-title { margin: 0; font-weight: 400; font-size: 14px; }
#ai-competitor-content .ai-cc-headings.collapsing { transition: none; display: flex; } /* no height animation: tags would stack unspaced mid-way */

/* research stages: independent traffic lights, no connecting line */
#ai-research-steps .ai-stage .timeline-line { display: none; }
#ai-research-steps .ai-stage { margin-bottom: .25rem; }

/* creation page: quota badge sits top-right of the panel, centred on the "New Article" title line */
#ai-step-form .ai-quota-badge { top: 1.65rem; right: 2.25rem; }
/* toolbar status badge: same height as the Write with AI button beside it */
#ai-status { height: 35px; display: inline-flex; align-items: center; padding-top: 0; padding-bottom: 0; }

/* page-bar Download button: Bootstrap's caret is inline text with a baseline offset, which sits high
   and tight against the label; as a flex item it centres on the label with a normal gap */
.ai-page-bar .btn.dropdown-toggle { display: inline-flex; align-items: center; }
.ai-page-bar .btn.dropdown-toggle::after { margin-left: .5rem; vertical-align: 0; }

/* Writing Tools dropdown (page bars): the free AI writing tools in three columns */
.ai-tools-dropdown { width: min(820px, calc(100vw - 2rem)); max-height: calc(100vh - 140px); overflow-y: auto; }
.ai-tools-columns { columns: 3; column-gap: 1.5rem; }
.ai-tools-group { break-inside: avoid; margin-bottom: 1.25rem; }
.ai-tools-dropdown .dropdown-item { white-space: normal; line-height: 1.35; }
.ai-tools-dropdown .dropdown-item:hover { background: var(--bs-primary-light); color: var(--bs-primary); }
.ai-tools-menu .btn.dropdown-toggle { display: inline-flex; align-items: center; }
.ai-tools-menu .btn.dropdown-toggle::after { margin-left: .5rem; vertical-align: 0; }
@media (max-width: 767px) { .ai-tools-columns { columns: 1; } }

/* articles list: keep the columns readable on phones; the table-responsive wrapper scrolls sideways.
   The percentage widths on the headers shrink with the table, so the two text columns get floors too. */
#ai-writer-documents { min-width: 900px; }
#ai-writer-documents th:nth-child(1) { min-width: 340px; }
#ai-writer-documents th:nth-child(2) { min-width: 200px; }

/* waiting for the first streamed words: the app's blue spinner, centred under the title (same as the panel loader) */
.ai-stream-wait { display: flex; justify-content: center; padding: .25rem 0 4rem; }
/* while the placeholder shows, the (empty) editor gives up its minimum height so the lines sit right under the title */
.ai-editor-card.is-waiting #ai-quill, .ai-editor-card.is-waiting #ai-quill .ql-editor { min-height: 0 !important; }

/* phones: page-bar buttons keep their size and wrap onto extra lines instead of squeezing
   (Back to Articles was wrapping its label, History its icon); the last three toolbar
   formats (quote/link/image, colour/align, clear) are hidden so the toolbar stays one row */
@media (max-width: 767px) {
    .ai-page-bar { flex-wrap: wrap; row-gap: .5rem; }
    .ai-page-bar > .d-flex { flex-wrap: wrap; row-gap: .5rem; }
    .ai-page-bar .btn { white-space: nowrap; flex-shrink: 0; }
    .ai-page-bar .btn i { display: inline-block; vertical-align: middle; }
    #ai-quill-toolbar .ql-formats:nth-last-child(-n+3) { display: none; }
}
