*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: sans-serif;
    background: #f0f0f0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 12px;
    gap: 0;
}

#top-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    flex-shrink: 0;
}

#container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 0;
}

.conn-hide {
    display: flex;
}

.conn-show {
    display: none;
}

.top-spacer { flex: 1; }

#btn-settings, #btn-clear, #btn-refresh {
    background: #1d5f7c;
    color: #fff;
    border: none;
    padding: 8px 14px;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 3px;
}

#btn-delete {
    background: transparent;
    color: #8b0000;
    border: none;
    padding: 8px 14px;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 3px;
}

#btn-connect {
    background: #2a7a2a;
    color: #fff;
    border: none;
    padding: 8px 14px;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 3px;
    white-space: nowrap;
}

#btn-connect.connected {
    background: #7a2a2a;
}

#user-label,
#token-label,
#session-name-label,
#plan-label {
    color: #555;
    font-size: 0.88rem;
    white-space: nowrap;
}

#user-input,
#token-input,
#session-name-input {
    background: #fff;
    color: #222;
    border: 1px solid #bbb;
    border-radius: 3px;
    padding: 6px 10px;
    font-size: 0.9rem;
    width: 110px;
    outline: none;
}

#session-name-input:read-only {
    background: #e8e8e8;
    color: #666;
    border: 1px solid #999;
    cursor: not-allowed;
}

#config-select,
#plan-select {
    background: #1d5f7c;
    color: #fff;
    border: none;
    border-radius: 3px;
    padding: 6px 10px;
    font-size: 0.9rem;
    cursor: pointer;
    max-width: 220px;
}

button:disabled,
#config-select:disabled {
    opacity: 0.4;
    cursor: default;
}

#main {
    display: flex;
    flex: 1 1 auto;
    gap: 12px;
    min-height: 0;
}

/* ── Left column ── */
#col-left {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 8px;
    min-height: 0;
}

#chat {
    flex: 1;
    background: #1d6f8c;
    color: #fff;
    border-radius: 4px;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#prompt-row {
    display: flex;
    gap: 8px;
}

#prompt {
    flex: 1;
    background: #1d6f8c;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 12px 16px;
    font-size: 1rem;
    resize: none;
    height: 52px;
    outline: none;
}

#prompt::placeholder { color: rgba(255,255,255,0.55); }

#btn-send {
    background: #1d5f7c;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 0 20px;
    font-size: 1rem;
    cursor: pointer;
}

/* ── Right column ── */
#col-right {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 8px;
    min-height: 0;
    overflow: hidden;
}

.panel {
    background: #1d6f8c;
    color: #fff;
    border-radius: 4px;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.panel-label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    opacity: 0.75;
    margin-bottom: 4px;
}

.panel textarea {
    flex: 1;
    background: rgba(0,0,0,0.15);
    color: #fff;
    border: none;
    border-radius: 3px;
    padding: 8px;
    font-size: 0.9rem;
    font-family: monospace;
    resize: none;
    outline: none;
    width: 100%;
}

.panel textarea::placeholder { color: rgba(255,255,255,0.4); }

#system-prompt {
    flex: 0 1 300px;
    min-height: 0;
}

#mid-row {
    display: flex;
    gap: 8px;
    flex: 0 1 220px;
    min-height: 0;
}

#json-schema { flex: 1; min-height: 0; }
#llm-params  { flex: 1; min-height: 0; }

#tool-impl {
    flex: 1;
    min-height: 0;
}

/* chat bubbles */
.msg-row { display: flex; width: 100%; }
.msg-row.user   { justify-content: flex-end; }
.msg-row.system { justify-content: flex-start; }
.msg { padding: 8px 12px; border-radius: 6px; max-width: 90%; font-size: 0.95rem; }
.msg.user   { background: rgba(255,255,255,0.15); text-align: right; }
.msg.system { background: rgba(0,0,0,0.2); }

/* tables */
.msg table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
}

.msg table th,
.msg table td {
    border: 1px solid rgba(255,255,255,0.3);
    padding: 10px 12px;
    text-align: left;
}

.msg table th {
    background: rgba(0,0,0,0.3);
    font-weight: bold;
}

.msg table tbody tr:nth-child(even) {
    background: rgba(0,0,0,0.1);
}

/* paragraph styling in messages */
.msg p {
    margin: 10px 0 0 0;
    line-height: 1.5;
}

.msg p:first-child {
    margin-top: 0;
}

/* spinner */
#spinner { display: none; align-self: center; width: 28px; height: 28px; border: 3px solid rgba(255,255,255,0.25); border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* prefill buttons */
.btn-prefill {
    background: rgba(255,255,255,0.15);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 3px;
    padding: 4px 10px;
    font-size: 0.75rem;
    cursor: pointer;
    margin-left: 12px;
    white-space: nowrap;
}

.btn-prefill:hover {
    background: rgba(255,255,255,0.25);
}

/* Log Panel */
#log-panel {
    display: flex;
    flex-direction: column;
    background: #1d6f8c;
    border-top: 1px solid #0a4a5c;
    flex-shrink: 0;
    min-height: 0;
    margin-top: 12px;
}

#log-panel.log-panel-expanded {
    flex: 0 0 50%;
    max-height: 50%;
}

.log-panel-header {
    display: flex;
    gap: 8px;
    padding: 6px 12px;
    background: #0a4a5c;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}

.log-toggle-btn {
    background: none;
    color: #fff;
    border: none;
    padding: 3px 6px;
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}

.log-toggle-btn:hover {
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
}

.log-refresh-btn {
    background: #1d5f7c;
    color: #fff;
    border: none;
    padding: 3px 10px;
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: 3px;
    flex-shrink: 0;
}

.log-refresh-btn:hover:not(:disabled) {
    background: #2a7a8c;
}

.log-refresh-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.log-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    font-family: monospace;
    font-size: 0.75rem;
    color: #fff;
    background: rgba(0,0,0,0.2);
    display: none;
    min-height: 0;
}

#log-panel.log-panel-expanded .log-content {
    display: block;
}

#log-text {
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.3;
}
