:root {
    --primary: #3b82f6;
    --indigo: #4f46e5;
    --text: #23272f;
    --muted: #64748b;
    --line: #d1d5db;
    --sidebar: #eff6ff;
    --page: #f8fafc;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    color: var(--text);
    background: #fff;
}

button, textarea { font-family: inherit; }

#app {
    display: flex;
    height: 100vh;
    min-height: 0;
    overflow: hidden;
    background: #fff;
}

#sidebar {
    width: 250px;
    flex: 0 0 250px;
    background: var(--sidebar);
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--line);
    background: var(--sidebar);
}

.sidebar-btn {
    width: 100%;
    padding: 10px 12px;
    background: #fff;
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-btn:hover { background: #f3f4f6; }

.sidebar-ico {
    width: 20px;
    display: inline-flex;
    justify-content: center;
    color: #4b5563;
}

#item-list {
    list-style: none;
    margin: 0;
    padding: 12px;
    overflow-y: auto;
    flex: 1 1 0;
    min-height: 0;
}

.list-item {
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.95rem;
}

.list-item:hover { background: #dbeafe; }

.list-item.active {
    background: var(--primary);
    color: #fff;
    font-weight: 500;
}

#main-content {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
    background: var(--page);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 28px 20px 40px;
}

#welcome-block {
    max-width: 760px;
    width: 100%;
    text-align: center;
    margin-bottom: 22px;
}

.welcome-title {
    font-size: 1.45rem;
    font-weight: 650;
    color: #1e293b;
    margin-bottom: 12px;
}

.welcome-desc {
    font-size: 1rem;
    color: var(--muted);
    line-height: 1.6;
    margin: 0 auto;
    max-width: 680px;
}

#active-item-block {
    display: none;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    border-radius: 8px;
    padding: 8px 14px;
    margin: 0 auto 12px;
    width: min(760px, 100%);
    text-align: center;
    font-size: 0.85rem;
    font-weight: 500;
    color: #047857;
}

#active-item-block.show { display: block; }

#system-message-block {
    display: none;
    width: min(760px, 100%);
    margin: 0 auto 12px;
    border-radius: 12px;
    padding: 10px 14px;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 500;
}

#system-message-block.show { display: block; }

#status-message.success {
    color: #047857;
    background: rgba(5, 150, 105, 0.08);
    border: 1px solid rgba(5, 150, 105, 0.25);
    border-radius: 10px;
    padding: 8px 12px;
}

#status-message.error {
    color: #be123c;
    background: rgba(225, 29, 72, 0.08);
    border: 1px solid rgba(225, 29, 72, 0.2);
    border-radius: 10px;
    padding: 8px 12px;
}

#status-message.info {
    color: #1e40af;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-radius: 10px;
    padding: 8px 12px;
}

#text-composer {
    width: min(760px, 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

#text-source {
    width: 100%;
    min-height: 42vh;
    max-height: 62vh;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    background: #fff;
    padding: 18px 16px;
    font-size: 0.95rem;
    line-height: 1.5;
    color: #1e293b;
    resize: vertical;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.04);
}

#text-source:focus {
    outline: none;
    border-color: #93c5fd;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

#upload-text-btn {
    background: var(--indigo);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
}

#upload-text-btn:hover { background: #4338ca; }
#upload-text-btn:disabled { opacity: 0.6; cursor: default; }

#sidebar-right {
    width: 380px;
    flex: 0 0 380px;
    background: #fff;
    border-left: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 12px 8px;
    font-weight: 650;
    font-size: 1rem;
}

.delete-btn {
    border: none;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
}

.delete-btn:hover { background: #f3f4f6; color: #ef4444; }
.delete-btn.hidden { display: none; }

#chat-history {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    padding: 8px 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-empty {
    color: #6b7280;
    font-size: 0.92rem;
    line-height: 1.45;
}

.chat-onboarding {
    color: #1f2937;
    font-size: 14px;
    line-height: 1.45;
}

.prompt-chip {
    width: 100%;
    text-align: left;
    padding: 12px 14px;
    border-radius: 12px;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    color: #111827;
    font-size: 14px;
    cursor: pointer;
}

.prompt-chip:hover {
    background: #eef2ff;
    border-color: #c7d2fe;
}

.prompt-chip:disabled { opacity: 0.6; cursor: default; }

.chat-message {
    padding: 7px 12px;
    border-radius: 14px;
    max-width: 95%;
    font-size: 0.97rem;
    line-height: 1.45;
}

.user-message {
    background: var(--primary);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}

.bot-message {
    align-self: flex-start;
    color: var(--text);
    max-width: 100%;
    padding-left: 0;
}

.pending {
    color: #6b7280;
    font-size: 0.92rem;
}

.md-body { white-space: normal; }
.md-body > *:first-child { margin-top: 0; }
.md-body > *:last-child { margin-bottom: 0; }
.md-body p { margin: 0 0 0.7em; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4 {
    margin: 1em 0 0.4em;
    line-height: 1.3;
    font-weight: 650;
}
.md-body h1 { font-size: 1.2em; }
.md-body h2 { font-size: 1.1em; }
.md-body h3 { font-size: 1.02em; }
.md-body ul, .md-body ol {
    margin: 0 0 0.7em;
    padding-left: 1.35em;
}
.md-body ul { list-style: disc; }
.md-body ol { list-style: decimal; }
.md-body li { margin: 0.2em 0; }
.md-body pre {
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 10px 12px;
    overflow-x: auto;
    font-size: 0.86rem;
}
.md-body code {
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.9em;
}
.md-body blockquote {
    margin: 0 0 0.7em;
    padding-left: 12px;
    border-left: 3px solid #cbd5e1;
    color: #475569;
}
.md-body table {
    border-collapse: collapse;
    width: 100%;
    margin: 0 0 0.7em;
    font-size: 0.9rem;
}
.md-body th, .md-body td {
    border: 1px solid #e5e7eb;
    padding: 6px 8px;
    text-align: left;
}
.md-body a { color: #2563eb; }

.text-input-block {
    padding: 12px 14px 16px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
}

.input-row { display: flex; align-items: stretch; }

#chat-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-right: none;
    border-radius: 12px 0 0 12px;
    padding: 12px;
    font-size: 0.9rem;
    resize: none;
    min-height: 44px;
    max-height: 140px;
    line-height: 1.35;
}

#chat-input:focus {
    outline: none;
    border-color: var(--indigo);
}

#send-btn {
    width: 44px;
    min-width: 44px;
    border: none;
    background: #a259f7;
    color: #fff;
    border-radius: 0 12px 12px 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#send-btn:hover { background: #7c3aed; }
#send-btn:disabled { opacity: 0.6; cursor: default; }

@media (max-width: 900px) {
    #app {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }
    #sidebar {
        width: 100%;
        flex: none;
        border-right: none;
        border-bottom: 1px solid #e5e7eb;
        max-height: 220px;
    }
    #sidebar-right {
        width: 100%;
        flex: none;
        height: 70vh;
        border-left: none;
        border-top: 1px solid #e5e7eb;
    }
    #main-content { overflow: visible; }
    #text-source { min-height: 240px; }
}
