:root {
    --bg-color: #1a1a1a;
    --card-bg: #2d2d2d;
    --text-main: #ffffff;
    --text-muted: #a0a0a0;
    --accent: #646cff;
    --accent-hover: #7d84ff;
    --success: #4caf50;
    --danger: #f44336;
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    margin: 0;
    display: flex;
    justify-content: center;
    min-height: 100vh;
    overflow-x: hidden;
}

#app {
    width: 100%;
    max-width: 960px;
    padding: 2rem;
}

/* Main Layout: Sidebar + Chat side-by-side */
.layout-main {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

/* Character Sidebar */
.sidebar {
    width: 220px;
    min-width: 220px;
    background-color: var(--card-bg);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

/* ========================================
   In-App Tooltip System
======================================== */
.tooltip-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.tooltip-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 700;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    vertical-align: middle;
    margin-left: 0.3rem;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.tooltip-btn:hover {
    background: rgba(255, 255, 255, 0.22);
    color: var(--text-main);
}

.tooltip-popup {
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    min-width: 200px;
    max-width: 280px;
    background: var(--card-bg, #2a2a2a);
    border: 1px solid var(--border, #444);
    border-radius: 8px;
    padding: 0.65rem 0.85rem;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--text-main);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    pointer-events: auto;
    white-space: normal;
}

/* Arrow */
.tooltip-popup::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-bottom-color: var(--border, #444);
}

.tooltip-popup::after {
    content: '';
    position: absolute;
    bottom: calc(100% - 1px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-bottom-color: var(--card-bg, #2a2a2a);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #444;
}

.sidebar-header h3 {
    margin: 0;
    font-size: 1rem;
    color: var(--text-muted);
}

.sidebar-header .btn.text {
    font-size: 1.2rem;
    padding: 0.2rem 0.5rem;
    line-height: 1;
}

#character-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.character-item {
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.15s;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.character-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.character-item .character-actions {
    display: none;
    gap: 0.25rem;
    margin-top: 0.25rem;
}

.character-item:hover .character-actions {
    display: flex;
}

.character-actions button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.75rem;
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
}

.character-actions button:hover {
    color: var(--text-main);
    background-color: rgba(255, 255, 255, 0.1);
}

.character-item.active {
    background-color: var(--accent);
}

.character-item.active .character-name {
    color: white;
}

.character-item.active .character-desc {
    color: rgba(255, 255, 255, 0.7);
}

.character-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-main);
}

.character-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.character-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    align-self: flex-start;
    margin-bottom: 0.15rem;
}

/* Character Modal — image preview */
.char-image-preview {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--border);
    margin-bottom: 0.5rem;
}

.char-image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Character Modal — detail entries */
.detail-entry {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.detail-entry-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
}

.detail-remove-btn {
    font-size: 0.75rem;
    padding: 0.1rem 0.4rem;
    color: var(--text-muted);
}

.detail-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.1rem;
    display: block;
}

.detail-keywords-input,
.detail-content-input {
    width: 100%;
    background: var(--input-bg, rgba(255,255,255,0.07));
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-main);
    font-size: 0.85rem;
    padding: 0.4rem 0.6rem;
    box-sizing: border-box;
    font-family: inherit;
    resize: vertical;
}

.detail-content-input {
    min-height: 60px;
}

/* Chat section fills remaining space */
.layout-main #chat-section {
    flex: 1;
    margin-top: 0;
}

/* ========================================
   Responsive — Tablet (≤700px)
   ======================================== */
@media (max-width: 700px) {
    #app {
        padding: 1rem;
    }

    h1 {
        font-size: 2rem;
    }

    header {
        margin-bottom: 1.5rem;
    }

    .layout-main {
        flex-direction: column;
    }

    /* Sidebar: 가로 스크롤 스트립으로 전환 */
    .sidebar {
        width: 100%;
        min-width: unset;
        padding: 0.6rem 0.75rem;
    }

    .sidebar-header {
        margin-bottom: 0.5rem;
        padding-bottom: 0.4rem;
    }

    #character-list {
        flex-direction: row;
        overflow-x: auto;
        gap: 0.4rem;
        padding-bottom: 0.3rem;
    }

    .character-item {
        flex-shrink: 0;
        min-width: 100px;
        max-width: 140px;
    }

    /* 호버 시 나타나는 액션 버튼은 모바일에서 항상 표시 */
    .character-item .character-actions {
        display: flex;
    }

    .chat-history {
        height: 50vh;
    }

    .user-info {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 0.5rem;
        overflow: hidden;
    }

    .user-info p {
        margin: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: calc(100% - 90px);
    }

    #session-toolbar {
        flex-wrap: wrap;
    }

    .modal-content {
        padding: 1.5rem;
    }

    /* DevTools: fit within viewport width */
    #devtools-container {
        width: calc(100vw - 2rem);
        right: 1rem;
    }

    .message .bubble {
        max-width: 88%;
    }
}

/* ========================================
   Responsive — Phone (≤480px)
   ======================================== */
@media (max-width: 480px) {
    #app {
        padding: 0.75rem;
    }

    h1 {
        font-size: 1.6rem;
    }

    header {
        margin-bottom: 1rem;
    }

    .btn {
        padding: 0.65rem 1.1rem;
        font-size: 0.9rem;
    }

    /* 카드 여백 축소 — 채팅창 크램핑 방지 */
    .card {
        padding: 0.9rem;
        margin-top: 0.75rem;
        border-radius: 8px;
    }

    .chat-history {
        height: 52vh;
    }

    #chat-input {
        padding: 0.6rem 0.75rem;
        font-size: 0.95rem;
    }

    .chat-input-area {
        gap: 0.4rem;
        margin-top: 0.6rem;
    }

    #session-toolbar {
        gap: 0.3rem;
        margin-bottom: 0.5rem;
    }

    #session-select {
        font-size: 0.8rem;
        padding: 0.4rem;
    }

    .message .bubble {
        max-width: 94%;
        padding: 0.6rem 0.9rem;
    }

    .modal-content {
        padding: 1rem;
        width: 95%;
    }

    .modal-actions {
        flex-direction: column;
        gap: 0.5rem;
    }

    .modal-actions .btn {
        width: 100%;
        text-align: center;
    }

    /* Floating buttons: smaller on phone */
    .floating-btn,
    #devtools-toggle {
        width: 42px;
        height: 42px;
        font-size: 1.2rem;
        right: 12px;
    }

    .floating-btn.settings-btn {
        bottom: 68px;
    }

    #devtools-toggle {
        bottom: 14px;
    }

    #devtools-container {
        width: calc(100vw - 1.5rem);
        right: 0.75rem;
        height: 60vh;
    }
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

h1 {
    font-size: 2.5rem;
    margin: 0;
    background: linear-gradient(45deg, #fff, #a5a5a5);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.btn {
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1rem;
}

.btn.primary {
    background-color: #fff;
    color: #333;
}

.btn.primary:hover {
    background-color: #f0f0f0;
}

.btn.success {
    background-color: var(--success);
    color: white;
}

.btn.text {
    background: none;
    color: var(--text-muted);
    padding: 0.5rem;
}

.btn.text:hover {
    color: var(--text-main);
}

.hidden {
    display: none !important;
}

/* Auth Section - Center alignment */
#auth-section {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
}

.card {
    background-color: var(--card-bg);
    padding: 1.5rem;
    border-radius: 12px;
    margin-top: 2rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.console {
    background-color: #111;
    border-radius: 6px;
    padding: 1rem;
    margin-top: 1rem;
    font-family: 'Fira Code', monospace;
    font-size: 0.9rem;
    min-height: 100px;
    max-height: 300px;
    overflow-y: auto;
}

.log-line {
    margin: 0.2rem 0;
    color: #ccc;
}

.log-line.success {
    color: var(--success);
}

.log-line.error {
    color: var(--danger);
}

.log-line.info {
    color: var(--accent);
}

/* Session Toolbar */
#session-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

#session-select {
    flex: 1;
    padding: 0.5rem;
    border-radius: 6px;
    border: 1px solid #444;
    background-color: #333;
    color: white;
    font-size: 0.85rem;
}

/* Chat UI */
.chat-history {
    height: 400px;
    overflow-y: auto;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 1rem;
    background-color: #222;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    display: flex;
}

.message.user {
    justify-content: flex-end;
}

.message.assistant {
    flex-direction: column;
    align-items: flex-start;
}

/* ── Message Edit / Delete Actions ──────────────────────────────────────── */

.message {
    position: relative;
}

.msg-actions {
    display: none;
    gap: 2px;
    position: absolute;
    top: 4px;
    right: 4px;
}

.message:hover .msg-actions {
    display: flex;
}

.msg-action-btn {
    background: rgba(255,255,255,0.08);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 0.75rem;
    padding: 1px 5px;
    cursor: pointer;
    line-height: 1.4;
    transition: background 0.15s;
}

.msg-action-btn:hover {
    background: rgba(255,255,255,0.18);
    color: var(--text-main);
}

.msg-delete-btn:hover {
    color: #f06060;
}

.msg-edit-textarea {
    width: 100%;
    font-size: 0.9rem;
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid var(--accent);
    background: rgba(0,0,0,0.25);
    color: var(--text-main);
    resize: vertical;
    margin-top: 6px;
    box-sizing: border-box;
}

.msg-edit-bar {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.msg-edit-confirm {
    font-size: 0.82rem;
    padding: 4px 10px;
}

.msg-edit-cancel {
    font-size: 0.82rem;
    padding: 4px 8px;
}

/* ── Reroll Actions ─────────────────────────────────────────────────────── */

.reroll-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
}

.reroll-btn {
    background: none;
    border: 1px solid #555;
    color: #777;
    border-radius: 4px;
    padding: 2px 10px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.reroll-btn:hover {
    color: #ddd;
    border-color: #999;
}

.alt-nav {
    background: none;
    border: 1px solid #555;
    color: #777;
    border-radius: 4px;
    padding: 2px 7px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.alt-nav:hover:not(:disabled) {
    color: #ddd;
    border-color: #999;
}

.alt-nav:disabled {
    opacity: 0.3;
    cursor: default;
}

.alt-counter {
    font-size: 0.75rem;
    color: #888;
    min-width: 28px;
    text-align: center;
}

.message .bubble {
    padding: 0.8rem 1.2rem;
    border-radius: 12px;
    max-width: 80%;
    line-height: 1.5;
}

.message.user .bubble {
    background-color: var(--accent);
    color: white;
    border-bottom-right-radius: 2px;
}

.message.assistant .bubble {
    background-color: #444;
    color: #ddd;
    border-bottom-left-radius: 2px;
}

.message.system .bubble {
    background-color: transparent;
    color: var(--danger);
    font-style: italic;
    border: 1px solid var(--danger);
}

/* Markdown rendering inside assistant bubbles */
.message.assistant .bubble p {
    margin: 0 0 0.6em 0;
}
.message.assistant .bubble p:last-child {
    margin-bottom: 0;
}
.message.assistant .bubble h1,
.message.assistant .bubble h2,
.message.assistant .bubble h3 {
    margin: 0.8em 0 0.4em 0;
    color: #fff;
    font-size: 1em;
    font-weight: bold;
}
.message.assistant .bubble ul,
.message.assistant .bubble ol {
    margin: 0.4em 0;
    padding-left: 1.4em;
}
.message.assistant .bubble li {
    margin: 0.2em 0;
}
.message.assistant .bubble code {
    background-color: #2a2a2a;
    color: #e5c07b;
    padding: 0.1em 0.4em;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}
.message.assistant .bubble pre {
    background-color: #2a2a2a;
    border-radius: 6px;
    padding: 0.8em 1em;
    margin: 0.6em 0;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
}
.message.assistant .bubble pre code {
    background: none;
    padding: 0;
    color: #abb2bf;
    font-size: 0.85em;
    white-space: pre-wrap;
}
.message.assistant .bubble blockquote {
    border-left: 3px solid #666;
    margin: 0.4em 0;
    padding-left: 0.8em;
    color: #aaa;
    font-style: italic;
}
.message.assistant .bubble a {
    color: var(--accent);
    text-decoration: underline;
}
.message.assistant .bubble strong {
    color: #fff;
}

.chat-input-area {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

#chat-input {
    flex: 1;
    padding: 0.8rem;
    border-radius: 8px;
    border: 1px solid #444;
    background-color: #333;
    color: white;
    font-size: 1rem;
}

#chat-input:focus {
    outline: 2px solid var(--accent);
    border-color: transparent;
}

/* Modal */
.modal {
    display: flex;
    /* Hidden by class check mostly */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    justify-content: center;
    align-items: center;
}

.modal.hidden {
    display: none !important;
}

.modal-content {
    background-color: var(--card-bg);
    padding: 2rem;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    position: relative;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.close {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
}

.close:hover {
    color: white;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.8rem;
    border-radius: 6px;
    border: 1px solid #444;
    background-color: #333;
    color: white;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 0.9rem;
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* Modal Tabs */
.modal-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid #444;
}

.tab-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.6rem 1.2rem;
    font-size: 0.95rem;
    font-weight: 600;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s, border-color 0.2s;
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-panel.hidden {
    display: none;
}

.divider {
    border: none;
    border-top: 1px solid #444;
    margin: 1rem 0;
}

.label-hint {
    color: var(--text-muted);
    font-weight: normal;
}

.form-group input:disabled,
.form-group select:disabled,
.form-group textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.form-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.75rem 0;
}

.persona-notice {
    background-color: rgba(100, 108, 255, 0.1);
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    line-height: 1.5;
}

.btn.secondary {
    background-color: #444;
    color: white;
}

.btn.secondary:hover {
    background-color: #555;
}

.btn.danger-btn {
    background-color: var(--danger);
    color: white;
}

.btn.danger-btn:hover {
    background-color: #d32f2f;
}

/* Loading Screen */
#loading-screen {
    text-align: center;
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 2rem 0;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.loading-message {
    color: var(--text-muted);
    margin: 0;
}

/* Floating Buttons */
.floating-btn {
    position: fixed;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: var(--card-bg);
    border: 1px solid #444;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    z-index: 9999;
    color: var(--text-main);
    transition: transform 0.2s, background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.floating-btn:hover {
    transform: scale(1.1);
    background-color: #444;
}

.floating-btn.settings-btn {
    bottom: 80px;
}

/* DevTools Styles */
#devtools-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: var(--card-bg);
    border: 1px solid #444;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    z-index: 9999;
    color: var(--text-main);
    transition: transform 0.2s;
}

#devtools-toggle:hover {
    transform: scale(1.1);
    background-color: #444;
}

#devtools-container {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 400px;
    height: 500px;
    background-color: #1a1a1a;
    border: 1px solid #444;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
}

#devtools-container.hidden {
    display: none;
}

.dt-header {
    background-color: #2d2d2d;
    padding: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #444;
}

.dt-tabs {
    display: flex;
    gap: 0.5rem;
}

.dt-tab {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
}

.dt-tab.active {
    background-color: #444;
    color: var(--text-main);
}

.dt-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
}

.dt-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
    background-color: #111;
}

.dt-content.hidden {
    display: none;
}

.dt-log-line {
    padding: 2px 0;
    border-bottom: 1px solid #222;
    word-break: break-all;
}

.dt-log-line.error {
    color: var(--danger);
}

.dt-log-line.success {
    color: var(--success);
}

.dt-log-line.info {
    color: var(--text-muted);
}

.dt-time {
    color: #666;
    margin-right: 5px;
}

.dt-llm-item {
    padding: 0.5rem;
    border-bottom: 1px solid #333;
    cursor: pointer;
}

.dt-llm-item:hover {
    background-color: #1f1f1f;
}

.dt-llm-header {
    font-weight: bold;
    margin-bottom: 2px;
    color: var(--accent);
}

.dt-llm-header.error {
    color: var(--danger);
}

.dt-llm-detail {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.dt-payload {
    background-color: #222;
    padding: 0.5rem;
    margin-top: 0.5rem;
    border-radius: 4px;
    white-space: pre-wrap;
    font-size: 0.75rem;
    color: #a0a0a0;
    overflow-wrap: break-word;
    word-break: break-all;
    max-width: 100%;
}

.dt-payload pre {
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-break: break-all;
    margin: 0;
}

.dt-payload.hidden {
    display: none;
}

/* ========================================
   Toast Notification System
   ======================================== */
#toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
    max-width: 90vw;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem 1.25rem;
    border-radius: 10px;
    background-color: #2d2d2d;
    border: 1px solid #444;
    color: var(--text-main);
    font-size: 0.9rem;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
    opacity: 0;
    transform: translateY(-20px);
    transition: opacity 0.3s, transform 0.3s;
    min-width: 250px;
    max-width: 450px;
}

.toast-show {
    opacity: 1;
    transform: translateY(0);
}

.toast-hide {
    animation: toastFadeOut 0.3s ease forwards;
}

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

.toast-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
    line-height: 1.4;
}

.toast-error {
    border-color: var(--danger);
    background-color: rgba(244, 67, 54, 0.15);
}

.toast-success {
    border-color: var(--success);
    background-color: rgba(76, 175, 80, 0.15);
}

.toast-warning {
    border-color: #ff9800;
    background-color: rgba(255, 152, 0, 0.15);
}

.toast-info {
    border-color: var(--accent);
    background-color: rgba(100, 108, 255, 0.15);
}

/* ========================================
   Offline Banner
   ======================================== */
.offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10001;
    background-color: rgba(255, 152, 0, 0.95);
    color: #1a1a1a;
    text-align: center;
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    transition: transform 0.3s ease;
}

.offline-banner.hidden {
    transform: translateY(-100%);
}

/* ========================================
   Model Parameters Section (Settings Modal)
======================================== */
.model-params-section {
    margin-top: 0.25rem;
}

.model-params-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.param-group {
    margin-bottom: 0.9rem;
}

.param-label-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.3rem;
}

.param-label-row label {
    margin-bottom: 0;
    font-size: 0.85rem;
}

.param-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent, #7c6fff);
    min-width: 2.5rem;
    text-align: right;
}

input[type="range"] {
    width: 100%;
    accent-color: var(--accent, #7c6fff);
    cursor: pointer;
    margin: 0;
}

input[type="range"]:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.param-enable-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
    cursor: pointer;
}

.param-enable-label input[type="checkbox"] {
    width: auto;
    cursor: pointer;
}

/* ========================================
   Chat Mode Toggle Bar
======================================== */
.chat-mode-bar {
    display: flex;
    gap: 6px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border, #333);
    background: rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
}

.mode-btn {
    background: none;
    border: 1px solid var(--border, #444);
    border-radius: 20px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 3px 14px;
    transition: color 0.15s, background 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.mode-btn:hover {
    color: var(--text-main);
    border-color: var(--accent);
}

.mode-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}

/* Subtle visual indicator when roleplay is active */
#chat-section.roleplay-active .chat-input-area {
    border-top: 2px solid var(--accent);
}

#chat-section.roleplay-active #chat-input {
    border-color: var(--accent);
}

/* Novelist mode — warm amber tint */
#chat-section.novelist-active .chat-input-area {
    border-top: 2px solid #f0a030;
}

#chat-section.novelist-active #chat-input {
    border-color: #f0a030;
}

/* ========================================
   Prompt Control Tab (Settings Modal)
======================================== */
.prompt-tab-desc {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin: 0 0 1rem 0;
    line-height: 1.5;
}

.prompt-elements-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.prompt-elements-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.prompt-element-item {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border, #333);
    border-radius: 6px;
    padding: 8px 10px;
}

.pe-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pe-row input[type="checkbox"] {
    width: auto;
    cursor: pointer;
    flex-shrink: 0;
}

.pe-label {
    flex: 1;
    font-size: 0.88rem;
    cursor: pointer;
    user-select: none;
}

.pe-order-btns {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

.pe-order-btn {
    background: none;
    border: 1px solid var(--border, #444);
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.7rem;
    line-height: 1;
    padding: 2px 5px;
    transition: color 0.15s, border-color 0.15s;
}

.pe-order-btn:hover:not(:disabled) {
    color: var(--text-main);
    border-color: var(--accent);
}

.pe-order-btn:disabled {
    opacity: 0.25;
    cursor: not-allowed;
}

/* Structural slots (history / current_message) — visually distinct */
.prompt-element-item.pe-structural {
    background: rgba(124, 111, 255, 0.07);
    border-color: rgba(124, 111, 255, 0.25);
    border-style: dashed;
}

.pe-label-structural {
    font-style: italic;
    color: var(--accent);
}

.pe-badge {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: 4px;
}

.pe-delete-btn {
    background: none;
    border: 1px solid #555;
    border-radius: 4px;
    color: #f44336;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    padding: 1px 5px;
    margin-left: 2px;
    transition: background 0.15s;
}

.pe-delete-btn:hover {
    background: rgba(244, 67, 54, 0.15);
    border-color: #f44336;
}

.pe-add-btn {
    width: 100%;
    margin: 6px 0 4px;
    font-size: 0.85rem;
    color: var(--accent);
    border: 1px dashed var(--accent);
    border-radius: 6px;
    padding: 5px;
}

.pe-add-btn:hover {
    background: rgba(124, 111, 255, 0.1);
}

.pe-content-wrap {
    margin-top: 6px;
}

.pe-content-wrap.hidden {
    display: none;
}

.pe-label-input {
    width: 100%;
    font-size: 0.8rem;
    margin-bottom: 4px;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-main);
    padding: 3px 6px;
}

.pe-content-textarea {
    width: 100%;
    font-size: 0.82rem;
    resize: vertical;
    min-height: 60px;
}

.prompt-preview {
    margin-top: 12px;
    border: 1px solid var(--border, #333);
    border-radius: 6px;
    overflow: hidden;
}

.prompt-preview-label {
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid var(--border, #333);
    font-size: 0.78rem;
    color: var(--text-muted);
    padding: 6px 10px;
    font-weight: 600;
}

.prompt-preview-content {
    font-family: monospace;
    font-size: 0.78rem;
    color: var(--text-main);
    padding: 10px;
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 240px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.2);
}

/* ── Preset Bar ──────────────────────────────────────────────────────────── */

.preset-bar {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 6px;
}

.preset-select {
    flex: 1;
    font-size: 0.82rem;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-main);
    padding: 4px 6px;
}

.preset-save-row {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 12px;
}

.preset-name-input {
    flex: 1;
    font-size: 0.82rem;
    padding: 4px 8px;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-main);
}

.preset-btn {
    font-size: 0.8rem;
    padding: 4px 10px;
    white-space: nowrap;
}

/* ── Prompt Inspector ────────────────────────────────────────────────────── */

.inspector-btn {
    font-size: 1rem;
    padding: 0 8px;
    opacity: 0.7;
    flex-shrink: 0;
}

.inspector-btn:hover {
    opacity: 1;
}

.inspector-modal-content {
    max-width: 680px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.inspector-title {
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.inspector-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 0 0 1rem 0;
}

.inspector-content {
    overflow-y: auto;
    flex: 1;
}

.inspector-summary {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.inspector-token-total {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--accent);
}

.inspector-token-breakdown,
.inspector-msg-count {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.inspector-msg {
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 8px;
    overflow: hidden;
}

.inspector-msg-role {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 4px 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.inspector-msg-system .inspector-msg-role {
    background: rgba(124, 111, 255, 0.15);
    color: var(--accent);
}

.inspector-msg-user .inspector-msg-role {
    background: rgba(100, 200, 100, 0.1);
    color: #7ec87e;
}

.inspector-msg-assistant .inspector-msg-role {
    background: rgba(200, 200, 200, 0.06);
    color: var(--text-muted);
}

.inspector-msg-content {
    font-family: monospace;
    font-size: 0.78rem;
    color: var(--text-main);
    padding: 8px 10px;
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 180px;
    overflow-y: auto;
    background: rgba(0,0,0,0.15);
}
