/* Theme variables in theme.css */

.companion-v2 {
    display: flex;
    flex-direction: column;
}

.companion-v2 * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

#overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 100;
}

#overlay.active {
    opacity: 1;
    pointer-events: auto;
}

#app {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    position: relative;
}

#sidebar {
    position: absolute;
    top: 24px;
    left: 24px;
    bottom: 24px;
    width: 260px;
    background: var(--bg-card);
    border-radius: 28px;
    padding: 0;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 20px var(--shadow-color);
    z-index: 102;
    transition: opacity 0.5s ease;
}

#sidebar .sidebar-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 16px;
    margin-top: calc(env(safe-area-inset-top) + 16px);
    margin-bottom: 4px;
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    padding-top: calc(env(safe-area-inset-top) + 16px);
    padding-left: 308px;
    padding-bottom: 120px;
    transition: padding-left 0.3s ease;
}

#sidebar .toolbar-icon {
    width: 20px;
    height: 20px;
    opacity: 0.8;
}

#sidebar .sidebar-row {
    display: flex;
    flex-direction: column;
    padding: 12px 8px;
    border-radius: 16px;
    cursor: pointer;
    user-select: none;
}


#sidebar .sidebar-row.active {
    background: var(--accent-active);
    color: var(--text-on-active);
}

#sidebar .sidebar-row.active .chat-item-title {
    color: var(--text-on-active);
}

#sidebar .sidebar-row.active .chat-item-time {
    color: var(--text-on-active-muted);
}

#sidebar .sidebar-row.active .chat-settings {
    filter: brightness(0) invert(1);
    opacity: 0.7;
}

#sidebar .sidebar-row.short {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding-left: 16px;
    padding-right: 16px;
    border-radius: 0;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

#sidebar .chat-item-title {
    font-size: 14px;
    font-weight: 500;
    line-height: 1.3;
    color: var(--text-secondary);
}

#sidebar .chat-item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

#sidebar .chat-item-time {
    font-size: 12px;
    color: var(--text-muted);
}

#sidebar .chat-settings {
    width: 16px;
    height: 16px;
    cursor: pointer;
    opacity: 0.5;
}


#sidebar .sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#sidebar .sidebar-footer .footer-buttons {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    padding: 2px 8px 8px 8px;
}

#sidebar .footer-btn {
    height: 36px;
    min-width: 36px;
    border-radius: 18px;
    border: none;
    background: var(--bg-card);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}


#sidebar .footer-btn img {
    width: 20px;
    height: 20px;
    opacity: 0.7;
}


#sidebar .new-chat-btn {
    gap: 6px;
    padding: 0 8px;
    font-size: 14px;
    color: var(--text-secondary);
}

#sidebar .close-sidebar-btn {
    display: none;
    background: var(--accent-primary);
}

#sidebar .close-sidebar-btn img {
    filter: brightness(0) invert(1);
    opacity: 1;
}

#sidebar .footer-notifications {
    height: 36px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 8px;
    background: var(--bg-card);
    border-radius: 18px;
    cursor: pointer;
}


#sidebar .footer-notifications .notification-badge {
    background: var(--accent-danger);
    color: var(--text-on-accent);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
}

#messages .message {
    max-width: 80%;
    padding: 12px 16px;
    margin-bottom: 12px;
    border-radius: 18px;
    line-height: 1.4;
    animation: slideInDown 0.3s ease-out;
}

#messages .welcome {
    text-align: center;
    color: rgba(0, 0, 0, 0.25);
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
    font-size: 14px;
    padding: 24px 16px;
}

#messages .message.no-animate {
    animation: none;
}

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#messages .message.user {
    background: var(--msg-user-bg);
    color: var(--msg-user-text);
    margin-left: auto;
}

#messages .message.assistant {
    background: var(--msg-assistant-bg);
    color: var(--msg-assistant-text);
    margin-right: auto;
}

#input {
    position: absolute;
    bottom: 24px;
    left: 308px;
    right: 24px;
    min-height: 60px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 8px 8px 20px;
    border-radius: 28px;
    overflow: hidden;
    transition: height 0.5s ease, background 0.5s ease;
    box-shadow: 0 4px 20px var(--shadow-color);
    z-index: 101;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

#input textarea {
    flex: 1;
    min-height: 44px;
    max-height: 120px;
    padding: 11px 0;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 16px;
    resize: none;
    line-height: 1.4;
    overflow-y: auto;
    font-family: inherit;
    box-sizing: border-box;
}

#input textarea::placeholder {
    color: var(--text-muted);
}

#input .button-cluster {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(240, 240, 240, 0.5);
    border-radius: 22px;
    padding: 4px;
}

#input .cluster-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
}


#input .cluster-btn img {
    width: 20px;
    height: 20px;
    opacity: 0.7;
}

#input .menu-btn {
    display: none;
}

#input .send-btn {
    font-size: 18px;
    display: none;
}

#input .stop-btn {
    display: none;
}

.drop-zone {
    position: absolute;
    top: 24px;
    bottom: 100px;
    left: 308px;
    right: 24px;
    background: color-mix(in srgb, var(--bg-card) 85%, transparent);
    border: 2px dashed var(--accent-primary);
    border-radius: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 103;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.drop-zone.active {
    opacity: 1;
}

.drop-zone-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    color: var(--text-secondary);
}

.camera-view {
    position: absolute;
    bottom: 24px;
    left: 308px;
    right: 24px;
    height: 60px;
    border-radius: 28px;
    overflow: hidden;
    background: black;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    z-index: 102;
}

.camera-view.active {
    opacity: 1;
    pointer-events: auto;
}

.camera-view video {
    width: 100%;
    height: auto;
}

.camera-view .shutter-btn {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 44px;
    border-radius: 22px;
    border: none;
    background: var(--accent-primary);
    cursor: pointer;
    box-shadow: inset 0 0 0 3px white;
}

.camera-view .shutter-btn:active {
    background: var(--accent-primary-hover);
}

.camera-view .close-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
}

.camera-view .swap-btn {
    position: absolute;
    bottom: 8px;
    left: 8px;
}

@media (max-width: 768px) {
    #sidebar {
        opacity: 0;
        pointer-events: none;
        width: auto;
        right: 24px;
    }
    #sidebar.open {
        opacity: 1;
        pointer-events: auto;
    }
    #sidebar .close-sidebar-btn {
        display: flex;
    }
    #messages {
        padding-left: 16px;
    }
    #input,
    .camera-view {
        left: 24px;
    }
    #input .menu-btn {
        display: flex;
    }
}

/* CSA mode - text-only, no sidebar */
.companion-v2.csa {
    padding: 0;
}

.companion-v2.csa #messages {
    padding-left: 16px;
    padding-right: 16px;
}

.companion-v2.csa #input,
.companion-v2.csa .camera-view {
    left: 24px;
}

.companion-v2.csa #input {
    padding-right: 8px;
}

.companion-v2.csa #input .button-cluster {
    display: none;
}

/* ESA mode root styling */

/* Main container fills space */
.companion-v2 .main {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* ─────────────────────────────────────────────
   Message Banner
   ───────────────────────────────────────────── */

.message-banner {
    --banner-size: 36px;
    --banner-text: var(--text-primary);

    height: var(--banner-size);
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: calc(var(--banner-size) / 2);
    display: flex;
    align-items: center;
    padding: 0 10px;
    gap: 8px;
    box-shadow: 0 2px 12px var(--shadow-color);
    z-index: 103;
}


.message-banner-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-primary);
}

.message-banner.success .message-banner-icon {
    color: #22c55e;
}

.message-banner.error .message-banner-icon {
    color: var(--accent-danger);
}

.message-banner-text {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    min-width: 0;
    color: var(--banner-text);
}

.message-banner-text span {
    display: inline-block;
}

.message-banner-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--accent-primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: banner-spin 0.8s linear infinite;
}

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

/* Test panel */
.test-panel {
    position: fixed;
    top: 16px;
    right: 16px;
    background: var(--bg-card);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 2px 12px var(--shadow-color);
    z-index: 104;
}

.test-panel button {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 13px;
}

.test-panel button:hover {
    background: var(--bg-hover);
}

.test-panel button.success { background: #22c55e; color: white; }
.test-panel button.error { background: var(--accent-danger); color: white; }
.test-panel button.progress { background: var(--accent-primary); color: white; }

/* ─────────────────────────────────────────────
   Draft Messages
   ───────────────────────────────────────────── */

.message-draft {
    max-width: 80%;
    padding: 12px 16px;
    margin-bottom: 12px;
    margin-right: auto;
    border-radius: 18px;
    line-height: 1.6;
    background: var(--draft-bg);
    color: var(--draft-text);
    border: 1px solid var(--draft-border);

    p {
        margin: 4px 0;
    }

    p:first-child {
        margin-top: 0;
    }

    .draft-text {
        border: 1px solid var(--draft-text-border);
        background: var(--draft-text-bg);
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, monospace;
        font-size: 13px;
        padding: 12px;
        margin-top: 8px;
        border-radius: 8px;
        word-wrap: break-word;
        overflow-x: auto;
        color: var(--draft-text-color);
        white-space: pre-wrap;
    }

    /* HTML signatures carry their own styling, so the chat styles are reset away */
    .draft-signature {
        all: initial;
        display: block;
        margin-top: 8px;
    }

    .draft-signature * {
        all: revert;
    }

    .draft-approve {
        margin-top: 12px;
        padding: 8px 16px;
        background: var(--accent-success);
        color: white;
        border: none;
        border-radius: 8px;
        font-weight: 600;
        font-size: 0.9rem;
        cursor: pointer;
        transition: background 0.2s ease, opacity 0.2s ease;
    }

    .draft-approve:hover:not(:disabled) {
        opacity: 0.9;
    }

    .draft-approve:disabled {
        background: var(--text-muted);
        cursor: not-allowed;
    }

    .draft-attachments {
        margin-top: 8px;
        display: flex;
        flex-direction: column;
        gap: 6px;
    }

    .draft-attachment {
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .draft-attachment-preview {
        width: 40px;
        height: 40px;
        border-radius: 6px;
        overflow: hidden;
        flex-shrink: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(255, 255, 255, 0.08);
        font-size: 20px;
    }

    .draft-attachment-preview img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .draft-attachment-name {
        font-size: 13px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* ─────────────────────────────────────────────
   Generated Images
   ───────────────────────────────────────────── */

.user-image-container {
    display: block;
    max-width: 80%;
    margin-left: auto;
    margin-bottom: 12px;

    .user-image {
        display: block;
        max-width: 100%;
        height: auto;
        border-radius: 12px;
        margin-left: auto;
    }
}

.download-btn {
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: pointer;
    flex-shrink: 0;
}

.message.assistant.download-message {
    display: flex;
    align-items: center;
    gap: 8px;
}

.message.assistant.download-message a {
    cursor: pointer;
    text-decoration: underline;
    color: inherit;
}

.message.assistant.download-message .download-btn {
    margin-left: auto;
}

.generated-image-container {
    position: relative;
    display: block;
    max-width: 80%;
    margin-right: auto;
    margin-bottom: 12px;

    .generated-image {
        display: block;
        max-width: 100%;
        height: auto;
        border-radius: 12px;
    }

    .download-btn {
        position: absolute;
        bottom: 8px;
        right: 8px;
    }
}

/* ─────────────────────────────────────────────
   Message Metrics
   ───────────────────────────────────────────── */

.message-metrics {
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.7;
}
.message-metrics a {
    color: inherit !important;
}

/* ─────────────────────────────────────────────
   Centered Message / Agent Selector
   ───────────────────────────────────────────── */

.companion-message-center {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    padding: 20px;
}

.agent-selector-box {
    background: var(--bg-card);
    padding: 24px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 4px 20px var(--shadow-color);
}

.agent-selector-box h2 {
    margin: 0 0 16px;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.agent-selector-box select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.95rem;
    margin-bottom: 16px;
}

.agent-selector-box select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a1a2e;
        --bg-card: #252542;
        --bg-input: #2d2d4a;
        --bg-hover: #363658;

        --accent-primary: #6366f1;
        --accent-primary-hover: #5254d4;
        --accent-active: rgba(99, 102, 241, 0.8);
        --accent-danger: #e74c3c;
        --accent-success: #22c55e;

        --text-primary: #d8d8e8;
        --text-secondary: #c0c0d0;
        --text-muted: #8888a0;
        --text-on-accent: white;
        --text-on-active: white;
        --text-on-active-muted: rgba(255, 255, 255, 0.7);

        --border-color: #3a3a5c;
        --shadow-color: rgba(0, 0, 0, 0.4);
        --overlay-color: rgba(0, 0, 0, 0.75);

        --msg-user-bg: var(--accent-primary);
        --msg-user-text: white;
        --msg-assistant-bg: #2d2d4a;
        --msg-assistant-text: #d8d8e8;

        /* Draft colors */
        --draft-bg: #3d3a28;
        --draft-text: #e8e4d0;
        --draft-border: #4a4730;
        --draft-text-bg: #2a2a3e;
        --draft-text-border: #4a4a60;
        --draft-text-color: #d0d0e0;
    }

    #messages .welcome {
        color: rgba(255, 255, 255, 0.15);
        text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
    }

    #sidebar .toolbar-icon,
    #sidebar .chat-settings,
    #sidebar .footer-btn img,
    #sidebar .footer-notifications .toolbar-icon,
    #input .cluster-btn img,
    .modal-actions img {
        filter: brightness(0) invert(0.85);
    }

    #input {
        background: rgba(37, 37, 66, 0.7);
    }

    #input .button-cluster {
        background: rgba(45, 45, 74, 0.5);
    }

    .message-banner {
        background: rgba(37, 37, 66, 0.7);
    }

    /* Signatures carry light-mode inline colors, so their own elements are inverted */
    .message-draft .draft-signature > * {
        filter: invert(1) hue-rotate(180deg);
    }
}

@media (min-width: 769px) {
    #sidebar .sidebar-row:hover {
        background: var(--bg-input);
    }
    #sidebar .chat-settings:hover {
        opacity: 1;
    }
    #sidebar .footer-btn:hover,
    #sidebar .footer-notifications:hover {
        background: var(--bg-input);
    }
    #input .cluster-btn:hover {
        background: var(--bg-hover);
    }
}

/* Widget FAB */

.widget-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 900;
    cursor: pointer;
    width: 128px;
    height: 128px;
    object-fit: contain;
    filter: drop-shadow(1px 2px 3px rgba(0, 0, 0, 0.5));
}
