:root {
    --bg: #0f1117;
    --surface: #1a1b23;
    --surface-2: #252631;
    --border: #2e3040;
    --text: #e1e2e8;
    --text-dim: #8b8d9e;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --success: #34d399;
    --error: #f87171;
    --warning: #fbbf24;
    --radius: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    display: flex;
    align-items: center;
    gap: 2rem;
    padding: 0.75rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
}

nav { display: flex; gap: 0.25rem; }

.tab {
    background: none;
    border: none;
    color: var(--text-dim);
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.15s;
}

.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { color: var(--text); background: var(--accent); }

main {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.panel {
    display: none;
    height: 100%;
    flex-direction: column;
    padding: 1rem 1.5rem;
}

.panel.active { display: flex; }

/* Messages */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.message {
    max-width: 75%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.9375rem;
}

.message.user {
    align-self: flex-end;
    background: var(--accent);
    color: white;
}

.message.assistant {
    align-self: flex-start;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.message .tool-call {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.8125rem;
    color: var(--warning);
}

/* Input area */
.input-area {
    display: flex;
    gap: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.input-area textarea {
    flex: 1;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    padding: 0.75rem;
    font-size: 0.9375rem;
    font-family: inherit;
    resize: none;
    outline: none;
}

.input-area textarea:focus { border-color: var(--accent); }

button {
    font-family: inherit;
    font-size: 0.875rem;
}

.input-area button,
#tts-synthesize,
#stt-upload-btn {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.15s;
}

.input-area button:hover,
#tts-synthesize:hover,
#stt-upload-btn:hover {
    background: var(--accent-hover);
}

/* TTS */
.tts-controls {
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

.tts-controls textarea {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    padding: 0.75rem;
    font-size: 0.9375rem;
    font-family: inherit;
    resize: vertical;
    outline: none;
}

.tts-controls textarea:focus { border-color: var(--accent); }

.sliders {
    margin: 1rem 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.sliders label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-dim);
}

.sliders input[type="range"] {
    flex: 1;
    accent-color: var(--accent);
}

.sliders span {
    min-width: 2.5rem;
    text-align: right;
    color: var(--text);
    font-weight: 600;
}

#tts-synthesize {
    width: 100%;
    padding: 0.875rem;
    font-size: 1rem;
}

/* STT */
.stt-controls {
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.stt-upload {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    width: 100%;
}

.stt-upload label {
    flex: 1;
    font-size: 0.875rem;
    color: var(--text-dim);
}

.stt-upload input[type="file"] {
    margin-top: 0.25rem;
    display: block;
    color: var(--text-dim);
    font-size: 0.8125rem;
}

.stt-divider {
    color: var(--text-dim);
    font-size: 0.8125rem;
}

.record-btn {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: var(--surface-2);
    border: 3px solid var(--border);
    color: var(--text);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.record-btn:hover { border-color: var(--accent); }
.record-btn.recording {
    background: var(--error);
    border-color: var(--error);
    color: white;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.result-box {
    width: 100%;
    min-height: 100px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    font-size: 0.9375rem;
    line-height: 1.5;
    white-space: pre-wrap;
}

/* Voice Chat */
.vc-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.ptt-btn {
    width: 160px;
    height: 60px;
    border-radius: var(--radius);
    background: var(--surface-2);
    border: 2px solid var(--border);
    color: var(--text);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
}

.ptt-btn:hover { border-color: var(--accent); }
.ptt-btn.active {
    background: var(--error);
    border-color: var(--error);
    color: white;
}

/* Status */
.status {
    font-size: 0.8125rem;
    color: var(--text-dim);
    min-height: 1.25rem;
}

.status.error { color: var(--error); }
.status.success { color: var(--success); }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* Disabled state */
button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Header right */
.header-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-info {
    font-size: 0.8125rem;
    color: var(--text-dim);
}

.user-info .role {
    background: var(--surface-2);
    border: 1px solid var(--border);
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    margin-left: 0.375rem;
    text-transform: uppercase;
}

.logout-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 0.375rem 0.875rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
}

.logout-btn:hover {
    border-color: var(--error);
    color: var(--error);
}

/* Admin Panel */
.admin-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.admin-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
}

.admin-tab {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
}

.admin-tab:hover { color: var(--text); border-color: var(--accent); }
.admin-tab.active { background: var(--accent); color: white; border-color: var(--accent); }

.admin-section { display: none; flex: 1; flex-direction: column; overflow: auto; }
.admin-section.active { display: flex; }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.section-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.small-btn {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 600;
    transition: background 0.15s;
}

.small-btn:hover { background: var(--accent-hover); }
.small-btn.secondary { background: var(--surface-2); border: 1px solid var(--border); }
.small-btn.secondary:hover { border-color: var(--accent); }
.small-btn.danger { background: var(--error); }
.small-btn.danger:hover { opacity: 0.8; }

.form-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.form-card input, .form-card select {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    font-family: inherit;
    outline: none;
}

.form-card input:focus, .form-card select:focus { border-color: var(--accent); }

.form-actions {
    display: flex;
    gap: 0.5rem;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.data-table th {
    text-align: left;
    padding: 0.625rem 0.75rem;
    border-bottom: 2px solid var(--border);
    color: var(--text-dim);
    font-weight: 600;
    white-space: nowrap;
}

.data-table td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

.data-table tr:hover td {
    background: var(--surface-2);
}

.data-table .badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge.admin { background: rgba(99,102,241,0.2); color: var(--accent); }
.badge.customer { background: rgba(52,211,153,0.2); color: var(--success); }
.badge.active { background: rgba(52,211,153,0.2); color: var(--success); }
.badge.inactive { background: rgba(248,113,113,0.2); color: var(--error); }

.key-display {
    background: var(--surface-2);
    border: 1px solid var(--success);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    font-family: monospace;
    font-size: 0.875rem;
    color: var(--success);
    word-break: break-all;
}

.section-header select {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
    font-family: inherit;
    outline: none;
}

/* TTS voice/language row */
.tts-row {
    display: flex;
    gap: 1rem;
    margin: 1rem 0;
}

.tts-field {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.tts-field label {
    font-size: 0.8125rem;
    color: var(--text-dim);
}

.tts-field select {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
    font-family: inherit;
    outline: none;
}

.tts-field select:focus { border-color: var(--accent); }

/* Voice cloning */
.voice-clone-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.voice-clone-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.hint {
    font-size: 0.8125rem;
    color: var(--text-dim);
    margin-bottom: 0.75rem;
}

/* API Docs */
.docs-container {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    overflow-y: auto;
    padding-bottom: 2rem;
}

.docs-container h2 {
    font-size: 1.375rem;
    margin-bottom: 0.25rem;
}

.docs-container > .hint {
    margin-bottom: 1.5rem;
}

.doc-section {
    margin-bottom: 2rem;
}

.doc-section h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--accent);
}

.doc-section p {
    font-size: 0.875rem;
    color: var(--text-dim);
    margin-bottom: 0.5rem;
}

.endpoint {
    display: inline-block;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.25rem 0.625rem;
    font-family: monospace;
    font-size: 0.8125rem;
    color: var(--success);
    margin-bottom: 0.375rem;
}

.doc-section pre {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    overflow-x: auto;
    margin-bottom: 1rem;
}

.doc-section code {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 0.8125rem;
    color: var(--text);
    line-height: 1.6;
}

.docs-container code {
    background: var(--surface-2);
    padding: 0.125rem 0.375rem;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.8125rem;
}

/* IVA Panel */
.iva-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    max-width: 700px;
    margin: 0 auto;
    width: 100%;
}

.iva-config {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.iva-display {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
}

.iva-block {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}

.iva-block label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.iva-text {
    min-height: 2rem;
    font-size: 1rem;
    line-height: 1.6;
    white-space: pre-wrap;
}

.iva-text.assistant {
    color: var(--accent);
}

.iva-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    margin-top: 1rem;
}
