/* ════════════════════════════════════════════════════════════════════
   AI Chat — popup window, styled to match the Itensity Svelte assistant.
   Light aesthetic: white / #FAFAFA surfaces, #072F48 ink, #C0D62E accent.
   ════════════════════════════════════════════════════════════════════ */

/* ── FAB ── */
#ai-chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #fff;
    color: #fff;
    border: 1px solid #E5E5E5;
    cursor: pointer;
    box-shadow: rgba(7, 47, 72, 0.18) 0 6px 22px;
    z-index: 99998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

#ai-chat-fab:hover {
    transform: scale(1.08);
    box-shadow: rgba(7, 47, 72, 0.28) 0 8px 28px;
}

#ai-chat-fab:active {
    transform: scale(0.95);
}

#ai-chat-fab svg {
    width: 34px;
    height: 34px;
}

/* ── Chat window ── */
#ai-chat-window {
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: 440px;
    max-width: calc(100vw - 48px);
    height: 640px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border: 1px solid #E5E5E5;
    border-radius: 16px;
    box-shadow: rgba(7, 47, 72, 0.16) 0 12px 48px;
    z-index: 99999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: #072F48;
}

#ai-chat-window.open {
    display: flex;
}

/* ── Header ── */
#ai-chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: #FAFAFA;
    border-bottom: 1px solid #E5E5E5;
    flex-shrink: 0;
}

#ai-chat-header-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

#ai-chat-header-title {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: #072F48;
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.2;
}

#ai-chat-header-title svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

#ai-chat-context {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-context-label {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: #9AA8B4;
}

.ai-context-chip {
    display: inline-flex;
    align-items: center;
    max-width: 200px;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    color: #072F48;
    background: #EDF1F4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#ai-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
}

#ai-chat-header-actions button {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: transparent;
    border: 1px solid #E0E4E8;
    color: #5A6B78;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

#ai-chat-header-actions button:hover {
    background: #EDF1F4;
}

#ai-chat-header-actions #ai-chat-close:hover {
    background: #FFECEB;
    color: #E5484D;
    border-color: #F5C2C2;
}

#ai-chat-header-actions svg {
    width: 14px;
    height: 14px;
}

/* ── Messages area ── */
#ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    background: #FAFAFA;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

#ai-chat-messages::-webkit-scrollbar {
    display: none;
}

/* ── Empty state ── */
.ai-chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 28px 8px 8px;
}

.ai-chat-empty .ai-petal {
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
}

.ai-empty-title {
    font-size: 14px;
    font-weight: 600;
    color: #072F48;
    margin: 0 0 6px;
}

.ai-empty-hint {
    font-size: 12.5px;
    line-height: 1.5;
    color: #5A6B78;
    margin: 0 0 24px;
    max-width: 280px;
}

.ai-empty-divider {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin-bottom: 16px;
}

.ai-empty-divider .line {
    flex: 1;
    height: 1px;
    background: #EAEEF1;
}

.ai-empty-divider .label {
    font-size: 10px;
    color: #C0C8CE;
}

/* ── Suggestions ── */
.ai-suggestion-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 100%;
    text-align: left;
}

.ai-potd {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    width: 100%;
    background: linear-gradient(135deg, #f7faec 0%, #eef4fb 100%);
    color: #072f48;
    border-radius: 999px;
    border: 1px solid rgba(192, 214, 46, 0.45);
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: all 0.15s ease;
}

.ai-potd:hover {
    border-color: #c0d62e;
    box-shadow: 0 4px 12px rgba(26, 115, 232, 0.1);
    transform: translateY(-1px);
}

.ai-potd-tag {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    background: rgba(192, 214, 46, 0.2);
    color: #6f7d2a;
    padding: 2px 7px;
    border-radius: 999px;
    flex-shrink: 0;
}

.ai-potd-label {
    flex: 1;
    min-width: 0;
}

.ai-sugg-group {
    display: flex;
    flex-direction: column;
}

.ai-sugg-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: #9aa8b4;
    margin: 0 0 6px 2px;
}

.ai-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ai-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #fff;
    border: 1px solid #eaeef1;
    border-radius: 999px;
    font-size: 12px;
    color: #072f48;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s ease;
}

.ai-pill:hover {
    border-color: #c8d2db;
    background: #fafbf6;
}

.ai-pill.link {
    color: #1575fb;
}

.ai-pill svg {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    color: #5a6b78;
}

.ai-pill.link svg {
    color: #1575fb;
}

/* ── Message bubbles ── */
.ai-msg {
    max-width: 86%;
    font-size: 14px;
    line-height: 21px;
    word-break: break-word;
}

.ai-msg-user {
    align-self: flex-end;
    background: #fff;
    border: 1px solid #E5E5E5;
    color: #072F48;
    border-radius: 14px;
    padding: 11px 14px;
    white-space: pre-wrap;
}

/* Assistant — full-width prose, no bubble, no avatar */
.ai-msg-assistant {
    align-self: stretch;
    max-width: 100%;
    color: #072F48;
}

.ai-msg-assistant p {
    margin: 0 0 8px;
}

.ai-msg-assistant p:last-child {
    margin-bottom: 0;
}

.ai-msg-assistant strong {
    color: #010507;
    font-weight: 600;
}

.ai-msg-assistant em {
    font-style: italic;
}

.ai-msg-assistant a {
    color: #072f48;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.ai-msg-assistant ul,
.ai-msg-assistant ol {
    padding-left: 18px;
    margin: 6px 0;
}

.ai-msg-assistant li {
    margin: 2px 0;
}

.ai-msg-assistant code {
    background: #EDF1F4;
    color: #072f48;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
    font-family: 'Consolas', 'Monaco', monospace;
}

.ai-msg-assistant pre {
    background: #0E1F2C;
    color: #D6E0E8;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid #1B3142;
    overflow-x: auto;
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    margin: 8px 0;
}

.ai-msg-assistant pre code {
    background: none;
    padding: 0;
    color: inherit;
}

/* ── Link buttons ── */
.ai-link-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    margin: 4px 0;
    background: #f0f7ff;
    border: 1px solid #d0e3f7;
    border-radius: 8px;
    color: #1575fb;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
}

.ai-link-btn:hover {
    background: #e1effe;
    border-color: #a8c8f0;
}

.ai-link-btn svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.ai-link-btn .ai-link-icon-ext {
    width: 12px;
    height: 12px;
    opacity: 0.55;
}

/* ── Thinking panel (Rovo-style step list) ── */
.ai-thinking {
    align-self: stretch;
    animation: ai-fade-in 0.2s ease-out;
}

.ai-thinking-header {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    background: transparent;
    border: 0;
    cursor: pointer;
    color: #9AA8B4;
    border-radius: 4px;
    transition: opacity 0.15s ease;
}

.ai-thinking-header:hover {
    opacity: 0.75;
}

.ai-thinking-header-text {
    font-size: 12px;
    font-weight: 400;
    color: #9AA8B4;
}

.ai-thinking-chevron {
    width: 12px;
    height: 12px;
    color: #9AA8B4;
    transition: transform 0.2s ease;
}

.ai-thinking.open .ai-thinking-chevron {
    transform: rotate(90deg);
}

.ai-thinking-steps {
    padding: 4px 0 4px 6px;
}

.ai-thinking.collapsed .ai-thinking-steps {
    display: none;
}

.ai-step {
    display: flex;
    gap: 10px;
    padding-top: 10px;
    animation: ai-step-in 0.25s ease-out;
}

.ai-step:first-child {
    padding-top: 0;
}

.ai-step-iconcol {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.ai-step-icon {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: 1px solid #EAEEF1;
    color: #5A6B78;
    transition: all 0.2s ease;
}

.ai-step-icon svg {
    width: 12px;
    height: 12px;
}

.ai-step.running .ai-step-icon {
    color: #072f48;
    border-color: #C8D2DB;
    background: #EDF1F4;
}

.ai-step-connector {
    flex: 1;
    width: 1px;
    min-height: 8px;
    background: #EAEEF1;
}

.ai-step:last-child .ai-step-connector {
    display: none;
}

.ai-step-content {
    flex: 1;
    min-width: 0;
    padding-bottom: 4px;
}

.ai-step-title {
    font-size: 12px;
    font-weight: 400;
    color: #5A6B78;
    margin: 0;
    line-height: 1.35;
}

.ai-step-detail {
    font-size: 11.5px;
    color: #9AA8B4;
    margin: 2px 0 0;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* ── Fallback tool indicator ── */
.ai-tool-indicator {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 10px;
    background: #FAFBF6;
    border: 1px solid #EAEEF1;
    font-size: 12px;
    color: #5A6B78;
    animation: ai-fade-in 0.2s ease-out;
}

.ai-tool-indicator .name {
    font-weight: 600;
    color: #072f48;
}

.ai-tool-indicator .summary {
    color: #9AA8B4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.ai-tool-check {
    color: #16a34a;
    flex-shrink: 0;
}

.ai-tool-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid #E2E8EC;
    border-top-color: #072f48;
    border-radius: 50%;
    animation: ai-spin 0.8s linear infinite;
    flex-shrink: 0;
}

/* ── Typing indicator ── */
.ai-typing {
    align-self: flex-start;
    display: flex;
    gap: 5px;
    padding: 4px 0;
}

.ai-typing-dot {
    width: 6px;
    height: 6px;
    background: #C0C8CE;
    border-radius: 50%;
    animation: ai-typing-bounce 1.4s infinite ease-in-out;
}

.ai-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0.3s; }

/* ── HTML preview placeholder ── */
.ai-html-placeholder {
    align-self: stretch;
    border: 1px solid #EAEEF1;
    border-radius: 12px;
    background: #FAFBF6;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    animation: ai-fade-in 0.2s ease-out;
}

.ai-html-placeholder-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-html-placeholder-header svg {
    width: 16px;
    height: 16px;
    color: #072f48;
    flex-shrink: 0;
}

.ai-html-placeholder-title {
    font-size: 12.5px;
    font-weight: 600;
    color: #072f48;
}

.ai-html-bars {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-html-bar {
    height: 10px;
    border-radius: 4px;
    background: linear-gradient(90deg, #EAEEF1 0%, #F4F6F8 50%, #EAEEF1 100%);
    background-size: 200% 100%;
    animation: ai-shimmer 1.4s ease-in-out infinite;
}

.ai-html-bar.b1 { width: 92%; }
.ai-html-bar.b2 { width: 78%; animation-delay: 0.15s; }
.ai-html-bar.b3 { width: 60%; animation-delay: 0.3s; }

/* ── HTML preview tabbed card ── */
.ai-preview-card {
    align-self: stretch;
    border: 1px solid #EAEEF1;
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
}

.ai-preview-tabs {
    display: flex;
    align-items: center;
    background: #FAFBF6;
    border-bottom: 1px solid #EAEEF1;
    padding: 0 4px;
}

.ai-preview-tab {
    padding: 10px 14px;
    font-size: 12px;
    font-weight: 600;
    background: transparent;
    border: 0;
    border-bottom: 2px solid transparent;
    color: #9AA8B4;
    cursor: pointer;
    transition: all 0.15s ease;
}

.ai-preview-tab:hover {
    color: #5A6B78;
}

.ai-preview-tab.active {
    color: #072f48;
    border-bottom-color: #072f48;
}

.ai-copy-btn {
    margin-left: auto;
    margin-right: 4px;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    background: #fff;
    border: 1px solid #EAEEF1;
    color: #5A6B78;
    cursor: pointer;
    transition: all 0.15s ease;
}

.ai-copy-btn:hover,
.ai-copy-btn.copied {
    background: #EDF1F4;
    color: #072f48;
    border-color: #072f48;
}

.ai-preview-body {
    padding: 14px;
}

.ai-preview-iframe-wrap {
    background: #FAFBF6;
}

.ai-preview-iframe-wrap iframe {
    width: 100%;
    height: 340px;
    border: 0;
    display: block;
}

.ai-preview-code {
    background: #0E1F2C;
    max-height: 360px;
    overflow: auto;
    margin: 0;
}

.ai-preview-code pre {
    margin: 0;
    padding: 16px;
    color: #D6E0E8;
    font-size: 12px;
    line-height: 1.5;
    font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ── Error message ── */
.ai-msg-error {
    align-self: center;
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 13px;
    text-align: center;
}

/* ── Input area ── */
#ai-chat-footer {
    flex-shrink: 0;
    padding: 12px 16px;
    border-top: 1px solid #E5E5E5;
    background: #FAFAFA;
}

#ai-chat-input-card {
    border: 1px solid #D4D4D4;
    border-radius: 14px;
    background: #fff;
    padding: 10px 10px 8px 14px;
    transition: border-color 0.15s;
}

#ai-chat-input-card:focus-within {
    border-color: #A3A3A3;
}

#ai-chat-input {
    width: 100%;
    border: 0;
    outline: none;
    resize: none;
    background: transparent;
    font-size: 14px;
    font-family: inherit;
    line-height: 21px;
    color: #072F48;
    min-height: 24px;
    max-height: 120px;
    padding: 0;
}

#ai-chat-input::placeholder {
    color: #A3A3A3;
}

#ai-chat-input:disabled {
    opacity: 0.5;
}

.ai-input-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
}

#ai-chat-attach {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: transparent;
    border: 0;
    color: #6A8291;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

#ai-chat-attach:hover {
    background: #F5F5F5;
}

#ai-chat-attach:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

#ai-chat-attach svg {
    width: 18px;
    height: 18px;
}

#ai-chat-send {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #F5F5F5;
    color: #A3A3A3;
    transition: background 0.15s, color 0.15s;
}

#ai-chat-send.active {
    background: #1575FB;
    color: #fff;
}

#ai-chat-send.active:hover {
    background: #0244A1;
}

#ai-chat-send:disabled {
    cursor: not-allowed;
}

#ai-chat-send svg {
    width: 17px;
    height: 17px;
}

/* ── File chips ── */
.ai-file-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    border-top: 1px solid #E5E5E5;
    padding-top: 8px;
}

.ai-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 11px;
    background: #fafafa;
    border: 1px solid #E5E5E5;
    color: #5A6B78;
}

.ai-file-chip .size {
    color: #C0C8CE;
}

.ai-file-chip button {
    background: none;
    border: 0;
    color: #9AA8B4;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
}

.ai-file-chip button:hover {
    color: #5A6B78;
}

.ai-file-chip svg {
    width: 12px;
    height: 12px;
}

/* ── Skill pills ── */
#ai-skill-row {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    margin-top: 8px;
    scrollbar-width: none;
}

#ai-skill-row::-webkit-scrollbar {
    display: none;
}

#ai-skill-row:empty {
    display: none;
}

.ai-skill-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    padding: 4px 10px 4px 8px;
    border-radius: 9999px;
    background: #fff;
    border: 1px solid #EAEEF1;
    color: #072f48;
    font-size: 11.5px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.ai-skill-pill:hover {
    background: #FAFBF6;
    border-color: #C8D2DB;
}

.ai-skill-pill svg {
    width: 11px;
    height: 11px;
    color: #5A6B78;
    flex-shrink: 0;
}

.ai-chat-hint {
    text-align: center;
    margin: 6px 0 0;
    font-size: 11.5px;
    color: #A3A3A3;
}

/* ── Maximized state ── */
#ai-chat-window.maximized {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    border: 0;
}

#ai-chat-window.maximized #ai-chat-messages > * {
    max-width: 820px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
}

/* ── Mobile ── */
@media (max-width: 520px) {
    #ai-chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
        border: 0;
    }

    #ai-chat-fab {
        bottom: 16px;
        right: 16px;
        width: 52px;
        height: 52px;
    }
}

/* ── Animations ── */
@keyframes ai-spin {
    to { transform: rotate(360deg); }
}

@keyframes ai-typing-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-4px); opacity: 1; }
}

@keyframes ai-fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes ai-step-in {
    from { opacity: 0; transform: translateY(-3px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes ai-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.ai-petal-orbit {
    transform-origin: 0 0;
    animation: ai-petal-orbit 5s alternate ease-in-out infinite;
}

@keyframes ai-petal-orbit {
    0%   { transform: translateY(4px)  rotate(0deg); }
    45%  { transform: translateY(-4px) rotate(81deg); }
    100% { transform: translateY(4px)  rotate(180deg); }
}

@media (prefers-reduced-motion: reduce) {
    .ai-petal-orbit { animation: none; }
}
