/* ============================================================================
   Echo Activity Monitor — Dark Mode Dashboard
   ============================================================================ */

:root {
    --bg: #0f1117;
    --card-bg: #1a1d27;
    --card-hover: #22262f;
    --border: #2a2d3a;
    --text: #e4e4e7;
    --text-muted: #9ca3af;
    --accent: #00c9a7;
    --accent-dim: rgba(0, 201, 167, 0.15);
    --accent-glow: rgba(0, 201, 167, 0.4);
    --warn: #ffc107;
    --green: #22c55e;
    --red: #ef4444;
    --purple: #a855f7;
}

* {
    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);
    min-height: 100vh;
    line-height: 1.6;
}

/* ============================================================================
   Layout
   ============================================================================ */

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* ============================================================================
   Header / Avatar
   ============================================================================ */

.header {
    display: flex;
    align-items: center;
    gap: 2rem;
    margin-bottom: 2rem;
}

.avatar-container {
    position: relative;
    flex-shrink: 0;
}

.avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00c9a7 0%, #1a1d27 100%);
    box-shadow: 0 0 30px var(--accent-glow);
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

/* Speech bubble (thinking indicator) */
.speech-bubble {
    position: absolute;
    top: -10px;
    right: -15px;
    background: var(--card-bg);
    border: 2px solid var(--accent);
    border-radius: 20px;
    padding: 6px 12px;
    display: none;
    align-items: center;
    gap: 4px;
}

.speech-bubble.visible {
    display: flex;
}

.speech-bubble .dot {
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    animation: dot-pulse 1.4s ease-in-out infinite;
}

.speech-bubble .dot:nth-child(2) { animation-delay: 0.2s; }
.speech-bubble .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* Action bubble (working indicator) */
.action-bubble {
    position: absolute;
    top: 0;
    left: -15px;
    font-size: 1.8rem;
    display: none;
    animation: rotate-slow 4s linear infinite;
}

.action-bubble.visible {
    display: block;
}

@keyframes rotate-slow {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Status container */
.status-container {
    flex: 1;
}

.state-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--accent-dim);
    border: 1px solid var(--accent);
    border-radius: 30px;
    margin-bottom: 0.5rem;
}

.state-icon {
    font-size: 1.4rem;
}

.state-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent);
}

.timestamp {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ============================================================================
   Sections
   ============================================================================ */

section {
    margin-bottom: 2rem;
}

section h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.badge {
    background: var(--card-bg);
    color: var(--text);
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
}

/* ============================================================================
   Activity Card
   ============================================================================ */

.activity-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
}

.activity-task {
    font-size: 1.1rem;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.activity-started {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ============================================================================
   Task Grid
   ============================================================================ */

.task-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.75rem;
}

.task-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    transition: transform 0.2s, box-shadow 0.2s;
}

.task-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.task-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.task-name {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.task-status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.task-status.pending { background: var(--text-muted); }
.task-status.in_progress { background: var(--warn); }
.task-status.complete { background: var(--green); }
.task-status.error { background: var(--red); }

/* ============================================================================
   Timeline (Recent Activity — chat-window style)
   ============================================================================ */

.timeline-list {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow-y: auto;
    max-height: 420px;
    scroll-behavior: smooth;
}

.timeline-entry {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

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

.timeline-entry:hover {
    background: var(--card-hover);
}

.t-t-icon {
    font-size: 1rem;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
}

.t-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    min-width: 70px;
    font-family: 'SF Mono', Monaco, monospace;
}

.t-msg {
    flex: 1;
    font-size: 0.9rem;
    color: var(--text);
}

.t-empty {
    padding: 1.5rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.timeline-outcome {
    font-size: 0.75rem;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-weight: 500;
    margin-left: auto;
    flex-shrink: 0;
}

.timeline-outcome.success {
    background: rgba(34, 197, 94, 0.15);
    color: var(--green);
}

.timeline-outcome.error {
    background: rgba(239, 68, 68, 0.15);
    color: var(--red);
}

/* ============================================================================
   Footer / Sound Toggle
   ============================================================================ */

.footer {
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

.sound-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.sound-toggle input {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

/* ============================================================================
   State-Based Avatar Animations
   ============================================================================ */

/* Idle — gentle breathing */
body.state-idle .avatar {
    animation: breathe 4s ease-in-out infinite;
}

@keyframes breathe {
    0%, 100% { transform: scale(1); box-shadow: 0 0 20px var(--accent-glow); }
    50% { transform: scale(1.03); box-shadow: 0 0 35px var(--accent-glow); }
}

/* Thinking — orbiting dots + glow */
body.state-thinking .avatar {
    animation: glow-pulse 2s ease-in-out infinite;
}

@keyframes glow-pulse {
    0%, 100% { box-shadow: 0 0 20px var(--accent-glow); }
    50% { box-shadow: 0 0 40px var(--accent-glow), 0 0 60px var(--accent-dim); }
}

body.state-thinking .speech-bubble {
    display: flex;
}

/* Working — action bubble visible */
body.state-working .action-bubble {
    display: block;
}

body.state-working .avatar {
    animation: work-pulse 1.5s ease-in-out infinite;
}

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

/* Chatting — bouncing speech bubble */
body.state-chatting .speech-bubble {
    display: flex;
    animation: bounce 0.6s ease-in-out;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Delegating — ripple effect */
body.state-delegating .avatar {
    animation: ripple 1s ease-out;
}

@keyframes ripple {
    0% { box-shadow: 0 0 0 0 var(--accent-glow); }
    100% { box-shadow: 0 0 0 30px transparent; }
}

/* Complete — burst */
body.state-complete .avatar {
    animation: complete-burst 0.6s ease-out;
}

@keyframes complete-burst {
    0% { transform: scale(1); }
    30% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

/* Error — shake */
body.state-error .avatar {
    animation: shake 0.5s ease-in-out;
    box-shadow: 0 0 30px rgba(239, 68, 68, 0.5);
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-5px); }
    40%, 80% { transform: translateX(5px); }
}

/* ============================================================================
   Responsive
   ============================================================================ */

@media (max-width: 640px) {
    .header {
        flex-direction: column;
        text-align: center;
    }

    .avatar {
        width: 100px;
        height: 100px;
    }

    .status-container {
        text-align: center;
    }

    .task-grid {
        grid-template-columns: 1fr;
    }

    .container {
        padding: 1rem;
    }
}
