/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    background: #08080e;
    color: #d0d0e0;
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
}

/* ===== Layout ===== */
.app {
    display: flex;
    height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    width: 220px;
    min-width: 220px;
    background: #0e0e18;
    border-right: 1px solid #1a1a2e;
    display: flex;
    flex-direction: column;
    padding: 0;
}

.sidebar-header {
    padding: 20px 16px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-header h1 {
    font-size: 1.15rem;
    font-weight: 600;
    color: #ebebff;
    letter-spacing: -0.01em;
}

.badge {
    font-size: 0.7rem;
    background: #6366f1;
    color: #fff;
    padding: 2px 7px;
    border-radius: 4px;
    font-weight: 600;
}

.sidebar-section {
    padding: 8px 0;
}

.section-label {
    padding: 4px 16px 6px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #5a5a7a;
}

nav { display: flex; flex-direction: column; }

.nav-link {
    display: block;
    padding: 7px 16px 7px 20px;
    color: #8888aa;
    text-decoration: none;
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}

.nav-link:hover {
    color: #c0c0e0;
    background: #14142a;
}

.nav-link.active {
    color: #a5a8ff;
    background: #14142a;
    border-left-color: #6366f1;
    font-weight: 500;
}

.sidebar-footer {
    margin-top: auto;
    padding: 12px 16px;
    border-top: 1px solid #1a1a2e;
}

.api-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
    color: #7777aa;
}

.api-status.large { font-size: 0.88rem; padding: 8px 0; }

.dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.dot.ok { background: #22c55e; box-shadow: 0 0 6px #22c55e55; }
.dot.err { background: #ef4444; box-shadow: 0 0 6px #ef444455; }

/* ===== Main Content ===== */
.main {
    flex: 1;
    overflow-y: auto;
    padding: 24px 32px;
}

.section { display: none; }
.section.active { display: block; }

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    gap: 16px;
    flex-wrap: wrap;
}

.section-head h2 {
    font-size: 1.4rem;
    font-weight: 600;
    color: #ebebff;
    margin-bottom: 4px;
}

.head-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.conn-status {
    font-size: 0.78rem;
    color: #7777aa;
    padding: 4px 10px;
    border-radius: 4px;
    background: #12121e;
}

.conn-status.connected { color: #22c55e; background: #0f1f16; }
.conn-status.connecting { color: #f59e0b; background: #1f1a0f; }
.conn-status.error { color: #ef4444; background: #1f0f0f; }

.muted { color: #6666888; font-size: 0.88rem; }
.muted.small { font-size: 0.78rem; margin-top: 2px; }

/* ===== Grid ===== */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

@media (max-width: 900px) {
    .grid-2 { grid-template-columns: 1fr; }
}

/* ===== Cards ===== */
.card {
    background: #0e0e1a;
    border: 1px solid #1a1a2e;
    border-radius: 8px;
    padding: 16px;
}

.card.fill { margin-bottom: 16px; }

.card h3 {
    font-size: 0.88rem;
    font-weight: 600;
    color: #b0b0cc;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* ===== Form Elements ===== */
label {
    display: block;
    font-size: 0.8rem;
    color: #7777aa;
    margin: 10px 0 4px;
}

label:first-child { margin-top: 0; }

.input {
    width: 100%;
    padding: 8px 10px;
    background: #0a0a14;
    border: 1px solid #22223a;
    border-radius: 6px;
    color: #d0d0e0;
    font-size: 0.88rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}

.input:focus { border-color: #6366f1; }
.input:disabled { opacity: 0.5; cursor: not-allowed; }

select.input { cursor: pointer; }
textarea.input { resize: vertical; min-height: 50px; }

.cb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: #b0b0cc;
    cursor: pointer;
    margin: 10px 0 4px;
}

.cb input[type="checkbox"] {
    accent-color: #6366f1;
    width: 15px;
    height: 15px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid transparent;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

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

.btn.primary {
    background: #6366f1;
    color: #fff;
    border-color: #6366f1;
}

.btn.primary:hover:not(:disabled) { background: #818cf8; border-color: #818cf8; }

.btn.primary.active-session {
    background: #ef4444;
    border-color: #ef4444;
}

.btn.primary.active-session:hover:not(:disabled) { background: #f87171; border-color: #f87171; }

.btn.secondary {
    background: #14142a;
    color: #b0b0cc;
    border-color: #22223a;
}

.btn.secondary:hover:not(:disabled) { background: #1e1e3a; border-color: #33335a; }

.btn.secondary.active {
    background: #1a2040;
    color: #a5a8ff;
    border-color: #6366f1;
}

.btn.block { width: 100%; }

.btn-group {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.btn-group .btn { flex: 1; }

/* ===== Audio Meters ===== */
.meters { margin-top: 16px; }

.meter-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.meter-row span {
    font-size: 0.75rem;
    color: #6666888;
    width: 50px;
    flex-shrink: 0;
}

.meter {
    flex: 1;
    height: 6px;
    background: #0a0a14;
    border-radius: 3px;
    overflow: hidden;
}

.meter-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #22c55e, #84cc16);
    border-radius: 3px;
    transition: width 0.1s;
}

/* ===== Chat Messages ===== */
.chat-messages {
    min-height: 200px;
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 12px;
    padding: 4px 0;
}

.chat-msg {
    padding: 8px 12px;
    margin-bottom: 8px;
    border-radius: 6px;
    font-size: 0.88rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-msg.user {
    background: #1a1a3a;
    border-left: 3px solid #6366f1;
}

.chat-msg.model {
    background: #0f1f16;
    border-left: 3px solid #22c55e;
}

.chat-msg.thought {
    background: #1a1a0f;
    border-left: 3px solid #f59e0b;
    font-style: italic;
    opacity: 0.85;
}

.chat-msg.fn-call {
    background: #0f0f1f;
    border-left: 3px solid #8b5cf6;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.8rem;
}

.chat-msg .msg-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
    opacity: 0.6;
}

.chat-input {
    display: flex;
    gap: 8px;
}

.chat-input .input { flex: 1; }

.empty {
    color: #444466;
    font-style: italic;
    padding: 20px;
    text-align: center;
}

/* ===== Transcription ===== */
.transcript {
    min-height: 120px;
    max-height: 400px;
    overflow-y: auto;
}

.transcript-entry {
    padding: 6px 0;
    font-size: 0.88rem;
    border-bottom: 1px solid #12121e;
}

.transcript-entry:last-child { border-bottom: none; }

.transcript-entry .speaker {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 2px;
}

.transcript-entry .speaker.user-speaker { color: #6366f1; }
.transcript-entry .speaker.model-speaker { color: #22c55e; }

/* ===== Video ===== */
.video-container {
    background: #06060c;
    border-radius: 6px;
    overflow: hidden;
    aspect-ratio: 16 / 9;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-container video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* ===== Function List ===== */
.fn-list { margin-bottom: 12px; }

.fn-item {
    padding: 8px 10px;
    background: #0a0a14;
    border-radius: 6px;
    margin-bottom: 6px;
}

.fn-item strong {
    color: #a5a8ff;
    font-size: 0.85rem;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

.fn-item .muted { font-size: 0.78rem; margin-top: 2px; }

.fn-log {
    min-height: 100px;
    max-height: 300px;
    overflow-y: auto;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.78rem;
}

.fn-log-entry {
    padding: 8px 10px;
    margin-bottom: 6px;
    border-radius: 4px;
}

.fn-log-entry.call {
    background: #0f0f1f;
    border-left: 3px solid #8b5cf6;
}

.fn-log-entry.response {
    background: #0f1f16;
    border-left: 3px solid #22c55e;
}

.fn-log-entry pre {
    white-space: pre-wrap;
    word-break: break-all;
}

/* ===== Capabilities Grid ===== */
.caps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 6px;
}

.cap {
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
}

.cap.yes {
    background: #0f1f16;
    color: #4ade80;
    border: 1px solid #1a3a28;
}

.cap.yes::before { content: "+ "; font-weight: 700; }

.cap.no {
    background: #1f0f0f;
    color: #888;
    border: 1px solid #2a1a1a;
}

.cap.no::before { content: "- "; font-weight: 700; }

/* ===== Protocol Log ===== */
.log-entries {
    min-height: 300px;
    max-height: calc(100vh - 200px);
    overflow-y: auto;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.75rem;
}

.log-entry {
    padding: 6px 10px;
    margin-bottom: 4px;
    border-radius: 4px;
    cursor: pointer;
}

.log-entry.sent { background: #10101e; border-left: 2px solid #6366f1; }
.log-entry.received { background: #0f1a16; border-left: 2px solid #22c55e; }

.log-entry .log-meta {
    display: flex;
    gap: 8px;
    margin-bottom: 2px;
    opacity: 0.5;
    font-size: 0.7rem;
}

.log-entry .log-type {
    font-weight: 600;
    color: #b0b0cc;
}

.log-entry pre {
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.2s;
}

.log-entry.expanded pre { max-height: 500px; overflow-y: auto; }

.log-entry .log-summary {
    color: #8888aa;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #22223a; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #33335a; }
