:root {
    --pollen-coral:       #FF6B35;
    --pollen-coral-light: #FF8A5C;
    --pollen-coral-dark:  #E55A2B;
    --pollen-dark:        #1A1A2E;
    --pollen-darker:      #0F0F1A;
    --pollen-card:        #16213E;
    --pollen-card-light:  #1E2A4A;
    --text-primary:       #FFFFFF;
    --text-secondary:     #A0AEC0;
    --text-muted:         #718096;
    --success:            #48BB78;
    --warning:            #ECC94B;
    --danger:             #F56565;
    --listening:          #63B3ED;
    --thinking:           #B794F4;
    --speaking:           #68D391;
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--pollen-darker);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
}

/* ── Header ─────────────────────────────────────────────────── */
.header {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 107, 53, 0.2);
    position: sticky;
    top: 0;
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo img {
    width: 32px;
    height: 32px;
    border-radius: 6px;
}

.logo-text {
    font-weight: 700;
    font-size: 1em;
    color: var(--pollen-coral);
}

.logo-text span {
    color: var(--text-secondary);
    font-weight: 400;
    font-size: 0.85em;
}

.user-section {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-badge {
    background: var(--pollen-card);
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 0.8em;
}

.btn-logout {
    background: transparent;
    border: 1px solid var(--text-muted);
    color: var(--text-secondary);
    padding: 4px 12px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.75em;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: color 0.2s;
    min-width: 44px;
    min-height: 44px;
}

.btn-icon:hover { color: var(--pollen-coral); }

.btn-icon svg {
    width: 20px;
    height: 20px;
}

/* ── Main Layout ─────────────────────────────────────────────── */
.app-container {
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 8px;
    max-width: 900px;
    margin: 0 auto;
}

/* ── Video ───────────────────────────────────────────────────── */
.video-container {
    position: relative;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    aspect-ratio: 16 / 9;
    width: 100%;
}

video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: linear-gradient(135deg, #0a0a15 0%, #1a1a2e 100%);
}

.video-overlay-top {
    position: absolute;
    top: 0; left: 0; right: 0;
    padding: 12px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.7), transparent);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.connection-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0,0,0,0.5);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 0.8em;
}

.latency-badge {
    background: rgba(0,0,0,0.5);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75em;
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
}

.latency-badge.good { color: var(--success); }
.latency-badge.ok   { color: var(--warning); }
.latency-badge.bad  { color: var(--danger);  }

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
}

.status-indicator.connected  { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-indicator.connecting { background: var(--warning); animation: blink 0.8s infinite; }

@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.robot-name {
    background: rgba(0,0,0,0.5);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 0.8em;
    font-weight: 500;
}

.video-overlay-bottom {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    padding: 12px;
    background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
}

.video-controls {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85em;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 44px;
}

.btn-primary   { background: var(--pollen-coral); color: white; }
.btn-secondary { background: rgba(255,255,255,0.15); color: white; }
.btn-danger    { background: var(--danger); color: white; }

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

.btn-mute {
    background: rgba(255,255,255,0.15);
    color: white;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-mute.muted { background: var(--danger); }
.btn-mute svg   { width: 16px; height: 16px; }

/* ── Panels ──────────────────────────────────────────────────── */
.panel {
    background: var(--pollen-card);
    border-radius: 12px;
    overflow: hidden;
}

.panel-header {
    padding: 10px 14px;
    background: rgba(0,0,0,0.2);
    font-weight: 600;
    font-size: 0.85em;
    color: var(--pollen-coral);
}

.panel-content { padding: 12px; }

/* ── Robot Selector ──────────────────────────────────────────── */
.robot-list { display: flex; flex-direction: column; gap: 8px; }

.robot-card {
    padding: 10px 14px;
    background: var(--pollen-darker);
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
}

.robot-card:hover  { background: var(--pollen-card-light); }
.robot-card.selected { border-color: var(--pollen-coral); }
.robot-card .name  { font-weight: 600; font-size: 0.9em; }
.robot-card .id    { font-size: 0.75em; color: var(--text-muted); font-family: monospace; }

/* ── Conversation History ────────────────────────────────────── */
.conversation-history {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 240px;
    overflow-y: auto;
    padding-bottom: 4px;
}

.message {
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 0.88em;
    line-height: 1.4;
    max-width: 90%;
    word-break: break-word;
}

.msg-user {
    background: var(--pollen-coral-dark);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 3px;
}

.msg-assistant {
    background: var(--pollen-card-light);
    color: var(--text-primary);
    align-self: flex-start;
    border-bottom-left-radius: 3px;
}

.msg-system {
    color: var(--text-muted);
    font-size: 0.82em;
    text-align: center;
    align-self: center;
    font-style: italic;
}

.interim-transcript {
    color: var(--text-muted);
    font-size: 0.85em;
    font-style: italic;
    min-height: 1.2em;
    margin-top: 6px;
    padding: 0 2px;
}

/* ── Talk Panel ──────────────────────────────────────────────── */
.talk-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 20px 12px;
}

.conv-state {
    font-size: 0.9em;
    font-weight: 600;
    letter-spacing: 0.03em;
    transition: color 0.3s;
}

.state-idle      { color: var(--text-muted); }
.state-listening { color: var(--listening); }
.state-thinking  { color: var(--thinking);  }
.state-speaking  { color: var(--speaking);  }

.talk-btn {
    width: 88px;
    height: 88px;
    border-radius: 50%;
    border: 3px solid var(--pollen-coral);
    background: transparent;
    color: var(--pollen-coral);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-size: 0.8em;
    font-weight: 600;
    transition: all 0.2s;
}

.talk-btn:hover:not(:disabled) {
    background: rgba(255,107,53,0.15);
    transform: scale(1.05);
}

.talk-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    border-color: var(--text-muted);
    color: var(--text-muted);
}

.talk-btn svg {
    width: 32px;
    height: 32px;
}

.error-text {
    color: var(--danger);
    font-size: 0.82em;
    text-align: center;
}

/* ── Modal ───────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 100;
}

.modal-card {
    background: var(--pollen-card);
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-card h3 {
    color: var(--pollen-coral);
    font-size: 1.1em;
    margin-bottom: 4px;
}

.setting-label {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--text-secondary);
}

.optional {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 0.9em;
}

.setting-input,
.setting-textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--pollen-darker);
    border: 1px solid var(--pollen-card-light);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.85em;
    font-family: inherit;
    resize: vertical;
}

.setting-input:focus,
.setting-textarea:focus {
    outline: none;
    border-color: var(--pollen-coral);
}

.modal-buttons {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 4px;
}

/* ── Login View ──────────────────────────────────────────────── */
.login-view {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    background: var(--pollen-card);
    padding: 40px;
    border-radius: 16px;
    text-align: center;
    max-width: 380px;
}

.login-logo {
    width: 72px;
    height: 72px;
    margin-bottom: 20px;
    border-radius: 12px;
}

.login-card h2 {
    color: var(--pollen-coral);
    margin-bottom: 10px;
    font-size: 1.5em;
}

.login-card p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 0.9em;
    line-height: 1.5;
}

.btn-hf {
    background: #FFD21E;
    color: #000;
    border: none;
    padding: 12px 28px;
    border-radius: 8px;
    font-size: 0.95em;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
}

/* ── Desktop Layout ──────────────────────────────────────────── */
@media (min-width: 768px) {
    .app-container {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "video       conversation"
            "robots      talk";
        align-items: start;
        gap: 12px;
    }

    .video-container        { grid-area: video; }
    #robotSelector          { grid-area: robots; }
    #conversationPanel      { grid-area: conversation; }
    #talkPanel              { grid-area: talk; }

    .conversation-history   { max-height: 320px; }
}

.hidden { display: none !important; }
