/* ============================================
   TaskFlow — Dark Theme Mobile-First PWA
   ============================================ */

:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-card: #1e1e1e;
    --bg-card-hover: #252525;
    --bg-input: #2a2a2a;
    --text-primary: #e8e8e8;
    --text-secondary: #999;
    --text-muted: #666;
    --accent: #6c63ff;
    --accent-dim: rgba(108, 99, 255, 0.15);
    --accent-glow: rgba(108, 99, 255, 0.3);
    --priority-high: #ff4757;
    --priority-high-bg: rgba(255, 71, 87, 0.12);
    --priority-medium: #ffa502;
    --priority-medium-bg: rgba(255, 165, 2, 0.12);
    --priority-low: #2ed573;
    --priority-low-bg: rgba(46, 213, 115, 0.12);
    --border: #2a2a2a;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --transition: 0.2s ease;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ---- Header ---- */
#header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(10px);
}

#header h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

#sync-indicator {
    font-size: 10px;
    transition: var(--transition);
}
.sync-ok { color: var(--priority-low); }
.syncing { color: var(--priority-medium); animation: pulse 1s infinite; }
.sync-err { color: var(--priority-high); }

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

/* ---- Screens ---- */
#screens {
    padding-bottom: calc(72px + var(--safe-bottom));
}

.screen {
    display: none;
    padding: 16px 20px;
    animation: fadeIn 0.2s ease;
}
.screen.active { display: block; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(8px); }
    to { opacity: 1; transform: translateX(0); }
}

.screen-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.screen-nav h2 {
    font-size: 18px;
    font-weight: 700;
}

/* ---- Sections ---- */
.section {
    margin-bottom: 28px;
}

.section-header {
    margin-bottom: 12px;
}

.section-header h2 {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
}

.section-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ---- Stats Grid ---- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 14px 12px;
    text-align: center;
    border: 1px solid var(--border);
}

.stat-card .stat-number {
    font-size: 28px;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 4px;
}

.stat-card .stat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card.clickable {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: var(--transition);
}

.stat-card.clickable:active {
    transform: scale(0.95);
    background: var(--bg-card-hover);
}

.stat-card.high .stat-number { color: var(--priority-high); }
.stat-card.medium .stat-number { color: var(--priority-medium); }
.stat-card.low .stat-number { color: var(--priority-low); }

/* ---- Card List ---- */
.card-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ---- Task Cards (MITs, individual tasks) ---- */
.task-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 14px 16px;
    border: 1px solid var(--border);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.task-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
}

.task-card.priority-high::before { background: var(--priority-high); }
.task-card.priority-medium::before { background: var(--priority-medium); }
.task-card.priority-low::before { background: var(--priority-low); }

.task-card .task-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 6px;
    line-height: 1.3;
}

.task-card .task-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.task-card .task-goal {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-input);
    padding: 2px 8px;
    border-radius: 4px;
}

.task-card .task-due {
    font-size: 11px;
    color: var(--text-secondary);
}

.priority-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.priority-badge.high { color: var(--priority-high); background: var(--priority-high-bg); }
.priority-badge.medium { color: var(--priority-medium); background: var(--priority-medium-bg); }
.priority-badge.low { color: var(--priority-low); background: var(--priority-low-bg); }

/* ---- Project Cards ---- */
.project-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.project-card:active {
    background: var(--bg-card-hover);
    transform: scale(0.98);
}

.project-card .project-name {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 8px;
}

.project-card .project-meta {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--text-secondary);
}

.project-card .project-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ---- Task List (Project Detail) ---- */
.task-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.task-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}

.task-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
}

.task-item.priority-high::before { background: var(--priority-high); }
.task-item.priority-medium::before { background: var(--priority-medium); }
.task-item.priority-low::before { background: var(--priority-low); }

.task-item .task-content {
    flex: 1;
    min-width: 0;
}

.task-item .task-name {
    font-size: 14px;
    font-weight: 500;
    line-height: 1.3;
    margin-bottom: 4px;
}

.task-item .task-details {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.task-item .task-owner {
    font-size: 11px;
    color: var(--accent);
    background: var(--accent-dim);
    padding: 1px 6px;
    border-radius: 3px;
}

/* ---- Goals Chips ---- */
.chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
}

.goal-chip {
    font-size: 12px;
    padding: 6px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-secondary);
}

/* ---- Bottom Nav ---- */
#bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding-bottom: var(--safe-bottom);
    z-index: 100;
}

.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 0 8px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 10px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: var(--transition);
}

.nav-btn.active {
    color: var(--accent);
}

.nav-btn svg {
    width: 22px;
    height: 22px;
}

/* ---- Back Button ---- */
.btn-icon {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    padding: 4px;
    -webkit-tap-highlight-color: transparent;
}

/* ---- Skeleton Loading ---- */
.skeleton {
    height: 72px;
    background: var(--bg-card);
    border-radius: var(--radius);
    animation: shimmer 1.5s infinite;
    border: 1px solid var(--border);
}

@keyframes shimmer {
    0% { background: var(--bg-card); }
    50% { background: var(--bg-card-hover); }
    100% { background: var(--bg-card); }
}

/* ---- Empty State ---- */
.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
    font-size: 14px;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ---- Responsive ---- */
@media (min-width: 480px) {
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
    #screens { max-width: 480px; margin: 0 auto; }
}

/* ---- Team section hidden by default ---- */
#team-section:empty { display: none; }
#team-section.has-tasks { display: block; }

/* ---- Context Menu ---- */
.context-menu {
    position: fixed;
    z-index: 1000;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 0;
    min-width: 140px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    animation: ctxFadeIn 0.15s ease;
}

@keyframes ctxFadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.ctx-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    font-size: 14px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: var(--transition);
}

.ctx-item:active {
    background: var(--bg-card-hover);
}

.ctx-danger {
    color: var(--priority-high);
}

.ctx-cancel {
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    margin-top: 4px;
    padding-top: 12px;
}

/* Deleting animation */
.task-item.deleting,
.task-card.deleting {
    opacity: 0.4;
    transform: scale(0.95);
    transition: all 0.3s ease;
}

/* ---- Install Banner ---- */
#install-banner {
    position: fixed;
    bottom: calc(72px + var(--safe-bottom) + 8px);
    left: 16px;
    right: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 12px 16px;
    z-index: 200;
    animation: slideUp 0.3s ease;
    max-width: 480px;
    margin: 0 auto;
}

@keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.install-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.install-content span {
    flex: 1;
    font-size: 14px;
    color: var(--text-primary);
}

.install-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.install-text small {
    color: var(--text-secondary);
    font-size: 12px;
}

.install-btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.install-btn:active {
    opacity: 0.8;
}

.install-dismiss {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    padding: 4px 8px;
    cursor: pointer;
}