:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #d97706;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

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

/* Header */
header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 1rem 0;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}
header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
header h1 { font-size: 1.25rem; color: var(--primary); cursor: pointer; }
.header-actions { display: flex; gap: 0.5rem; align-items: center; }
.user-badge {
    background: var(--primary);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.85rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.15s;
    font-weight: 500;
}
.btn:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.3rem;
    font-size: 0.875rem;
}
input[type="text"], input[type="password"], textarea, select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-size: 0.9rem;
    font-family: inherit;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
textarea { resize: vertical; min-height: 80px; }

/* Cards */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}

/* Views */
.view { display: none; padding: 1.5rem 0; }
.view.active { display: block; }

/* Setup Page */
.setup-container {
    max-width: 400px;
    margin: 4rem auto;
    text-align: center;
}
.setup-container h2 { margin-bottom: 0.5rem; }
.setup-container p { color: var(--text-muted); margin-bottom: 1.5rem; }

/* Suggestion List */
.suggestion-item {
    cursor: pointer;
    transition: border-color 0.15s;
}
.suggestion-item:hover { border-color: var(--primary); }
.suggestion-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}
.suggestion-title { font-size: 1.1rem; font-weight: 600; }
.suggestion-meta {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Status Badges */
.status-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    white-space: nowrap;
}
.status-DRAFT { background: #f1f5f9; color: #475569; }
.status-DISCUSSING { background: #dbeafe; color: #1e40af; }
.status-PLANNED { background: #fef3c7; color: #92400e; }
.status-APPROVED { background: #d1fae5; color: #065f46; }
.status-IN_PROGRESS { background: #e0e7ff; color: #3730a3; }
.status-TESTING { background: #fce7f3; color: #9d174d; }
.status-DEV_COMPLETE { background: #d1fae5; color: #065f46; }
.status-FINAL_REVIEW { background: #dbeafe; color: #1e40af; }
.status-MERGED { background: #bbf7d0; color: #14532d; }
.status-DENIED { background: #fee2e2; color: #991b1b; }
.status-TIMED_OUT { background: #f1f5f9; color: #64748b; }

/* Priority Badges */
.priority-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    white-space: nowrap;
}
.priority-HIGH   { background: #fee2e2; color: #991b1b; }
.priority-MEDIUM { background: #fef3c7; color: #92400e; }
.priority-LOW    { background: #f1f5f9; color: #64748b; }

/* Votes */
.vote-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.vote-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    padding: 0.2rem 0.5rem;
    cursor: pointer;
    font-size: 1rem;
}
.vote-btn:hover { background: var(--bg); }
.vote-count { font-weight: 600; font-size: 0.9rem; }

/* Thread / Messages */
.thread-container {
    max-height: 500px;
    overflow-y: auto;
    margin: 1rem 0;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    background: var(--bg);
}
.message {
    margin-bottom: 0.75rem;
    padding: 0.75rem;
    border-radius: 0.5rem;
    max-width: 85%;
}
.message-USER {
    background: #dbeafe;
    margin-left: auto;
}
.message-AI {
    background: var(--card-bg);
    border: 1px solid var(--border);
}
.message-SYSTEM {
    background: #fef3c7;
    margin: 0 auto;
    text-align: center;
    max-width: 90%;
    font-size: 0.85rem;
}
.message-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}
.message-content {
    font-size: 0.9rem;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Reply Box */
.reply-box {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
.reply-box input { flex: 1; }

/* Phase Indicator */
.phase-indicator {
    padding: 0.5rem 0.75rem;
    background: #e0e7ff;
    border-radius: 0.375rem;
    font-size: 0.85rem;
    color: #3730a3;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.phase-indicator .spinner {
    width: 14px;
    height: 14px;
    border: 2px solid #3730a3;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Admin Actions */
.admin-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}
.suggestion-quick-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

/* Filter toolbar */
.filter-toolbar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    align-items: center;
}
.filter-search {
    flex: 1;
    min-width: 180px;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-size: 0.9rem;
    background: var(--card-bg);
    color: var(--text);
}
.filter-search:focus { outline: none; border-color: var(--primary); }
.filter-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-size: 0.85rem;
    background: var(--card-bg);
    color: var(--text);
    cursor: pointer;
}
.filter-select:focus { outline: none; border-color: var(--primary); }

/* Settings Page */
.settings-grid {
    display: grid;
    gap: 1rem;
}
.toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}
.toggle-label { font-weight: 500; }
.toggle {
    position: relative;
    width: 44px;
    height: 24px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #cbd5e1;
    border-radius: 12px;
    transition: 0.2s;
}
.toggle-slider:before {
    content: "";
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider:before { transform: translateX(20px); }

/* Loading */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

/* Back button */
.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    cursor: pointer;
    margin-bottom: 1rem;
}
.back-btn:hover { color: var(--text); }

/* Clarification Wizard */
.clarification-wizard {
    margin-top: 1rem;
    border: 2px solid var(--primary);
    background: #f0f4ff;
}
.clarification-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}
.clarification-header h4 {
    color: var(--primary);
    font-size: 1rem;
}
.clarification-progress {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
}
.clarification-progress-bar {
    width: 100%;
    height: 4px;
    background: #cbd5e1;
    border-radius: 2px;
    margin-bottom: 1rem;
    overflow: hidden;
}
.clarification-progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    transition: width 0.3s ease;
}
.clarification-question {
    font-size: 0.95rem;
    font-weight: 500;
    padding: 0.75rem;
    background: white;
    border-radius: 0.375rem;
    border: 1px solid var(--border);
}
.clarification-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-top: 0.5rem;
}

/* Task list */
.task-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid #f1f5f9;
}
.task-item:last-child { border-bottom: none; }
.task-icon {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    margin-top: 2px;
}
.task-icon.pending { background: #e2e8f0; color: #94a3b8; }
.task-icon.in_progress { background: #dbeafe; color: #2563eb; animation: pulse 1.5s infinite; }
.task-icon.reviewing { background: #fef3c7; color: #d97706; animation: pulse 1.5s infinite; }
.task-icon.completed { background: #dcfce7; color: #16a34a; }
.task-icon.failed { background: #fee2e2; color: #dc2626; }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:0.5; } }
@keyframes taskComplete {
    0% { background: #dcfce7; }
    50% { background: #bbf7d0; }
    100% { background: transparent; }
}
@keyframes taskFail {
    0% { background: #fee2e2; }
    50% { background: #fecaca; }
    100% { background: transparent; }
}
@keyframes taskStart {
    0% { background: #dbeafe; }
    50% { background: #bfdbfe; }
    100% { background: transparent; }
}
.task-item { transition: background 0.5s ease; }
.task-item.just-completed { animation: taskComplete 1.5s ease; }
.task-item.just-failed { animation: taskFail 1.5s ease; }
.task-item.just-started { animation: taskStart 1.5s ease; }
.task-body { flex: 1; min-width: 0; }
.task-title { font-size: 0.9rem; font-weight: 500; }
.task-title.completed { text-decoration: line-through; color: #94a3b8; }
.task-desc { font-size: 0.8rem; color: #64748b; margin-top: 2px; }
.task-meta { font-size: 0.75rem; color: #94a3b8; margin-top: 2px; display: flex; gap: 0.75rem; }
.task-item.task-active { background: #f0f7ff; border-radius: 6px; padding: 0.6rem 0.5rem; margin: 0 -0.5rem; }
.task-activity {
    display: flex; align-items: center; gap: 6px;
    font-size: 0.78rem; color: #2563eb; margin-top: 4px;
    font-weight: 500;
}
.task-activity-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: #2563eb; flex-shrink: 0;
    animation: activityPulse 1.5s ease-in-out infinite;
}
@keyframes activityPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.7); }
}
.task-completed-detail { font-size: 0.75rem; color: #16a34a; margin-top: 2px; }
.task-failed-detail { font-size: 0.75rem; color: #dc2626; margin-top: 2px; }

/* Expert review list */
.expert-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid #f1f5f9;
}
.expert-item:last-child { border-bottom: none; }
.expert-icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
}
.expert-pending .expert-icon { background: #f1f5f9; color: #94a3b8; }
.expert-in_progress .expert-icon { background: #f3e8ff; color: #7c3aed; animation: pulse 1.5s infinite; }
.expert-completed .expert-icon { background: #dcfce7; color: #16a34a; }
.expert-name { font-size: 0.9rem; font-weight: 500; }

/* Status badge for EXPERT_REVIEW */
.status-EXPERT_REVIEW { background: #f3e8ff; color: #7c3aed; }

/* Responsive */
@media (max-width: 640px) {
    .suggestion-header { flex-direction: column; }
    .message { max-width: 95%; }
}

/* Dashboard / Leaderboard */
.leaderboard-table { width: 100%; border-collapse: collapse; }
.leaderboard-table th,
.leaderboard-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: left; }
.leaderboard-table tbody tr:hover { background: var(--bg); }
.rank-medal { font-size: 1.2em; }
.contributor-link { color: var(--primary); cursor: pointer; text-decoration: underline; }
#userHistoryPanel { margin-top: 2rem; padding: 1rem; border: 1px solid var(--border); border-radius: 8px; }
.history-suggestion-card { padding: 0.75rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
