/* Color System & CSS variables */
:root {
    --bg-primary: #090c15;
    --bg-secondary: #111726;
    --bg-tertiary: #192239;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-light: rgba(99, 102, 241, 0.15);
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --border-color: rgba(255, 255, 255, 0.08);
    --bubble-user: linear-gradient(135deg, #6366f1, #4f46e5);
    --bubble-bot: #1f293d;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.35);
}

/* Global resets & Scrollbar Styling */
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

#layout {
    display: grid;
    grid-template-columns: 240px 1fr 280px;
    height: 100%;
}

/* Sidebar General Styles */
#left-panel, #right-panel {
    background: var(--bg-secondary);
    padding: 24px 20px;
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

#right-panel {
    border-right: none;
    border-left: 1px solid var(--border-color);
}

h3 {
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 0.9em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

/* Buttons */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--accent);
    color: white;
    font-weight: 500;
    font-size: 0.9em;
    text-decoration: none;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

/* Left Panel - History Area */
#chat-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.chat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

.chat-item:hover {
    border-color: rgba(99, 102, 241, 0.3);
    background: rgba(99, 102, 241, 0.05);
}

.chat-item a {
    color: var(--text-main);
    text-decoration: none;
    font-size: 0.85em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.chat-item .delete-btn {
    color: #ef4444;
    font-weight: bold;
    text-decoration: none;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 1.1em;
    transition: background 0.2s;
}

.chat-item .delete-btn:hover {
    background: rgba(239, 68, 68, 0.15);
}

/* Center Chat Area */
#chat-main {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg-primary);
    min-height: 0; /* Allows grid item to shrink and enables scroll inside flex child */
}

#chatbox {
    flex: 1;
    overflow-y: auto;
    padding: 40px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Chat bubble aesthetics */
.msg {
    max-width: 75%;
    padding: 12px 16px;
    font-size: 0.95em;
    line-height: 1.5;
    box-shadow: var(--shadow-sm);
    word-wrap: break-word;
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
}

.msg.user {
    background: var(--bubble-user);
    color: white;
    align-self: flex-end;
    border-radius: 18px 18px 2px 18px;
}

.msg.bot, .msg.model {
    background: var(--bubble-bot);
    color: var(--text-main);
    align-self: flex-start;
    border-radius: 18px 18px 18px 2px;
    border: 1px solid var(--border-color);
}

/* Interactive Floating Input Column */
#input-area {
    padding: 24px 40px;
    display: flex;
    gap: 12px;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
}

#userInput {
    flex: 1;
    padding: 14px 20px;
    background: var(--bg-secondary);
    color: white;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    outline: none;
    font-size: 0.95em;
    transition: all 0.2s ease;
}

#userInput:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

#sendButton {
    padding: 0 24px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 10px;
    font-weight: 500;
    font-size: 0.95em;
    cursor: pointer;
    transition: all 0.2s ease;
}

#sendButton:hover {
    background: var(--accent-hover);
}

/* Right Panel Inputs & Grouping Panels */
.config-group, .prompt-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#right-panel input, #right-panel select, #right-panel textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9em;
    outline: none;
    box-sizing: border-box;
    transition: all 0.2s ease;
}

#right-panel input:focus, #right-panel select:focus, #right-panel textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

#right-panel label {
    font-size: 0.75em;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* Integrated Lock/Key Container */
.api-key-container {
    display: flex;
    align-items: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding-right: 6px;
    transition: all 0.2s ease;
}

.api-key-container:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

.api-key-container input {
    border: none !important;
    background: transparent !important;
    margin-bottom: 0 !important;
    box-shadow: none !important;
}

#unlock-api-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.1em;
    color: var(--text-muted);
    padding: 4px 8px;
    transition: color 0.2s;
}

#unlock-api-btn:hover {
    color: var(--text-main);
}

hr {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 24px 0;
}



/* Styling for Raw Payload View Block */
.payload-group {
    margin-top: 5px;
}

#raw-payload-viewer {
    background: var(--bg-primary);
    color: #10b981; /* Soft green standard console code color */
    font-family: "Courier New", Courier, monospace;
    font-size: 0.8em;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    max-height: 250px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
}

/* Chat bubble metadata & retranslate button */
.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    font-size: 0.72em;
    opacity: 0.6;
    margin-top: 2px;
    user-select: none;
}

.msg.user .msg-meta {
    color: rgba(255, 255, 255, 0.8);
}

.msg.bot .msg-meta, .msg.model .msg-meta {
    color: var(--text-muted);
}

.retranslate-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.1em;
    padding: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: inherit;
    opacity: 0.6;
    transition: opacity 0.2s, transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.retranslate-btn:hover {
    opacity: 1;
    transform: rotate(180deg);
}

.retranslate-btn.loading {
    animation: spin-retranslate 1s linear infinite;
    pointer-events: none;
    opacity: 1;
}

.msg.loading-translation .msg-text {
    opacity: 0.4;
    transition: opacity 0.3s;
}

@keyframes spin-retranslate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Collapsible Raw Payload Header */
.collapsible-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    padding: 6px 0;
}

.collapsible-header h3 {
    margin: 0;
}

.toggle-icon {
    font-size: 0.85em;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.collapsible-header.active .toggle-icon {
    transform: rotate(180deg);
}