/* ===== Reset & Base ===== */

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

:root {
    --bg-primary: #09090b;
    --bg-secondary: #18181b;
    --bg-card: #1c1c20;
    --bg-elevated: #27272a;
    --bg-input: #27272a;
    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --border: #27272a;
    --border-hover: #3f3f46;
    --ring: rgba(59, 130, 246, 0.5);
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.1);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.1);
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, 0.1);
    --info: #3b82f6;
    --info-bg: rgba(59, 130, 246, 0.1);
    --radius: 8px;
    --radius-lg: 12px;
    --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
    --bg-primary: #fafafa;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-elevated: #f4f4f5;
    --bg-input: #f4f4f5;
    --text-primary: #09090b;
    --text-secondary: #52525b;
    --text-muted: #a1a1aa;
    --border: #e4e4e7;
    --border-hover: #d4d4d8;
    --ring: rgba(59, 130, 246, 0.3);
    --success-bg: rgba(34, 197, 94, 0.08);
    --warning-bg: rgba(245, 158, 11, 0.08);
    --error-bg: rgba(239, 68, 68, 0.08);
    --info-bg: rgba(59, 130, 246, 0.08);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

header {
    background: var(--bg-secondary);
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border);
}

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

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo {
    color: var(--accent);
    display: flex;
    align-items: center;
}

header h1 {
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

/* ===== Connection Status ===== */

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--error);
    flex-shrink: 0;
}

.status-indicator.connected .status-dot {
    background: var(--success);
}

.status-indicator.disconnected .status-dot {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ===== Icon Button ===== */

.icon-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

.icon-btn:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.icon-btn:active {
    transform: scale(0.95);
}

.icon-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* ===== Agent Summary ===== */

.agent-summary {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.agent-summary .attention-count {
    color: var(--warning);
    font-weight: 600;
}

/* ===== Scroll-to-Attention FAB ===== */

.fab {
    position: fixed;
    bottom: 24px;
    right: 20px;
    z-index: 90;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--warning);
    color: #000;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: all var(--transition);
    animation: fab-appear 0.2s ease;
}

.fab:hover {
    transform: scale(1.08);
}

.fab:active {
    transform: scale(0.95);
}

.fab.hidden {
    display: none;
}

.fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: var(--error);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

@keyframes fab-appear {
    from { opacity: 0; transform: scale(0.5); }
    to { opacity: 1; transform: scale(1); }
}

/* ===== Main ===== */

main {
    padding: 12px;
    max-width: 640px;
    margin: 0 auto;
}

/* ===== Loading ===== */

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.loading-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Empty State ===== */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state h2 {
    margin-bottom: 8px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 0.875rem;
}

/* ===== Agent Card ===== */

.agent-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px;
    margin-bottom: 8px;
    transition: border-color var(--transition);
}

.agent-card:hover {
    border-color: var(--border-hover);
}

.agent-card.needs-attention {
    border-color: var(--warning);
    background: var(--warning-bg);
}

.agent-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    gap: 8px;
}

.agent-header-left {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    min-width: 0;
}

/* ===== Badges ===== */

.agent-type {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--bg-elevated);
    color: var(--text-secondary);
    padding: 2px 8px;
    border-radius: 4px;
}

.agent-status {
    font-size: 0.7rem;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 9999px;
    white-space: nowrap;
    flex-shrink: 0;
}

.agent-status.idle {
    background: var(--success-bg);
    color: var(--success);
}

.agent-status.processing {
    background: var(--info-bg);
    color: var(--info);
}

.agent-status.awaiting_approval {
    background: var(--warning-bg);
    color: var(--warning);
}

.agent-status.error {
    background: var(--error-bg);
    color: var(--error);
}

.agent-status.unknown {
    background: var(--bg-elevated);
    color: var(--text-muted);
}

.agent-status.offline {
    color: var(--text-muted);
}

.team-badge {
    font-size: 0.65rem;
    font-weight: 500;
    background: var(--info-bg);
    color: var(--info);
    padding: 2px 6px;
    border-radius: 4px;
}

.git-badge {
    font-size: 0.65rem;
    font-weight: 500;
    background: var(--bg-elevated);
    color: var(--text-muted);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
}

.git-badge.git-dirty {
    background: var(--warning-bg);
    color: var(--warning);
}

.git-badge.git-worktree {
    background: color-mix(in srgb, var(--accent) 15%, transparent);
    color: var(--accent);
}

/* ===== Agent Info ===== */

.agent-info {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.agent-info .session {
    color: var(--text-primary);
    font-weight: 500;
}

.agent-cwd {
    font-size: 0.7rem;
    color: var(--text-muted);
    word-break: break-all;
    margin-bottom: 10px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
}

/* ===== Details ===== */

.agent-details {
    font-size: 0.8rem;
    background: var(--bg-elevated);
    padding: 10px 12px;
    border-radius: var(--radius);
    margin-bottom: 10px;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 200px;
    overflow-y: auto;
    line-height: 1.6;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

/* ===== Auto-approve Badge ===== */

.auto-approve-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 9999px;
    margin-bottom: 8px;
}

.auto-approve-badge.judging {
    background: var(--info-bg);
    color: var(--info);
}

.auto-approve-badge.approved {
    background: var(--success-bg);
    color: var(--success);
}

/* ===== Action Buttons ===== */

.agent-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    flex: 1;
    min-width: 80px;
    text-align: center;
}

.btn:active {
    transform: scale(0.97);
}

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

.btn-approve {
    background: var(--success);
    color: #000;
}

.btn-approve:hover {
    opacity: 0.9;
}

.btn-reject {
    background: var(--error);
    color: #fff;
}

.btn-reject:hover {
    opacity: 0.9;
}

.btn-select {
    background: var(--accent);
    color: #fff;
    flex: none;
    padding: 8px 14px;
}

.btn-select:hover {
    background: var(--accent-hover);
}

.btn-submit {
    background: var(--accent);
    color: #fff;
    width: 100%;
    margin-top: 8px;
}

.btn-submit:hover {
    background: var(--accent-hover);
}

/* ===== Choices ===== */

.choices {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.choice-btn {
    padding: 10px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.8rem;
    text-align: left;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
}

.choice-btn:hover {
    border-color: var(--accent);
    background: var(--info-bg);
}

.choice-btn:active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.choice-btn.selected {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.choice-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    flex-shrink: 0;
}

.choice-btn:not(.selected) .choice-number {
    background: var(--border);
    color: var(--text-secondary);
}

/* ===== Text Input ===== */

.text-input-container {
    margin-top: 10px;
    display: flex;
    gap: 6px;
}

.text-input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    color: var(--text-primary);
    font-size: 0.8rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.text-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--ring);
}

.text-input::placeholder {
    color: var(--text-muted);
}

.btn-send {
    background: var(--accent);
    color: #fff;
    padding: 8px 14px;
    flex-shrink: 0;
    font-size: 0.8rem;
    border: none;
    border-radius: var(--radius);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-send:hover {
    background: var(--accent-hover);
}

.btn-send:active {
    transform: scale(0.97);
}

/* ===== Special Keys ===== */

.special-keys {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    margin-top: 8px;
}

.key-btn {
    min-width: 36px;
    height: 32px;
    padding: 4px 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.key-btn:hover {
    background: var(--bg-input);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.key-btn:active {
    transform: scale(0.93);
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* ===== Preview ===== */

.preview-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    user-select: none;
    transition: color var(--transition);
    font-weight: 500;
}

.preview-toggle:hover {
    color: var(--text-secondary);
}

.preview-toggle svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
    transition: transform 0.2s ease;
}

.preview-toggle.expanded svg {
    transform: rotate(90deg);
}

.preview-content {
    margin-top: 8px;
    background: #0c0c0e;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    max-height: 280px;
    overflow: auto;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
    font-size: 0.75rem;
    line-height: 1.5;
    color: #a1a1aa;
    white-space: pre-wrap;
    word-break: break-all;
}

[data-theme="light"] .preview-content {
    background: #18181b;
    color: #a1a1aa;
}

.preview-hr {
    border: none;
    border-top: 1px solid #3f3f46;
    margin: 4px 0;
}

[data-theme="light"] .preview-hr {
    border-top-color: #52525b;
}

.preview-loading {
    color: var(--text-muted);
    font-style: italic;
}

/* ===== Team Groups ===== */

.team-group {
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 10px;
    background: var(--bg-secondary);
}

.team-header {
    padding: 6px 8px;
    margin-bottom: 8px;
}

.team-header-top {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

.team-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.team-description {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.team-progress {
    display: flex;
    align-items: center;
    gap: 8px;
}

.progress-bar {
    flex: 1;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--success);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* ===== Toast ===== */

.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 10px 20px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1100;
    font-size: 0.8rem;
    font-weight: 500;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
    pointer-events: none;
}

.toast.success {
    border-left: 3px solid var(--success);
}

.toast.error {
    border-left: 3px solid var(--error);
}

.toast.warning {
    border-left: 3px solid var(--warning);
}

/* ===== Voice Input ===== */

.btn-mic {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 10px;
    flex-shrink: 0;
    font-size: 1rem;
    cursor: pointer;
    transition: all var(--transition);
    line-height: 1;
}

.btn-mic:hover {
    background: var(--bg-input);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.btn-mic:active {
    transform: scale(0.95);
}

.voice-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.voice-modal-backdrop[hidden] {
    display: none;
}

.voice-modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.voice-modal-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.voice-recording-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--error);
    animation: voice-pulse 1s ease-in-out infinite;
}

@keyframes voice-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.8); }
}

.voice-interim {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
    min-height: 1.2em;
    margin-bottom: 8px;
    overflow-wrap: break-word;
}

.voice-result {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: inherit;
    resize: vertical;
    margin-bottom: 12px;
    transition: border-color var(--transition), box-shadow var(--transition);
    line-height: 1.5;
}

.voice-result:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--ring);
}

.voice-result::placeholder {
    color: var(--text-muted);
}

.voice-modal-actions {
    display: flex;
    gap: 8px;
}

.voice-modal-actions .btn {
    flex: 1;
}

/* ===== Screen reader only ===== */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* ===== Scrollbar ===== */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-hover);
}
