/* ============================================================
   Joe — Atelier-Assistent (v25.0)
   Loaded via <link> in <head>, before the monolith's own <style>
   block, so every rule here relies on the app's design tokens
   (--ui-bg, --ui-border, --accent-primary, --text-*, --space-*,
   --radius-*, --glass-blur, --transition-*, --touch-min) which are
   defined on :root in index.html. Falls back gracefully if a token
   is ever renamed (var() second argument).
   ============================================================ */

/* ---------- Top-bar avatar button ---------- */
#joe-btn {
    padding: 2px !important;
}
.joe-avatar-wrap {
    display: block;
    width: 28px;
    height: 28px;
    color: var(--accent-primary, #00ff88);
    transform-origin: 50% 90%;
}
.joe-avatar-wrap.joe-avatar-sm {
    width: 24px;
    height: 24px;
}
#joe-header-avatar.joe-avatar-wrap {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

/* Mood/state animations — only on non-idle states, reduced-motion safe. */
@media (prefers-reduced-motion: no-preference) {
    .joe-avatar-wrap.joe-thinking #joe-brush {
        animation: joeWiggle 0.9s ease-in-out infinite;
        transform-box: fill-box;
        transform-origin: bottom left;
    }
    .joe-avatar-wrap.joe-speaking {
        animation: joeBob 0.5s ease-in-out infinite;
    }
}
@keyframes joeWiggle {
    0%, 100% { transform: rotate(-12deg); }
    50% { transform: rotate(12deg); }
}
@keyframes joeBob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-2px); }
}
.joe-avatar-wrap.joe-happy #joe-eyes { display: none; }
.joe-avatar-wrap.joe-happy #joe-eyes-happy { display: inline; }
.joe-avatar-wrap.joe-speaking #joe-mouth { display: none; }
.joe-avatar-wrap.joe-speaking #joe-mouth-open { display: inline; }

/* ---------- Panel shell ---------- */
.joe-panel {
    position: fixed;
    right: 12px;
    bottom: 64px;
    width: 380px;
    max-width: calc(100vw - 24px);
    height: min(560px, 70vh);
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    background: var(--ui-bg, rgba(20, 20, 20, 0.95));
    border: 1px solid var(--ui-border, rgba(255, 255, 255, 0.1));
    border-radius: var(--radius-lg, 14px);
    backdrop-filter: var(--glass-blur, blur(15px));
    box-shadow: var(--shadow-md, 0 4px 20px rgba(0, 0, 0, 0.4));
    z-index: 120;
    opacity: 0;
    transform: translateY(12px) scale(0.98);
    pointer-events: none;
    transition: opacity var(--transition-base, 0.25s ease), transform var(--transition-base, 0.25s ease);
    overflow: hidden;
}
.joe-panel.joe-panel--open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}
.joe-panel.joe-panel--minimized .joe-messages,
.joe-panel.joe-panel--minimized .joe-chips,
.joe-panel.joe-panel--minimized .joe-inputbar,
.joe-panel.joe-panel--minimized .joe-settings {
    display: none !important;
}
.joe-panel.joe-panel--minimized {
    height: auto;
}

.joe-sheet-handle { display: none; }

/* ---------- Header ---------- */
.joe-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm, 8px);
    padding: var(--space-sm, 8px) var(--space-md, 12px);
    border-bottom: 1px solid var(--ui-border, rgba(255, 255, 255, 0.1));
    cursor: grab;
    flex-shrink: 0;
}
.joe-header-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.joe-title { font-size: var(--text-base, 14px); font-weight: 600; color: var(--text-primary, #fff); }
.joe-subtitle { font-size: var(--text-xs, 11px); color: var(--text-secondary, #ccc); opacity: 0.8; }
.joe-status {
    font-size: var(--text-xs, 11px);
    color: var(--text-secondary, #ccc);
    white-space: nowrap;
    padding: 2px 6px;
    border-radius: var(--radius-full, 999px);
    background: var(--glass-light, rgba(255, 255, 255, 0.06));
    flex-shrink: 0;
}
.joe-hdr-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm, 6px);
    color: var(--text-primary, #fff);
    font-size: var(--text-base, 14px);
    cursor: pointer;
    transition: background var(--transition-fast, 0.15s ease);
    flex-shrink: 0;
}
.joe-hdr-btn:hover { background: var(--glass-medium, rgba(255, 255, 255, 0.08)); }

/* ---------- Messages ---------- */
.joe-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md, 12px);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm, 8px);
}
.joe-msg { display: flex; gap: var(--space-sm, 8px); max-width: 92%; }
.joe-msg--user { align-self: flex-end; flex-direction: row-reverse; }
.joe-msg--joe { align-self: flex-start; }
.joe-msg-content {
    padding: var(--space-sm, 8px) var(--space-md, 12px);
    border-radius: var(--radius-md, 16px);
    font-size: var(--text-sm, 13px);
    line-height: 1.4;
    color: var(--text-primary, #fff);
    white-space: pre-wrap;
    word-break: break-word;
}
.joe-msg--joe .joe-msg-content {
    background: var(--glass-medium, rgba(255, 255, 255, 0.08));
    border-bottom-left-radius: var(--radius-sm, 6px);
}
.joe-msg--user .joe-msg-content {
    background: rgba(var(--accent-primary-rgb, 0, 255, 136), 0.22);
    border-bottom-right-radius: var(--radius-sm, 6px);
}
.joe-msg--joe > .joe-avatar-wrap { flex-shrink: 0; margin-top: 2px; }

/* ---------- Cards ---------- */
.joe-card {
    align-self: flex-start;
    max-width: 92%;
    background: var(--glass-light, rgba(255, 255, 255, 0.04));
    border: 1px solid var(--ui-border, rgba(255, 255, 255, 0.1));
    border-radius: var(--radius-md, 16px);
    padding: var(--space-md, 12px);
    font-size: var(--text-sm, 13px);
    color: var(--text-primary, #fff);
}
.joe-card--gallery { border-left: 3px solid var(--accent-primary, #00ff88); }
.joe-card--error { border-left: 3px solid #ff6b6b; }
.joe-card--image { border-left: 3px solid #ffb020; }
.joe-card-title { font-weight: 600; margin-bottom: var(--space-xs, 4px); }
.joe-card-body { color: var(--text-secondary, #ccc); line-height: 1.4; }
.joe-card-meta { font-size: var(--text-xs, 11px); color: var(--text-secondary, #ccc); margin-top: 2px; opacity: 0.85; }
.joe-card-actions { display: flex; flex-wrap: wrap; gap: var(--space-xs, 4px); margin-top: var(--space-sm, 8px); }
.joe-action-line { font-size: var(--text-xs, 11px); color: var(--text-secondary, #ccc); }

/* ---------- Chips ---------- */
.joe-chips {
    display: flex;
    gap: var(--space-xs, 4px);
    padding: var(--space-xs, 4px) var(--space-md, 12px);
    overflow-x: auto;
    flex-shrink: 0;
    scrollbar-width: thin;
}
.joe-chips--styles { border-top: 1px solid var(--ui-border, rgba(255, 255, 255, 0.1)); }
.joe-chip {
    flex-shrink: 0;
    padding: 6px 10px;
    font-size: var(--text-xs, 11px);
    color: var(--text-primary, #fff);
    background: var(--glass-medium, rgba(255, 255, 255, 0.08));
    border: 1px solid var(--ui-border, rgba(255, 255, 255, 0.1));
    border-radius: var(--radius-full, 999px);
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--transition-fast, 0.15s ease);
    min-height: 28px;
}
.joe-chip:hover { background: var(--glass-heavy, rgba(255, 255, 255, 0.12)); }
.joe-chip:disabled { opacity: 0.5; cursor: default; }

/* ---------- Input bar ---------- */
.joe-inputbar {
    display: flex;
    align-items: flex-end;
    gap: var(--space-xs, 4px);
    padding: var(--space-sm, 8px) var(--space-md, 12px);
    border-top: 1px solid var(--ui-border, rgba(255, 255, 255, 0.1));
    flex-shrink: 0;
}
.joe-input {
    flex: 1;
    resize: none;
    max-height: 120px;
    min-height: 36px;
    padding: 8px 10px;
    font-size: var(--text-sm, 13px);
    font-family: inherit;
    color: var(--text-primary, #fff);
    background: var(--glass-light, rgba(255, 255, 255, 0.05));
    border: 1px solid var(--ui-border, rgba(255, 255, 255, 0.1));
    border-radius: var(--radius-md, 16px);
}
.joe-input:focus { outline: 1px solid var(--accent-primary, #00ff88); }
.joe-send {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: var(--radius-full, 999px);
    border: none;
    background: var(--accent-primary, #00ff88);
    color: #05130c;
    font-size: var(--text-base, 14px);
    cursor: pointer;
    flex-shrink: 0;
}

/* ---------- Settings drawer ---------- */
.joe-settings {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm, 8px);
    padding: var(--space-md, 12px);
    border-bottom: 1px solid var(--ui-border, rgba(255, 255, 255, 0.1));
    max-height: 45%;
    overflow-y: auto;
    flex-shrink: 0;
}
.joe-set-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm, 8px);
    font-size: var(--text-xs, 11px);
    color: var(--text-secondary, #ccc);
}
.joe-set-row select,
.joe-set-row input[type="text"],
.joe-set-row input[type="password"] {
    flex: 1;
    min-width: 0;
    min-height: 32px;
    padding: 0 8px;
    font-size: var(--text-xs, 11px);
    color: var(--text-primary, #fff);
    background: var(--glass-light, rgba(255, 255, 255, 0.05));
    border: 1px solid var(--ui-border, rgba(255, 255, 255, 0.1));
    border-radius: var(--radius-sm, 6px);
}
.joe-set-toggle input[type="checkbox"] { width: 18px; height: 18px; }
#joe-test-result { font-size: var(--text-xs, 11px); color: var(--text-secondary, #ccc); }

/* ---------- Mobile: bottom sheet ---------- */
@media (max-width: 768px) {
    .joe-panel {
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        height: 60vh;
        max-height: 80vh;
        border-radius: 16px 16px 0 0;
        z-index: 300;
        transform: translateY(100%);
    }
    .joe-panel.joe-panel--open { transform: translateY(0); }
    .joe-sheet-handle {
        display: block;
        width: 36px;
        height: 4px;
        margin: 8px auto 0;
        border-radius: 2px;
        background: var(--ui-border, rgba(255, 255, 255, 0.2));
        flex-shrink: 0;
    }
    .joe-header { cursor: default; }
    .joe-hdr-btn { min-width: var(--touch-min, 44px); min-height: var(--touch-min, 44px); }
    .joe-send { min-width: var(--touch-min, 44px); min-height: var(--touch-min, 44px); width: var(--touch-min, 44px); height: var(--touch-min, 44px); }
}

/* ---------- Hide legacy AI menus by default (Joe replaces them) ----------
   Re-enabled via body.joe-expert (Joe settings -> "Experten-Modus"). Uses a
   class-gated selector so specificity beats the plain-ID mobile visibility
   rule for #ai-quick-btn in index.html regardless of stylesheet order. */
body:not(.joe-expert) #chatbot-section,
body:not(.joe-expert) #ai-tools-section,
body:not(.joe-expert) #ai-styles-section,
body:not(.joe-expert) #ai-generate-section,
body:not(.joe-expert) #ai-analysis-section,
body:not(.joe-expert) #ai-edit-section,
body:not(.joe-expert) #ai-quick-menu,
body:not(.joe-expert) #ai-quick-btn {
    display: none !important;
}

/* v26: the right panel's "Werkzeuge" section duplicates the left panel's
   tools 1:1 (same 10 tools, "-right" id suffix), and "Power Controls"
   duplicates the dock's size/intensity/opacity sliders — both were always
   visible, doubling the same controls. Hidden by default; Experten-Modus
   (same toggle as the legacy AI menus) brings them back for anyone who
   preferred having tools in both panels. */
body:not(.joe-expert) #mini-tools-section,
body:not(.joe-expert) #power-controls-section {
    display: none !important;
}
