/* --- File: web/static/css/style.css (Final Corrected Version) --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans TC", sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    color: #2c3e50;
    font-size: 16px;
}

.app-wrapper {
    max-width: 1200px;
    height: 100vh;
    margin: 0 auto;
    background: white;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
}

/* Header & Workflow Nav */
.app-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    flex-shrink: 0;
    position: relative;
}

.logo {
    font-size: 1.8rem;
    font-weight: 700;
    font-style: italic;
    flex-shrink: 0;
}

.header-center-area {
    display: flex;
    justify-content: center;
    margin: 0 60px;
    flex-grow: 1;
}

.header-actions {
    position: absolute;
    right: 2rem;
    top: 50%;
    transform: translateY(-50%);
}

.workflow-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.workflow-nav .step {
    position: relative;
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    background: rgba(255,255,255,0.1);
    transition: all 0.3s ease;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    color: white;
}

.workflow-nav .step:active {
    transform: none; 
}


.workflow-nav .step.active {
    background: rgba(255,255,255,0.25);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.workflow-nav .step.has-unread::after {
    content: '';
    position: absolute;
    top: 5px;
    right: 5px;
    width: 8px;
    height: 8px;
    background-color: #ffc107;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 0 5px rgba(255, 193, 7, 0.8);
}

.workflow-nav .step:hover {
    background: rgba(255,255,255,0.2);
}

.workflow-nav .step-arrow {
    margin: 0 0.3rem;
    color: rgba(255,255,255,0.6);
    font-size: 0.8rem;
    user-select: none;
}

.header-actions .icon-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: white;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1.2rem;
}

.header-actions .icon-btn:hover {
    background: rgba(255,255,255,0.2);
}

/* Main Content Area */
.app-main {
    padding: 1rem 1.5rem;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    overflow: hidden;
}

.chat-display {
    flex-grow: 1; 
    background: #f8f9fa;
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    border: 1px solid #e9ecef;
    overflow-y: auto;
}

/* Welcome Message */
.welcome-message-container {
    display: flex;
    flex-direction: column; 
    align-items: center;
    justify-content: center;
    gap: 1rem; 
    padding: 1rem 0;
}

.welcome-message {
    text-align: left;
    color: #495057;
    padding: 2rem;
    background-color: #f0f2f5;
    border-radius: 8px;
    font-size: 1rem; 
    line-height: 1.7;
    width: 100%;
    max-width: 80%;
}

.welcome-message h2 {
    font-size: 1.5rem; 
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 1rem;
}

.welcome-message pre {
    white-space: pre-wrap;
    font-family: inherit;
}

/* Messages */
.message {
    margin-bottom: 12px;
    padding: 12px 18px;
    border-radius: 12px;
    max-width: 85%;
    word-wrap: break-word;
    line-height: 1.6;
    box-shadow: 0 2px 5px rgba(0,0,0,0.08);
}

.user-message {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    margin-left: auto;
}

.assistant-message {
    background-color: #e9ecef;
    border: 1px solid #dee2e6;
    margin-right: auto;
    color: #212529;
    white-space: pre-wrap;
}

.system-message {
    background-color: #fffbe6;
    border: 1px solid #ffe58f;
    color: #d46b08;
    font-size: 0.9em;
    padding: 10px 15px;
    box-shadow: none;
    border-radius: 8px;
    width: 100%;
    max-width: 80%;
    align-self: center; 
}

.dependency-prompt-message button {
    margin-top: 10px;
    margin-right: 10px;
}

/* Code Block Styles */
.code-block-wrapper {
    background-color: #282c34;
    color: #abb2bf;
    padding: 1em 1.2em;
    border-radius: 5px;
    margin: 12px 0;
    overflow-x: auto;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
    font-size: 0.95em;
    line-height: 1.5;
}
.code-block-lang {
    font-size: 0.85em;
    color: #61afef;
    margin-bottom: 0.6em;
    text-transform: lowercase;
}
.code-block-wrapper pre {
    margin: 0;
    white-space: pre;
    word-wrap: normal;
}
.code-block-wrapper code {
    font-size: 1em;
    padding: 0;
    background: none;
    border: none;
    color: inherit;
}

/* 動態狀態標籤 (強化版) */
.assistant-status-chip {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.7em;
    margin-left: 5%; 
    margin-right: auto;
    margin-top: -5px;
    margin-bottom: 12px;
    padding: 8px 16px;
    max-width: 80%;
    background-color: rgba(102, 126, 234, 0.1);
    border: 1px solid rgba(102, 126, 234, 0.2);
    color: #5a67d8;
    font-size: 0.9em;
    font-weight: 500;
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    animation: fadeInPulse 1.5s infinite ease-in-out;
}

@keyframes fadeInPulse {
    0% { 
        opacity: 0.8;
        transform: translateY(-2px) scale(1);
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    }
    50% {
        opacity: 1;
        transform: translateY(0) scale(1.02);
        box-shadow: 0 6px 10px -1px rgba(102, 126, 234, 0.1);
    }
    100% {
        opacity: 0.8;
        transform: translateY(-2px) scale(1);
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    }
}

/* 載入中 Spinner */
.assistant-status-chip .spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(102, 126, 234, 0.3);
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Input Controls */
.input-controls {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    border-top: 1px solid #e9ecef;
    box-shadow: 0 -4px 15px rgba(0,0,0,0.05);
    flex-shrink: 0;
}

.action-buttons-group {
    display: flex;
    gap: 0.8rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-secondary {
    background: #f8f9fa;
    color: #495057;
    border: 1px solid #dee2e6;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.btn:active {
    transform: none; 
}

.small-btn {
    padding: 0.5rem 1rem;
    font-size: 0.85em;
}

/* File Upload */
#upload-status-container {
    font-size: 0.9rem;
    color: #6c757d;
    margin-bottom: 1rem;
    min-height: 1.5em;
}

#file-preview-area {
    display: none;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
    margin-bottom: 12px;
    padding: 8px;
    border: 1px dashed #ced4da;
    border-radius: 8px;
    background-color: #fcfcfc;
    max-height: 150px;
    overflow-y: auto;
}

.file-preview-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    background-color: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    font-size: 0.85em;
}

.file-preview-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-grow: 1;
    margin-right: 8px;
}

.file-preview-remove {
    background: none;
    border: none;
    color: #dc3545;
    font-weight: bold;
    cursor: pointer;
    font-size: 1.2em;
    padding: 0 4px;
}

/* Text Input Area */
.input-area {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
}

.text-input {
    flex: 1;
    border: 1px solid #ced4da;
    border-radius: 20px;
    padding: 0.8rem 1.2rem;
    font-size: 1rem;
    resize: none;
    min-height: 44px;
    max-height: 150px;
    transition: all 0.3s ease;
}

.text-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.send-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 0.8rem 1.5rem;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    height: 44px;
}

.send-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.stop-btn {
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 20px;
    padding: 0.8rem 1.5rem;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    height: 44px;
}

.stop-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.4);
}


/* Sidebar & Resizer */
.resizer {
    position: fixed;
    top: 0;
    right: 420px;
    width: 8px;
    height: 100%;
    cursor: col-resize;
    z-index: 1001;
}

.sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 420px;
    max-width: 90%;
    height: 100vh;
    background-color: #ffffff;
    border-left: 1px solid #dee2e6;
    box-shadow: -5px 0 15px rgba(0,0,0,0.1);
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.25, 0.1, 0.25, 1);
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

.sidebar.visible {
    transform: translateX(0);
}

.close-sidebar-btn {
    position: absolute;
    top: 12px;
    right: 15px;
    background: none;
    border: none;
    font-size: 2.2em;
    cursor: pointer;
    color: #adb5bd;
    z-index: 10;
}

.sidebar-panel {
    padding: 50px 25px 35px 25px;
    display: none;
    flex-grow: 1;
    overflow-y: auto;
}

.sidebar-panel.active {
    display: flex;
    flex-direction: column;
}

.file-selector-container {
    margin-bottom: 18px;
}

#file-selector {
    width: 100%;
    padding: 10px 12px;
    border-radius: 4px;
    border: 1px solid #ced4da;
}

#file-content-display {
    white-space: pre-wrap;
    word-wrap: break-word;
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    padding: 15px;
    border-radius: 4px;
    flex-grow: 1;
    font-family: monospace;
}

.assets-gallery-container {
    flex-grow: 1;
}

.assets-gallery-container h4 {
    margin: 20px 0 12px;
    color: #343a40;
    font-size: 1.15em;
    border-bottom: 1px solid #e9ecef;
    padding-bottom: 10px;
}

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 15px;
}

.asset-card {
    text-align: center;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    background-color: white;
    box-shadow: 0 2px 5px rgba(0,0,0,0.08);
}

.asset-card img {
    width: 100%;
    height: 130px;
    object-fit: cover;
    border-radius: 4px;
    cursor: pointer;
}

.asset-card p {
    margin: 4px 0 2px 0;
    font-weight: 600;
    font-size: 0.95em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.asset-card .asset-id {
    font-size: 0.8em;
    color: #6c757d;
    margin-top: 3px;
    word-break: break-all;
}

.no-assets-message {
    font-style: italic;
    color: #6c757d;
}

/* Console & Lightbox */
.console-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 35%;
    background-color: #1e1e1e;
    color: #d4d4d4;
    z-index: 2000;
    border-top: 1px solid #383838;
    display: none;
    flex-direction: column;
}

.console-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 15px;
    background-color: #252526;
}

#console-output {
    flex-grow: 1;
    overflow-y: auto;
    font-family: monospace;
    padding: 10px 15px;
}
#console-output pre {
    white-space: pre-wrap;
    word-break: break-all;
    display: inline;
}


.image-lightbox {
    display: none;
    position: fixed;
    z-index: 1001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.85);
    padding-top: 60px;
    box-sizing: border-box;
}
.image-lightbox-content {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 85vh;
    object-fit: contain;
    animation-name: zoomIn;
    animation-duration: 0.4s;
}
.image-lightbox-close-btn {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
    cursor: pointer;
    z-index: 1002;
}
.image-lightbox-close-btn:hover, .image-lightbox-close-btn:focus {
    color: #bbb;
    text-decoration: none;
}
@keyframes zoomIn {
    from {transform: scale(0.8)}
    to {transform: scale(1)}
}


/* Decision Tree Panel */
.decision-tree-panel {
    gap: 1rem;
}

#tree-legend {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 15px;
    font-size: 0.9em;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #e9ecef;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}
.legend-color-box {
    width: 16px;
    height: 16px;
    border: 2px solid;
    border-radius: 4px;
}

#tree-container {
    flex-shrink: 0;
    min-height: 300px;
    border: 1px solid #e9ecef;
}

.tree-editor-area {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e9ecef;
}

#tree-code-editor {
    width: 100%;
    height: 200px; 
    min-height: 100px;
    font-family: monospace;
    border: 1px solid #ced4da;
    padding: 10px;
    resize: vertical; 
}

.tree-editor-controls {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

/* Drop Overlay for Drag and Drop */
.drop-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(102, 126, 234, 0.8);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 2em;
    font-weight: bold;
    text-align: center;
    pointer-events: none;
}

/* Responsive */
@media (max-width: 768px) {
    .app-header {
        display: flex;
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
        position: static;
    }
    .header-center-area {
        margin: 0;
        order: 2;
    }
    .logo {
        order: 1;
    }
    .header-actions {
        order: 3;
        position: static;
        transform: none;
        margin-top: 0.5rem;
    }

    .workflow-nav {
        flex-wrap: wrap;
        justify-content: center;
    }
    .app-main {
        padding: 1rem;
    }
    .input-area {
        flex-direction: column;
        align-items: stretch;
    }
    .send-btn {
        width: 100%;
        margin-top: 5px;
    }
    .sidebar {
        width: 100%;
        max-width: 100%;
    }
}

/* 企劃書 Markdown 渲染美化樣式 */
#file-content-display h1,
#file-content-display h2,
#file-content-display h3,
#file-content-display h4 {
    margin-top: 1.6em;
    margin-bottom: 0.8em;
    font-weight: 600;
    line-height: 1.3;
    color: #2c3e50;
    border-bottom: 1px solid #e9ecef;
    padding-bottom: 0.4em;
}

#file-content-display h1 { font-size: 1.8em; }
#file-content-display h2 { font-size: 1.5em; }
#file-content-display h3 { font-size: 1.25em; }

#file-content-display p {
    margin-bottom: 1.2em;
    line-height: 1.7;
    color: #495057;
}

#file-content-display ul,
#file-content-display ol {
    margin-bottom: 1.2em;
    padding-left: 1.8em;
}

#file-content-display li {
    margin-bottom: 0.6em;
}

#file-content-display strong {
    color: #343a40;
}

#file-content-display code {
    background-color: rgba(102, 126, 234, 0.1);
    color: #667eea;
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: monospace;
}

#file-content-display blockquote {
    border-left: 4px solid #667eea;
    margin: 1em 0;
    padding: 0.5em 1em;
    color: #6c757d;
    background-color: #f8f9fa;
}