/* AI Template Editor Component Styles */

.ai-template-editor {
    width: 100%;
}

.ai-template-editor .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #f8f9fa;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #dee2e6;
}

.ai-template-editor .card-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #495057;
}

.ai-template-editor .monaco-editor-wrapper {
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
    overflow: hidden;
}

.ai-template-editor textarea[style*="monospace"] {
    background-color: #1e1e1e;
    color: #d4d4d4;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    line-height: 1.6;
    padding: 12px;
}

.ai-template-editor iframe {
    background: white;
    display: block;
}

.ai-template-editor .spinner-border-sm {
    width: 1rem;
    height: 1rem;
    border-width: 0.15em;
}

.ai-template-editor .alert {
    display: flex;
    align-items: center;
}

.ai-template-editor .alert svg,
.ai-template-editor .alert i {
    margin-right: 0.5rem;
}

.ai-template-editor .badge {
    font-size: 0.85rem;
    padding: 0.35em 0.65em;
}

/* Loading animation */
@keyframes spin {
    to { transform: rotate(360deg); }
}

.ai-template-editor .spinner-border {
    display: inline-block;
    width: 2rem;
    height: 2rem;
    vertical-align: text-bottom;
    border: 0.25em solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

.ai-template-editor .spinner-border-sm {
    width: 1rem;
    height: 1rem;
    border-width: 0.2em;
}

/* Preview iframe adjustments */
.ai-template-editor .preview-container {
    position: relative;
    width: 100%;
    height: 500px;
}

/* Code editor enhancements */
.ai-template-editor .code-editor {
    position: relative;
}

.ai-template-editor .code-editor::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    border: 1px solid #dee2e6;
    border-radius: 0.25rem;
}

/* Button improvements */
.ai-template-editor button[disabled] {
    opacity: 0.65;
    cursor: not-allowed;
}

.ai-template-editor .btn-group {
    display: flex;
    gap: 0.5rem;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .ai-template-editor .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .ai-template-editor .preview-container {
        height: 300px;
    }
}

/* Dark mode support (optional) */
@media (prefers-color-scheme: dark) {
    .ai-template-editor .card {
        background-color: #2b2b2b;
        border-color: #3a3a3a;
    }
    
    .ai-template-editor .card-header {
        background-color: #1e1e1e;
        border-bottom-color: #3a3a3a;
    }
    
    .ai-template-editor .card-title {
        color: #e0e0e0;
    }
}

/* ===== AI generation workspace (guided brief + chat — #559) ===== */
.ai-gen-workspace { width: 100%; }
.ai-gen-left { flex: 0 0 var(--ai-gen-left-basis, 42%); min-width: 320px; }
.ai-gen-right { flex: 1 1 auto; min-width: 320px; }
.ai-gen-splitter { flex: 0 0 6px; align-self: stretch; cursor: col-resize; background: #dee2e6; border-radius: 3px; transition: background .15s; }
.ai-gen-splitter:hover { background: var(--bs-primary); }
@media (max-width: 991.98px) { .ai-gen-splitter { display: none; } }

.ai-template-preview-wrapper { width: 100%; height: 520px; background: #fff; border: 1px solid #dee2e6; border-radius: 0.375rem; overflow: hidden; }

/* Type cards */
.ai-gen-type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 0.5rem; }
.ai-gen-type-card { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.25rem; padding: 0.6rem 0.4rem; border: 1px solid #dee2e6; border-radius: 0.5rem; background: #fff; cursor: pointer; transition: border-color .15s, box-shadow .15s; text-align: center; }
.ai-gen-type-card:hover:not([disabled]) { border-color: var(--bs-primary); }
.ai-gen-type-card.selected { border-color: var(--bs-primary); box-shadow: 0 0 0 2px rgba(13,110,253,.25); }
.ai-gen-type-card[disabled] { opacity: .6; cursor: not-allowed; }
.ai-gen-type-emoji { font-size: 1.4rem; line-height: 1; }
.ai-gen-type-label { font-size: .8rem; }

/* Quick-add chips */
.ai-gen-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.ai-gen-chip { border: 1px dashed #adb5bd; border-radius: 1rem; background: #f8f9fa; padding: 0.2rem 0.6rem; font-size: .8rem; cursor: pointer; }
.ai-gen-chip:hover:not([disabled]) { background: #e9ecef; }
.ai-gen-chip[disabled] { opacity: .6; cursor: not-allowed; }

/* Numbered step badges in the brief (#1065 P13) */
.ai-gen-step-num { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; background: var(--bs-primary-bg-subtle, #cfe2ff); color: var(--bs-primary); font-size: 11px; font-weight: 700; line-height: 1; margin-right: 8px; flex-shrink: 0; vertical-align: middle; }

/* Variables-in-template banner (#1065 P10) */
.ai-gen-vars-banner { display: flex; gap: 0.6rem; align-items: flex-start; background: #e7f1ff; border: 1px solid #cfe2ff; border-radius: 0.5rem; padding: 0.6rem 0.8rem; margin-top: 0.5rem; }
.ai-gen-vars-icon { color: var(--bs-primary); margin-top: 2px; }
.ai-gen-vars-title { font-size: .85rem; font-weight: 600; color: #212529; margin-bottom: 0.3rem; }
.ai-gen-vars-list { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.ai-gen-var-pill { background: #fff; border: 1px solid #cfe2ff; border-radius: 1rem; padding: 0.1rem 0.55rem; font-size: .78rem; font-family: 'SF Mono', Menlo, monospace; color: var(--bs-primary); }
.ai-gen-vars-note { font-size: .76rem; color: #6c757d; margin-top: 0.35rem; }

/* Chat */
.ai-gen-chat-messages { display: flex; flex-direction: column; gap: 0.75rem; max-height: 360px; overflow-y: auto; padding: 0.25rem; }
.ai-gen-msg { display: flex; align-items: flex-start; gap: 0.5rem; }
.ai-gen-msg.user { flex-direction: row-reverse; }
.ai-gen-msg.assistant { flex-direction: row; }
.ai-gen-msg-avatar { flex: 0 0 auto; width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: .95rem; line-height: 1; background: #f1f3f5; }
.ai-gen-msg.user .ai-gen-msg-avatar { background: var(--bs-primary); }
.ai-gen-msg-content { display: flex; flex-direction: column; min-width: 0; max-width: 85%; }
.ai-gen-msg.user .ai-gen-msg-content { align-items: flex-end; }
.ai-gen-msg.assistant .ai-gen-msg-content { align-items: flex-start; }
.ai-gen-msg-bubble { max-width: 100%; padding: 0.5rem 0.75rem; border-radius: 0.75rem; white-space: pre-wrap; word-break: break-word; font-size: .9rem; }
.ai-gen-msg.user .ai-gen-msg-bubble { background: var(--bs-primary); color: #fff; border-bottom-right-radius: 0.15rem; }
.ai-gen-msg.assistant .ai-gen-msg-bubble { background: #f1f3f5; color: #212529; border-bottom-left-radius: 0.15rem; }
.ai-gen-edit-pill { margin-top: 0.2rem; border: none; background: transparent; color: var(--bs-primary); font-size: .78rem; cursor: pointer; }
/* Send button: fixed square so the single icon (or spinner) stays centred and never clips. */
.ai-gen-send-btn { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; min-width: 42px; }
.ai-gen-commit { display: flex; justify-content: flex-end; margin-top: 0.5rem; }

/* AI usage quota strip (#1065 P14/P17) */
.ai-gen-usage { padding: 0.6rem 0.8rem; border: 1px solid #dee2e6; border-radius: 0.5rem; background: #f8f9fa; }
.ai-gen-usage-row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.ai-gen-usage-bar { flex: 1 1 160px; height: 8px; background: #e9ecef; border-radius: 1rem; overflow: hidden; }
.ai-gen-usage-bar-fill { display: block; height: 100%; border-radius: 1rem; transition: width 0.3s ease; }
.ai-gen-usage-bar-fill.low { background: var(--bs-success); }
.ai-gen-usage-bar-fill.medium { background: var(--bs-warning); }
.ai-gen-usage-bar-fill.high { background: var(--bs-danger); }
.ai-gen-usage-text { font-size: .85rem; color: #212529; white-space: nowrap; }
.ai-gen-usage-hint { font-size: .76rem; color: #6c757d; margin-top: 0.35rem; }

/* Collapsed chat strip (fills the chat panel while collapsed) */
.ai-gen-chat-strip { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; padding: 0.5rem; border: 1px solid #dee2e6; border-radius: 0.5rem; cursor: pointer; background: #f8f9fa; height: 100%; transition: background 0.15s ease; }
.ai-gen-chat-strip:hover { background: #eef0f2; }
.ai-gen-chat-strip-label { writing-mode: vertical-rl; transform: rotate(180deg); font-size: .8rem; letter-spacing: .1rem; color: #6c757d; }

/* Accordion collapse (#1065 P9b): the chat panel stays in the DOM and animates its width between full and
   a thin strip, instead of swapping elements. overflow:hidden clips the inner content while it narrows so
   the morph stays clean. */
/* overflow: clip + clip-margin (not hidden) so the GroupBox's floating title isn't cut off at the top,
   while still clipping the horizontal content spill during the width animation. */
.ai-gen-chat-panel { transition: flex-basis 0.25s ease, min-width 0.25s ease; overflow: clip; overflow-clip-margin: 0.8rem; }
/* Collapse is a desktop-only affordance (frees horizontal space for the preview). Below 992px the panels
   stack full-width, so the 44px override is scoped to >=992px to avoid a broken 44px-tall strip on mobile;
   the collapse toggle button is hidden on mobile too (see .razor). #1065 P9b. */
@media (min-width: 992px) {
    .ai-gen-chat-panel.collapsed { flex: 0 0 44px; min-width: 44px; }
}

/* Brief/chat panel fades in on first mount (#1065 P9). */
@keyframes aiGenPanelIn { from { opacity: 0; transform: translateX(-6px); } to { opacity: 1; transform: translateX(0); } }
.ai-gen-left { animation: aiGenPanelIn 0.22s ease; }

@media (max-width: 992px) {
    .ai-gen-left, .ai-gen-right { flex: 1 1 100%; }
}

/* Action buttons in the chat/preview GroupBox headers: the Core .groupbox-title-end floats on the top
   border with overflow-clip that clips ~3px off Size.Small buttons. Allow overflow only for the boxes
   that actually have a title-end slot (the collapsable Brand box has none, so its animation is untouched). */
.ai-gen-workspace .groupbox-content > .groupbox-content-inner:has(> .groupbox-title-end) {
    overflow: visible;
}

/* The Core slot floats centered on the top border (translateY(-50%)), which clips the top of a full
   Size.Small button row. Lower it a touch inside the AI workspace so the buttons are not cut. #1042. */
@media (min-width: 576px) {
    .ai-gen-workspace .groupbox-title-end {
        transform: translateY(-30%);
    }
}

/* Expand modal: make it wide regardless of Blazorise size enum quirks. */
.ai-gen-expand-modal .modal-dialog {
    max-width: 92vw;
    width: 92vw;
}

/* Preview overlay (generating) + empty state */
.ai-template-preview-wrapper { position: relative; }
.ai-gen-preview-overlay,
.ai-gen-preview-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    text-align: center;
    padding: 1rem;
}
.ai-gen-preview-overlay { background: rgba(255, 255, 255, 0.85); }
.ai-gen-overlay-msg { color: #495057; font-weight: 500; }
.ai-gen-preview-empty { color: #6c757d; background: #fff; gap: 1rem; }
.ai-gen-empty-icon { font-size: 42px; line-height: 1; opacity: 0.4; }
.ai-gen-empty-text { max-width: 280px; }

/* Centre the mobile-frame preview within the (narrow) SMS preview pane (#939) */
.ai-gen-sms-preview-center { display: flex; justify-content: center; }

/* Relative area so the generating overlay / empty state (absolute, inset:0) fill the same footprint as the
   565px mobile frame — keeps the panel from collapsing before the first SMS is generated (#939). */
.ai-gen-sms-preview-area { position: relative; min-height: 565px; }

/* SMS encoding + char count + parts indicator under the preview (#939 AC18) */
.ai-gen-sms-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; justify-content: center; margin-top: 0.75rem; font-size: 0.8rem; color: #6c757d; }
.ai-gen-sms-enc { font-weight: 600; background: #e7f1ff; color: var(--bs-primary); border-radius: 1rem; padding: 0.05rem 0.55rem; }
.ai-gen-sms-enc.ucs { background: #fff3cd; color: #7a5d00; }
.ai-gen-sms-parts.multi { color: var(--bs-warning); font-weight: 700; }
.ai-gen-sms-tip { margin-top: 0.5rem; font-size: 0.78rem; color: #7a5d00; background: #fff3cd; border: 1px solid #ffe69c; border-radius: 0.375rem; padding: 0.4rem 0.6rem; text-align: center; }

/* Curated emoji picker for the WhatsApp header/footer brief fields (#940) */
.ai-gen-emoji-menu { display: grid; grid-template-columns: repeat(8, 1fr); gap: 0.15rem; padding: 0.4rem; min-width: 320px; }
.ai-gen-emoji-btn { display: inline-flex; align-items: center; justify-content: center; min-width: 2.25rem; min-height: 2.25rem; border: none; background: transparent; font-size: 1.25rem; line-height: 1; padding: 0.25rem; cursor: pointer; border-radius: 0.25rem; }
.ai-gen-emoji-btn:hover { background: #e9ecef; }

/* WhatsApp per-section character counters under the preview (#940 AC22) */
.ai-gen-wa-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; justify-content: center; margin-top: 0.75rem; font-size: 0.8rem; color: #6c757d; }
.ai-gen-wa-sec { background: #f1f3f5; border-radius: 1rem; padding: 0.05rem 0.55rem; }
.ai-gen-wa-sec.over { background: #f8d7da; color: #b02a37; font-weight: 700; }

/* Colour swatch in the "adopt image-derived palette" confirm (#941) */
.ai-gen-color-swatch { display: inline-block; width: 1.5rem; height: 1.5rem; border-radius: 0.25rem; border: 1px solid rgba(0, 0, 0, 0.15); flex: 0 0 auto; }
