/* ── Dark theme variables ── */
:root {
    --bg-page: #0d1117;
    --bg-surface: #161b22;
    --bg-surface-2: #1c2128;
    --bg-bubble-bot: #21262d;
    --bg-bubble-user: #a02334;
    --bg-header: #0a0c10;
    --border-subtle: #30363d;
    --border-strong: #484f58;
    --text-primary: #c9d1d9;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent: #c41e3a;
    --accent-hover: #e0334d;
    --danger: #f85149;
    --warning: #d29922;
}

html, body {
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--bg-page);
    color: var(--text-primary);
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-surface);
}

::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

/* ── Full-screen layout ── */
.app-layout {
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--bg-page);
}

.chat-wrapper {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.setup-alert {
    margin: 12px;
    flex-shrink: 0;
}

/* ── Chat container ── */
.chat-container {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* ── Main chat column ── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--bg-header);
    color: var(--text-primary);
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-subtle);
}

.chat-title {
    font-size: 1.05rem;
    font-weight: 600;
    flex: 1;
}

.chat-badges {
    display: flex;
    gap: 6px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg-page);
}

/* ── Persona section ── */
.persona-section {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.persona-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    cursor: pointer;
    user-select: none;
    font-size: 0.88rem;
    color: var(--text-primary);
}

.persona-toggle:hover {
    background: var(--bg-surface-2);
}

.persona-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.persona-label {
    font-weight: 600;
    color: var(--text-primary);
    flex-shrink: 0;
}

.persona-preview {
    flex: 1;
    color: var(--text-secondary);
    font-style: italic;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.persona-chevron {
    color: var(--text-secondary);
    font-size: 0.7rem;
    flex-shrink: 0;
}

.persona-body {
    padding: 0 14px 12px 14px;
}

.persona-input {
    font-size: 0.9rem;
    resize: vertical;
    min-height: 120px;
}

.persona-hint {
    display: block;
    margin-top: 6px;
    color: var(--text-secondary);
    font-size: 0.78rem;
}

.persona-gen-trigger {
    margin-bottom: 10px;
    font-size: 0.82rem;
}

.persona-generator-panel {
    background: #2a0c14;
    border: 1px solid #5a1a26;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 10px;
}

.persona-gen-label {
    display: block;
    font-size: 0.8rem;
    color: #ff7b8a;
    margin-bottom: 6px;
    font-weight: 500;
}

.persona-notes-input {
    font-size: 0.88rem;
    resize: vertical;
    margin-bottom: 8px;
}

.persona-gen-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

.persona-gen-warning {
    display: block;
    margin-top: 8px;
    color: var(--warning);
    font-size: 0.76rem;
}

.summary-banner {
    background: #2d2510;
    border: 1px solid #614c1a;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.83rem;
    color: #e3b341;
    flex-shrink: 0;
}

/* ── Message bubbles ── */
.message {
    display: flex;
    flex-direction: column;
    gap: 3px;
    max-width: 82%;
}

.msg-user {
    align-self: flex-end;
    align-items: flex-end;
}

.msg-bot {
    align-self: flex-start;
    align-items: flex-start;
}

/* ── Per-message actions (hover-revealed) ── */
.message-actions {
    display: flex;
    gap: 4px;
    opacity: 0.3;
    transition: opacity 0.15s;
}

.message:hover .message-actions {
    opacity: 1;
}

.msg-action-btn {
    background: var(--bg-surface-2);
    border: 1px solid var(--border-subtle);
    border-radius: 4px;
    padding: 4px 6px;
    line-height: 0;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.msg-action-btn svg {
    width: 14px;
    height: 14px;
    display: block;
}

.msg-action-btn:hover {
    background: var(--bg-bubble-bot);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.msg-action-btn.delete:hover {
    color: var(--danger);
    border-color: var(--danger);
    background: #2d0e0e;
}

/* ── Inline edit mode ── */
.message-bubble.editing {
    background: var(--bg-surface) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--accent);
    border-radius: 12px !important;
    padding: 10px !important;
    box-shadow: 0 2px 12px rgba(196, 30, 58, 0.25) !important;
    width: min(520px, 80vw);
}

.edit-textarea {
    font-size: 0.93rem;
    resize: vertical;
    margin-bottom: 8px;
    width: 100%;
}

.edit-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    align-items: center;
}

/* ── Inline "Direct..." panel ── */
.direct-panel {
    background: var(--bg-surface);
    border: 1px solid var(--accent);
    border-radius: 12px;
    padding: 10px;
    box-shadow: 0 2px 12px rgba(196, 30, 58, 0.25);
    width: min(520px, 80vw);
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
}

.direct-textarea {
    font-size: 0.9rem;
    resize: vertical;
}

.direct-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    align-items: center;
}

/* Force inline action-row buttons to natural width — prevents flex/bootstrap from stretching them */
.edit-actions .btn,
.direct-actions .btn,
.persona-gen-actions .btn {
    flex: 0 0 auto;
    width: auto;
    white-space: nowrap;
}

.message-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 0.93rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

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

.msg-bot .message-bubble {
    background: var(--bg-bubble-bot);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* ── Role-play actions ── */
.action-text {
    display: block;
    font-style: italic;
    margin: 4px 0;
    white-space: pre-wrap;
}

.msg-bot .action-text {
    color: var(--text-muted);
}

.msg-user .action-text {
    color: rgba(255, 255, 255, 0.7);
}

/* ── Thinking animation ── */
.thinking {
    display: flex;
    gap: 5px;
    align-items: center;
    padding: 12px 14px !important;
}

.thinking span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: bounce 1.2s infinite;
}

.thinking span:nth-child(2) { animation-delay: 0.2s; }
.thinking span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* ── Input area ── */
.chat-input-area {
    padding: 10px 14px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.message-input {
    flex: 1;
    resize: none;
    border-radius: 12px;
    font-size: 0.93rem;
}

.send-btn {
    padding: 8px 22px;
    border-radius: 12px;
    white-space: nowrap;
    flex: 0 0 auto;
}

.error-bubble {
    background: #2d0e0e !important;
    color: #f85149 !important;
    border: 1px solid #8b2828;
    box-shadow: none !important;
}

/* Bootstrap overrides for dark theme */
.form-control {
    background: var(--bg-surface-2);
    color: var(--text-primary);
    border-color: var(--border-subtle);
}

.form-control:focus {
    background: var(--bg-surface-2);
    color: var(--text-primary);
    border-color: var(--accent);
    box-shadow: 0 0 0 0.2rem rgba(196, 30, 58, 0.25);
}

.form-control::placeholder {
    color: var(--text-muted);
}

.btn-primary {
    background-color: var(--accent);
    border-color: var(--accent);
    color: white;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-outline-secondary {
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.btn-outline-secondary:hover {
    background: var(--bg-surface-2);
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

.btn-outline-light {
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.btn-outline-light:hover {
    background: var(--bg-surface-2);
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

.btn-outline-primary {
    color: var(--accent-hover);
    border-color: var(--accent);
}

.btn-outline-primary:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

a, .btn-link {
    color: var(--accent-hover);
}

.btn:focus, .btn:active:focus, .form-control:focus, .form-check-input:focus {
    box-shadow: 0 0 0 0.2rem rgba(196, 30, 58, 0.35);
}

.alert-warning {
    background: #2d2510;
    border-color: #614c1a;
    color: #e3b341;
}

.alert-warning code {
    color: #f0b352;
    background: rgba(0,0,0,0.25);
    padding: 1px 4px;
    border-radius: 3px;
}

.badge.bg-info {
    background: #3a1822 !important;
    color: #ff7b8a !important;
}

.badge.bg-secondary {
    background: var(--bg-surface-2) !important;
    color: var(--text-secondary) !important;
}

.blazor-error-boundary {
    background: #2d0e0e;
    border: 1px solid #8b2828;
    padding: 1rem;
    color: #f85149;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

.validation-message {
    color: var(--danger);
}
