/* /assets/styles.css */
/* A single, combined stylesheet for all ByteGuard Frontend components. */

/* --- Global Styles --- */
html,
body {
    background: #fff;
}

:root {
    --bgf-primary: #FACC15;          /* amber/yellow */
    --bgf-primary-hover: #EAB308;    /* darker on hover */
    --bgf-primary-text: #111827;     /* readable on yellow */
    --focus-ring: #2563eb;           /* accessible focus color */

    /* Cap used by chat window auto-grow JS (read via getComputedStyle). */
    --composer-actions-h: 140;
}

*:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

/* --- Layout & Utilities --- */
.bgf-wrap {
    max-width: 720px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 1rem;
    height: calc(100vh - 100px);
    padding: 1rem;
    width: 100%;
    min-height: 0;
}

@supports (height: 100dvh) {
    .layout {
        height: calc(100dvh - 100px);
    }
}

.main {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.card {
    border: 1px solid #e3e6ea;
    border-radius: 12px;
    padding: 1rem;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.lbl {
    font-size: .85rem;
    color: #57606a;
    font-weight: 500;
}

.muted {
    color: #6b7280;
    font-size: .9rem;
}

.muted.success {
    color: #0c7a43;
}

.muted.danger {
    color: #b42318;
}

.link {
    color: #2563eb;
    text-decoration: none;
}

.link:hover {
    text-decoration: underline;
}

.inp {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: .6rem .7rem;
    font: inherit;
    background: #f9fafb;
    transition: box-shadow .15s, border-color .15s, background-color .15s;
}

.inp.small {
    padding: .3rem .5rem;
    font-size: .9rem;
}

.inp:focus,
.inp:focus-visible {
    background: #fff;
    border-color: #94a3b8;
    box-shadow: 0 0 0 3px rgba(148, 163, 184, .25);
}

.btn {
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    padding: .5rem .8rem;
    border-radius: 10px;
    font: inherit;
    cursor: pointer;
    transition: background-color 0.2s, box-shadow .15s, border-color .15s;
}

.btn:hover {
    background: #eef2ff;
}

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

.btn.btn-primary {
    background: var(--bgf-primary);
    border-color: var(--bgf-primary);
    color: var(--bgf-primary-text);
    font-weight: 500;
}

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

.btn.btn-primary:focus-visible {
    box-shadow: 0 0 0 3px rgba(250, 204, 21, .45);
}

.btn.btn-ghost {
    background: transparent;
    border: none;
    color: #475569;
}

.btn.btn-ghost:hover {
    background: #f1f5f9;
}

/* Inline action buttons */
.btn-inline {
    all: unset;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    cursor: pointer;
    font-size: .85rem;
    color: #2563eb;
    padding: 2px 8px;
    border-radius: 999px;
}
.btn-inline:hover {
    background: #e2e8f0;
}
.btn-inline:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

/* --- API Keys (AI settings) --- */
.api-keys-card {
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.api-keys-row {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}

.api-keys-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
}

.api-keys-table th,
.api-keys-table td {
    padding: .5rem .6rem;
    border-bottom: 1px solid #e5e7eb;
    text-align: left;
    font-size: .9rem;
    vertical-align: top;
}

.api-keys-table th {
    background: #f8fafc;
    color: #475569;
    font-weight: 600;
}

.api-key-raw {
    padding: .6rem .7rem;
    border: 1px solid #fde68a;
    background: #fffbeb;
    border-radius: 10px;
    color: #92400e;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    word-break: break-all;
}

.model-narrative {
    margin: .45rem 0 .55rem;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
    padding: .55rem .65rem;
    display: grid;
    gap: .25rem;
}

.model-narrative-name {
    font-size: .87rem;
    font-weight: 600;
    color: #0f172a;
}

.model-narrative-line {
    font-size: .83rem;
    color: #334155;
    line-height: 1.3;
}

.model-current-row {
    align-items: center;
}

.current-agent-name {
    font-size: .86rem;
    font-weight: 700;
    color: #78350f;
    background: #fde68a;
    border: 1px solid #facc15;
    border-radius: 999px;
    padding: .15rem .6rem;
    max-width: 64%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.model-select-row {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.model-select-row #agentSelect {
    flex: 1 1 auto;
}

.voice-clone-controls {
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.voice-clone-select-row {
    display: flex;
    align-items: center;
}

.voice-clone-select-row #voiceCloneSelect {
    flex: 1 1 auto;
}

.voice-clone-action-row {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.voice-clone-add-wrap {
    flex: 1 1 50%;
    min-width: 0;
}

.voice-clone-add-wrap #addVoiceBtn {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.voice-clone-right-wrap {
    flex: 1 1 50%;
    min-width: 0;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: .4rem;
}

.voice-clone-right-wrap #testVoiceBtn {
    min-width: 112px;
}

.voice-clone-right-wrap #deleteVoiceBtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 640px) {
    .voice-clone-action-row {
        flex-direction: column;
        align-items: stretch;
    }

    .voice-clone-right-wrap {
        justify-content: space-between;
    }
}

/* --- Toast Notification Styles --- */
.toast {
    background: #111827;
    color: #fff;
    padding: .5rem .75rem;
    border-radius: 8px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .15);
    font-size: .9rem;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 360px;
}

.toast.error {
    background: #b42318;
}

.toast-message {
    flex-grow: 1;
}

.toast-close-btn {
    margin-left: 8px;
    background: transparent;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    padding: 0.25rem;
}

/* --- Responsive & Accessibility --- */
@media (max-width: 900px) {
    .layout {
        grid-template-columns: 1fr;
        height: auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    .btn,
    .inp,
    .conv-item,
    .toggle-switch,
    .composer textarea {
        transition: none;
    }
}

/* --- Chat Window --- */
.chat-window-shell {
    position: relative;
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    height: min(78vh, 920px);
    max-height: 920px;
    min-height: 520px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #fff;
}

@supports (height: 100dvh) {
    .chat-window-shell {
        height: min(78dvh, 920px);
    }
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .75rem 1rem;
    border-bottom: 1px solid #e5e7eb;
    flex: 0 0 auto;
}

.chat {
    flex: 1 1 auto;
    min-height: 220px;
    overflow-y: auto;
    scrollbar-width: thin;
    overscroll-behavior: contain;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.chat::-webkit-scrollbar {
    width: 10px;
}

.chat::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.chat::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
}

.msg {
    display: flex;
}

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

.msg.ai,
.msg.error {
    justify-content: flex-start;
}

.bubble {
    max-width: min(90%, 760px);
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    background: #f8fafc;
    padding: .7rem .8rem;
}

.msg.user .bubble {
    background: #fef9c3;
    border-color: #facc15;
}

.bubble.error {
    background: #fef2f2;
    border-color: #fecaca;
}

.bubble-content {
    white-space: pre-wrap;
    word-break: break-word;
}

.msg-actions {
    display: flex;
    align-items: center;
    gap: .45rem;
    margin: .25rem 0 .75rem;
}

.thinking-panel,
.narration-bar {
    margin: 0 1rem .5rem;
    border: 1px solid #dbeafe;
    background: #eff6ff;
    border-radius: 10px;
    padding: .5rem .65rem;
    flex: 0 0 auto;
}

.thinking-panel.is-loading {
    border-color: #facc15;
    background: #fffbeb;
}

.thinking-panel.is-loading #thinkingSummary {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
}

.thinking-panel.is-loading #thinkingSummary::before {
    content: "";
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(245, 158, 11, .35);
    border-top-color: #f59e0b;
    border-radius: 50%;
    animation: bgf-spin .8s linear infinite;
}

.thinking-content,
.narration-content {
    margin-top: .4rem;
    max-height: 160px;
    overflow: auto;
    font-size: .86rem;
    color: #1e3a8a;
}

.thinking-line {
    padding: .2rem 0;
    border-bottom: 1px dashed #bfdbfe;
}

.thinking-line:last-child {
    border-bottom: none;
}

.chat-load-status {
    margin: 0 1rem .5rem;
    padding: .55rem .7rem;
    border-radius: 8px;
    border: 1px solid #fed7aa;
    background: #fff7ed;
    color: #9a3412;
    font-size: .9rem;
    flex: 0 0 auto;
    display: none !important;
}

.chat-load-status[hidden] {
    display: none !important;
}

.composer {
    border-top: 1px solid #e5e7eb;
    padding: .8rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .6rem;
    background: #fff;
    flex: 0 0 auto;
}

.composer textarea {
    width: 100%;
    resize: none;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: .65rem .75rem;
    font: inherit;
    line-height: 1.45;
    max-height: 140px;
}

.composer-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .5rem;
}

.attachment-preview {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: .2rem .35rem;
    background: #f8fafc;
}

.attachment-preview img {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 6px;
}

.chat-busy-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .42);
    backdrop-filter: blur(1px);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    display: none !important;
}

.chat-busy-overlay[hidden] {
    display: none !important;
}

.chat-busy-box {
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    background: #111827;
    color: #fff;
    border-radius: 999px;
    padding: .6rem 1rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}

.bgf-spinner,
.btn-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, .35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: bgf-spin .8s linear infinite;
}

.btn-inline.is-loading {
    opacity: .95;
    color: #334155;
    cursor: wait;
}

.btn-inline.is-loading .btn-spinner {
    width: 14px;
    height: 14px;
    border-color: rgba(37, 99, 235, .35);
    border-top-color: #2563eb;
}

body.bgf-page-locked {
    overflow: hidden !important;
}

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

@media (max-width: 900px) {
.chat-window-shell {
        height: 70vh;
        min-height: 70vh;
        max-height: none;
    }

    .bubble {
        max-width: 96%;
    }
}

.chat-window-shell.bgf-interaction-locked {
    cursor: progress;
}

body.bgf-ui-locked #convList,
body.bgf-ui-locked .conv-item,
body.bgf-ui-locked .conv-actions,
body.bgf-ui-locked .conv-action-btn,
.chat-window-shell.bgf-interaction-locked .conv-list,
.chat-window-shell.bgf-interaction-locked .conv-item {
    pointer-events: none;
}

body.bgf-ui-locked #chatWindowShell {
    cursor: progress;
}
